12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\admin\logic;
- use app\model\AdminModel;
- use app\model\AdminTokenModel;
- use app\model\CommonModel;
- use think\facade\Db;
- use think\response\Json;
- class CommonLogic extends BaseLogic
- {
- //登录
- public static function Logic(array $data = []): Json
- {
- $res = AdminModel::field(true)
- ->where(["is_del" => AdminModel::$del_normal, "username" => $data['username']])
- ->findOrEmpty();
- if ($res->isEmpty()) return json_show(CommonModel::$error_token, '该账户不存在');
- if ($res->status == AdminModel::$status_disable) return json_show(CommonModel::$error_token, '该账户已禁用');
- if (getPassword($data['password'], $res->salt) != $res->password) return json_show(CommonModel::$error_token, '账户密码错误');
- $token = makeToken($res->id, $data['username'], $res->salt);
- $userinfo = [
- "username" => $res->username,
- "nickname" => $res->nickname,
- "mobile" => $res->mobile,
- "role_id" => $res->role_id,
- 'token' => $token
- ];
- // write_log("账户{$account['username']}登录系统","","login","",0);
- return json_show(0, "登录成功", $userinfo);
- }
- //登出
- public static function logout(string $token = ''): Json
- {
- $info = AdminTokenModel::where(['token' => $token])->save(['token' => '', 'expiretime' => date('Y-m-d H:i:s')]);
- return $info ? json_show(CommonModel::$success, '登出成功') : json_show(CommonModel::$error_param, '登出失败');
- }
- //上传图片
- public static function upload($files): Json
- {
- $list = UploadImg($files);
- return (is_array($list) && !empty($list)) ? json_show(CommonModel::$success, '上传成功', $list) : json_show(CommonModel::$error_default, '上传失败');
- }
- //获取全部商品单位
- public static function unitAll(string $keyword = ''): Json
- {
- $where = [['is_del', '=', CommonModel::$del_normal]];
- if ($keyword != '') $where[] = ['unit', 'like', $keyword . '%'];
- $list = Db::name('unit')
- ->field('id unit_id,unit unit_title')
- ->where($where)
- ->order('id', 'desc')
- ->select()
- ->toArray();
- return json_show(CommonModel::$success, '获取全部商品单位成功', $list);
- }
- }
|