OwnerPriceLogistic.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Traits\ModelLogChanging;
  6. class OwnerPriceLogistic extends Model
  7. {
  8. use ModelLogChanging;
  9. protected $fillable = [
  10. "name", //名称
  11. "unit_range", //单价一区间
  12. "unit_id", //单位一ID
  13. "other_unit_range", //单位二区间
  14. "other_unit_id", //单位二ID
  15. "pick_up_price", //提货费
  16. "fuel_price", //燃油附加费
  17. "service_price", //信息服务费
  18. "operation", //操作
  19. "target_id", //目标ID
  20. "tax_rate_id", //税率
  21. ];
  22. public function getUnitRangeJsonAttribute()
  23. {
  24. return json_encode(explode(",",$this->unit_range));
  25. }
  26. public function getOtherUnitRangeJsonAttribute()
  27. {
  28. return json_encode(explode(",",$this->other_unit_range));
  29. }
  30. public function details()
  31. {
  32. return $this->hasMany(OwnerPriceLogisticDetail::class,"owner_price_logistic_id","id");
  33. }
  34. public function unit()
  35. { //单位一
  36. return $this->hasOne(Unit::class,"id","unit_id");
  37. }
  38. public function otherUnit()
  39. { //单位二
  40. return $this->hasOne(Unit::class,"id","other_unit_id");
  41. }
  42. public function owners()
  43. { //货主
  44. return $this->belongsToMany(Owner::class,"owner_price_logistic_owner","owner_price_logistic_id","owner_id");
  45. }
  46. public function logistics()
  47. { //物流
  48. return $this->belongsToMany(Logistic::class,"owner_price_logistic_logistic","owner_price_logistic_id","logistic_id");
  49. }
  50. public function taxRate()
  51. { //税率
  52. return $this->belongsTo(TaxRate::class);
  53. }
  54. public function getOwnerIdAttribute()
  55. { //获取货主ID数组
  56. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_logistic_owner WHERE owner_price_logistic_id = ?"),[$this->id]),"owner_id");
  57. }
  58. public function getLogisticIdAttribute()
  59. { //获取快递ID数组
  60. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_logistic_logistic WHERE owner_price_logistic_id = ?"),[$this->id]),"logistic_id");
  61. }
  62. }