OwnerReport.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App;
  3. use App\Traits\ModelTimeFormat;
  4. use Carbon\Carbon;
  5. use Illuminate\Database\Eloquent\Model;
  6. use App\Traits\ModelLogChanging;
  7. class OwnerReport extends Model
  8. {
  9. use ModelLogChanging;
  10. use ModelTimeFormat;
  11. protected $fillable = [
  12. "owner_id", //货主ID
  13. "counting_month", //结算月
  14. "daily_average_order_amount", //日均单量
  15. "to_business_quantity", //ToB单量
  16. "to_customer_quantity", //ToC单量
  17. "current_month_counting_area", //结算月盘点面积
  18. "last_month_counting_area", //结算月上月盘点面积
  19. "owner_bill_report_id" //账单ID
  20. ];
  21. public $timestamps = false;
  22. protected $appends=[
  23. "total"
  24. ];
  25. public function owner()
  26. { //货主
  27. return $this->hasOne(Owner::class,"id","owner_id");
  28. }
  29. public function ownerBillReport()
  30. { //账单
  31. return $this->hasOne(OwnerBillReport::class,"id","owner_bill_report_id");
  32. }
  33. /* 结算月格式转换,仅截取至月
  34. * 引用:CreateOwnerReport
  35. */
  36. public function getCountingMonthAttribute($value)
  37. {
  38. return substr($value,0,7);
  39. }
  40. public function getTotalAttribute()
  41. { //总单量
  42. return $this->to_business_quantity + $this->to_customer_quantity;
  43. }
  44. }