|
@@ -37,7 +37,9 @@ class Account
|
|
|
|
|
|
//更新token
|
|
|
$token = Str::random(40, -1);
|
|
|
- $expire_time = date('Y-m-d H:i:s', time() + mt_rand(3600, 7200));
|
|
|
+
|
|
|
+ $expire_int = mt_rand(3600, 7200);
|
|
|
+ $expire_time = date('Y-m-d H:i:s', time() + $expire_int);
|
|
|
|
|
|
$rs = $db
|
|
|
->where($db->getPk(), $res[$db->getPk()])
|
|
@@ -63,15 +65,16 @@ class Account
|
|
|
'supplier_list' => $list,
|
|
|
];
|
|
|
|
|
|
- Cache::set(Config::get('redis_key.user_info_token') . $token, json_encode($info), $expire_time);
|
|
|
+ //过期时间指定一个具体的日期的时候,还没到这个日期缓存就过期了,指定一个秒数,可以符合预期,邪门儿
|
|
|
+ Cache::set(Config::get('redis_key.user_info_token') . $token, json_encode($info), $expire_int);
|
|
|
|
|
|
return json_show(0, '登录成功', $info);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
- //获取供应商下普通账号列表
|
|
|
- public static function geAccounttList(array $param = [])
|
|
|
+ //获取供应商账号列表
|
|
|
+ public static function getAccountList(array $param = [])
|
|
|
{
|
|
|
|
|
|
$db = new SupplierRelationUserModel();
|
|
@@ -85,11 +88,12 @@ class Account
|
|
|
]);
|
|
|
|
|
|
if ($param['keyword'] != '') $rs->whereLike('b.nickname|b.mobile', '%' . $param['keyword'] . '%');
|
|
|
+ if ($param['status'] != '') $rs->where('a.status', $param['status']);
|
|
|
|
|
|
$count = $rs->count('a.id');
|
|
|
|
|
|
$list = $rs
|
|
|
- ->field('a.id,b.uid,b.nickname,b.mobile,b.email,a.status')
|
|
|
+ ->field('a.id,b.uid,b.nickname,b.mobile,b.email,a.status,a.addtime,a.creater')
|
|
|
->order('a.addtime', 'desc')
|
|
|
->page($param['page'], $param['size'])
|
|
|
->select()
|
|
@@ -99,7 +103,7 @@ class Account
|
|
|
|
|
|
}
|
|
|
|
|
|
- //修改密码
|
|
|
+ //修改供应商账号密码
|
|
|
public static function changePassword(array $param = [])
|
|
|
{
|
|
|
|
|
@@ -124,14 +128,14 @@ class Account
|
|
|
$password = get_encryption_password($param['new_password']);
|
|
|
|
|
|
$rs = $db
|
|
|
- ->where($db->getPk(), $res[$db->getPk()])
|
|
|
+ ->where('uid', $res['uid'])
|
|
|
->save(['password' => $password['password'], 'salt' => $password['salt']]);
|
|
|
|
|
|
return $rs ? json_show(0, '修改密码成功') : json_show(1005, '修改密码失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
- //获取账号信息
|
|
|
+ //获取供应商账号账号信息
|
|
|
public static function readAccount(array $param = [])
|
|
|
{
|
|
|
$res = SupplierUser::field('uid,nickname,mobile,email')
|
|
@@ -158,9 +162,18 @@ class Account
|
|
|
}
|
|
|
|
|
|
//添加供应商账号
|
|
|
- public static function addAccount(array $param = [])
|
|
|
+ public static function addAccount(array $param = [], string $token = '')
|
|
|
{
|
|
|
|
|
|
+ $user = GetUserInfo($token);
|
|
|
+
|
|
|
+ //查找供应商名称
|
|
|
+ $supplierName = Db::name('supplier')
|
|
|
+ ->where(['code' => $param['supplierNo']])
|
|
|
+ ->value('name', '');
|
|
|
+
|
|
|
+ if ($supplierName == '') return json_show(1004, '该供应商名称不存在');
|
|
|
+
|
|
|
Db::connect('mysql_sys')->startTrans();
|
|
|
|
|
|
try {
|
|
@@ -186,6 +199,8 @@ class Account
|
|
|
'salt' => $password['salt'],//盐值
|
|
|
'status' => $db::$status_normal,
|
|
|
'is_del' => $db::$is_del_normal,
|
|
|
+ 'createrid' => $user['data']['user_id'] ?? 0,
|
|
|
+ 'creater' => $user['data']['nickname'] ?? '',
|
|
|
]);
|
|
|
|
|
|
$res->status = $db::$status_normal;
|
|
@@ -200,7 +215,8 @@ class Account
|
|
|
])->findOrEmpty()
|
|
|
->isEmpty();
|
|
|
|
|
|
- if (!$rs) $is_insert = false;//该关联关系已存在,无需新增
|
|
|
+ if ($rs) throw new Exception('不能重复添加');//该关联关系已存在,无需新增
|
|
|
+ else $is_insert = false;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -208,9 +224,11 @@ class Account
|
|
|
SupplierRelationUserModel::create([
|
|
|
'uid' => $res->uid,
|
|
|
'supplierNo' => $param['supplierNo'],
|
|
|
- 'supplierName' => $param['supplierName'],
|
|
|
+ 'supplierName' => $supplierName,
|
|
|
'status' => $res->status,
|
|
|
'is_del' => $db::$is_del_normal,
|
|
|
+ 'createrid' => $user['data']['user_id'] ?? 0,
|
|
|
+ 'creater' => $user['data']['nickname'] ?? '',
|
|
|
])->save();
|
|
|
}
|
|
|
|
|
@@ -227,62 +245,55 @@ class Account
|
|
|
public static function editAccount(array $param = [])
|
|
|
{
|
|
|
|
|
|
- Db::connect('mysql_sys')->startTrans();
|
|
|
+ $db = new SupplierUserModel();
|
|
|
|
|
|
- try {
|
|
|
+ $res = $db
|
|
|
+ ->field('uid')
|
|
|
+ ->where(['uid' => $param['uid'], 'is_del' => $db::$is_del_normal])
|
|
|
+ ->findOrEmpty()
|
|
|
+ ->isEmpty();
|
|
|
|
|
|
- $db = new SupplierUserModel();
|
|
|
+ if ($res) return json_show(1004, '该账号不存在');
|
|
|
|
|
|
- $res = $db
|
|
|
- ->where('is_del', $db::$is_del_normal)
|
|
|
- ->whereIn('mobile', [$param['mobile'], $param['old_mobile']])
|
|
|
- ->column('uid,status', 'mobile');
|
|
|
+ $rs = $db
|
|
|
+ ->where('uid', $param['uid'])
|
|
|
+ ->save($param);
|
|
|
|
|
|
- $is_insert = true;
|
|
|
- if (!isset($res[$param['mobile']])) {
|
|
|
- //新增账号
|
|
|
- $password = get_encryption_password(Config::get('app.default_password'));
|
|
|
- $res[$param['mobile']]['uid'] = $db->insertGetId([
|
|
|
- 'nickname' => $param['nickname'],//姓名
|
|
|
- 'mobile' => $param['mobile'],//手机号
|
|
|
- 'email' => $param['email'],//邮箱
|
|
|
- 'password' => $password['password'],//密码密文
|
|
|
- 'salt' => $password['salt'],//盐值
|
|
|
- 'status' => $db::$status_normal,
|
|
|
- 'is_del' => $db::$is_del_normal,
|
|
|
- ]);
|
|
|
+ return $rs ? json_show(0, '修改成功') : json_show(1005, '修改失败');
|
|
|
|
|
|
- $res[$param['mobile']]['status'] = $db::$status_normal;
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
+ //修改供应商账号状态
|
|
|
+ public static function statusAccount(array $param = [])
|
|
|
+ {
|
|
|
|
|
|
- $rs = SupplierRelationUserModel::field('id')
|
|
|
- ->where([
|
|
|
- 'is_del' => $db::$is_del_normal,
|
|
|
- 'uid' => $res[$param['mobile']]['uid'],
|
|
|
- 'supplierNo' => $param['supplierNo'],
|
|
|
- ])->findOrEmpty()
|
|
|
- ->isEmpty();
|
|
|
+ Db::connect('mysql_sys')->startTrans();
|
|
|
|
|
|
- if (!$rs) $is_insert = false;//该关联关系已存在,无需新增
|
|
|
+ try {
|
|
|
|
|
|
- }
|
|
|
+ $db = new SupplierUserModel();
|
|
|
|
|
|
- if ($is_insert) {
|
|
|
- SupplierRelationUserModel::create([
|
|
|
- 'uid' => $res[$param['mobile']]['uid'],
|
|
|
- 'supplierNo' => $param['supplierNo'],
|
|
|
- 'supplierName' => $param['supplierName'],
|
|
|
- 'status' => $res[$param['mobile']]['status'],
|
|
|
+ $res = $db
|
|
|
+ ->field('uid,status')
|
|
|
+ ->where([
|
|
|
+ 'uid' => $param['uid'],
|
|
|
'is_del' => $db::$is_del_normal,
|
|
|
- ])->save();
|
|
|
- }
|
|
|
- //把旧的账号的关联关系解除
|
|
|
+ ])->findOrEmpty();
|
|
|
+
|
|
|
+ if ($res->isEmpty()) throw new Exception('该账号不存在');
|
|
|
+ if ($res->status == $param['status']) throw new Exception('不能重复操作');
|
|
|
+
|
|
|
+ $db->where([
|
|
|
+ 'uid' => $param['uid'],
|
|
|
+ 'is_del' => $db::$is_del_normal,
|
|
|
+ ])->where('status', '<>', $param['status'])
|
|
|
+ ->save(['status' => $param['status']]);
|
|
|
+
|
|
|
SupplierRelationUserModel::where([
|
|
|
+ 'uid' => $param['uid'],
|
|
|
'is_del' => $db::$is_del_normal,
|
|
|
- 'uid' => $res[$param['old_mobile']]['uid'],
|
|
|
- 'supplierNo' => $param['supplierNo'],
|
|
|
- ])->save(['is_del' => $db::$is_del_deleted]);
|
|
|
+ ])->where('status', '<>', $param['status'])
|
|
|
+ ->save(['status' => $param['status']]);
|
|
|
|
|
|
Db::connect('mysql_sys')->commit();
|
|
|
return json_show(0, '操作成功');
|
|
@@ -293,8 +304,8 @@ class Account
|
|
|
|
|
|
}
|
|
|
|
|
|
- //修改供应商账号状态
|
|
|
- public static function statusAccount(array $param = [])
|
|
|
+ //删除供应商账号
|
|
|
+ public static function deleteAccount(int $uid = 0)
|
|
|
{
|
|
|
|
|
|
Db::connect('mysql_sys')->startTrans();
|
|
@@ -306,48 +317,26 @@ class Account
|
|
|
$res = $db
|
|
|
->field('uid')
|
|
|
->where([
|
|
|
+ 'uid' => $uid,
|
|
|
'is_del' => $db::$is_del_normal,
|
|
|
- 'mobile' => $param['mobile'],
|
|
|
])->findOrEmpty();
|
|
|
|
|
|
- if (!$res->isEmpty()) {
|
|
|
-
|
|
|
- $rs = SupplierRelationUserModel::field('id')->where([
|
|
|
- 'is_del' => $db::$is_del_normal,
|
|
|
- 'uid' => $res->uid,
|
|
|
- 'supplierNo' => $param['supplierNo'],
|
|
|
- ])
|
|
|
- ->where('status', '<>', $param['status'])
|
|
|
- ->findOrEmpty();
|
|
|
+ if ($res->isEmpty()) throw new Exception('该账号不存在或已删除');
|
|
|
|
|
|
- if ($rs->isEmpty()) throw new Exception('当前供应商账号未与当前供应商绑定或重复操作');
|
|
|
- else SupplierRelationUserModel::where('id', $rs->id)->save(['status' => $param['status']]);
|
|
|
+ $db->where('uid', $uid)
|
|
|
+ ->where('is_del', $db::$is_del_normal)
|
|
|
+ ->save(['is_del' => $db::$is_del_deleted]);
|
|
|
|
|
|
- } else throw new Exception('当前供应商账号不存在');
|
|
|
+ SupplierRelationUserModel::where('uid', $uid)
|
|
|
+ ->where('is_del', $db::$is_del_normal)
|
|
|
+ ->save(['is_del' => $db::$is_del_deleted]);
|
|
|
|
|
|
Db::connect('mysql_sys')->commit();
|
|
|
- return json_show(0, '操作成功');
|
|
|
+ return json_show(0, '删除成功');
|
|
|
} catch (Exception $exception) {
|
|
|
Db::connect('mysql_sys')->rollback();
|
|
|
- return json_show(1005, '操作失败,' . $exception->getMessage());
|
|
|
+ return json_show(1005, '删除失败,' . $exception->getMessage());
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //删除供应商账号
|
|
|
- public static function deleteAccount(array $param = [])
|
|
|
- {
|
|
|
-
|
|
|
- $where = [['is_del', '=', SupplierUserModel::$is_del_normal]];
|
|
|
-
|
|
|
- if (isset($param['supplierNo']) && $param['supplierNo'] != '') $where[] = ['supplierNo', '=', $param['supplierNo']];
|
|
|
- if (isset($param['id']) && $param['id'] != '') $where[] = ['id', '=', $param['id']];
|
|
|
-
|
|
|
- $res = SupplierRelationUserModel::where($where)
|
|
|
- ->save(['is_del' => SupplierUserModel::$is_del_deleted]);
|
|
|
-
|
|
|
- return $res ? json_show(0, '操作成功') : json_show(1005, '操作失败');
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|