123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace app\model\api;
- use app\model\system\ProductAttrValue;
- use library\basic\BaseModel;
- use think\Model;
- /**
- * @mixin \think\Model
- */
- class Order extends BaseModel
- {
- public function getUserOrderList($uid, $where){
- $list = $this->where('status', $where['type'])->where('uid', $uid)
- ->order('time DESC')->page((int)$where['page'], (int)$where['limit'])->select()->toArray();
- foreach ($list as $k =>$v){
- $list[$k]['_time'] = date('Y-m-d H:i:s', $v['time']);
- $product = ProductAttrValue::alias('a')->join('product s', 'a.product_id=s.id')
- ->where('a.product_id',$v['pro_id'])->where('a.unique',$v['unique'])->field('a.*,s.store_name')->find();
- if(!empty($product['store_name'])) {
- $list[$k]['store_name'] = $product['store_name'];
- }else{
- $list[$k]['store_name'] = '';
- }
- if(!empty($product['image'])) {
- $list[$k]['image'] = $product['image'];
- }else{
- $list[$k]['image'] = '';
- }
- if(!empty($product['suk'])) {
- $list[$k]['suk'] = $product['suk'];
- }else{
- $list[$k]['suk'] = '';
- }
- }
- return $list;
- }
- /**
- * 获取列表数据
- * @param $page
- * @param $where
- * @param $pageCount
- * @param $desc
- */
- public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = 'id desc'){
- $data = $this
- ->field("o.*,pf.name as platfrom_name,p.title as pro_title,p.img as pro_img"
- .",(select count(*) from table_order_info where o_id = o.id " .
- (empty($where['shop_id']) ? '' : (' AND shop_id='.$where['shop_id']) )
- . ") as order_count"
- )
- ->alias("o")
- ->join('platform pf',"pf.id=o.platform_id")
- ->when(!empty($where),function ($query) use($where){
- //分站
- if(!empty($where['sassid'])) {
- $query->where('o.sassid',$where['sassid']);
- }
- //店铺信息
- if(!empty($where['shop_id'])) {
- $query->whereRaw("(SELECT count(*) from table_order_info where o_id = o.id AND shop_id =:shop_id) > 0",
- ['shop_id'=>$where['shop_id']]);
- }
- //用户
- 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['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']);
- }
- //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');
- }
- }
- })
- ->leftJoin('product p',"p.id = o.pro_id")
- ->order($desc)
- ->paginate(['list_rows'=>$pageCount,'page'=>$page])
- ->toArray();
- //echo $this->getLastSql();
- return [$data['total'],$data['data']];
- }
- }
|