## 授权门店设置
>[info]功能:
1,显示数据:查询 `yf_shop_base` 授权门店表 显示授权门店
/*
*@desc 搜索
*/
public function scopeDefaultWhere($query)
{
parent::scopeDefaultWhere($query);
$wq = request_data('wq');
if($wq){
$query->whereHas("users",function($q) use($wq)
{
$q->where('ucenter_name', 'like', "%".$wq."%");
});
}
$shop_id = request_data('shop_id');
if($shop_id){
$query->where('id',$shop_id);
}
$in = \cs\login::login_user(1);
if($in){
$query->whereIn('id',$in);
}
}
>[info] 2,插入数据:新建授权门店 ,编辑数据:修改授权门店信息
/*
* @desc 保存表单数据
*
*/
static function saveForm(){
$data = post_data();
$max = users::where('id',$data['user_id'])->first();
if($max){
$max_stores = $max->yf_shop_base->count();
}else{
$max_stores = 0;
}
if($data['shop_num'] > $max['max_nums']){
exit(json_encode(['status'=>0,'msg'=>__('店员数不能超过授权账号最大店员数')]));
}
if($data['id']){
$data['updated'] = time();
$model = self::find($data['id']);
}else{
if($max_stores >= $max['max_stores']){
exit(json_encode(['status'=>0,'msg'=>__('已超出该账号的最大店铺数')]));
}
$data['created'] = time();
$model = new self;
}
$model->data($data)->save();
}
>[info]3,删除数据:删除门店 则此门店下 所有数据不能正常显示
/*
* @desc 删除表单数据
*/
static function deleteForm($id){
$model = self::where('id',$id);
$model->delete();
$shop_user = shop_users::where('yf_shop_base_id',$id);
$shop_user->delete();
$yf_goods_shop_common = yf_goods_shop_common::where('shop_id',$id);
$yf_goods_shop_common->delete();
}
>[info]4,关联`users` 授权账号表
/**
*@desc 用户
*/
public function users()
{
return $this->belongsTo('models\users','user_id','id');
}