refill_detail.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. require_once(BASE_HELPER_PATH . '/refill/util.php');
  3. use refill\util;
  4. class refill_detailControl extends SystemControl
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function indexOp()
  11. {
  12. $mod = Model('refill_detail');
  13. $condition = [];
  14. $_GET['query_start_time'] = $_GET['query_start_time'] ?? date("Y-m-d 00:00:00");
  15. $order_state_send = ORDER_STATE_SEND;
  16. $order_state_queue = ORDER_STATE_QUEUE;
  17. $order_state_handled = ORDER_STATE_HANDLED;
  18. $condition['order_state'] = ['in',"{$order_state_send},{$order_state_queue},{$order_state_handled}"];
  19. if(!empty($_GET['mchid'])) {
  20. $condition['mchid'] = $_GET['mchid'];
  21. }
  22. if(in_array($_GET['order_state'], [$order_state_send,$order_state_queue,$order_state_handled])) {
  23. $condition['order_state'] = $_GET['order_state'];
  24. }
  25. if (!empty($_GET['mch_orders'])) {
  26. $mch_orders = rtrim($_GET['mch_orders'],',');
  27. $condition['mch_order'] = ['in', $mch_orders];
  28. }
  29. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  30. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  31. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  32. $condition['order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  33. } elseif ($start_unixtime > 0) {
  34. $condition['order_time'] = ['egt', $start_unixtime];
  35. } elseif ($end_unixtime > 0) {
  36. $condition['order_time'] = ['lt', $end_unixtime];
  37. } else {
  38. $start = strtotime(date('Y-m-d', time()));
  39. $condition['order_time'] = ['egt', $start];
  40. }
  41. $merchants = [];
  42. $merchant_list = $this->merchants();
  43. foreach ($merchant_list as $value) {
  44. $merchants[$value['mchid']] = $value;
  45. }
  46. if($_GET['export'] == 1) {
  47. $this->RefillDetailExport($condition,$merchants);
  48. exit;
  49. }else{
  50. $list = $mod->getRefillDetailList($condition,200);
  51. $list = $this->DataFormat($list,$merchants);
  52. }
  53. Tpl::output('merchant_list', $merchants);
  54. Tpl::output('list', $list);
  55. Tpl::output('show_page', $mod->showpage());
  56. Tpl::showpage('refill.detail');
  57. }
  58. private function DataFormat($list,$merchants)
  59. {
  60. foreach ($list as $key => $value) {
  61. $params = json_decode($value['params'],true);
  62. $list[$key]['company_name'] = $merchants[$value['mchid']]['company_name'];
  63. $list[$key]['params'] = $params;
  64. if($value['order_state'] == ORDER_STATE_SEND) {
  65. $list[$key]['order_state_text'] = '待收货';
  66. } elseif ($value['order_state'] == ORDER_STATE_QUEUE) {
  67. $list[$key]['order_state_text'] = '队列中';
  68. } elseif ($value['order_state'] == ORDER_STATE_HANDLED) {
  69. $list[$key]['order_state_text'] = '已处理';
  70. } else {
  71. $list[$key]['order_state_text'] = '/';
  72. }
  73. }
  74. return $list;
  75. }
  76. private function RefillDetailExport($condition, $merchants)
  77. {
  78. $i = 0;
  79. $result = [];
  80. while (true) {
  81. $start = $i * 1000;
  82. $list = Model('')->table('refill_detail')->where($condition)->order('order_time desc')->limit("{$start},1000")->select();
  83. if (empty($list)) {
  84. break;
  85. }
  86. $i++;
  87. foreach ($list as $value) {
  88. $result[] = $value;
  89. }
  90. }
  91. $result = $this->DataFormat($result,$merchants);
  92. $this->createExcel($result);
  93. }
  94. private function createExcel($data = array())
  95. {
  96. Language::read('export');
  97. import('libraries.excel');
  98. $excel_obj = new Excel();
  99. $excel_data = array();
  100. //设置样式
  101. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  102. //header
  103. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构编码');
  104. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构名称');
  105. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构单号');
  106. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号');
  107. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值面值');
  108. $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期');
  109. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态');
  110. //data
  111. foreach ((array)$data as $v) {
  112. $tmp = array();
  113. $tmp[] = array('data' => $v['mchid']);
  114. $tmp[] = array('data' => $v['company_name']);
  115. $tmp[] = array('data' => $v['mch_order']);
  116. $tmp[] = array('data' => $v['params']['card_no']);
  117. $tmp[] = array('data' => $v['params']['amount']);
  118. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['order_time']));
  119. $tmp[] = array('data' => $v['order_state_text']);
  120. $excel_data[] = $tmp;
  121. }
  122. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  123. $excel_obj->addArray($excel_data);
  124. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  125. $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
  126. exit;
  127. }
  128. public function order_disposeOp()
  129. {
  130. $id = $_GET['id'];
  131. $type = $_GET['type'];
  132. $condition['detail_id'] = ['in',$id];
  133. $order_state_send = ORDER_STATE_SEND;
  134. $order_state_queue = ORDER_STATE_QUEUE;
  135. $condition['order_state'] = ['in',"{$order_state_send},{$order_state_queue}"];
  136. $refill_detail = Model('refill_detail')->where($condition)->select();
  137. $mod = Model('refill_order');
  138. foreach ($refill_detail as $detail)
  139. {
  140. $mchid = $detail['mchid'];
  141. $mch_order = $detail['mch_order'];
  142. Log::record("mchid: {$mchid} , mch_order: {$mch_order}", Log::DEBUG);
  143. $refill_order = $mod->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
  144. if (empty($refill_order))
  145. {
  146. Log::record("order dispose type:{$type}, params:{$detail['params']}",Log::DEBUG);
  147. $params = json_decode($detail['params'],true);
  148. if ($type == 'cancel') {
  149. //零元订单失败
  150. Log::record("cancel",Log::DEBUG);
  151. if ($detail['order_state'] == ORDER_STATE_SEND) {
  152. util::pop_queue_order($mchid, $mch_order);
  153. } elseif ($detail['order_state'] == ORDER_STATE_QUEUE) {
  154. util::push_add_zero($params);
  155. }
  156. }
  157. elseif ($type == 'anew') {
  158. //重新补充
  159. Log::record("anew",Log::DEBUG);
  160. util::push_add($params);
  161. } else {
  162. continue;
  163. }
  164. }
  165. else {
  166. util::pop_queue_order($mchid,$mch_order);
  167. }
  168. }
  169. showMessage('操作成功','index.php?act=refill_detail&op=index');
  170. }
  171. public function DelQueueOrderOp()
  172. {
  173. $id = $_GET['id'];
  174. $condition['detail_id'] = ['in',$id];
  175. $refill_detail = Model('refill_detail')->where($condition)->select();
  176. foreach ($refill_detail as $detail)
  177. {
  178. $mchid = $detail['mchid'];
  179. $mch_order = $detail['mch_order'];
  180. util::del_queue_order($mchid,$mch_order);
  181. }
  182. showMessage('操作成功','index.php?act=refill_detail&op=index');
  183. }
  184. }