123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- <?php
- require_once(BASE_ROOT_PATH . '/mobile/control/merchantweb.php');
- class merchant_orderControl extends mbMerchantControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function listOp()
- {
- $model_vr_order = Model('refill_order');
- $cond['mchid'] = $this->mchid();
- $cond['inner_status'] = 0;
- if (!empty($_GET['card_type'])) {
- if(in_array($_GET['card_type'] , ['1' , '2' , '4' , '5' , '6'])) {
- $cond['refill_order.card_type'] = $_GET['card_type'];
- }
- if($_GET['card_type'] == 'oil') {
- $cond['refill_order.card_type'] = ['in' , ['1' , '2']];
- }
- if($_GET['card_type'] == 'phone') {
- $cond['refill_order.card_type'] = ['in' , ['4' , '5' , '6']];
- }
- }
- if (!empty($_GET['card_no'])) {
- $cond['refill_order.card_no'] = $_GET['card_no'];
- }
- if (!empty($_GET['refill_amount'])) {
- $cond['refill_order.refill_amount'] = $_GET['refill_amount'];
- }
- if (!empty($_GET['mch_order'])) {
- $cond['refill_order.mch_order'] = $_GET['mch_order'];
- }
- if (!empty($_GET['order_sn'])) {
- $cond['refill_order.order_sn'] = $_GET['order_sn'];
- }
- if (!empty($_GET['quality'])) {
- $cond['refill_order.quality'] = $_GET['quality'];
- }
- $start_unixtime = intval($_GET['start_time']);
- $end_unixtime = intval($_GET['end_time']);
- if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
- $cond['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- } elseif ($start_unixtime > 0) {
- $cond['refill_order.order_time'] = ['egt', $start_unixtime];
- } elseif ($end_unixtime > 0) {
- $cond['refill_order.order_time'] = ['lt', $end_unixtime];
- } else {
- $start = strtotime(date('Y-m-d', time()));
- $cond['refill_order.order_time'] = ['egt', $start];
- }
- if (in_array($_GET['order_state'], array('0', '30', '40'))) {
- $cond['vr_order.order_state'] = $_GET['order_state'];
- if($_GET['order_state'] == 30 && $_GET['time'] == 1){
- $cond['refill_order.order_time'] = ['lt', (time() - 3600)];
- }
- }
- $fields = 'refill_order.*,vr_order.order_state';
- $order_list = $model_vr_order->getMerchantOrderList($cond, $this->page, $fields, 'refill_order.order_time desc');
- $order_list = $this->merchant_order_format($order_list);
- $result['data'] = $order_list;
- $result['total'] = $model_vr_order->gettotalpage();
- return self::outsuccess($result);
- }
- public function OrderStatsOp()
- {
- if(empty($_GET['time_type']) || empty($_GET['start_time']) || empty($_GET['end_time'])) {
- return self::outerr(errcode::ErrInputParam, "参数错误.");
- }
- $cond['inner_status'] = 0;
- $time_type = $_GET['time_type'];
- if ($time_type == 'order_time') {
- $cond['order_time'] = ['time', [$_GET['start_time'], $_GET['end_time']]];
- }
- if ($time_type == 'notify_time') {
- $cond['notify_time'] = ['time', [$_GET['start_time'], $_GET['end_time']]];
- }
- if(empty($cond)) {
- return self::outerr(errcode::ErrInputParam, "筛选日期类型错误.");
- }
- $cond['mchid'] = $this->mchid();
- $stats = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(mch_amount) as mch_amounts, order_state')
- ->where($cond)->group('order_state')->select();
- $result['count'] = $result['sendCount'] = $result['errorCount'] = $result['successCount'] = $result['refill_amounts'] = $result['mch_amounts'] = 0;
- foreach ($stats as $stat) {
- $result['count'] += $stat['order_count'];
- if($stat['order_state'] == ORDER_STATE_SEND) {
- $result['sendCount'] = $stat['order_count'];
- }
- if($stat['order_state'] == ORDER_STATE_CANCEL) {
- $result['errorCount'] = $stat['order_count'];
- }
- if($stat['order_state'] == ORDER_STATE_SUCCESS) {
- $result['successCount'] = $stat['order_count'];
- $result['mch_amounts'] = $stat['mch_amounts'];
- $result['refill_amounts'] = $stat['refill_amounts'];
- }
- }
- return self::outsuccess($result);
- }
- private function merchant_order_format($orders)
- {
- $data = [];
- foreach ($orders as $order) {
- if($order['notify_time'] > 0)
- {
- $order['diff_time_text'] = $this->elapse_time($order['notify_time'] - $order['order_time']);
- $order['diff_time'] = $order['notify_time'] - $order['order_time'];
- }
- else
- {
- $order['diff_time_text'] = $this->elapse_time(time() - $order['order_time']);
- $order['diff_time'] = time() - $order['order_time'];
- }
- if (isset($order['order_time'])) {
- $order['order_time'] = date('Y-m-d H:i:s', $order['order_time']);
- }
- if (isset($order['notify_time'])) {
- $order['notify_time'] = date('Y-m-d H:i:s', $order['notify_time']);
- }
- if($order['is_retrying'] == 1) {
- $order['order_state'] = ORDER_STATE_SEND;
- }
- if ($order['order_state'] == ORDER_STATE_NEW || $order['order_state'] == ORDER_STATE_PAY) {
- $order['order_state'] = ORDER_STATE_SEND;
- }
- $order['order_state_text'] = $this->_orderState($order['order_state']);
- $order['card_type_name'] = $this->scard_type($order['card_type']);
- $data[] = $order;
- }
- return $data;
- }
- /**
- * 取得订单状态文字输出形式
- *
- * @param int $order_state 订单数组
- * @return string
- */
- private function _orderState($order_state)
- {
- switch ($order_state) {
- case ORDER_STATE_CANCEL:
- $text = '已取消';
- break;
- case ORDER_STATE_NEW:
- $text = '新订单';
- break;
- case ORDER_STATE_SEND:
- $text = '充值中';
- break;
- case ORDER_STATE_PAY:
- $text = '支付成功';
- break;
- case ORDER_STATE_SUCCESS:
- $text = '充值成功';
- break;
- case 'retrying':
- $text = '重试中';
- break;
- default:
- $text = '未知状态';
- }
- return $text;
- }
- private function scard_type(int $card_type)
- {
- if ($card_type == mtopcard\PetroChinaCard) { //中石油
- return '中石油';
- } elseif ($card_type == mtopcard\SinopecCard) { //中石化
- return '中石化';
- } elseif ($card_type == mtopcard\ChinaMobileCard) { //中国移动
- return '中国移动';
- } elseif ($card_type == mtopcard\ChinaUnicomCard) { //中国联通
- return '中国联通';
- } elseif ($card_type == mtopcard\ChinaTelecomCard) { //中国电信
- return '中国电信';
- } elseif ($card_type == mtopcard\ThirdRefillCard) { //中国电信
- return '增值业务';
- } else {
- return 'unknown';
- }
- }
- private function elapse_time($seconds)
- {
- $minutes = intval($seconds / 60);
- $second = intval($seconds % 60);
- if($minutes >= 60) {
- $minute = $minutes % 60;
- $hours = intval($minutes / 60);
- $result = "{$minute}:{$second}";
- }
- else {
- if($minutes > 0){
- $result = "{$minutes}:{$second}";
- }else{
- $result = "{$second}";
- }
- }
- if(isset($hours))
- {
- $result = "{$hours}:" . $result;
- }
- return $result;
- }
- public function OrderExportOp()
- {
- $model_vr_order = Model('refill_order');
- $cond['mchid'] = $this->mchid();
- $cond['inner_status'] = 0;
- if (!empty($_GET['card_type'])) {
- if(in_array($_GET['card_type'] , ['1' , '2' , '4' , '5' , '6'])) {
- $cond['refill_order.card_type'] = $_GET['card_type'];
- }
- if($_GET['card_type'] == 'oil') {
- $cond['refill_order.card_type'] = ['in' , ['1' , '2']];
- }
- if($_GET['card_type'] == 'phone') {
- $cond['refill_order.card_type'] = ['in' , ['4' , '5' , '6']];
- }
- }
- if (!empty($_GET['card_no'])) {
- $cond['refill_order.card_no'] = $_GET['card_no'];
- }
- if (!empty($_GET['refill_amount'])) {
- $cond['refill_order.refill_amount'] = $_GET['refill_amount'];
- }
- if (!empty($_GET['mch_order'])) {
- $cond['refill_order.mch_order'] = $_GET['mch_order'];
- }
- if (!empty($_GET['order_sn'])) {
- $cond['refill_order.order_sn'] = $_GET['order_sn'];
- }
- if (!empty($_GET['quality'])) {
- $cond['refill_order.quality'] = $_GET['quality'];
- }
- $start_unixtime = intval($_GET['start_time']);
- $end_unixtime = intval($_GET['end_time']);
- if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
- $cond['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- } elseif ($start_unixtime > 0) {
- $cond['refill_order.order_time'] = ['egt', $start_unixtime];
- } elseif ($end_unixtime > 0) {
- $cond['refill_order.order_time'] = ['lt', $end_unixtime];
- } else {
- $start = strtotime(date('Y-m-d', time()));
- $cond['refill_order.order_time'] = ['egt', $start];
- }
- if (in_array($_GET['order_state'], array('0', '30', '40'))) {
- $cond['vr_order.order_state'] = $_GET['order_state'];
- if($_GET['order_state'] == 30 && $_GET['time'] == 1){
- $cond['refill_order.order_time'] = ['lt', (time() - 3600)];
- }
- }
- $fields = 'refill_order.*,vr_order.order_state';
- $order_list = $model_vr_order->getMerchantOrderList($cond, '10000', $fields, 'refill_order.order_id desc');
- $order_list = $this->merchant_order_format($order_list);
- $result = $this->export_order_exec($order_list);
- return self::outsuccess($result);
- }
- private function export_order_exec($order_list)
- {
- $card_type = ['1'=>'中石油' , '2' =>'中石化' , '4' => '移动' , '5' => '联通' , '6' => '电信'];
- $datas = [];
- if(defined('COMPANY_NAME') && COMPANY_NAME === 'LZKJ_COMPANY') {
- $title = [
- ['value' => '代理商账号'],
- ['value' => '商品名称'],
- ['value' => '交易账号'],
- ['value' => '交易金额'],
- ['value' => '交易面值'],
- ['value' => '交易日期'],
- ['value' => '交易状态'],
- ['value' => '处理时间'],
- ['value' => '第三方流水']
- ];
- foreach ($order_list as $order) {
- $data = [];
- $official_sn = $order['official_sn'];
- $notify_time = $order['$notify_time'];
- if(empty($order['official_sn'])) {
- $official_sn = '';
- }
- if(empty($order['$notify_time'])) {
- $notify_time = '';
- }
- $data[] = ['value' => $order['mchid']];
- $data[] = ['value' => "{$card_type[$order['card_type']]}{$order['refill_amount']}元"];
- $data[] = ['value' => $order['card_no']];
- $data[] = ['value' => $order['mch_amount']];
- $data[] = ['value' => $order['refill_amount']];
- $data[] = ['value' => $order['order_time']];
- $data[] = ['value' => $order['order_state_text']];
- $data[] = ['value' => $notify_time];
- $data[] = ['value' => $official_sn];
- $datas[] = $data;
- }
- }
- else
- {
- $title = [
- ['value' => '商户号'],
- ['value' => '客户订单号'],
- ['value' => '平台单号'],
- ['value' => '面额'],
- ['value' => '充值卡号'],
- ['value' => '充值卡类型'],
- ['value' => '下单日期'],
- ['value' => '完成日期'],
- ['value' => '官方流水号'],
- ['value' => '订单状态'],
- ['value' => '扣款金额']
- ];
- foreach ($order_list as $order) {
- $data = [];
- $data[] = ['value'=>$order['mchid']];
- $data[] = ['value'=>$order['mch_order']];
- $data[] = ['value'=>$order['order_sn']];
- $data[] = ['value'=>$order['refill_amount']];
- $data[] = ['value'=>$order['card_no']];
- $data[] = ['value'=>$order['card_type_name']];
- $data[] = ['value'=>$order['order_time']];
- $data[] = ['value'=>$order['notify_time']];
- $data[] = ['value'=>$order['official_sn']];
- $data[] = ['value'=>$order['order_state_text']];
- $data[] = ['value'=>$order['mch_amount']];
- $datas[] = $data;
- }
- }
- return ['title' => $title , 'data' => $datas];
- }
- }
|