'电子卡', 2=>'实体卡']; const COUPON_CATEGORY = [1=>'兑换卡', 2=>'储值卡']; protected $name = 'user_coupon_detail'; /** * 兑换详细列表 * @param string $dataType 订单类型 * @param array $param * @return mixed */ public function getAllList(array $param = []) { // 检索查询条件 $filter = $this->getQueryFilter($param); // 获取数据列表 $query = $this->with([])->where($filter) ->leftJoin('user', 'user.user_id = detail.user_id') ->alias('detail') ->field('detail.*,user.mobile,user.nick_name'); $list = $query->order(['detail.id' => 'desc'])->paginate(15); foreach($list as $row){ $row->coupon_user = User::field('mobile,nick_name')->where("user_id",$row->coupon_user_id)->find(); $goodsku = GoodsSkuModel::where('goods_sku_id',$row->good_sku_id)->where('goods_id',$row->good_id)->find(); $goods = GoodsModel::field('goods_name')->where("goods_id",$row->good_id)->find(); $row->sku_name = $goodsku->goods_props[0]['value']['name']??''; $row->good_name = $goods->goods_name??''; } return $list; } //查询 public function getQueryFilter($param){ if($param['user_coupon_id']>0){ return $param; } } /** * 获取兑换明细列表 * @param int|null $limit 获取的数量 * @param bool $onlyReceive 只显示可领取 * @return \think\Collection * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getList(array $user_coupon_id_arr,int $limit = 15){ // 查询构造器 $query = $this->getNewQuery(); //查询数量 $limit > 0 && $query->limit($limit); $list = $query->where('user_coupon_id','in',$user_coupon_id_arr) ->order(['id' => 'desc']) ->select(); return $list; } }