'array', ]; public function scopePaidStatus($query) { return $query->whereNotIn("pay_status", [self::UNPAIDSTATUS]); } public function scopeOwner($query, $user_id=null) { if ($user_id) { return $query->where('user_id', $user_id); } return $query; } public function scopeShop($query, $shop_id=null) { if ($shop_id) { return $query->where('shop_id', $shop_id); } return $query; } public function status() { return $this->hasMany(ShopOrderStatus::class, 'order_id', 'id'); } public function scopeStatus($query) { $pay_status = request()->pay_status; if ($pay_status) { return $query->where("pay_status", $pay_status); }else { return $query->where("pay_status", "<>", self::UNPAIDSTATUS); } // return $query; } public function scopeProblem($query) { $problem_status = request()->problem_status; if ($problem_status) { return $query->where("problem_status", $problem_status); } return $query; } public function scopeKeyword($query) { $keyword = request()->keyword; if ($keyword) { return $query->where(function ($sql) use ($keyword) { $sql->where("mobile", "like", "%$keyword%") ->orWhere("name", "like", "%$keyword%") ->orWhere("trade_no", "like", "%$keyword%") ->orWhereHas('shop', function ($query) use($keyword){ $query->where("title", 'like', "%$keyword%"); }); }); } return $query; } public function shop() { return $this->belongsTo(Shop::class, 'shop_id', 'id'); } public function user() { return $this->belongsTo(User::class, 'user_id', 'id'); } public function refundOrders() { return $this->hasMany(ShopRefundOrder::class, 'order_id', 'id'); } //介绍人 public function recommendUser() { return $this->hasOneThrough(User::class, RecommendUser::class, 'user_id', 'id', 'user_id', 'recommend_user_id')->selectRaw("ufutx_users.id, ufutx_users.name, ufutx_users.mobile"); } public function comments() { return $this->hasMany(ShopOrderComment::class, 'order_id', 'id'); } }