| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020/10/13
- * Time: 9:56
- */
- namespace app\common\models;
- use app\framework\Database\Eloquent\Builder;
- class DispatchTypeSet extends BaseModel
- {
- public $table = 'yz_dispatch_type_set';
- protected $guarded = ['id'];
- public function scopeByDispatchTypeId(Builder $query, $dispatch_type_id = 0)
- {
- return $query->where('dispatch_type_id', $dispatch_type_id);
- }
- public static function relationSave($dispatchType, $data)
- {
- $set = self::byDispatchTypeId($dispatchType->id)->first();
- if (is_null($set)) {
- $set = new self();
- $data = array_merge(['enable'=> $dispatchType->enable, 'sort'=> $dispatchType->sort], $data);
- }
- $data['dispatch_type_id'] = $dispatchType->id;
- $data['uniacid'] = \YunShop::app()->uniacid;
- $set->fill($data);
- if ($set->save()) {
- return true;
- }
- return false;
- }
- public static function boot()
- {
- parent::boot(); // TODO: Change the autogenerated stub
- self::addGlobalScope(function(Builder $query){
- return $query->uniacid();
- });
- }
- }
|