refill_order.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. class refill_orderControl extends SystemControl
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. }
  8. public function indexOp()
  9. {
  10. $fShowStat = $_GET['fShowStat'];
  11. $this->refill_order($fShowStat == 1);
  12. }
  13. public function refill_order($fShowStat = false)
  14. {
  15. $model_refill_order = Model('refill_order');
  16. $condition['inner_status'] = 0;
  17. $fSingle = false;
  18. if (!empty($_GET['order_sn'])) {
  19. $condition['refill_order.order_sn'] = $_GET['order_sn'];
  20. $fSingle = true;
  21. }
  22. if (!empty($_GET['mch_order'])) {
  23. $condition['refill_order.mch_order'] = $_GET['mch_order'];
  24. $fSingle = true;
  25. }
  26. if (!empty($_GET['ch_trade_no'])) {
  27. $condition['refill_order.ch_trade_no'] = $_GET['ch_trade_no'];
  28. $fSingle = true;
  29. }
  30. if (!empty($_GET['card_no'])) {
  31. $condition['refill_order.card_no'] = $_GET['card_no'];
  32. $fSingle = true;
  33. }
  34. if (!empty($_GET['no_mchid'])) {
  35. $no_mchid = explode(',', $_GET['no_mchid']);
  36. $condition['refill_order.mchid'] = ['not in', $no_mchid];
  37. }
  38. if (!empty($_GET['mchid'])) {
  39. $condition['refill_order.mchid'] = $_GET['mchid'];
  40. }
  41. if (!empty($_GET['channel_name'])) {
  42. $condition['refill_order.channel_name'] = $_GET['channel_name'];
  43. }
  44. if (!empty($_GET['store_id'])) {
  45. $condition['vr_order.store_id'] = $_GET['store_id'];
  46. }
  47. if (!empty($_GET['refill_amount'])) {
  48. $condition['refill_order.refill_amount'] = $_GET['refill_amount'];
  49. }
  50. if (!empty($_GET['quality'])) {
  51. $condition['refill_order.quality'] = $_GET['quality'];
  52. }
  53. if (!empty($_GET['card_type'])) {
  54. if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) {
  55. $condition['refill_order.card_type'] = intval($_GET['card_type']);
  56. }
  57. if ($_GET['card_type'] == 'oil') {
  58. $condition['refill_order.card_type'] = ['in', [1, 2]];
  59. }
  60. if ($_GET['card_type'] == 'phone') {
  61. $condition['refill_order.card_type'] = ['in', [4, 5, 6]];
  62. }
  63. }
  64. $fToday = false;
  65. if (!$fSingle) {
  66. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  67. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  68. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  69. $condition['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  70. } elseif ($start_unixtime > 0) {
  71. $condition['refill_order.order_time'] = ['egt', $start_unixtime];
  72. } elseif ($end_unixtime > 0) {
  73. $condition['refill_order.order_time'] = ['lt', $end_unixtime];
  74. } else {
  75. $start = strtotime(date('Y-m-d', time()));
  76. $condition['refill_order.order_time'] = ['egt', $start];
  77. $fToday = true;
  78. }
  79. if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40'])) {
  80. $condition['vr_order.order_state'] = $_GET['order_state'];
  81. if ($_GET['order_state'] == ORDER_STATE_SEND) {
  82. if ($_GET['time'] == 1) {
  83. $condition['refill_order.order_time'] = ['between', [(time() - 3600), (time() - 1800)]];
  84. }
  85. if ($_GET['time'] == 2) {
  86. $condition['refill_order.order_time'] = ['lt', (time() - 3600)];
  87. }
  88. }
  89. }
  90. }
  91. if (!empty($_GET['export']) || !empty($_GET['export_stats'])) {
  92. $this->RefillOrderExport($condition);
  93. }
  94. $merchants = [];
  95. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  96. foreach ($merchant_list as $key => $value) {
  97. $merchants[$value['mchid']] = $value;
  98. }
  99. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  100. foreach ($order_list as $order_id => $order_info) {
  101. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  102. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  103. if ($order_info['notify_time'] > 0) {
  104. $diff_time = $order_info['notify_time'] - $order_info['order_time'];
  105. } else {
  106. $diff_time = time() - $order_info['order_time'];
  107. }
  108. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
  109. $order_list[$order_id]['diff_time'] = $diff_time;
  110. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'],$order_info['card_type']);
  111. $order_list[$order_id]['org_quality_text'] = $this->quality_format($order_info['org_quality'],$order_info['card_type']);
  112. }
  113. $provider_list = Model('')->table('refill_provider,store')
  114. ->field('refill_provider.*,store.store_name')
  115. ->join('inner')
  116. ->on('store.store_id=refill_provider.store_id')
  117. ->order('opened asc, provider_id desc')
  118. ->limit(1000)
  119. ->select();
  120. if ($fShowStat) {
  121. $stat = $this->all_order_state_stat($condition);
  122. Tpl::output('stat', $stat);
  123. }
  124. Tpl::output('admin_info', $this->getAdminInfo());
  125. Tpl::output('ftoday', $fToday);
  126. Tpl::output('order_list', $order_list);
  127. Tpl::output('provider_list', $provider_list);
  128. Tpl::output('merchant_list', $merchant_list);
  129. Tpl::output('show_page', $model_refill_order->showpage());
  130. Tpl::showpage('refill.order.index');
  131. }
  132. private function RefillOrderExport($condition)
  133. {
  134. if(!empty($_GET['export_stats'])) {
  135. if(!empty($condition['refill_order.order_time'])) {
  136. $condition['refill_order.notify_time'] = $condition['refill_order.order_time'];
  137. unset($condition['refill_order.order_time']);
  138. }
  139. }
  140. $i = 0;
  141. $result = [];
  142. while (true) {
  143. $start = $i * 1000;
  144. $order_list = Model('')->table('refill_order,vr_order')->field('refill_order.*,vr_order.order_state')
  145. ->where($condition)->join('inner')->on('refill_order.order_id=vr_order.order_id')->order('refill_order.order_time desc')->limit("{$start},1000")->select();
  146. if (empty($order_list)) {
  147. break;
  148. }
  149. $i++;
  150. foreach ($order_list as $order) {
  151. $result[] = $order;
  152. }
  153. }
  154. $this->createExcel($result);
  155. }
  156. private function createExcel($data = array())
  157. {
  158. Language::read('export');
  159. import('libraries.excel');
  160. $excel_obj = new Excel();
  161. $excel_data = array();
  162. //设置样式
  163. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  164. //header
  165. $excel_data[0][] = array('styleid' => 's_title', 'data' => '商户号');
  166. $excel_data[0][] = array('styleid' => 's_title', 'data' => '客户订单号');
  167. $excel_data[0][] = array('styleid' => 's_title', 'data' => '平台单号');
  168. $excel_data[0][] = array('styleid' => 's_title', 'data' => '面额');
  169. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号');
  170. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡类型');
  171. $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期');
  172. $excel_data[0][] = array('styleid' => 's_title', 'data' => '完成日期');
  173. $excel_data[0][] = array('styleid' => 's_title', 'data' => '官方流水号');
  174. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态');
  175. $excel_data[0][] = array('styleid' => 's_title', 'data' => '扣款金额');
  176. //data
  177. foreach ((array)$data as $k => $v) {
  178. $tmp = array();
  179. $tmp[] = array('data' => $v['mchid']);
  180. $tmp[] = array('data' => $v['mch_order']);
  181. $tmp[] = array('data' => $v['order_sn']);
  182. $tmp[] = array('data' => $v['refill_amount']);
  183. $tmp[] = array('data' => $v['card_no']);
  184. $tmp[] = array('data' => $this->scard_type($v['card_type']));
  185. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['order_time']));
  186. if (empty($v['notify_time'])) {
  187. $tmp[] = array('data' => '');
  188. } else {
  189. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['notify_time']));
  190. }
  191. $tmp[] = array('data' => $v['official_sn']);
  192. $tmp[] = array('data' => orderState($v));
  193. $tmp[] = array('data' => $v['mch_amount']);
  194. $excel_data[] = $tmp;
  195. }
  196. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  197. $excel_obj->addArray($excel_data);
  198. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  199. $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
  200. exit;
  201. }
  202. private function all_order_state_stat($condition)
  203. {
  204. $counts = Model('')->table('refill_order,vr_order')->join('inner')
  205. ->on('refill_order.order_id=vr_order.order_id')
  206. ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts, order_state')
  207. ->where($condition)
  208. ->group('order_state')
  209. ->select();
  210. $all = [];
  211. $data['order_count'] = $data['refill_amounts'] = $data['channel_amounts'] = $data['mch_amounts'] = 0;
  212. $sending = $success = $cancel = $data;
  213. foreach ($counts as $count) {
  214. if ($count['order_state'] == ORDER_STATE_SEND) {
  215. $sending = $count;
  216. } elseif ($count['order_state'] == ORDER_STATE_SUCCESS) {
  217. $success = $count;
  218. } elseif ($count['order_state'] == ORDER_STATE_CANCEL) {
  219. $cancel = $count;
  220. }
  221. $all['order_count'] += $count['order_count'];
  222. $all['refill_amounts'] += ncPriceFormat($count['refill_amounts']);
  223. $all['channel_amounts'] += ncPriceFormat($count['channel_amounts']);
  224. $all['mch_amounts'] += ncPriceFormat($count['mch_amounts']);
  225. }
  226. return ['all' => $all, 'sending' => $sending, 'success' => $success, 'cancel' => $cancel];
  227. }
  228. public function merchant_dataOp()
  229. {
  230. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  231. $result = [];
  232. foreach ($merchant_list as $key => $value) {
  233. $data['name'] = $value['company_name'] ?? $value['name'];
  234. $data['value'] = $value['mchid'];
  235. $result[] = $data;
  236. }
  237. echo json_encode($result);
  238. exit;
  239. }
  240. public function refill_third_infoOP()
  241. {
  242. $order_id = $_GET['order_id'];
  243. $model_refill_order = Model('refill_order');
  244. $order_info = $model_refill_order->getOrderInfo(['order_id' => $order_id]);
  245. if (empty($model_refill_order) || $order_info['card_type'] != mtopcard\ThirdRefillCard) {
  246. $res = ['state' => -1, 'msg' => '订单不存在或类型错误'];
  247. exit(json_encode($res));
  248. }
  249. $third_refill = Model('thrid_refill');
  250. $data = $third_refill->getThird($order_id);
  251. $data['card_info'] = $data['card_info'] ?? '';
  252. $account_type_text = ['手机号','QQ号','微信号'];
  253. $data['account_type_text'] = $account_type_text[$data['account_type']-1];
  254. $ret_state_text = ['初始化','已解析','解析失败'];
  255. $data['ret_state_text'] = $ret_state_text[$data['ret_state']];
  256. $res = ['state' => 1, 'data' => $data];
  257. exit(json_encode($res));
  258. }
  259. }