ordersendlist.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  3. require_once(BASE_HELPER_PATH . '/refill/util.php');
  4. use refill\util;
  5. class ordersendlistControl extends SystemControl
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function indexOp()
  12. {
  13. $model_refill_order = Model('refill_order');
  14. $condition['refill_order.inner_status'] = 0;
  15. $condition['vr_order.order_state'] = ORDER_STATE_SEND;
  16. $time = time();
  17. $condition['refill_order.order_time'] = ['exp', "refill_order.order_time < ({$time} - merchant.time_out)"];
  18. if (!empty($_GET['mchid'])) {
  19. $condition['refill_order.mchid'] = $_GET['mchid'];
  20. }
  21. if (!empty($_GET['store_id'])) {
  22. $condition['vr_order.store_id'] = $_GET['store_id'];
  23. }
  24. $time_cond = [
  25. ['between', [(time() - 3600), (time() - 1800)]],
  26. ['lt', (time() - 3600)]];
  27. if ($_GET['time'] == 1) {
  28. $condition['refill_order.order_time'] = ['between', [(time() - 3600), (time() - 1800)]];
  29. }
  30. if ($_GET['time'] == 2) {
  31. $condition['refill_order.order_time'] = ['lt', (time() - 3600)];
  32. }
  33. $time_out_order = function ($time_out, $condition) {
  34. $mchids = Model('')->table('merchant')->where(['time_out' => ['elt', $time_out]])->field('mchid')->select();
  35. $mchids = array_column($mchids, 'mchid');
  36. $mchids = implode(',', $mchids);
  37. $condition['refill_order.order_time'] = ['lt', (time() - $time_out)];
  38. $condition['refill_order.mchid'] = ['in', $mchids];
  39. return $condition;
  40. };
  41. if ($_GET['time'] == 3) {
  42. $condition = $time_out_order(180, $condition);
  43. $time_cond[] = ['lt', (time() - 180)];
  44. $_GET['card_type'] = 'phone';
  45. }
  46. if ($_GET['time'] == 4) {
  47. $condition = $time_out_order(300, $condition);
  48. $time_cond[] = ['lt', (time() - 300)];
  49. $_GET['card_type'] = 'phone';
  50. }
  51. if ($_GET['time'] == 5) {
  52. $condition = $time_out_order(600, $condition);
  53. $time_cond[] = ['lt', (time() - 600)];
  54. $_GET['card_type'] = 'phone';
  55. }
  56. if ($_GET['time'] == 6) {
  57. $condition = $time_out_order(900, $condition);
  58. $time_cond[] = ['lt', (time() - 900)];
  59. $_GET['card_type'] = 'phone';
  60. }
  61. if ($_GET['time'] == 7) {
  62. $condition = $time_out_order(7200, $condition);
  63. $time_cond[] = ['lt', (time() - 7200)];
  64. $_GET['card_type'] = 'phone';
  65. }
  66. if (!empty($_GET['card_type'])) {
  67. if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) {
  68. $condition['refill_order.card_type'] = $_GET['card_type'];
  69. }
  70. if ($_GET['card_type'] == 'oil') {
  71. $condition['refill_order.card_type'] = ['in', ['1', '2']];
  72. }
  73. if ($_GET['card_type'] == 'phone') {
  74. $condition['refill_order.card_type'] = ['in', ['4', '5', '6']];
  75. }
  76. }
  77. if (!empty($_GET['quality'])) {
  78. $condition['refill_order.quality'] = $_GET['quality'];
  79. }
  80. $order_list = $model_refill_order->getMerchantTimeOut($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  81. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  82. ->on('refill_order.order_id=vr_order.order_id')
  83. ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  84. ->where($condition)->find();
  85. $count = $this->refill_stats($condition, $time_cond);
  86. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  87. $order_list = $this->orderFormat($order_list, $merchant_list);
  88. $provider_list = Model('')->table('refill_provider,store')
  89. ->field('refill_provider.*,store.store_name')
  90. ->join('inner')
  91. ->on('store.store_id=refill_provider.store_id')
  92. ->order('opened asc, provider_id desc')
  93. ->limit(1000)
  94. ->select();
  95. Tpl::output('stat', $stat);
  96. Tpl::output('count', $count);
  97. Tpl::output('order_list', $order_list);
  98. Tpl::output('merchant_list', $merchant_list);
  99. Tpl::output('provider_list', $provider_list);
  100. Tpl::output('show_page', $model_refill_order->showpage());
  101. Tpl::showpage('refill.order.send.index');
  102. }
  103. private function refill_stats($condition, $times): array
  104. {
  105. $stat_order = function ($condition) {
  106. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  107. ->on('refill_order.order_id=vr_order.order_id')
  108. ->field('count(*) as order_count ')
  109. ->where($condition)->find();
  110. return $stat['order_count'];
  111. };
  112. $result = [];
  113. $condition['order_state'] = ORDER_STATE_SEND;
  114. foreach ($times as $time) {
  115. $condition['refill_order.order_time'] = $time;
  116. $result[] = $stat_order($condition);
  117. }
  118. return $result;
  119. }
  120. public function neterr_orderOp()
  121. {
  122. $model_refill_order = Model('refill_order');
  123. if (!empty($_GET['store_id'])) {
  124. $condition['vr_order.store_id'] = $_GET['store_id'];
  125. }
  126. $condition['refill_order.inner_status'] = 0;
  127. $condition['refill_order.neterr'] = 1;
  128. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  129. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  130. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  131. $order_list = $this->orderFormat($order_list, $merchant_list);
  132. $provider_list = Model('')->table('refill_provider,store')
  133. ->field('refill_provider.*,store.store_name')
  134. ->join('inner')
  135. ->on('store.store_id=refill_provider.store_id')
  136. ->order('name asc')
  137. ->limit(1000)
  138. ->select();
  139. Tpl::output('provider_list', $provider_list);
  140. Tpl::output('order_list', $order_list);
  141. Tpl::output('show_page', $model_refill_order->showpage());
  142. Tpl::showpage('refill.order.neterr.index');
  143. }
  144. public function neterr_order_manualOp()
  145. {
  146. $type = $_GET['type'];
  147. $official_sn = $_GET['official_sn'] ?? '';
  148. if ($type != 'success' && $type != 'cancel') {
  149. showMessage('手动操作类型错误');
  150. }
  151. $order_ids = $_GET['order_ids'];
  152. $model_refill_order = Model('refill_order');
  153. $condition['refill_order.order_id'] = ['in', $order_ids];
  154. $condition['refill_order.inner_status'] = 0;
  155. $condition['refill_order.neterr'] = 1;
  156. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  157. $order_list = $model_refill_order->getMerchantOrderList($condition);
  158. if (empty($order_list)) {
  159. showMessage('暂无数据');
  160. }
  161. $logic_vr_order = Logic("vr_order");
  162. $mod_vr_order = Model('vr_order');
  163. foreach ($order_list as $order) {
  164. $order_id = $order['order_id'];
  165. if ($type == 'success') {
  166. $logic_vr_order->changeOrderStateSuccess($order_id, true);
  167. if (!empty($official_sn)) {
  168. $model_refill_order->edit($order_id, ['official_sn' => $official_sn]);
  169. }
  170. } elseif ($type == 'cancel') {
  171. $order_info = $mod_vr_order->getOrderInfo(['order_id' => $order_id]);
  172. $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
  173. } else {
  174. continue;
  175. }
  176. if ($order['notify_time'] == 0) {
  177. $model_refill_order->edit($order_id, ['notify_state' => 1, 'notify_time' => time()]);
  178. }
  179. util::pop_queue_order($order['mchid'], $order['mch_order']);
  180. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  181. }
  182. showMessage('操作成功');
  183. }
  184. public function orderFormat($order_list, $merchant_list): array
  185. {
  186. if(empty($order_list)) return [];
  187. $merchants = [];
  188. foreach ($merchant_list as $value) {
  189. $merchants[$value['mchid']] = $value;
  190. }
  191. foreach ($order_list as $order_id => $order_info) {
  192. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  193. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  194. if ($order_info['notify_time'] > 0) {
  195. $diff_time = $order_info['notify_time'] - $order_info['order_time'];
  196. } else {
  197. $diff_time = time() - $order_info['order_time'];
  198. }
  199. $order_list[$order_id]['diff_time'] = $diff_time;
  200. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
  201. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'], $order_info['card_type']);
  202. if ($diff_time > $merchants[$order_info['mchid']]['time_out'] && $order_info['order_state'] == ORDER_STATE_SEND) {
  203. $order_list[$order_id]['time_out_state'] = 0;
  204. if (in_array($order_info['card_type'], [mtopcard\PetroChinaCard, mtopcard\SinopecCard]) && $diff_time >= 1800) {
  205. $order_list[$order_id]['time_out_state'] = 1;
  206. }
  207. if (in_array($order_info['card_type'], [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
  208. if (in_array($order_info['quality'], [
  209. \refill\Quality::SlowTwentyFour,
  210. \refill\Quality::SlowSix,
  211. \refill\Quality::SlowTwo,
  212. \refill\Quality::SlowFortyEight,
  213. \refill\Quality::SlowSeventyTwo])) {
  214. $order_list[$order_id]['time_out_state'] = 2;
  215. } elseif (in_array($order_info['mchid'], [10132])) {
  216. //重点机构
  217. $order_list[$order_id]['time_out_state'] = 3;
  218. } else {
  219. $order_list[$order_id]['time_out_state'] = 4;
  220. }
  221. }
  222. } else {
  223. $order_list[$order_id]['time_out_state'] = 0;
  224. }
  225. }
  226. return $order_list;
  227. }
  228. public function notify_err_orderOp()
  229. {
  230. $model_refill_order = Model('refill_order');
  231. $order_state_cancel = ORDER_STATE_CANCEL;
  232. $order_state_success = ORDER_STATE_SUCCESS;
  233. $condition['refill_order.inner_status'] = 0;
  234. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  235. $condition['refill_order.mch_notify_state'] = 0;
  236. if (empty($_GET['time'])) {
  237. $_GET['time'] = 1;
  238. }
  239. if (empty($_GET['notify_time'])) {
  240. $_GET['notify_time'] = 180;
  241. }
  242. $time = $_GET['time'] * 3600;
  243. $condition['refill_order.order_time'] = ['gt', (time() - $time)];
  244. $notify_time = $_GET['notify_time'];
  245. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  246. $order_list = $model_refill_order->getMerchantOrderList($condition, '', 'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  247. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  248. $order_list = $this->orderFormat($order_list, $merchant_list);
  249. $provider_list = Model('')->table('refill_provider,store')
  250. ->field('refill_provider.*,store.store_name')
  251. ->join('inner')
  252. ->on('store.store_id=refill_provider.store_id')
  253. ->order('name asc')
  254. ->limit(1000)
  255. ->select();
  256. Tpl::output('provider_list', $provider_list);
  257. Tpl::output('order_list', $order_list);
  258. Tpl::output('show_page', $model_refill_order->showpage());
  259. Tpl::showpage('refill.order.notify.err.index');
  260. }
  261. public function notifyerr_all_notifyOp()
  262. {
  263. if (empty($_GET['time']) || empty($_GET['notify_time'])) {
  264. showMessage('日期条件错误');
  265. }
  266. $model_refill_order = Model('refill_order');
  267. $order_state_cancel = ORDER_STATE_CANCEL;
  268. $order_state_success = ORDER_STATE_SUCCESS;
  269. $condition['refill_order.inner_status'] = 0;
  270. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  271. $condition['refill_order.mch_notify_state'] = 0;
  272. $time = $_GET['time'] * 3600;
  273. $condition['refill_order.order_time'] = ['gt', (time() - $time)];
  274. $notify_time = $_GET['notify_time'];
  275. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  276. $order_list = $model_refill_order->getMerchantOrderList($condition, '', 'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  277. foreach ($order_list as $order) {
  278. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  279. }
  280. showMessage('操作成功');
  281. }
  282. }