Store.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Agent\AgentDwbsUser;
  4. use App\Models\DwbsUser;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use Illuminate\Database\Eloquent\Model;
  7. use App\Models\DwbsWarea;
  8. use App\Models\DBUser;
  9. class Store extends Model
  10. {
  11. use SoftDeletes;
  12. protected $table='store';
  13. protected $guarded=[];
  14. public function user(){
  15. return $this->hasOne(DwbsUser::class,'id','user_id')->withTrashed();
  16. }
  17. public function warea(){
  18. return $this->hasOne(DwbsWarea::class,'id','warea_id');
  19. }
  20. public function dwuser(){
  21. return $this->belongsTo(DwbsUser::class,'user_id','id')->withTrashed();
  22. }
  23. public function users(){
  24. return $this->hasMany(User::class,'store_id','id');
  25. }
  26. public function order(){
  27. return $this->hasMany(Order::class,'store_id','id');
  28. }
  29. public function order_detail(){
  30. return $this->hasMany(OrderDetail::class,'store_id','id');
  31. }
  32. public function order_details(){
  33. return $this->hasMany(OrderDetail::class,'store_id','id')->whereHas('order',function($query){
  34. $query->where('is_pay',1);
  35. });
  36. }
  37. public function orderDetail(){
  38. return $this->belongsToMany(OrderDetail::class,'store_id','id');
  39. }
  40. public function comment(){
  41. return $this->hasMany(Comment::class,'store_id','id')->where('is_reply',1);
  42. }
  43. public static function getTest(){
  44. return [];
  45. }
  46. public function posts()
  47. {
  48. return $this->hasManyThrough(
  49. 'App\Models\OrderDetail',
  50. 'App\Models\Order',
  51. 'store_id', // 国家表外键...
  52. 'order_id', // 用户表外键...
  53. 'id', // 国家表本地键...
  54. 'id' // 用户表本地键...
  55. );
  56. }
  57. }