| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace app\workerapi\logic;
- use app\common\enum\YesNoEnum;
- use app\common\logic\BaseLogic;
- use app\common\model\master_worker\MasterWorker;
- use think\facade\Config;
- /**
- * @author 林海涛
- * @date 2024/7/10 下午1:45
- */
- class MasterWorkerLogic extends BaseLogic
- {
- public static function changePassword(array $params, int $userId)
- {
- try {
- $user = MasterWorker::findOrEmpty($userId);
- if ($user->isEmpty()) {
- throw new \Exception('用户不存在');
- }
- // 密码盐
- $passwordSalt = Config::get('project.unique_identification');
- if (!empty($user['password'])) {
- if (empty($params['old_password'])) {
- throw new \Exception('请填写旧密码');
- }
- $oldPassword = create_password($params['old_password'], $passwordSalt);
- if ($oldPassword != $user['password']) {
- throw new \Exception('原密码不正确');
- }
- }
- // 保存密码
- $password = create_password($params['password'], $passwordSalt);
- $user->password = $password;
- $user->save();
- return true;
- } catch (\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- public static function changeMobile(array $params, int $userId)
- {
- try {
- $user = MasterWorker::findOrEmpty($userId);
- if ($user->isEmpty()) {
- throw new \Exception('用户不存在');
- }
- if($user->mobile == $params['mobile']){
- throw new \Exception('输入的手机号相同');
- }
- $where = [['mobile', '=', $params['mobile']]];
- $existUser = MasterWorker::where($where)->findOrEmpty();
- if (!$existUser->isEmpty()) {
- throw new \Exception('该手机号已被使用');
- }
- $user->mobile= $params['mobile'];
- $user->save();
- return true;
- } catch (\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- public static function logOff(int $userId)
- {
- try {
- $user = MasterWorker::findOrEmpty($userId);
- if ($user->isEmpty()) {
- throw new \Exception('用户不存在');
- }
- $user->is_disable = YesNoEnum::YES;
- $user->save();
- return true;
- } catch (\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- public static function detail($userId): array
- {
- return MasterWorker::field('id,sn,avatar,real_avatar,real_name,nickname,account,mobile,sex,estimate_money,user_money,earnest_money,exp')
- ->findOrEmpty($userId)
- ->toArray();
- }
- }
|