SdkOrderLogic.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. $yearRange = getYearRange($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 ($yearRange as $year){
  48. $tableName = 'sdk_order_' . $year;
  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($params)
  64. {
  65. $orderId = $params['order_id'];
  66. $desc = $params['desc'];
  67. $userInfo = getCurrentInfo();
  68. Db::connect('db_game_log')->table("sdk_order_resend")
  69. ->save([
  70. 'order_id' => $orderId,
  71. 'desc' => $desc,
  72. 'created_user' => $userInfo['id']
  73. ]);
  74. return true;
  75. }
  76. /**
  77. * 审核补单
  78. */
  79. public function auditResend($params)
  80. {
  81. $id = $params['id'];
  82. $status = $params['status'];
  83. $error = $params['error'];
  84. $userInfo = getCurrentInfo();
  85. Db::connect('db_game_log')->table("sdk_order_resend")
  86. ->where("id", $id)
  87. ->update([
  88. 'status' => $status,
  89. 'error' => $error,
  90. 'updated_user' => $userInfo['id']
  91. ]);
  92. return $this->success();
  93. }
  94. // 补单管理审核列表
  95. public function getReissueAuditList($params)
  96. {
  97. $orderId = $params['order_id'] ?? '';
  98. $status = $params['status'] ?? '';
  99. $resendType = $params['resend_type'] ?? '';
  100. $where = [];
  101. if(!empty($orderId)){
  102. $where[] = ['order_id', '=', $orderId];
  103. }
  104. if($resendType!=''){
  105. $where[] = ['resend_type', '=', $resendType];
  106. }
  107. if(!empty($status)){
  108. $where[] = ['status', '=', $status];
  109. }
  110. $data = Db::connect('db_game_log')->table('sdk_order_resend')
  111. ->where($where)
  112. ->order('create_time', 'desc')
  113. ->select()->toArray();
  114. return [
  115. 'data'=>$this->trandformListColumn($data, ['author']),
  116. 'total'=>count($data)
  117. ];
  118. }
  119. // 补单审核
  120. public function reissueAudit($params): mixed
  121. {
  122. $id = $params['id'];
  123. $status = $params['status'];
  124. $userInfo = getCurrentInfo();
  125. Db::connect('db_game_log')->table('sdk_order_resend')
  126. ->where("id", $id)
  127. ->update([
  128. 'status' => $status,
  129. 'update_user' => $userInfo['id'],
  130. ]);
  131. return true;
  132. }
  133. }