ordersendlist.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. class ordersendlistControl extends SystemControl
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. }
  8. public function indexOp()
  9. {
  10. $model_refill_order = Model('refill_order');
  11. $condition['refill_order.inner_status'] = 0;
  12. $condition['vr_order.order_state'] = ORDER_STATE_SEND;
  13. $condition['refill_order.order_time'] = ['lt', (time() - 300)];
  14. if (!empty($_GET['mchid'])) {
  15. $condition['refill_order.mchid'] = $_GET['mchid'];
  16. }
  17. if (!empty($_GET['store_id'])) {
  18. $condition['vr_order.store_id'] = $_GET['store_id'];
  19. }
  20. $time_cond = [
  21. ['between', [(time() - 3600), (time() - 1800)]],
  22. ['lt', (time() - 3600)]];
  23. if ($_GET['time'] == 1) {
  24. $condition['refill_order.order_time'] = ['between', [(time() - 3600), (time() - 1800)]];
  25. }
  26. if ($_GET['time'] == 2) {
  27. $condition['refill_order.order_time'] = ['lt', (time() - 3600)];
  28. }
  29. $time_out_order = function($time_out, $condition){
  30. $mchids = Model('')->table('merchant')->where(['time_out' => ['elt', $time_out]])->field('mchid')->select();
  31. $mchids = array_column($mchids, 'mchid');
  32. $mchids = implode(',', $mchids);
  33. $condition['refill_order.order_time'] = ['lt', (time() - $time_out)];
  34. $condition['refill_order.mchid'] = ['in',$mchids];
  35. return $condition;
  36. };
  37. if ($_GET['time'] == 3) {
  38. $condition = $time_out_order(180, $condition);
  39. $time_cond[] = ['lt', (time() - 180)];
  40. $_GET['card_type'] = 'phone';
  41. }
  42. if ($_GET['time'] == 4) {
  43. $condition = $time_out_order(300, $condition);
  44. $time_cond[] = ['lt', (time() - 300)];
  45. $_GET['card_type'] = 'phone';
  46. }
  47. if ($_GET['time'] == 5) {
  48. $condition = $time_out_order(600, $condition);
  49. $time_cond[] = ['lt', (time() - 600)];
  50. }
  51. if ($_GET['time'] == 6) {
  52. $condition = $time_out_order(900, $condition);
  53. $time_cond[] = ['lt', (time() - 900)];
  54. $_GET['card_type'] = 'phone';
  55. }
  56. if (!empty($_GET['card_type'])) {
  57. if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) {
  58. $condition['refill_order.card_type'] = $_GET['card_type'];
  59. }
  60. if ($_GET['card_type'] == 'oil') {
  61. $condition['refill_order.card_type'] = ['in', ['1', '2']];
  62. }
  63. if ($_GET['card_type'] == 'phone') {
  64. $condition['refill_order.card_type'] = ['in', ['4', '5', '6']];
  65. }
  66. }
  67. if (!empty($_GET['quality'])) {
  68. $condition['refill_order.quality'] = $_GET['quality'];
  69. }
  70. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  71. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  72. ->on('refill_order.order_id=vr_order.order_id')
  73. ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  74. ->where($condition)->find();
  75. $count = $this->refill_stats($condition,$time_cond);
  76. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  77. $order_list = $this->orderFormat($order_list,$merchant_list);
  78. $provider_list = Model('')->table('refill_provider,store')
  79. ->field('refill_provider.*,store.store_name')
  80. ->join('inner')
  81. ->on('store.store_id=refill_provider.store_id')
  82. ->order('opened asc, provider_id desc')
  83. ->limit(1000)
  84. ->select();
  85. Tpl::output('stat', $stat);
  86. Tpl::output('count', $count);
  87. Tpl::output('order_list', $order_list);
  88. Tpl::output('merchant_list', $merchant_list);
  89. Tpl::output('provider_list', $provider_list);
  90. Tpl::output('show_page', $model_refill_order->showpage());
  91. Tpl::showpage('refill.order.send.index');
  92. }
  93. private function refill_stats($condition, $times): array
  94. {
  95. $stat_order = function ($condition) {
  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 ')
  99. ->where($condition)->find();
  100. return $stat['order_count'];
  101. };
  102. $result = [];
  103. $condition['order_state'] = ORDER_STATE_SEND;
  104. foreach ($times as $time) {
  105. $condition['refill_order.order_time'] = $time;
  106. $result[] = $stat_order($condition);
  107. }
  108. return $result;
  109. }
  110. public function neterr_orderOp()
  111. {
  112. $model_refill_order = Model('refill_order');
  113. if(!empty($_GET['store_id'])) {
  114. $condition['vr_order.store_id'] = $_GET['store_id'];
  115. }
  116. $condition['refill_order.inner_status'] = 0;
  117. $condition['refill_order.neterr'] = 1;
  118. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  119. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  120. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  121. $order_list = $this->orderFormat($order_list,$merchant_list);
  122. $provider_list = Model('')->table('refill_provider,store')
  123. ->field('refill_provider.*,store.store_name')
  124. ->join('inner')
  125. ->on('store.store_id=refill_provider.store_id')
  126. ->order('name asc')
  127. ->limit(1000)
  128. ->select();
  129. Tpl::output('provider_list', $provider_list);
  130. Tpl::output('order_list', $order_list);
  131. Tpl::output('show_page', $model_refill_order->showpage());
  132. Tpl::showpage('refill.order.neterr.index');
  133. }
  134. public function orderFormat($order_list, $merchant_list)
  135. {
  136. $merchants = [];
  137. foreach ($merchant_list as $value) {
  138. $merchants[$value['mchid']] = $value;
  139. }
  140. foreach ($order_list as $order_id => $order_info) {
  141. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  142. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  143. $order_list[$order_id]['diff_time_text'] = $this->elapse_time(time() - $order_info['order_time']);
  144. $order_list[$order_id]['diff_time'] = time() - $order_info['order_time'];
  145. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'],$order_info['card_type']);
  146. }
  147. return $order_list;
  148. }
  149. }