OwnerPriceLogistic.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. ];
  21. public function getUnitRangeJsonAttribute()
  22. {
  23. return json_encode(explode(",",$this->unit_range));
  24. }
  25. public function getOtherUnitRangeJsonAttribute()
  26. {
  27. return json_encode(explode(",",$this->other_unit_range));
  28. }
  29. public function details()
  30. {
  31. return $this->hasMany(OwnerPriceLogisticDetail::class,"owner_price_logistic_id","id");
  32. }
  33. public function unit()
  34. { //单位一
  35. return $this->hasOne(Unit::class,"id","unit_id");
  36. }
  37. public function otherUnit()
  38. { //单位二
  39. return $this->hasOne(Unit::class,"id","other_unit_id");
  40. }
  41. public function owners()
  42. { //货主
  43. return $this->belongsToMany(Owner::class,"owner_price_logistic_owner","owner_price_logistic_id","owner_id");
  44. }
  45. public function logistics()
  46. { //物流
  47. return $this->belongsToMany(Logistic::class,"owner_price_logistic_logistic","owner_price_logistic_id","logistic_id");
  48. }
  49. public function getOwnerIdAttribute()
  50. { //获取货主ID数组
  51. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_logistic_owner WHERE owner_price_logistic_id = ?"),[$this->id]),"owner_id");
  52. }
  53. public function getLogisticIdAttribute()
  54. { //获取快递ID数组
  55. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_logistic_logistic WHERE owner_price_logistic_id = ?"),[$this->id]),"logistic_id");
  56. }
  57. }