SdkOrderLogic.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 = getMonthRange($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].'00:00:00'), strtotime($params['pay_time'][1].'23:59:59')]];
  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. $list = $db->table($fullSql)->order($orderBy, $orderType)->paginate($params['limit'])->toArray();
  56. $list['data'] = $this->trandformListColumn($list['data'], ['game', 'pay_channel']);
  57. $allMoney = $db->table($fullSql)->where(["sync_status"=>1])->value("round(sum(money), 2)");
  58. $list['totalRow'] = [
  59. 'money' => $allMoney,
  60. ];
  61. return $list;
  62. }
  63. /**
  64. * 补发
  65. */
  66. public function send($order_id)
  67. {
  68. return Redis::lpush("request_cp_callback_queue", $order_id);
  69. }
  70. }