merchant_order.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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'] = ['between', [$_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. public function OrderStatsOp()
  54. {
  55. if(empty($_GET['time_type']) || empty($_GET['start_time']) || empty($_GET['end_time'])) {
  56. return self::outerr(errcode::ErrInputParam, "参数错误.");
  57. }
  58. $cond['inner_status'] = 0;
  59. $time_type = $_GET['time_type'];
  60. if ($time_type == 'order_time') {
  61. $cond['order_time'] = ['time', [$_GET['start_time'], $_GET['end_time']]];
  62. }
  63. if ($time_type == 'notify_time') {
  64. $cond['notify_time'] = ['time', [$_GET['start_time'], $_GET['end_time']]];
  65. }
  66. if(empty($cond)) {
  67. return self::outerr(errcode::ErrInputParam, "筛选日期类型错误.");
  68. }
  69. $cond['mchid'] = $this->mchid();
  70. $stats = Model('')->table('refill_order,vr_order')->join('inner')
  71. ->on('refill_order.order_id=vr_order.order_id')
  72. ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(mch_amount) as mch_amounts, order_state')
  73. ->where($cond)->group('order_state')->select();
  74. $result['count'] = $result['sendCount'] = $result['errorCount'] = $result['successCount'] = $result['refill_amounts'] = $result['mch_amounts'] = 0;
  75. foreach ($stats as $stat) {
  76. $result['count'] += $stat['order_count'];
  77. if($stat['order_state'] == ORDER_STATE_SEND) {
  78. $result['sendCount'] = $stat['order_count'];
  79. }
  80. if($stat['order_state'] == ORDER_STATE_CANCEL) {
  81. $result['errorCount'] = $stat['order_count'];
  82. }
  83. if($stat['order_state'] == ORDER_STATE_SUCCESS) {
  84. $result['successCount'] = $stat['order_count'];
  85. $result['mch_amounts'] = $stat['mch_amounts'];
  86. $result['refill_amounts'] = $stat['refill_amounts'];
  87. }
  88. }
  89. return self::outsuccess($result);
  90. }
  91. private function merchant_order_format($orders)
  92. {
  93. $data = [];
  94. foreach ($orders as $order) {
  95. if($order['notify_time'] > 0)
  96. {
  97. $order['diff_time_text'] = $this->elapse_time($order['notify_time'] - $order['order_time']);
  98. $order['diff_time'] = $order['notify_time'] - $order['order_time'];
  99. }
  100. else
  101. {
  102. $order['diff_time_text'] = $this->elapse_time(time() - $order['order_time']);
  103. $order['diff_time'] = time() - $order['order_time'];
  104. }
  105. if (isset($order['order_time'])) {
  106. $order['order_time'] = date('Y-m-d H:i:s', $order['order_time']);
  107. }
  108. if (isset($order['notify_time'])) {
  109. $order['notify_time'] = date('Y-m-d H:i:s', $order['notify_time']);
  110. }
  111. if($order['is_retrying'] == 1) {
  112. $order['order_state'] = ORDER_STATE_SEND;
  113. }
  114. if ($order['order_state'] == ORDER_STATE_NEW || $order['order_state'] == ORDER_STATE_PAY) {
  115. $order['order_state'] = ORDER_STATE_SEND;
  116. }
  117. $order['order_state_text'] = $this->_orderState($order['order_state']);
  118. $order['card_type_name'] = $this->scard_type($order['card_type']);
  119. $data[] = $order;
  120. }
  121. return $data;
  122. }
  123. /**
  124. * 取得订单状态文字输出形式
  125. *
  126. * @param int $order_state 订单数组
  127. * @return string
  128. */
  129. private function _orderState($order_state)
  130. {
  131. switch ($order_state) {
  132. case ORDER_STATE_CANCEL:
  133. $text = '已取消';
  134. break;
  135. case ORDER_STATE_NEW:
  136. $text = '新订单';
  137. break;
  138. case ORDER_STATE_SEND:
  139. $text = '充值中';
  140. break;
  141. case ORDER_STATE_PAY:
  142. $text = '支付成功';
  143. break;
  144. case ORDER_STATE_SUCCESS:
  145. $text = '充值成功';
  146. break;
  147. case 'retrying':
  148. $text = '重试中';
  149. break;
  150. default:
  151. $text = '未知状态';
  152. }
  153. return $text;
  154. }
  155. private function scard_type(int $card_type)
  156. {
  157. if ($card_type == mtopcard\PetroChinaCard) { //中石油
  158. return '中石油';
  159. } elseif ($card_type == mtopcard\SinopecCard) { //中石化
  160. return '中石化';
  161. } elseif ($card_type == mtopcard\ChinaMobileCard) { //中国移动
  162. return '中国移动';
  163. } elseif ($card_type == mtopcard\ChinaUnicomCard) { //中国联通
  164. return '中国联通';
  165. } elseif ($card_type == mtopcard\ChinaTelecomCard) { //中国电信
  166. return '中国电信';
  167. } elseif ($card_type == mtopcard\ThirdRefillCard) { //中国电信
  168. return '增值业务';
  169. } else {
  170. return 'unknown';
  171. }
  172. }
  173. private function elapse_time($seconds)
  174. {
  175. $minutes = intval($seconds / 60);
  176. $second = intval($seconds % 60);
  177. if($minutes >= 60) {
  178. $minute = $minutes % 60;
  179. $hours = intval($minutes / 60);
  180. $result = "{$minute}:{$second}";
  181. }
  182. else {
  183. if($minutes > 0){
  184. $result = "{$minutes}:{$second}";
  185. }else{
  186. $result = "{$second}";
  187. }
  188. }
  189. if(isset($hours))
  190. {
  191. $result = "{$hours}:" . $result;
  192. }
  193. return $result;
  194. }
  195. public function OrderExportOp()
  196. {
  197. $model_vr_order = Model('refill_order');
  198. $cond['mchid'] = $this->mchid();
  199. $cond['inner_status'] = 0;
  200. if (!empty($_GET['card_type'])) {
  201. if(in_array($_GET['card_type'] , ['1' , '2' , '4' , '5' , '6'])) {
  202. $cond['refill_order.card_type'] = $_GET['card_type'];
  203. }
  204. if($_GET['card_type'] == 'oil') {
  205. $cond['refill_order.card_type'] = ['in' , ['1' , '2']];
  206. }
  207. if($_GET['card_type'] == 'phone') {
  208. $cond['refill_order.card_type'] = ['in' , ['4' , '5' , '6']];
  209. }
  210. }
  211. if (!empty($_GET['card_no'])) {
  212. $cond['refill_order.card_no'] = $_GET['card_no'];
  213. }
  214. if (!empty($_GET['refill_amount'])) {
  215. $cond['refill_order.refill_amount'] = $_GET['refill_amount'];
  216. }
  217. if (!empty($_GET['mch_order'])) {
  218. $cond['refill_order.mch_order'] = $_GET['mch_order'];
  219. }
  220. if (!empty($_GET['order_sn'])) {
  221. $cond['refill_order.order_sn'] = $_GET['order_sn'];
  222. }
  223. if (in_array($_GET['order_state'], array('0', '30', '40'))) {
  224. $cond['vr_order.order_state'] = $_GET['order_state'];
  225. if($_GET['order_state'] == 30 && $_GET['time'] == 1){
  226. $cond['refill_order.order_time'] = ['lt', (time() - 3600)];
  227. }
  228. }
  229. if ($_GET['start_time'] > 0 && $_GET['end_time'] > 0) {
  230. $cond['refill_order.order_time'] = ['time', [$_GET['start_time'], $_GET['end_time']]];
  231. }
  232. $fields = 'refill_order.*,vr_order.order_state';
  233. $order_list = $model_vr_order->getMerchantOrderList($cond, '10000', $fields, 'refill_order.order_id desc');
  234. $order_list = $this->merchant_order_format($order_list);
  235. $result = $this->export_order_exec($order_list);
  236. return self::outsuccess($result);
  237. }
  238. private function export_order_exec($order_list)
  239. {
  240. $title = [
  241. ['value' => '代理商账号'],
  242. ['value' => '商品名称'],
  243. ['value' => '交易账号'],
  244. ['value' => '交易金额'],
  245. ['value' => '交易面值'],
  246. ['value' => '交易日期'],
  247. ['value' => '交易状态'],
  248. ['value' => '处理时间'],
  249. ['value' => '第三方流水']
  250. ];
  251. $card_type = ['1'=>'中石油' , '2' =>'中石化' , '4' => '移动' , '5' => '联通' , '6' => '电信'];
  252. foreach ($order_list as $order) {
  253. $data = [];
  254. $official_sn = $order['official_sn'];
  255. $notify_time = $order['$notify_time'];
  256. if(empty($order['official_sn'])) {
  257. $official_sn = '';
  258. }
  259. if(empty($order['$notify_time'])) {
  260. $notify_time = '';
  261. }
  262. $data[] = ['value' => $order['mchid']];
  263. $data[] = ['value' => "{$card_type[$order['card_type']]}{$order['refill_amount']}元"];
  264. $data[] = ['value' => $order['card_no']];
  265. $data[] = ['value' => $order['mch_amount']];
  266. $data[] = ['value' => $order['refill_amount']];
  267. $data[] = ['value' => $order['order_time']];
  268. $data[] = ['value' => $order['order_state_text']];
  269. $data[] = ['value' => $notify_time];
  270. $data[] = ['value' => $official_sn];
  271. $datas[] = $data;
  272. }
  273. Log::record(json_encode($datas),Log::DEBUG);
  274. return ['title' => $title , 'data' => $datas];
  275. }
  276. }