SdkOrderLogic.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_time']){
  30. throw new ApiException('请选择时间范围');
  31. }
  32. // 获取年月
  33. $monthRange = getMonthsBetweenDates($params['pay_time'][0], $params['pay_time'][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. if($params['send_status']!=''){
  42. $where['send_status'] = $params['send_status'];
  43. }
  44. if($params['sync_status']!=''){
  45. $where['sync_status'] = $params['sync_status'];
  46. }
  47. $where[] = ['pay_time', 'between', [strtotime($params['pay_time'][0]), strtotime($params['pay_time'][1])]];
  48. $db = Db::connect('db_game_log');
  49. $unionQuery = [];
  50. foreach ($monthRange as $month){
  51. $tableName = 'sdk_order_' . $month;
  52. $unionQuery[] = $db->table($tableName)->where($where)->buildSql();
  53. }
  54. $fullSql = "(" . implode(' UNION ALL ', $unionQuery) . ") as unTable";
  55. echo $fullSql;
  56. $list = $db->table($fullSql)->order($orderBy, $orderType)->paginate($params['limit'])->toArray();
  57. $list['data'] = $this->trandformListColumn($list['data'], ['game', 'pay_channel']);
  58. $allMoney = $db->table($fullSql)->where(["sync_status"=>1])->value("round(sum(money), 2)");
  59. $list['totalRow'] = [
  60. 'money' => $allMoney,
  61. ];
  62. return $list;
  63. }
  64. /**
  65. * 补发
  66. */
  67. public function send($order_id)
  68. {
  69. return Redis::lpush("request_cp_callback_queue", $order_id);
  70. }
  71. }