1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?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" => CommonModel::$del_normal, "username" => $data['username']])
- ->findOrEmpty();
- if ($res->isEmpty()) return json_show(CommonModel::$error_token, '该账户不存在');
- if ($res->status == CommonModel::$status_disable) return json_show(CommonModel::$error_token, '该账户已禁用');
- if (get_password($data['password'], $res->salt) != $res->password) return json_show(CommonModel::$error_token, '账户密码错误');
- $token = make_token($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 = upload_img($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);
- }
- //获取省市区地址
- public static function getAddr(string $parent_code = ''): Json
- {
- $rs = Db::name('area')
- ->field('id,name,code,level')
- ->where('parent_code', $parent_code)
- ->select()
- ->toArray();
- return json_show(CommonModel::$success, '获取省市区地址成功', $rs);
- }
- }
|