<?php
namespace app\common\model\store;
use think\Session;
use app\common\model\BaseModel;
class User extends BaseModel
{
protected $name = 'store_user';
public function wxapp()
{
$module = self::getCalledModule() ?: 'common';
return $this->belongsTo("app\\{$module}\\model\\Wxapp");
}
public function role()
{
return $this->belongsToMany('Role', 'StoreUserRole');
}
public static function checkExist($user_name)
{
return !!static::useGlobalScope(false)
->where('user_name', '=', $user_name)
->value('store_user_id');
}
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);
}
public function loginState($user)
{
$wxapp = $user['wxapp'];
Session::set('tpwe_admin', [
'user' => [
'store_user_id' => $user['store_user_id'],
'user_name' => $user['user_name'],
],
'wxapp' => $wxapp->toArray(),
'is_login' => true,
]);
}
}