2020-04-25 22:20:29 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\model\store;
|
|
|
|
|
|
|
|
use think\Session;
|
|
|
|
use app\common\model\BaseModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 商家用户模型
|
|
|
|
* Class User
|
|
|
|
* @package app\common\model
|
|
|
|
*/
|
|
|
|
class User extends BaseModel
|
|
|
|
{
|
|
|
|
protected $name = 'store_user';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 关联微信小程序表
|
|
|
|
* @return \think\model\relation\BelongsTo
|
|
|
|
*/
|
|
|
|
public function wxapp()
|
|
|
|
{
|
|
|
|
$module = self::getCalledModule() ?: 'common';
|
|
|
|
return $this->belongsTo("app\\{$module}\\model\\Wxapp");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 关联用户角色表表
|
|
|
|
* @return \think\model\relation\BelongsToMany
|
|
|
|
*/
|
|
|
|
public function role()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany('Role', 'StoreUserRole');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 验证用户名是否重复
|
2020-04-25 22:34:57 +08:00
|
|
|
* @param $userName
|
2020-04-25 22:20:29 +08:00
|
|
|
* @return bool
|
|
|
|
*/
|
2020-04-25 22:34:57 +08:00
|
|
|
public static function checkExist($userName)
|
2020-04-25 22:20:29 +08:00
|
|
|
{
|
|
|
|
return !!static::useGlobalScope(false)
|
2020-04-25 22:34:57 +08:00
|
|
|
->where('user_name', '=', $userName)
|
2020-04-25 22:20:29 +08:00
|
|
|
->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,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|