123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- require_once(BASE_HELPER_PATH . '/refill/util.php');
- use refill\util;
- class refill_detailControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $mod = Model('refill_detail');
- $condition = [];
- $_GET['query_start_time'] = $_GET['query_start_time'] ?? date("Y-m-d 00:00:00");
- $order_state_send = ORDER_STATE_SEND;
- $order_state_queue = ORDER_STATE_QUEUE;
- $order_state_handled = ORDER_STATE_HANDLED;
- $condition['order_state'] = ['in',"{$order_state_send},{$order_state_queue},{$order_state_handled}"];
- if(!empty($_GET['mchid'])) {
- $condition['mchid'] = $_GET['mchid'];
- }
- if(in_array($_GET['order_state'], [$order_state_send,$order_state_queue,$order_state_handled])) {
- $condition['order_state'] = $_GET['order_state'];
- }
- if (!empty($_GET['mch_orders'])) {
- $mch_orders = rtrim($_GET['mch_orders'],',');
- $condition['mch_order'] = ['in', $mch_orders];
- }
- $start_unixtime = intval(strtotime($_GET['query_start_time']));
- $end_unixtime = intval(strtotime($_GET['query_end_time']));
- if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
- $condition['order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- } elseif ($start_unixtime > 0) {
- $condition['order_time'] = ['egt', $start_unixtime];
- } elseif ($end_unixtime > 0) {
- $condition['order_time'] = ['lt', $end_unixtime];
- } else {
- $start = strtotime(date('Y-m-d', time()));
- $condition['order_time'] = ['egt', $start];
- }
- $merchants = [];
- $merchant_list = $this->merchants();
- foreach ($merchant_list as $value) {
- $merchants[$value['mchid']] = $value;
- }
- if($_GET['export'] == 1) {
- $this->RefillDetailExport($condition,$merchants);
- exit;
- }else{
- $list = $mod->getRefillDetailList($condition,200);
- $list = $this->DataFormat($list,$merchants);
- }
- Tpl::output('merchant_list', $merchants);
- Tpl::output('list', $list);
- Tpl::output('show_page', $mod->showpage());
- Tpl::showpage('refill.detail');
- }
- private function DataFormat($list,$merchants)
- {
- foreach ($list as $key => $value) {
- $params = json_decode($value['params'],true);
- $list[$key]['company_name'] = $merchants[$value['mchid']]['company_name'];
- $list[$key]['params'] = $params;
- if($value['order_state'] == ORDER_STATE_SEND) {
- $list[$key]['order_state_text'] = '待收货';
- } elseif ($value['order_state'] == ORDER_STATE_QUEUE) {
- $list[$key]['order_state_text'] = '队列中';
- } elseif ($value['order_state'] == ORDER_STATE_HANDLED) {
- $list[$key]['order_state_text'] = '已处理';
- } else {
- $list[$key]['order_state_text'] = '/';
- }
- }
- return $list;
- }
- private function RefillDetailExport($condition, $merchants)
- {
- $i = 0;
- $result = [];
- while (true) {
- $start = $i * 1000;
- $list = Model('')->table('refill_detail')->where($condition)->order('order_time desc')->limit("{$start},1000")->select();
- if (empty($list)) {
- break;
- }
- $i++;
- foreach ($list as $value) {
- $result[] = $value;
- }
- }
- $result = $this->DataFormat($result,$merchants);
- $this->createExcel($result);
- }
- private function createExcel($data = array())
- {
- Language::read('export');
- import('libraries.excel');
- $excel_obj = new Excel();
- $excel_data = array();
- //设置样式
- $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
- //header
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构编码');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构名称');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构单号');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值面值');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态');
- //data
- foreach ((array)$data as $v) {
- $tmp = array();
- $tmp[] = array('data' => $v['mchid']);
- $tmp[] = array('data' => $v['company_name']);
- $tmp[] = array('data' => $v['mch_order']);
- $tmp[] = array('data' => $v['params']['card_no']);
- $tmp[] = array('data' => $v['params']['amount']);
- $tmp[] = array('data' => date('Y-m-d H:i:s', $v['order_time']));
- $tmp[] = array('data' => $v['order_state_text']);
- $excel_data[] = $tmp;
- }
- $excel_data = $excel_obj->charset($excel_data, CHARSET);
- $excel_obj->addArray($excel_data);
- $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
- $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
- exit;
- }
- public function order_disposeOp()
- {
- $id = $_GET['id'];
- $type = $_GET['type'];
- $condition['detail_id'] = ['in',$id];
- $order_state_send = ORDER_STATE_SEND;
- $order_state_queue = ORDER_STATE_QUEUE;
- $condition['order_state'] = ['in',"{$order_state_send},{$order_state_queue}"];
- $refill_detail = Model('refill_detail')->where($condition)->select();
- $mod = Model('refill_order');
- foreach ($refill_detail as $detail)
- {
- $mchid = $detail['mchid'];
- $mch_order = $detail['mch_order'];
- Log::record("mchid: {$mchid} , mch_order: {$mch_order}", Log::DEBUG);
- $refill_order = $mod->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
- if (empty($refill_order))
- {
- Log::record("order dispose type:{$type}, params:{$detail['params']}",Log::DEBUG);
- $params = json_decode($detail['params'],true);
- if ($type == 'cancel') {
- //零元订单失败
- Log::record("cancel",Log::DEBUG);
- if ($detail['order_state'] == ORDER_STATE_SEND) {
- util::pop_queue_order($mchid, $mch_order);
- } elseif ($detail['order_state'] == ORDER_STATE_QUEUE) {
- util::push_add_zero($params);
- }
- }
- elseif ($type == 'anew') {
- //重新补充
- Log::record("anew",Log::DEBUG);
- util::push_add($params);
- } else {
- continue;
- }
- }
- else {
- util::pop_queue_order($mchid,$mch_order);
- }
- }
- showMessage('操作成功','index.php?act=refill_detail&op=index');
- }
- public function DelQueueOrderOp()
- {
- $id = $_GET['id'];
- $condition['detail_id'] = ['in',$id];
- $refill_detail = Model('refill_detail')->where($condition)->select();
- foreach ($refill_detail as $detail)
- {
- $mchid = $detail['mchid'];
- $mch_order = $detail['mch_order'];
- util::del_queue_order($mchid,$mch_order);
- }
- showMessage('操作成功','index.php?act=refill_detail&op=index');
- }
- }
|