belongsTo("app\\{$module}\\model\\Wxapp"); } /** * 关联用户角色表表 * @return \think\model\relation\BelongsToMany */ public function role() { return $this->belongsToMany('Role', 'StoreUserRole'); } /** * 验证用户名是否重复 * @param $userName * @return bool */ public static function checkExist($userName) { return !!static::useGlobalScope(false) ->where('user_name', '=', $userName) ->where('is_delete', '=', 0) ->value('store_user_id'); } /** * 商家用户详情 * @param $where * @param array $with * @return static|null * @throws \think\exception\DbException */ public static function detail($where, $with = []) { !is_array($where) && $where = ['store_user_id' => (int)$where]; return static::get(array_merge(['is_delete' => 0], $where), $with); } /** * 保存登录状态 * @param $user * @throws \think\Exception */ public function loginState($user) { /** @var \app\common\model\Wxapp $wxapp */ $wxapp = $user['wxapp']; // 保存登录状态 Session::set('yoshop_store', [ 'user' => [ 'store_user_id' => $user['store_user_id'], 'user_name' => $user['user_name'], ], 'wxapp' => $wxapp->toArray(), 'is_login' => true, ]); } }