merchant_order.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. require_once(BASE_ROOT_PATH . '/mobile/control/merchantweb.php');
  3. class merchant_orderControl extends mbMerchantControl
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. public function listOp()
  10. {
  11. $model_vr_order = Model('refill_order');
  12. $cond['mchid'] = $this->mchid();
  13. $cond['inner_status'] = 0;
  14. if (!empty($_GET['card_type'])) {
  15. if(in_array($_GET['card_type'] , ['1' , '2' , '4' , '5' , '6'])) {
  16. $cond['refill_order.card_type'] = $_GET['card_type'];
  17. }
  18. if($_GET['card_type'] == 'oil') {
  19. $cond['refill_order.card_type'] = ['in' , ['1' , '2']];
  20. }
  21. if($_GET['card_type'] == 'phone') {
  22. $cond['refill_order.card_type'] = ['in' , ['4' , '5' , '6']];
  23. }
  24. }
  25. if (!empty($_GET['card_no'])) {
  26. $cond['refill_order.card_no'] = $_GET['card_no'];
  27. }
  28. if (!empty($_GET['refill_amount'])) {
  29. $cond['refill_order.refill_amount'] = $_GET['refill_amount'];
  30. }
  31. if (!empty($_GET['mch_order'])) {
  32. $cond['refill_order.mch_order'] = $_GET['mch_order'];
  33. }
  34. if (!empty($_GET['order_sn'])) {
  35. $cond['refill_order.order_sn'] = $_GET['order_sn'];
  36. }
  37. if (in_array($_GET['order_state'], array('0', '30', '40'))) {
  38. $cond['vr_order.order_state'] = $_GET['order_state'];
  39. if($_GET['order_state'] == 30 && $_GET['time'] == 1){
  40. $cond['refill_order.order_time'] = ['lt', (time() - 3600)];
  41. }
  42. }
  43. if ($_GET['start_time'] > 0 && $_GET['end_time'] > 0) {
  44. $cond['refill_order.order_time'] = ['time', [$_GET['start_time'], $_GET['end_time']]];
  45. }
  46. $fields = 'refill_order.*,vr_order.order_state';
  47. $order_list = $model_vr_order->getMerchantOrderList($cond, $this->page, $fields, 'refill_order.order_id desc');
  48. $order_list = $this->merchant_order_format($order_list);
  49. $result['data'] = $order_list;
  50. $result['total'] = $model_vr_order->gettotalpage();
  51. return self::outsuccess($result);
  52. }
  53. private function merchant_order_format($orders)
  54. {
  55. $data = [];
  56. foreach ($orders as $order) {
  57. if($order['notify_time'] > 0)
  58. {
  59. $order['diff_time_text'] = $this->elapse_time($order['notify_time'] - $order['order_time']);
  60. $order['diff_time'] = $order['notify_time'] - $order['order_time'];
  61. }
  62. else
  63. {
  64. $order['diff_time_text'] = $this->elapse_time(time() - $order['order_time']);
  65. $order['diff_time'] = time() - $order['order_time'];
  66. }
  67. if (isset($order['order_time'])) {
  68. $order['order_time'] = date('Y-m-d H:i:s', $order['order_time']);
  69. }
  70. if (isset($order['notify_time'])) {
  71. $order['notify_time'] = date('Y-m-d H:i:s', $order['notify_time']);
  72. }
  73. if($order['channel_name'] != 'bjb') {
  74. $order['ch_trade_no'] = '';
  75. }
  76. if($order['is_retrying'] == 1) {
  77. $order['order_state'] = 'retrying';
  78. }
  79. if ($order['order_state'] == ORDER_STATE_NEW || $order['order_state'] == ORDER_STATE_PAY) {
  80. $order['order_state'] = ORDER_STATE_SEND;
  81. }
  82. $order['order_state_text'] = $this->_orderState($order['order_state']);
  83. $order['card_type_name'] = $this->scard_type($order['card_type']);
  84. $data[] = $order;
  85. }
  86. return $data;
  87. }
  88. /**
  89. * 取得订单状态文字输出形式
  90. *
  91. * @param int $order_state 订单数组
  92. * @return string
  93. */
  94. private function _orderState($order_state)
  95. {
  96. switch ($order_state) {
  97. case ORDER_STATE_CANCEL:
  98. $text = '已取消';
  99. break;
  100. case ORDER_STATE_NEW:
  101. $text = '新订单';
  102. break;
  103. case ORDER_STATE_SEND:
  104. $text = '充值中';
  105. break;
  106. case ORDER_STATE_PAY:
  107. $text = '支付成功';
  108. break;
  109. case ORDER_STATE_SUCCESS:
  110. $text = '充值成功';
  111. break;
  112. case 'retrying':
  113. $text = '重试中';
  114. break;
  115. default:
  116. $text = '未知状态';
  117. }
  118. return $text;
  119. }
  120. private function scard_type(int $card_type)
  121. {
  122. if ($card_type == mtopcard\PetroChinaCard) { //中石油
  123. return '中石油';
  124. } elseif ($card_type == mtopcard\SinopecCard) { //中石化
  125. return '中石化';
  126. } elseif ($card_type == mtopcard\ChinaMobileCard) { //中国移动
  127. return '中国移动';
  128. } elseif ($card_type == mtopcard\ChinaUnicomCard) { //中国联通
  129. return '中国联通';
  130. } elseif ($card_type == mtopcard\ChinaTelecomCard) { //中国电信
  131. return '中国电信';
  132. } else {
  133. return 'unknown';
  134. }
  135. }
  136. private function elapse_time($seconds)
  137. {
  138. $minutes = intval($seconds / 60);
  139. $second = intval($seconds % 60);
  140. if($minutes >= 60) {
  141. $minute = $minutes % 60;
  142. $hours = intval($minutes / 60);
  143. $result = "{$minute}:{$second}";
  144. }
  145. else {
  146. if($minutes > 0){
  147. $result = "{$minutes}:{$second}";
  148. }else{
  149. $result = "{$second}";
  150. }
  151. }
  152. if(isset($hours))
  153. {
  154. $result = "{$hours}:" . $result;
  155. }
  156. return $result;
  157. }
  158. }