🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 员工账号设置 >[info] 功能: 1,显示数据:查询 `shop_users` 员工数据表 显示员工账号 /* *@desc 门店员工账号- 根据登录账号信息获取数据列表 * */ public function scopeDefaultWhere($query) { parent::scopeDefaultWhere($query); $in = \cs\login::login_user(1); if($in){ $query->whereIn('yf_shop_base_id',$in); } $wq = request_data('wq'); if($wq){ $query->where(function($query)use($wq){ $query->where('nickname', 'like', "%".$wq."%"); $query->orwhere('user', 'like', "%".$wq."%"); $query->orwhere('phone', 'like', "%".$wq."%"); }); } $query->orderby('created','desc'); $shop_id = request_data('shop_id'); if($shop_id){ $query->where('yf_shop_base_id',$shop_id); } } >[info] 2,插入数据:新建员工账号 ,编辑数据:修改员工账号信息 /* * @desc 开启事务 保存表单数据 * */ static function saveForm(){ try{ DB::transaction(function() { $data = post_data(); if($data['pwd']){ $data['pwd'] = password_hash($data['pwd'], PASSWORD_DEFAULT); } if($data['id']){ $info = login::recharge($data['user'],2,'shop_users',$data['id']); if($info == false && $data['user']){ exit(json_encode(['status'=>0,'msg'=>__('该账号已存在')])); } $num = self::where('yf_shop_base_id',$data['yf_shop_base_id']) ->where('id','!=',$data['id']) ->where('num' , '=' ,$data['num']) ->first(); if ($num ) { exit(json_encode(['status'=>0,'msg'=>'员工编号必须唯一'])); } $card = self::where('id','!=',$data['id']) ->where('id_card' , '=' ,$data['id_card']) ->first(); if ($card ) { exit(json_encode(['status'=>0,'msg'=>'该身份证号码已存在'])); } if(!$data['pwd']){ unset($data['pwd']); } $model = self::find($data['id']); }else{ $info = login::recharge($data['user'],1); if($info == false && $data['user']){ exit(json_encode(['status'=>0,'msg'=>__('该账号已存在')])); } if($data['yf_shop_base_id']){ $base = yf_shop_base::where('id',$data['yf_shop_base_id'])->first(); $shop_num = $base->shop_num; //允许的最大店员数 $shop_user_num = $base->shop_users->count(); //当前店员数 if($shop_user_num >= $shop_num){ exit(json_encode(['status'=>0,'msg'=>'员工账号添加失败,已超出最大店员数'])); } } //验证员工编号 $num = self::where('yf_shop_base_id',$data['yf_shop_base_id']) ->where('num',$data['num']) ->first(); if($num){ exit(json_encode(['status'=>0,'msg'=>'员工编号必须唯一'])); } $card = self::where('id_card',$data['id_card'])->first(); if($card){ exit(json_encode(['status'=>0,'msg'=>'该身份证号码已存在'])); } $data['created'] = time(); $model = new self; } $model->data($data)->save(); //插入到role_users表中 $role_all = new role_users; $role_info = $role_all->where('user_id','=',$model->id)->first(); if($role_info->id){ $wula = $role_all->find($role_info->id); }else{ $wula = $role_all; } $role_date['user_id'] = $model->id; $role_date['role_id'] = post_data('role_id'); $wula->data($role_date)->save(); }); }catch(Exception $e){ exit(json_encode(['status'=>0,'msg'=>__($e->getMessage())])); return false; } return true; } >[info]3,删除数据:删除员工账号 /* * @desc 删除表单数据 * */ static function deleteForm($id){ $model = self::where('id',$id); $model->delete(); } >[info] 4,关联`yf_shop_base` 员工账号表 员工账号隶属哪家门店 /** * @desc 获取所属店铺信息 */ public function yf_shop_base() { return $this->hasOne('models\yf_shop_base','id','yf_shop_base_id'); }