'array', 'cert_ids' => 'array', ]; public static function boot() { parent::boot(); // self::created(function ($model) { // $area_ids = Area::where('type', '省级')->pluck('id'); // foreach ($area_ids as $area_id) { // $model->freights()->create([ // 'area_id' => $area_id, // ]); // } // }); } public function admins() { return $this->hasMany(Admin::class); } public function storage() { return $this->belongsTo(Storage::class)->withDefault(); } public function agency() { return $this->belongsTo(Agency::class)->withDefault(['name' => '未设置']); } //返回多图 public function getStoragesAttribute() { $list = Storage::whereIn('id', $this->storage_ids)->get(); return $list; } //返回多图 资质 public function getCertsAttribute() { $list = Storage::whereIn('id', $this->cert_ids)->get(); return $list; } //封面 public function cover() { return $this->belongsTo(Storage::class, 'cover_id', 'id')->withDefault(); } //微信二维码 public function wechat() { return $this->belongsTo(Storage::class, 'wechat_id', 'id')->withDefault(); } public function freights() { return $this->hasMany(Freight::class); } public function getGoodsFirst() { $goods = Goods::where('seller_id', $this->id) ->whereHas('params', function ($query) {return $query->where('stock', '>', 0)->where('status', 1);}) ->where('status', 1) ->orderBy('created_at', 'desc') ->first(); if ($goods) { return $goods->storage->path ?? ''; } else { return ''; } } public function goods() { return $this->hasMany(Goods::class); } public function orders() { return $this->hasMany(Order::class); } /** * 是否可删除 * @Author: * @Date:2018-11-30 * @return boolean */ public function canDel(): bool { return $this->status == 1 && count($this->orders) == 0 && count($this->goods) == 0 ? true : false; } /** * 是否可关闭 * @Author: * @Date:2018-11-30 * @return boolean */ public function canCancel(): bool { return $this->status == 1 && $this->goods()->where('status', 1)->count() == 0 ? true : false; } protected function getStatusTextAttribute() { return $this->status == 1 ? "正常" : "锁定"; } protected function getTypeTextAttribute() { switch ($this->type) { case 'organ': return '机构'; break; case 'seller': return '商家'; break; default: return '未知'; break; } } public function user() { return $this->belongsTo(User::class); } public function reports() { return $this->hasMany(WindupReport::class); } protected function getAllAddressAttribute() { return str_replace(",", "-", $this->Area->info) . '-' . $this->address; } public function Area() { return $this->belongsTo(OpenArea::class, 'area_sn', 'sn'); } public function Province() { return $this->belongsTo(OpenArea::class, 'province_sn', 'sn'); } public function category() { return $this->belongsTo(Category::class)->withDefault(); } public function lesson() { return $this->hasMany(SellerLesson::class); } public function getTitle() { return $this->name; } public function salesman() { return $this->belongsTo(User::class, 'salesman_id', 'id')->withDefault(); } //获取屏蔽分类id public function getTopCateIdAttribute() { $cateids = $this->lesson()->pluck('category_id')->toArray(); $parenids = []; if ($cateids) { foreach ($cateids as $key => $id) { $parenids[] = Category::findTop($id, 1); } } else { return []; } $findcateids = Category::whereIn('parent_id', $parenids)->OrwhereIn('id', $parenids)->pluck('id')->toArray(); return $findcateids; } //机构报课数 public function getLessonLogsCountAttribute() { $lessons = $this->lesson()->with(['logs'])->get(); return $lessons->sum('logs_count'); } }