SdkOrderLogic.php 2.2 KB

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