ordersendlist.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. $time = time();
  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. $order_list = $model_refill_order->getMerchantTimeOut($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  86. // $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  87. $stat = Model('')->table('refill_order,vr_order,merchant')->join('inner,inner')
  88. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  89. ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  90. ->where($condition)->find();
  91. // $stat = Model('')->table('refill_order,vr_order')->join('inner')
  92. // ->on('refill_order.order_id=vr_order.order_id')
  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. $count = $this->refill_stats($condition, $time_cond);
  96. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  97. if(!empty($order_list)) {
  98. $order_list = $this->orderFormat($order_list, $merchant_list);
  99. }
  100. $provider_list = Model('')->table('refill_provider,store')
  101. ->field('refill_provider.*,store.store_name')
  102. ->join('inner')
  103. ->on('store.store_id=refill_provider.store_id')
  104. ->order('opened asc, provider_id desc')
  105. ->limit(1000)
  106. ->select();
  107. Tpl::output('stat', $stat);
  108. Tpl::output('count', $count);
  109. Tpl::output('order_list', $order_list);
  110. Tpl::output('merchant_list', $merchant_list);
  111. Tpl::output('provider_list', $provider_list);
  112. Tpl::output('show_page', $model_refill_order->showpage());
  113. Tpl::showpage('refill.order.send.index');
  114. }
  115. private function refill_stats($condition, $times): array
  116. {
  117. $stat_order = function ($condition) {
  118. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  119. ->on('refill_order.order_id=vr_order.order_id')
  120. ->field('count(*) as order_count ')
  121. ->where($condition)->find();
  122. return $stat['order_count'];
  123. };
  124. $result = [];
  125. $condition['order_state'] = ORDER_STATE_SEND;
  126. foreach ($times as $time) {
  127. $condition['refill_order.order_time'] = $time;
  128. $result[] = $stat_order($condition);
  129. }
  130. return $result;
  131. }
  132. public function neterr_orderOp()
  133. {
  134. $model_refill_order = Model('refill_order');
  135. if (!empty($_GET['store_id'])) {
  136. $condition['vr_order.store_id'] = $_GET['store_id'];
  137. }
  138. $condition['refill_order.inner_status'] = 0;
  139. $condition['refill_order.neterr'] = 1;
  140. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  141. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  142. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  143. $order_list = $this->orderFormat($order_list, $merchant_list);
  144. $provider_list = Model('')->table('refill_provider,store')
  145. ->field('refill_provider.*,store.store_name')
  146. ->join('inner')
  147. ->on('store.store_id=refill_provider.store_id')
  148. ->order('name asc')
  149. ->limit(1000)
  150. ->select();
  151. Tpl::output('provider_list', $provider_list);
  152. Tpl::output('order_list', $order_list);
  153. Tpl::output('show_page', $model_refill_order->showpage());
  154. Tpl::showpage('refill.order.neterr.index');
  155. }
  156. public function neterr_order_manualOp()
  157. {
  158. $type = $_GET['type'];
  159. $official_sn = $_GET['official_sn'] ?? '';
  160. if ($type != 'success' && $type != 'cancel') {
  161. showMessage('手动操作类型错误');
  162. }
  163. $order_ids = $_GET['order_ids'];
  164. $model_refill_order = Model('refill_order');
  165. $condition['refill_order.order_id'] = ['in', $order_ids];
  166. $condition['refill_order.inner_status'] = 0;
  167. $condition['refill_order.neterr'] = 1;
  168. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  169. $order_list = $model_refill_order->getMerchantOrderList($condition);
  170. if (empty($order_list)) {
  171. showMessage('暂无数据');
  172. }
  173. $logic_vr_order = Logic("vr_order");
  174. $mod_vr_order = Model('vr_order');
  175. foreach ($order_list as $order) {
  176. $order_id = $order['order_id'];
  177. if ($type == 'success') {
  178. $logic_vr_order->changeOrderStateSuccess($order_id, true);
  179. if (!empty($official_sn)) {
  180. $model_refill_order->edit($order_id, ['official_sn' => $official_sn]);
  181. }
  182. } elseif ($type == 'cancel') {
  183. $order_info = $mod_vr_order->getOrderInfo(['order_id' => $order_id]);
  184. $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
  185. } else {
  186. continue;
  187. }
  188. if ($order['notify_time'] == 0) {
  189. $model_refill_order->edit($order_id, ['notify_state' => 1, 'notify_time' => time()]);
  190. }
  191. util::pop_queue_order($order['mchid'], $order['mch_order']);
  192. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  193. }
  194. showMessage('操作成功');
  195. }
  196. public function orderFormat($order_list, $merchant_list): array
  197. {
  198. $merchants = [];
  199. foreach ($merchant_list as $value) {
  200. $merchants[$value['mchid']] = $value;
  201. }
  202. foreach ($order_list as $order_id => $order_info) {
  203. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  204. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  205. if ($order_info['notify_time'] > 0) {
  206. $diff_time = $order_info['notify_time'] - $order_info['order_time'];
  207. } else {
  208. $diff_time = time() - $order_info['order_time'];
  209. }
  210. $order_list[$order_id]['diff_time'] = $diff_time;
  211. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
  212. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'], $order_info['card_type']);
  213. if ($diff_time > $merchants[$order_info['mchid']]['time_out'] && $order_info['order_state'] == ORDER_STATE_SEND) {
  214. $order_list[$order_id]['time_out_state'] = 0;
  215. if (in_array($order_info['card_type'], [mtopcard\PetroChinaCard, mtopcard\SinopecCard])) {
  216. $order_list[$order_id]['time_out_state'] = 1;
  217. }
  218. if (in_array($order_info['card_type'], [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
  219. if (in_array($order_info['quality'], [
  220. \refill\Quality::SlowTwentyFour,
  221. \refill\Quality::SlowSix,
  222. \refill\Quality::SlowTwo,
  223. \refill\Quality::SlowFortyEight,
  224. \refill\Quality::SlowSeventyTwo])) {
  225. $order_list[$order_id]['time_out_state'] = 2;
  226. } elseif (in_array($order_info['mchid'], [10132])) {
  227. //重点机构
  228. $order_list[$order_id]['time_out_state'] = 3;
  229. } else {
  230. $order_list[$order_id]['time_out_state'] = 4;
  231. }
  232. }
  233. } else {
  234. $order_list[$order_id]['time_out_state'] = 0;
  235. }
  236. }
  237. return $order_list;
  238. }
  239. public function notify_err_orderOp()
  240. {
  241. $model_refill_order = Model('refill_order');
  242. $order_state_cancel = ORDER_STATE_CANCEL;
  243. $order_state_success = ORDER_STATE_SUCCESS;
  244. $condition['refill_order.inner_status'] = 0;
  245. $condition['refill_order.is_retrying'] = 0;
  246. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  247. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  248. if (empty($_GET['time'])) {
  249. $_GET['time'] = 1;
  250. }
  251. if (empty($_GET['notify_time'])) {
  252. $_GET['notify_time'] = 180;
  253. }
  254. $time = $_GET['time'] * 3600;
  255. $condition['refill_order.order_time'] = ['gt', (time() - $time)];
  256. $notify_time = $_GET['notify_time'];
  257. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  258. $order_list = $model_refill_order->getMerchantOrderList($condition, '', 'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  259. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  260. $order_list = $this->orderFormat($order_list, $merchant_list);
  261. $provider_list = Model('')->table('refill_provider,store')
  262. ->field('refill_provider.*,store.store_name')
  263. ->join('inner')
  264. ->on('store.store_id=refill_provider.store_id')
  265. ->order('name asc')
  266. ->limit(1000)
  267. ->select();
  268. Tpl::output('provider_list', $provider_list);
  269. Tpl::output('order_list', $order_list);
  270. Tpl::output('show_page', $model_refill_order->showpage());
  271. Tpl::showpage('refill.order.notify.err.index');
  272. }
  273. public function notifyerr_all_notifyOp()
  274. {
  275. if (empty($_GET['time']) || empty($_GET['notify_time'])) {
  276. showMessage('日期条件错误');
  277. }
  278. $model_refill_order = Model('refill_order');
  279. $order_state_cancel = ORDER_STATE_CANCEL;
  280. $order_state_success = ORDER_STATE_SUCCESS;
  281. $condition['refill_order.inner_status'] = 0;
  282. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  283. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  284. $time = $_GET['time'] * 3600;
  285. $condition['refill_order.order_time'] = ['gt', (time() - $time)];
  286. $notify_time = $_GET['notify_time'];
  287. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  288. $order_list = $model_refill_order->getMerchantOrderList($condition, '', 'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  289. foreach ($order_list as $order) {
  290. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  291. }
  292. showMessage('操作成功');
  293. }
  294. }