ordersendlist.php 15 KB

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