OwnerPriceExpress.php 1.3 KB

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