ordersendlist.php 15 KB

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