<?php
declare (strict_types = 1);

namespace app\model\system;

use Closure;
use library\basic\BaseModel;
use library\traits\JwtAuthModelTrait;
use library\traits\ModelTrait;
use think\Model;

/**
 * @mixin \think\Model
 */
class ExpCost extends BaseModel
{
    use ModelTrait;
    use JwtAuthModelTrait;
    //


    /**
     * 获取列表数据
     * @param $page
     * @param $where
     * @param $pageCount
     * @param $desc
     */
    public function getList2($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
        $data =  $this
            ->field("ec.*,s.name as site_name,e.title as exp_name,w.name as warehouse_name,ml.name as level_name,
                (SELECT money from table_exp_cost where sassid = 0 AND express_id = ec.express_id AND warehouse_id = ec.warehouse_id AND level_id = -1) as exp_money
            ")
            ->alias("ec")
            ->join('site s',"ec.sassid = s.sassid")
            ->join('express e',"e.id = ec.express_id")
            ->join('warehouse w',"w.id = ec.warehouse_id")
            ->leftJoin("member_level ml","ml.id = ec.level_id")
            ->when(!empty($where),function ($query) use($where){
                if(!empty($where['sassid'])) {
                    $query->where('ec.sassid',$where['sassid']);
                }
                if(!empty($where['level_id'])) {
                    $query->where('ec.level_id',$where['level_id']);
                }
            })
            ->order($desc)
            ->paginate(['list_rows'=>$pageCount,'page'=>$page])
            ->toArray();
        //echo $this->getLastSql();
        return [$data['total'],$data['data']];
    }
}
