ordersendlist.php 12 KB

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