OwnerPriceExpress.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\DB;
  5. class OwnerPriceExpress extends Model
  6. {
  7. protected $fillable = [
  8. "name", //名称
  9. "initial_weight", //首重
  10. "additional_weight",//续重
  11. ];
  12. public function owners()
  13. { //货主
  14. return $this->belongsToMany(Owner::class,"owner_price_express_owner","owner_price_express_id","owner_id");
  15. }
  16. public function logistics()
  17. { //物流
  18. return $this->belongsToMany(Logistic::class,"owner_price_express_logistic","owner_price_express_id","logistic_id");
  19. }
  20. public function details()
  21. { //计费详情
  22. return $this->hasMany(OwnerPriceExpressProvince::class,"owner_price_express_id","id");
  23. }
  24. public function getOwnerIdAttribute()
  25. { //获取货主ID数组
  26. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_express_owner WHERE owner_price_express_id = ?"),[$this->id]),"owner_id");
  27. }
  28. public function getLogisticIdAttribute()
  29. { //获取快递ID数组
  30. return array_column(DB::select(DB::raw("SELECT * FROM owner_price_express_logistic WHERE owner_price_express_id = ?"),[$this->id]),"logistic_id");
  31. }
  32. }