$userId]) ->findOrEmpty(); $user['channel'] = UserTerminalEnum::getTermInalDesc($user['channel']); // $user->sex = $user->getData('sex'); $user['qualification']=json_decode($user->qualification,true); $user['deposit_date'] = date('Y-m-d', $user['deposit_date']); if($user->is_contract==1){ $user['contract']=Contract::where(['type'=>2,'party_b'=>$userId])->with(['party_a_info','contractType'])->find(); } return $user->toArray(); } /** * @notes 更新用户信息 * @param array $params * @return User * @author 段誉 * @date 2022/9/22 16:38 */ public static function setUserInfo(array $params) { return User::update([ 'id' => $params['id'], 'nickname' => $params['nickname'], 'account' => $params['account'], 'mobile' => $params['account'], 'id_card' => $params['id_card'], 'channel' => 0, 'sex' => $params['sex'], 'province' => $params['province'], 'city' => $params['city'], 'area' => $params['area'], 'street' => $params['street'], 'village' => $params['village'], 'brigade' => $params['brigade'], 'address' => $params['address'], 'qualification' => json_encode($params['qualification']), 'company_id' => $params['company_id'], 'deposit' => $params['deposit'], 'deposit_date' => strtotime($params['deposit_date']), 'user_information_count' => $params['user_information_count'], 'register_num' => $params['register_num'], 'merchant_num' => $params['merchant_num'], 'trade_amount' => $params['trade_amount'], ]); } public static function editUser($params) { return User::update([ 'id' => $params['id'], 'nickname' => $params['nickname'], 'account' => $params['account'], 'mobile' => $params['account'], 'id_card' => $params['id_card'], 'avatar' => $params['avatar'], 'channel' => 0, 'sex' => $params['sex'], 'province' => $params['province'], 'city' => $params['city'], 'area' => $params['area'], 'street' => $params['street'], 'village' => $params['village'], 'brigade' => $params['brigade'], 'address' => $params['address'], 'qualification' => json_encode($params['qualification']), 'company_id' => $params['company_id'], 'deposit' => $params['deposit'], 'deposit_date' => strtotime($params['deposit_date']), 'user_information_count' => $params['user_information_count'], 'register_num' => $params['register_num'], 'merchant_num' => $params['merchant_num'], 'trade_amount' => $params['trade_amount'], 'update_time' => time() ]); } /** * @notes 调整用户余额 * @param array $params * @return bool|string * @author 段誉 * @date 2023/2/23 14:25 */ public static function adjustUserMoney(array $params) { Db::startTrans(); try { $user = User::find($params['user_id']); if (AccountLogEnum::INC == $params['action']) { //调整可用余额 $user->user_money += $params['num']; $user->save(); //记录日志 AccountLogLogic::add( $user->id, AccountLogEnum::UM_INC_ADMIN, AccountLogEnum::INC, $params['num'], '', $params['remark'] ?? '' ); } else { $user->user_money -= $params['num']; $user->save(); //记录日志 AccountLogLogic::add( $user->id, AccountLogEnum::UM_DEC_ADMIN, AccountLogEnum::DEC, $params['num'], '', $params['remark'] ?? '' ); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); return $e->getMessage(); } } public static function addUser($params) { // 手机号已被使用 $mobileUser = User::where(['account' => $params['account']])->find(); if (!empty($mobileUser)) { self::setError('手机号已被注册'); return false; } // $count = User::where('company_id', $params['company_id'])->count(); // $value = DictData::where('id', 28)->value('value'); // if ($count >= $value) { // self::setError('你创建的账号已达上限'); // return false; // } $group_id = $params['group_id']; // 每个公司市场部长只有1个 // if($group_id == 16) { // $marketManger = User::where(['group_id' =>$group_id,'company_id'=>$params['company_id']])->findOrEmpty(); // if (!$marketManger->isEmpty()) { // self::setError('公司已创建市场部长账号'); // return false; // } // } // 每个公司服务部长只有1个 // if($group_id == 14) { // $marketManger = User::where(['group_id' =>$group_id,'company_id'=>$params['company_id']])->findOrEmpty(); // if (!$marketManger->isEmpty()) { // self::setError('公司已创建服务部长账号'); // return false; // } // } $userSn = User::createUserSn(); $passwordSalt = Config::get('project.unique_identification'); $password = create_password(123456, $passwordSalt); if ($params['avatar'] != '') { $avatar = $params['avatar']; } else { $avatar = ConfigService::get('default_image', 'user_avatar'); } User::create([ 'sn' => $userSn, 'avatar' => $avatar, 'is_captain' => $group_id == 2? 1: 0, 'nickname' => $params['nickname'], 'account' => $params['account'], 'mobile' => $params['account'], 'id_card' => $params['id_card'], 'password' => $password, 'channel' => 0, 'sex' => $params['sex'], 'province' => $params['province'], 'city' => $params['city'], 'area' => $params['area'], 'street' => $params['street'], 'village' => $params['village'], 'brigade' => $params['brigade'], 'address' => $params['address'], 'qualification' => json_encode($params['qualification']), 'company_id' => $params['company_id'], 'group_id' => $group_id, 'deposit' => $params['deposit'], 'deposit_date' => strtotime($params['deposit_date']), 'user_information_count' => $params['user_information_count'], 'register_num' => $params['register_num'], 'merchant_num' => $params['merchant_num'], 'trade_amount' => $params['trade_amount'], 'invite_code' => generate_rand_code(10), ]); return true; } }