SdkOrderLogic.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\v1\logic\customer;
  3. use plugin\saiadmin\basic\BaseLogic;
  4. use plugin\saiadmin\exception\ApiException;
  5. use plugin\saiadmin\utils\Helper;
  6. use app\v1\model\customer\SdkOrder;
  7. use DateTime;
  8. use support\Redis;
  9. use support\think\Db;
  10. /**
  11. * 用户订单记录逻辑层
  12. */
  13. class SdkOrderLogic extends BaseLogic
  14. {
  15. /**
  16. * 构造函数
  17. */
  18. public function __construct()
  19. {
  20. $this->model = new SdkOrder();
  21. }
  22. /**
  23. * 获取订单列表
  24. */
  25. public function getOrderList($params)
  26. {
  27. $orderBy = $params['orderBy'] ?: 'pay_date';
  28. $orderType = $params['orderType'] ?: 'DESC';
  29. if(!$params['pay_date']){
  30. throw new ApiException('请选择时间范围');
  31. }
  32. // 获取年月
  33. $monthRange = getMonthsBetweenDates($params['pay_date'][0], $params['pay_date'][1]);
  34. $eqWhere = ["game_id", "user_name", "order_id", "trade_id", "role_id", "role_name"];
  35. $where = [];
  36. foreach ($eqWhere as $field){
  37. if (!empty($params[$field])) {
  38. $where[$field] = $params[$field];
  39. }
  40. }
  41. $where[] = ['pay_date', 'between', [$params['pay_date'][0]." 00:00:00", $params['pay_date'][1]." 23:59:59"]];
  42. $db = Db::connect('db_game_log');
  43. $unionQuery = [];
  44. foreach ($monthRange as $month){
  45. $tableName = 'sdk_order_' . $month;
  46. $unionQuery[] = $db->table($tableName)->where($where)->buildSql();
  47. }
  48. $fullSql = "(" . implode(' UNION ALL ', $unionQuery) . ") as unTable";
  49. $list = $db->table($fullSql)->order($orderBy, $orderType)->paginate($params['limit'])->toArray();
  50. $list['data'] = $this->trandformListColumn($list['data'], ['game', 'pay_channel']);
  51. $list['totalRow'] = $db->table($fullSql)->where(["sync_status"=>1])->value("round(sum(money), 2)");
  52. return $list;
  53. }
  54. /**
  55. * 补发
  56. */
  57. public function send($order_id)
  58. {
  59. return Redis::lpush("request_cp_callback_queue", $order_id);
  60. }
  61. }