where("user_id", "like", "%" . $value . "%"); } } /** * 搜索器:用户优惠券卡券名字 * @param $value * @param $data */ public function searchCouponsIdAttr($query, $value, $data) { if ($value) { $id_arr = Coupons::where("name", "like", "%" . $value . "%")->column('id'); if ($id_arr) { $query->whereIn('coupons_id', $id_arr); } } } /** * 搜索器:用户优惠券卡券面值 * @param $value * @param $data */ public function searchNominalValueAttr($query, $value, $data) { $start = empty($value[0]) ? 0 : $value[0]; $end = empty($value[1]) ? 0 : $value[1]; $id_arr = []; if ($start > 0 && $end > 0) { $id_arr = Coupons::where([["nominal_value", "between", [$start, $end]]])->column('id'); } else if ($start > 0 && $end == 0) { $id_arr = Coupons::where([["nominal_value", ">=", $start]])->column('id'); } else if ($start == 0 && $end > 0) { $id_arr = Coupons::where([["nominal_value", "<=", $end]])->column('id'); } if ($id_arr) { $query->whereIn('coupons_id', $id_arr); } } /** * 搜索器:用户优惠券是否可用 * @param $value * @param $data */ public function searchIsShowAttr($query, $value, $data) { if ($value) { $query->where("is_show", $value); } } /** * 搜索器:用户优惠券创建时间 * @param $value * @param $data */ public function searchCreateTimeAttr($query, $value, $data) { $start = empty($value[0]) ? 0 : strtotime($value[0]); $end = empty($value[1]) ? 0 : strtotime($value[1]); if ($start > 0 && $end > 0) { $query->where([["create_time", "between", [$start, $end]]]); } else if ($start > 0 && $end == 0) { $query->where([["create_time", ">=", $start]]); } else if ($start == 0 && $end > 0) { $query->where([["create_time", "<=", $end]]); } } public function site() { return $this->hasOne(\app\model\site\Site::class, 'site_id', 'site_id'); } public function user() { return $this->hasOne(\addon\hygl\app\model\user\User::class, 'id', 'user_id'); } public function coupons() { return $this->hasOne(Coupons::class, 'id', 'coupons_id'); } // public function user(){ // return $this->hasOne(User::class, 'user_id', 'id')->joinType('left')->withField('name,id')->bind(['user_id_name'=>'name']); // } }