### 控制器
***
开发指南将以实际业务出发来讲解如何进行开发,下面将以常用的订单管理来演示。
## 示例代码
```
<?php
/**
* +----------------------------------------------------------------------
* | 草帽支付系统 [ WE CAN DO IT JUST THINK ]
* +----------------------------------------------------------------------
* | Copyright (c) 2018 http://www.iredcap.cn All rights reserved.
* +----------------------------------------------------------------------
* | Licensed ( https://www.apache.org/licenses/LICENSE-2.0 )
* +----------------------------------------------------------------------
* | Author: Brian Waring <BrianWaring98@gmail.com>
* +----------------------------------------------------------------------
*/
namespace app\admin\controller;
use app\common\library\enum\CodeEnum;
class Orders extends BaseAdmin
{
/**
* 订单列表
*
* @author 勇敢的小笨羊 <brianwaring98@gmail.com>
*
* @return mixed
*/
public function index(){
$this->assign($this->logicOrders->getOrdersAllStat());
return $this->fetch();
}
/**
* 交易列表
*
* @author 勇敢的小笨羊 <brianwaring98@gmail.com>
*
*/
public function getList(){
//状态
$where['status'] = ['eq', $this->request->param('status','0')];
//组合搜索
!empty($this->request->param('trade_no|out_trade_no')) && $where['trade_no|out_trade_no']
= ['like', '%'.$this->request->param('trade_no').'%'];
!empty($this->request->param('uid')) && $where['uid']
= ['eq', $this->request->param('uid')];
!empty($this->request->param('channel')) && $where['channel']
= ['eq', $this->request->param('channel')];
//时间搜索 时间戳搜素
$where['create_time'] = $this->parseRequestDate();
$data = $this->logicOrders->getOrderList($where,true, 'create_time desc',false);
$count = $this->logicOrders->getOrdersCount($where);
$this->result($data || !empty($data) ?
[
'code' => CodeEnum::SUCCESS,
'msg'=> '',
'count'=>$count,
'data'=>$data
] : [
'code' => CodeEnum::ERROR,
'msg'=> '暂无数据',
'count'=>$count,
'data'=>$data
]
);
}
/**
* 获取详情
* 1.基本
* 2.回调
* 3.商户
* 4.结算
*
* @author 勇敢的小笨羊 <brianwaring98@gmail.com>
*
* @return mixed
*/
public function details(){
$where['id'] = $this->request->param('id','0');
//时间搜索 时间戳搜素
$where['create_time'] = $this->parseRequestDate();
$this->assign('order', $this->logicOrders->getOrderList($where));
return $this->fetch();
}
/**
* 退款列表
*
* @author 勇敢的小笨羊 <brianwaring98@gmail.com>
*
* @return mixed
*/
public function refund(){
$where = [];
//组合搜索
!empty($this->request->param('keywords')) && $where['trade_no|out_trade_no|uid|id']
= ['like', '%'.$this->request->param('keywords').'%'];
!empty($this->request->param('channel')) && $where['channel']
= ['eq', $this->request->param('channel')];
!empty($this->request->param('status')) && $where['status']
= ['eq', $this->request->param('status')];
$this->assign('list', $this->logicOrders->getOrderList($where));
return $this->fetch();
}
/**
* 商户订单统计
*
* @author 勇敢的小笨羊 <brianwaring98@gmail.com>
*
*/
public function user(){
return $this->fetch();
}
/**
* 商户交易统计
*
* @author 勇敢的小笨羊 <brianwaring98@gmail.com>
*
*/
public function userList(){
$where = [];
//组合搜索
!empty($this->request->param('uid')) && $where['uid']
= ['eq', $this->request->param('uid')];
//时间搜索 时间戳搜素
$where['create_time'] = $this->parseRequestDate();
$data = $this->logicOrders->getOrderUserStat($where);
//$this->result($data || !empty($data) ? [CodeEnum::SUCCESS,'',$data] : [CodeEnum::ERROR,'暂无数据','']);
$count = count($data);
$this->result($data || !empty($data) ?
[
'code' => CodeEnum::SUCCESS,
'msg'=> '',
'count'=>$count,
'data'=>$data
] : [
'code' => CodeEnum::ERROR,
'msg'=> '暂无数据',
'count'=>$count,
'data'=>$data
]
);
}
/**
* 商户渠道统计
*
* @author 勇敢的小笨羊 <brianwaring98@gmail.com>
*
*/
public function channel(){
return $this->fetch();
}
/**
* 商户渠道统计
*
* @author 勇敢的小笨羊 <brianwaring98@gmail.com>
*
*/
public function channelList(){
$where = [];
//组合搜索
!empty($this->request->param('cnl_id')) && $where['a.cnl_id']
= ['eq', $this->request->param('cnl_id')];
//时间搜索 时间戳搜素
$where['a.create_time'] = $this->parseRequestDate();
$data = $this->logicOrders->getOrderChannelStat($where);
$count = count($data);
$this->result($data || !empty($data) ?
[
'code' => CodeEnum::SUCCESS,
'msg'=> '',
'count'=>$count,
'data'=>$data
] : [
'code' => CodeEnum::ERROR,
'msg'=> '暂无数据',
'count'=>$count,
'data'=>$data
]
);
}
}
```