|
@@ -0,0 +1,153 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\admin\logic;
|
|
|
+
|
|
|
+use app\admin\controller\Common;
|
|
|
+use app\model\AdminModel;
|
|
|
+use app\model\CommonModel;
|
|
|
+use think\exception\ValidateException;
|
|
|
+use think\facade\Config;
|
|
|
+use think\response\Json;
|
|
|
+
|
|
|
+class AdminLogic extends BaseLogic
|
|
|
+{
|
|
|
+ //获取运营账号列表
|
|
|
+ public static function list(array $data = []): Json
|
|
|
+ {
|
|
|
+ $db = AdminModel::alias('a')
|
|
|
+ ->leftJoin('role b', 'b.id=a.role_id')
|
|
|
+ ->where('a.is_del', CommonModel::$del_normal);
|
|
|
+
|
|
|
+ if ($data['username'] != '') $db->whereLike('a.username', '%' . $data['username'] . '%');
|
|
|
+ if ($data['nickname'] != '') $db->whereLike('a.nickname', '%' . $data['nickname'] . '%');
|
|
|
+ if ($data['mobile'] != '') $db->whereLike('a.mobile', '%' . $data['mobile'] . '%');
|
|
|
+ if ($data['status'] != '') $db->where('a.status', $data['status']);
|
|
|
+
|
|
|
+ $count = $db->count('a.id');
|
|
|
+
|
|
|
+ $list = $db->field('a.id,a.username,a.nickname,a.mobile,a.status,a.addtime,b.name as role_name')
|
|
|
+ ->order(['a.id' => 'desc'])
|
|
|
+ ->page($data['page'], $data['size'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ return json_show(CommonModel::$success, '获取运营账号列表成功', ['count' => $count, 'list' => $list]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加运营账号
|
|
|
+ public static function add(array $data = []): Json
|
|
|
+ {
|
|
|
+ $salt = randomkeys(6);
|
|
|
+ $data = array_merge($data, [
|
|
|
+ 'salt' => $salt,
|
|
|
+ 'password' => getPassword(Config::get('common.default_password'), $salt),
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'status' => CommonModel::$status_normal,
|
|
|
+ 'addtime' => date('Y-m-d H:i:s'),
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $rs = AdminModel::create($data)->save();
|
|
|
+
|
|
|
+ return $rs ? json_show(CommonModel::$success, '添加运营账号成功') : json_show(CommonModel::$error_param, '添加运营账号失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取运营账号详情
|
|
|
+ public static function read(int $id = 0): Json
|
|
|
+ {
|
|
|
+ $rs = AdminModel::where(['id' => $id, 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->withoutField('password,salt')
|
|
|
+ ->findOrEmpty()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ return json_show(CommonModel::$success, '获取运营账号详情成功', $rs);
|
|
|
+ }
|
|
|
+
|
|
|
+ //编辑运营账号
|
|
|
+ public static function edit(array $data = []): Json
|
|
|
+ {
|
|
|
+ $data = array_merge($data, [
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $rs = AdminModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])->save($data);
|
|
|
+
|
|
|
+ return $rs ? json_show(CommonModel::$success, '编辑运营账号成功') : json_show(CommonModel::$error_param, '编辑运营账号失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除运营账号
|
|
|
+ public static function delete(int $id = 0): Json
|
|
|
+ {
|
|
|
+
|
|
|
+ $rs = AdminModel::where(['id' => $id, 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->save([
|
|
|
+ 'is_del' => CommonModel::$del_deleted,
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $rs ? json_show(CommonModel::$success, '删除运营账号成功') : json_show(CommonModel::$error_param, '删除运营账号失败,该账号不存在或重复删除');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //启禁用运营账号
|
|
|
+ public static function status(array $data = []): Json
|
|
|
+ {
|
|
|
+ $data = array_merge($data, ['updatetime' => date('Y-m-d H:i:s')]);
|
|
|
+
|
|
|
+ $rs = AdminModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->where('status', '<>', $data['status'])
|
|
|
+ ->save($data);
|
|
|
+
|
|
|
+ return $rs ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$error_param, '操作失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //更改密码
|
|
|
+ public static function changePasswod(array $data = []): Json
|
|
|
+ {
|
|
|
+ $rs = AdminModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->field('id,password,salt,status')
|
|
|
+ ->findOrEmpty();
|
|
|
+
|
|
|
+ if ($rs->isEmpty()) throw new ValidateException('该运营账号不存在');
|
|
|
+ if (getPassword($data['old_password'], $rs->salt) != $rs->password) throw new ValidateException('旧密码错误');
|
|
|
+
|
|
|
+ $salt = randomkeys(6);
|
|
|
+ $password = getPassword($data['new_password'], $salt);
|
|
|
+
|
|
|
+ $da = [
|
|
|
+ 'salt' => $salt,
|
|
|
+ 'password' => $password,
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $rs = AdminModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->save($da);
|
|
|
+
|
|
|
+ return $rs ? json_show(CommonModel::$success, '更改密码成功') : json_show(CommonModel::$error_param, '更改密码失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //重置密码(慎用)
|
|
|
+ public static function resetPasswod(int $id = 0): Json
|
|
|
+ {
|
|
|
+ $rs = AdminModel::where(['id' => $id, 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->field('id')
|
|
|
+ ->findOrEmpty()
|
|
|
+ ->isEmpty();
|
|
|
+
|
|
|
+ if ($rs) throw new ValidateException('该运营账号不存在');
|
|
|
+
|
|
|
+ $salt = randomkeys(6);
|
|
|
+
|
|
|
+ $da = [
|
|
|
+ 'salt' => $salt,
|
|
|
+ 'password' => getPassword(Config::get('common.default_password'), $salt),
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $rs = AdminModel::where(['id' => $id, 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->save($da);
|
|
|
+
|
|
|
+ return $rs ? json_show(CommonModel::$success, '重置密码成功') : json_show(CommonModel::$error_param, '重置密码失败');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|