OwnerPriceExpress.php 1.4 KB

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