Logistic.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * @method static Builder orderBy(string $string, string $string1)
  7. */use App\Traits\ModelTimeFormat;
  8. use App\Traits\ModelLogChanging;
  9. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  10. use Illuminate\Database\Eloquent\SoftDeletes;
  11. class Logistic extends Model
  12. {
  13. use ModelLogChanging;
  14. use SoftDeletes;
  15. use ModelTimeFormat;
  16. protected $fillable = ['name','code',"type","mobile","remark","delivery_fee","is_bunched","english_name",'belong_company',"tag"];
  17. const TAGS=[
  18. 0 => "专线",
  19. 1 => "直发车",
  20. 2 => "德邦物流",
  21. ];
  22. static function nameById($id){
  23. $logistic=Logistic::where('id',$id)->first();
  24. return $logistic?$logistic['name']:'';
  25. }
  26. public function ownerPriceExpresses()
  27. {
  28. return $this->belongsToMany(OwnerPriceExpress::class,"owner_price_express_logistic","logistic_id","owner_price_express_id");
  29. }
  30. public function getTagAttribute($value):string
  31. {
  32. if ($value==="" || $value===null)return "";
  33. $tag = explode(",",$value);
  34. foreach ($tag as &$t)$t = self::TAGS[$t];
  35. return implode(",",$tag);
  36. }
  37. public function users():BelongsToMany
  38. { //用户
  39. return $this->belongsToMany(User::class,"logistic_user","logistic_id","user_id");
  40. }
  41. }