ordersendlist.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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() - 1800)];
  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(300, $condition);
  39. $time_cond[] = ['lt', (time() - 300)];
  40. }
  41. if ($_GET['time'] == 4) {
  42. $condition = $time_out_order(900, $condition);
  43. $time_cond[] = ['lt', (time() - 900)];
  44. }
  45. if (!empty($_GET['card_type'])) {
  46. if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) {
  47. $condition['refill_order.card_type'] = $_GET['card_type'];
  48. }
  49. if ($_GET['card_type'] == 'oil') {
  50. $condition['refill_order.card_type'] = ['in', ['1', '2']];
  51. }
  52. if ($_GET['card_type'] == 'phone') {
  53. $condition['refill_order.card_type'] = ['in', ['4', '5', '6']];
  54. }
  55. }
  56. if (!empty($_GET['quality'])) {
  57. $condition['refill_order.quality'] = $_GET['quality'];
  58. }
  59. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  60. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  61. ->on('refill_order.order_id=vr_order.order_id')
  62. ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  63. ->where($condition)->find();
  64. $count = $this->refill_stat($condition,$time_cond);
  65. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  66. foreach ($merchant_list as $key => $value) {
  67. $merchants[$value['mchid']] = $value;
  68. }
  69. foreach ($order_list as $order_id => $order_info) {
  70. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  71. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  72. $order_list[$order_id]['diff_time_text'] = $this->elapse_time(time() - $order_info['order_time']);
  73. $order_list[$order_id]['diff_time'] = time() - $order_info['order_time'];
  74. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality']);
  75. }
  76. $provider_list = Model('')->table('refill_provider,store')
  77. ->field('refill_provider.*,store.store_name')
  78. ->join('inner')
  79. ->on('store.store_id=refill_provider.store_id')
  80. ->order('opened asc, provider_id desc')
  81. ->limit(1000)
  82. ->select();
  83. Tpl::output('stat', $stat);
  84. Tpl::output('count', $count);
  85. Tpl::output('order_list', $order_list);
  86. Tpl::output('merchant_list', $merchant_list);
  87. Tpl::output('provider_list', $provider_list);
  88. Tpl::output('show_page', $model_refill_order->showpage());
  89. Tpl::showpage('refill.order.send.index');
  90. }
  91. private function scard_type(int $card_type)
  92. {
  93. if ($card_type == 1) { //中石油
  94. return '中石油';
  95. } elseif ($card_type == 2) { //中石化
  96. return '中石化';
  97. } elseif ($card_type == 4) { //中国移动
  98. return '中国移动';
  99. } elseif ($card_type == 5) { //中国联通
  100. return '中国联通';
  101. } elseif ($card_type == 6) { //中国电信
  102. return '中国电信';
  103. } elseif ($card_type == 7) { //中国电信
  104. return '增值业务';
  105. } else {
  106. return 'unknown';
  107. }
  108. }
  109. private function quality_format($quality) {
  110. switch ($quality) {
  111. case 1:
  112. $text = "普充";
  113. break;
  114. case 2:
  115. $text = "快充";
  116. break;
  117. case 3:
  118. $text = "卡密";
  119. break;
  120. case 4:
  121. $text = "三方";
  122. break;
  123. case 5:
  124. $text = "慢充二十四小时";
  125. break;
  126. case 6:
  127. $text = "慢充六小时";
  128. break;
  129. case 7:
  130. $text = "慢充两小时";
  131. break;
  132. default:
  133. return '其他';
  134. break;
  135. }
  136. return $text;
  137. }
  138. private function elapse_time($seconds)
  139. {
  140. $minutes = intval($seconds / 60);
  141. $second = intval($seconds % 60);
  142. if ($minutes >= 60) {
  143. $minute = $minutes % 60;
  144. $hours = intval($minutes / 60);
  145. $result = "{$minute}m{$second}s";
  146. } elseif ($minutes > 0) {
  147. $result = "{$minutes}m{$second}s";
  148. } else {
  149. $result = "{$second}s";
  150. }
  151. if (isset($hours)) {
  152. $result = "{$hours}h{$minute}m";
  153. }
  154. return $result;
  155. }
  156. private function refill_stat($condition, $times)
  157. {
  158. $stat_order = function ($condition) {
  159. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  160. ->on('refill_order.order_id=vr_order.order_id')
  161. ->field('count(*) as order_count ')
  162. ->where($condition)->find();
  163. return $stat['order_count'];
  164. };
  165. $result = [];
  166. $condition['order_state'] = ORDER_STATE_SEND;
  167. foreach ($times as $time) {
  168. $condition['refill_order.order_time'] = $time;
  169. $result[] = $stat_order($condition);
  170. }
  171. return $result;
  172. }
  173. }