OwnerPriceExpress.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. ];
  18. protected $casts = [
  19. "amount_interval" => "array",
  20. "weight_interval" => "array"
  21. ];
  22. public function owners()
  23. { //货主
  24. return $this->belongsToMany(Owner::class,"owner_price_express_owner","owner_price_express_id","owner_id");
  25. }
  26. public function logistics()
  27. { //物流
  28. return $this->belongsToMany(Logistic::class,"owner_price_express_logistic","owner_price_express_id","logistic_id");
  29. }
  30. public function details()
  31. { //计费详情
  32. return $this->hasMany(OwnerPriceExpressProvince::class,"owner_price_express_id","id");
  33. }
  34. public function getOwnerIdAttribute()
  35. { //获取货主ID数组
  36. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_express_owner WHERE owner_price_express_id = ?"),[$this->id]),"owner_id");
  37. }
  38. public function getLogisticIdAttribute()
  39. { //获取快递ID数组
  40. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_express_logistic WHERE owner_price_express_id = ?"),[$this->id]),"logistic_id");
  41. }
  42. }