123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- declare (strict_types = 1);
- namespace app\model\system;
- use library\basic\BaseModel;
- use think\Model;
- /**
- * @mixin \think\Model
- */
- class Order extends BaseModel
- {
- /**
- * 获取列表数据
- * @param $page
- * @param $where
- * @param $pageCount
- * @param $desc
- */
- public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
- if($where['type'] == 1){
- $model = $this
- ->field(
- "o.*,p.store_name as pro_title,p.image as pro_img,m.mobile,m.avatar,
- (select count(*) from table_order_info where o_id = o.id) as order_count,
- (select count(*) from table_order_info where o_id = o.id and status = 2) as send_count,
- (SELECT title from table_express where id = o.express_id) as exp_name,
- (SELECT name from table_warehouse where id = o.warehouse_id) as ck_name"
- )
- ->alias("o")
- //->join('platform pf',"pf.id=o.platform_id")
- ->leftJoin('member m','m.uid=o.uid')
- ->leftJoin('product p',"p.id = o.pro_id")
- ->where('o.type',1);
- }else{
- $model = $this
- ->field("o.*,p.store_name as pro_title,a.image as pro_img,m.mobile,m.avatar,f.name,f.mobile,f.address,a.suk")
- ->alias("o")
- ->leftJoin('orderInfo f',"f.o_id=o.id")
- ->leftJoin('member m','m.uid=o.uid')
- ->leftJoin('product p',"p.id = o.pro_id")
- ->leftJoin('product_attr_value a',"a.product_id = o.pro_id and a.unique = o.unique")
- ->where('o.type',0);
- }
- $data = $model->when(!empty($where),function ($query) use($where){
- //用户
- if(!empty($where['uid'])) {
- $query->where('o.uid',$where['uid']);
- }
- //搜索订单
- if(!empty($where['order_id'])) {
- $query->whereLike('o.order_id',"%{$where['order_id']}%");
- }
- //搜索平台
- if(!empty($where['platform_id'])) {
- $query->whereLike('o.platform_id',$where['platform_id']);
- }
- //仓库
- if(!empty($where['warehouse_id'])) {
- $query->whereLike('o.warehouse_id',$where['warehouse_id']);
- }
- //搜索备注信息
- if(!empty($where['mono'])) {
- $query->whereLike('o.order_id',"%{$where['mono']}%");
- }
- //查询日期
- if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
- $query->whereTime('o.time','between',$where['data']);
- }
- //订单类型
- if(is_numeric($where['orderType'])) {
- $query->where('o.status',$where['orderType']);
- } else {
- $query->where('o.status','>',0);
- }
- //timeType[今日,昨日,最近7天,最近30天]
- if(!empty($where['timeType'])) {
- if($where['timeType'] == 'day') {
- $query->whereDay('o.time');
- }
- if($where['timeType'] == 'yesterday') {
- $query->whereDay('o.time','yesterday');
- }
- if($where['timeType'] == 'last7') {
- $query->whereTime('o.time','-7 day');
- }
- if($where['timeType'] == 'last30') {
- $query->whereTime('o.time','-30 day');
- }
- }
- })
- ->order($desc)
- ->paginate(['list_rows'=>$pageCount,'page'=>$page])
- ->toArray();
- //echo $this->getLastSql();exit;
- return [$data['total'],$data['data']];
- }
- /**
- * 获取推送数据
- * @param $page
- * @param array $where
- * @param int $pageCount
- * @param string $filed
- * @param string $desc
- * @return array
- */
- public function getPushList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
- $data = $this
- ->field(
- "o.*,p.store_name as pro_title,p.image as pro_img,m.mobile,m.avatar,
- (select count(*) from table_order_info where o_id = o.id) as order_count,
- (select count(*) from table_order_info where o_id = o.id and is_push = 1) as push_count,
- (SELECT title from table_express where id = o.express_id) as exp_name,
- (SELECT name from table_warehouse where id = o.warehouse_id) as ck_name"
- )
- ->alias("o")
- //->join('platform pf',"pf.id=o.platform_id")
- ->join('member m','m.uid=o.uid')
- ->leftJoin('product p',"p.id = o.pro_id")
- ->when(!empty($where),function ($query) use($where){
- //用户
- if(!empty($where['uid'])) {
- $query->where('o.uid',$where['uid']);
- }
- //搜索订单
- if(!empty($where['order_id'])) {
- $query->whereLike('o.order_id',"%{$where['order_id']}%");
- }
- //搜索平台
- if(!empty($where['platform_id'])) {
- $query->whereLike('o.platform_id',$where['platform_id']);
- }
- //仓库
- if(!empty($where['warehouse_id'])) {
- $query->whereLike('o.warehouse_id',$where['warehouse_id']);
- }
- //查询日期
- if(!empty($where['data']) && !empty($where['data'][0]) && !empty($where['data'][1])) {
- $query->whereTime('o.time','between',$where['data']);
- }
- //订单类型
- if(is_numeric($where['orderType'])) {
- $query->where('o.status',$where['orderType']);
- } else {
- $query->where('o.status','>',0);
- }
- })
- ->order($desc)
- ->paginate(['list_rows'=>$pageCount,'page'=>$page])
- ->toArray();
- //echo $this->getLastSql();exit;
- return [$data['total'],$data['data']];
- }
- }
|