OrderDetail.php 958 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class OrderDetail extends Model
  5. {
  6. protected $table='order_detail';
  7. protected $guarded=[];
  8. public function order(){
  9. return $this->belongsTo(Order::class,'order_no','order_no');
  10. }
  11. public function goods(){
  12. return $this->HasOne(Goods::class,'id','goods_id');
  13. }
  14. public function store(){
  15. return $this->hasOne(Store::class,'id','store_id');
  16. }
  17. public function getPriceAttribute($value){
  18. return round($value);
  19. }
  20. public function getAccountAttribute($value){
  21. return round($value);
  22. }
  23. public function user()
  24. {
  25. return $this->hasOneThrough(
  26. 'App\Models\DwbsUser',
  27. 'App\Models\Store',
  28. 'id', // 店铺表外键...
  29. 'id', // 表外键...
  30. 'store_id', // 详情表本地键...
  31. 'user_id' // 店铺表本地键...
  32. );
  33. }
  34. }