refill_order.php 13 KB

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