ordersendlist.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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(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 asc');
  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_stats($condition,$time_cond);
  65. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  66. $order_list = $this->orderFormat($order_list,$merchant_list);
  67. $provider_list = Model('')->table('refill_provider,store')
  68. ->field('refill_provider.*,store.store_name')
  69. ->join('inner')
  70. ->on('store.store_id=refill_provider.store_id')
  71. ->order('opened asc, provider_id desc')
  72. ->limit(1000)
  73. ->select();
  74. Tpl::output('stat', $stat);
  75. Tpl::output('count', $count);
  76. Tpl::output('order_list', $order_list);
  77. Tpl::output('merchant_list', $merchant_list);
  78. Tpl::output('provider_list', $provider_list);
  79. Tpl::output('show_page', $model_refill_order->showpage());
  80. Tpl::showpage('refill.order.send.index');
  81. }
  82. private function refill_stats($condition, $times): array
  83. {
  84. $stat_order = function ($condition) {
  85. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  86. ->on('refill_order.order_id=vr_order.order_id')
  87. ->field('count(*) as order_count ')
  88. ->where($condition)->find();
  89. return $stat['order_count'];
  90. };
  91. $result = [];
  92. $condition['order_state'] = ORDER_STATE_SEND;
  93. foreach ($times as $time) {
  94. $condition['refill_order.order_time'] = $time;
  95. $result[] = $stat_order($condition);
  96. }
  97. return $result;
  98. }
  99. public function neterr_orderOp()
  100. {
  101. $model_refill_order = Model('refill_order');
  102. $condition['refill_order.inner_status'] = 0;
  103. $condition['refill_order.neterr'] = 1;
  104. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  105. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  106. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  107. $order_list = $this->orderFormat($order_list,$merchant_list);
  108. Tpl::output('order_list', $order_list);
  109. Tpl::output('show_page', $model_refill_order->showpage());
  110. Tpl::showpage('refill.order.neterr.index');
  111. }
  112. public function orderFormat($order_list, $merchant_list)
  113. {
  114. $merchants = [];
  115. foreach ($merchant_list as $value) {
  116. $merchants[$value['mchid']] = $value;
  117. }
  118. foreach ($order_list as $order_id => $order_info) {
  119. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  120. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  121. $order_list[$order_id]['diff_time_text'] = $this->elapse_time(time() - $order_info['order_time']);
  122. $order_list[$order_id]['diff_time'] = time() - $order_info['order_time'];
  123. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'],$order_info['card_type']);
  124. }
  125. return $order_list;
  126. }
  127. }