OwnerPriceExpress.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Traits\ModelLogChanging;
  6. class OwnerPriceExpress extends Model
  7. {
  8. use ModelLogChanging;
  9. protected $fillable = [
  10. "name", //名称
  11. "initial_weight", //首重
  12. "additional_weight",//续重
  13. "operation", //操作
  14. "target_id", //目标ID
  15. "amount_interval", //数量区间
  16. "weight_interval", //重量区间
  17. "tax_rate_id", //税率
  18. ];
  19. protected $casts = [
  20. "amount_interval" => "array",
  21. "weight_interval" => "array"
  22. ];
  23. public function owners()
  24. { //货主
  25. return $this->belongsToMany(Owner::class,"owner_price_express_owner","owner_price_express_id","owner_id");
  26. }
  27. public function logistics()
  28. { //物流
  29. return $this->belongsToMany(Logistic::class,"owner_price_express_logistic","owner_price_express_id","logistic_id");
  30. }
  31. public function details()
  32. { //计费详情
  33. return $this->hasMany(OwnerPriceExpressProvince::class,"owner_price_express_id","id");
  34. }
  35. public function taxRate()
  36. { //税率
  37. return $this->belongsTo(TaxRate::class);
  38. }
  39. public function getOwnerIdAttribute()
  40. { //获取货主ID数组
  41. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_express_owner WHERE owner_price_express_id = ?"),[$this->id]),"owner_id");
  42. }
  43. public function getLogisticIdAttribute()
  44. { //获取快递ID数组
  45. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_express_logistic WHERE owner_price_express_id = ?"),[$this->id]),"logistic_id");
  46. }
  47. }