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('用户不存在'); } if($user->work_status == 0 ){ throw new Exception('请先申请长期停单'); } if($user->work_status == 1 ){ throw new Exception('请等待长期停单审核'); } $user->is_disable = YesNoEnum::YES; $user->save(); return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } public static function stopWork(int $userId) { try { $user = MasterWorker::findOrEmpty($userId); if ($user->isEmpty()) { throw new \Exception('用户不存在'); } if($user->work_status == 1 ){ throw new Exception('请等待长期停单审核'); } if($user->work_status == 2 ){ throw new Exception('长期停单审核通过'); } $user->work_status = 1; $user->save(); return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } public static function detail($userId): array { $worker = MasterWorker::field('id,sn,avatar,real_avatar,real_name,nickname,account,mobile,sex,estimate_money,user_money,earnest_money,exp,worker_number,work_status,accept_order_status') ->findOrEmpty($userId) ->toArray(); //今日收益 $worker['account_today'] = MasterWorkerAccountLog::where(['worker_id'=> $worker['id'],'action'=>1,'change_type'=>WorkerAccountLogEnum::UM_INC_ADMIN])->whereTime('create_time', 'today')->sum('change_amount'); //本月成功订单 $worker['success_work'] = ServiceWork::where(['master_worker_id'=>$worker['id'],'service_status'=>3])->whereTime('create_time', 'month')->count(); //本月失败单 $worker['fail_work'] = ServiceWork::where(['master_worker_id'=>$worker['id'],'service_status'=>4])->whereTime('create_time', 'month')->count(); return $worker; } public static function setInfo(int $userId, array $params) { try { if ($params['field'] == "avatar" || $params['field'] == "real_avatar") { $params['value'] = FileService::setFileUrl($params['value']); } if($params['field'] == 'accept_order_status'){ //验证身份证信息是否审核通过 $idCard = MasterWorkerInfo::where(['worker_id'=>$userId])->findOrEmpty(); if ($idCard->isEmpty()) { throw new \Exception('请先完善身份证信息',20); } if($idCard->audit_state == 0){ throw new \Exception('身份证信息核验中,请等待核验完成',20); } if($idCard->audit_state == 1){ throw new \Exception('身份证信息核验不通过,请重新填写',20); } //验证银行卡信息是否审核通过 $bank = BankAccount::where(['worker_id'=>$userId])->findOrEmpty(); if ($bank->isEmpty()) { throw new \Exception('请先完善银行卡信息',21); } if($bank->audit_state == 0){ throw new \Exception('银行卡信息核验中,请等待核验完成',21); } if($bank->audit_state == 1){ throw new \Exception('银行卡信息核验不通过,请重新填写',21); } } return MasterWorker::update([ 'id' => $userId, $params['field'] => $params['value']] ); } catch (\Exception $e) { self::$error = $e->getMessage(); self::$returnCode = $e->getCode(); return false; } } }