DispatchTypeSet.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/10/13
  6. * Time: 9:56
  7. */
  8. namespace app\common\models;
  9. use app\framework\Database\Eloquent\Builder;
  10. class DispatchTypeSet extends BaseModel
  11. {
  12. public $table = 'yz_dispatch_type_set';
  13. protected $guarded = ['id'];
  14. public function scopeByDispatchTypeId(Builder $query, $dispatch_type_id = 0)
  15. {
  16. return $query->where('dispatch_type_id', $dispatch_type_id);
  17. }
  18. public static function relationSave($dispatchType, $data)
  19. {
  20. $set = self::byDispatchTypeId($dispatchType->id)->first();
  21. if (is_null($set)) {
  22. $set = new self();
  23. $data = array_merge(['enable'=> $dispatchType->enable, 'sort'=> $dispatchType->sort], $data);
  24. }
  25. $data['dispatch_type_id'] = $dispatchType->id;
  26. $data['uniacid'] = \YunShop::app()->uniacid;
  27. $set->fill($data);
  28. if ($set->save()) {
  29. return true;
  30. }
  31. return false;
  32. }
  33. public static function boot()
  34. {
  35. parent::boot(); // TODO: Change the autogenerated stub
  36. self::addGlobalScope(function(Builder $query){
  37. return $query->uniacid();
  38. });
  39. }
  40. }