userInfo['user_status']) ? intval($this->userInfo['user_status']) : 0; $freezingChoose = isset($this->userInfo['freezing_choose']) ? intval($this->userInfo['freezing_choose']) : 0; if ($this->userInfo && $userStatus != 1) { if ($userStatus == -1) { showJson(1006, 1016, ['url' => 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg3ODEzNjMzMQ==&scene=124#wechat_redirect']); } $uncheck = input('uncheck', 0); $action = request()->action(); if (!in_array($action, ['getRecommendList']) && (($action == 'getInfo' || $action == 'getHomeInfo') && !$uncheck)) { showJson(1006, $freezingChoose > 0 ? 1020 + $freezingChoose : 1011, ['url' => url('/weixin/page/custom', '', '', true)]); } } } /** * 获取有用户信息 */ public function getInfo() { $type = input('type', 0); $id = input('id', 0); // 当前浏览的用户ID $userId = $this->userId; $cacheKey = "caches:member:temp:{$userId}_{$type}"; $memberInfo = PRedis::get($cacheKey); if($memberInfo){ showJson(1005, 1001, $memberInfo); } $memberInfo = Member::getInfo(['id' => $userId]); if ($type == 1) { Member::visitCount($this->userId, 'center'); } else if ($type == 8) { Member::visitCount($this->userId, 'home'); } // 冻结 $userStatus = isset($memberInfo['user_status']) ? intval($memberInfo['user_status']) : 0; if ((!in_array($type, [1, 8])) && $userStatus != 1 && $type != 1) { showJson(1006, 2102, ['url' => url('/weixin/page/custom', '', '', true)]); } // VIP有效状态和时间 $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0; $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0; $vipTime = isset($memberInfo['vip_time']) && $memberInfo['vip_time']? strtotime($memberInfo['vip_time']) : 0; $memberInfo['vip_type'] = 1; // 默认老VIP if($vipTime > strtotime('2022-04-20 00:00:00')){ $memberInfo['vip_type'] = 2; } if ($vipAuth && $vipExpire >= time()) { $memberInfo['vip_auth'] = 1; $memberInfo['vip_expire'] = date('Y-m-d', $vipExpire); if ($vipExpire <= time() + 86400 * 2) { $memberInfo['vip_expire_near'] = 1; } } else { $memberInfo['vip_auth'] = 0; $memberInfo['vip_expire'] = ''; $memberInfo['vip_expire_near'] = 0; } if ($memberInfo) { $memberInfo['avatar'] = $memberInfo['avatar'] ? cmf_get_image_preview_url($memberInfo['avatar']) : ''; if (isset($memberInfo['mobile'])) { $memberInfo['mobile'] = $memberInfo['mobile'] ? formatStr($memberInfo['mobile']) : ''; } if ($type == 1) { $memberInfo['collectCount'] = UserCollect::getUserCount($userId, $memberInfo['vip_auth']); $memberInfo['rechargeCount'] = Member::getRechargeCount($userId); $memberInfo['messageCount'] = Member::getMessageTotal($userId, ['type' => 1, 'status' => 2]); $memberInfo['accessCount'] = Member::getAccessCount($userId); } if ($type == 2) { $qrcodeData = Wechat::makeQrcode($userId, $userId); $memberInfo['qrcode'] = isset($qrcodeData['qrcode']) ? $qrcodeData['qrcode'] : ''; $memberInfo['invite_count'] = Member::getInviteCount($userId); $memberInfo['profile_complete'] = UserProfile::checkUserProfile($userId) ? 1 : 0; // $memberInfo['avatar'] = Wechat::loadImage($memberInfo['avatar'],'avatar'); } if($type == 1 || $type == 2){ $memberInfo['signed'] = 0; $showSign = PRedis::get("caches:signs:close:".$this->userId.'_'.date('Ymd')); $memberInfo['showSign'] = $showSign? 0 : 1; $signDay = isset($memberInfo['sign_day'])? $memberInfo['sign_day'] : 1; $signAt = isset($memberInfo['sign_at'])? $memberInfo['sign_at'] : ''; if($signDay && (empty($signAt) || $signAt <= date('Y-m-d', strtotime(date('Y-m-d')) - 86400))){ $memberInfo['sign_day'] = 0; $memberInfo['sign_at'] = ''; }else if($signDay && (empty($signAt) || $signAt >= date('Y-m-d'))){ $memberInfo['signed'] = 1; }else if($signDay && $signDay>=7 && $signAt <= date('Y-m-d')){ $memberInfo['sign_day'] = 0; $memberInfo['sign_at'] = ''; } } if ($type == 3) { $accountConfig = cmf_get_option('account_config'); $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0; $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1; $memberInfo['charge_rate'] = $chargeRate > 0 ? $chargeRate : 1; $memberInfo['min_recharge'] = $minRecharge ? $minRecharge : 1; $clearData = Member::getSignReadheart($userId); $signClear = isset($clearData['sign_clear'])? $clearData['sign_clear'] : 0; $signTotal = isset($clearData['sign_total'])? $clearData['sign_total'] : 0; $memberInfo['redheart_temp'] = $memberInfo['redheart']; // $memberInfo['redheart'] = $memberInfo['redheart']>$signClear? $memberInfo['redheart'] - $signClear : 0; $memberInfo['redheart_forever'] = $memberInfo['redheart']>$signTotal? $memberInfo['redheart'] - $signTotal : 0; $memberInfo['clearData'] = $clearData; } // 是否已经认证 if ($type == 2 || $type == 4 || $type == 1) { $field = 'idcard_check,education_check,position_check,wechat_code'; $authData = UserProfile::where(['userid' => $userId]) ->field($field) ->find(); $memberInfo['is_auth'] = 0; $memberInfo['idcard_check'] = isset($authData['idcard_check']) ? intval($authData['idcard_check']) : 0; $memberInfo['education_check'] = isset($authData['education_check']) ? intval($authData['education_check']) : 0; $memberInfo['position_check'] = isset($authData['position_check']) ? intval($authData['position_check']) : 0; $memberInfo['wechat_code'] = isset($authData['wechat_code']) ? $authData['wechat_code'] : ''; if ($memberInfo['idcard_check'] == 2 && $memberInfo['education_check'] == 2 && $memberInfo['position_check'] == 2) { $memberInfo['is_auth'] = 1; } } // 认证数据 if ($type == 5) { $field = 'idcard,front_idcard,back_idcard,idcard_fail,idcard_check,idcard_type,idcard_online_check'; $authData = UserProfile::where(['userid' => $userId]) ->field($field) ->find(); $authData = $authData ? $authData : []; $authData['realname'] = isset($memberInfo['real_name']) ? trim($memberInfo['real_name']) : ''; $authData['front_idcard_preview'] = isset($authData['front_idcard']) ? cmf_get_image_preview_url($authData['front_idcard']) : ''; $authData['back_idcard_preview'] = isset($authData['back_idcard']) ? cmf_get_image_preview_url($authData['back_idcard']) : ''; $authData['idcard_check'] = isset($authData['idcard_check']) ? $authData['idcard_check'] : 0; $memberInfo['authInfo'] = $authData; } if ($type == 6) { $field = 'graduate,education,education_img,education_fail,education_check,education_code,education_type'; $authData = UserProfile::where(['userid' => $userId]) ->field($field) ->find(); $authData['education_img_preview'] = isset($authData['education_img']) ? cmf_get_image_preview_url($authData['education_img']) : ''; $authData['education_check'] = isset($authData['education_check']) ? $authData['education_check'] : 0; $memberInfo['authInfo'] = $authData ? $authData : []; } if ($type == 7) { $field = 'company,occupation,position_img,position_fail,position_check,position_type,position_hide'; $authData = UserProfile::where(['userid' => $userId]) ->field($field) ->find(); $authData['position_img_preview'] = isset($authData['position_img']) ? cmf_get_image_preview_url($authData['position_img']) : ''; $authData['position_check'] = isset($authData['position_check']) ? $authData['position_check'] : 0; $memberInfo['authInfo'] = $authData ? $authData : []; } // 验证是否已经收藏过 $memberInfo['is_collect'] = 0; if ($id && UserCollect::checkCollect($userId, $id)) { $memberInfo['is_collect'] = 1; } // 收藏剩余有效时间 if (isset($memberInfo['collect_expire'])) { $memberInfo['collect_expire'] = intval($memberInfo['collect_expire']) - time(); $memberInfo['collect_expire'] = $memberInfo['collect_expire'] > 0 ? $memberInfo['collect_expire'] : 0; } if ($type == 8) { $accountConfig = cmf_get_option('account_config'); $contactPay = isset($accountConfig['contact_pay']) ? intval($accountConfig['contact_pay']) : 0; $contactPay = $contactPay ? $contactPay : 1; $memberInfo['contact_pay'] = $contactPay; $contactRefundPay = isset($accountConfig['apply_refund_pay']) ? intval($accountConfig['apply_refund_pay']) : 0; $contactRefundPay = $contactRefundPay ? $contactRefundPay : 3; $memberInfo['contact_refund_pay'] = $contactRefundPay; $siteConfig = cmf_get_option('site_info'); $contactTime = isset($siteConfig['contact_time']) ? intval($siteConfig['contact_time']) : 1; $contactTime = $contactTime ? $contactTime * 24 : 24; $memberInfo['contact_time'] = $contactTime; $regAward = isset($siteConfig['invite_award_redheart'])? $siteConfig['invite_award_redheart'] : 0; $idcardAward = isset($siteConfig['idcard_invite_award_redheart'])? $siteConfig['idcard_invite_award_redheart'] : 0; $educationAward = isset($siteConfig['education_invite_award_redheart'])? $siteConfig['education_invite_award_redheart'] : 0; $positionAward = isset($siteConfig['position_invite_award_redheart'])? $siteConfig['position_invite_award_redheart'] : 0; $memberInfo['share_invite_award'] = intval($regAward + $idcardAward + $educationAward + $positionAward); } if($type == 9){ $accountConfig = cmf_get_option('account_config'); $pay = isset($accountConfig['lock_access_pay']) ? intval($accountConfig['lock_access_pay']) : 0; $pay = $pay ? $pay : 1; $memberInfo['lock_access_pay'] = $memberInfo['vip_auth']==1? 0 : $pay; } } PRedis::set($cacheKey, $memberInfo, rand(2,5)); showJson(1005, 1001, $memberInfo); } /** * 注册完善资料 * @throws \think\Exception * @throws \think\exception\PDOException */ public function setProfile() { try { $params = input(); $userId = input('uid', 0); $validate = new MemberValidate(); if (!$validate->scene('reg')->check($params)) { showJson(1004, $validate->getError()); } $mobile = isset($params['mobile']) ? trim($params['mobile']) : ''; $code = isset($params['code']) ? trim($params['code']) : ''; $result = Sms::checkCode($mobile, $code); if (!$userId && $result !== true) { showJson(1004, $result); } if ($this->userId <= 1) { showJson(1004, 2009); } $sex = isset($params['sex']) ? intval($params['sex']) : 0; if (!in_array($sex, [1, 2])) { showJson(1004, 2023); } // 头像 $avatar = ''; $wxInfo = session('wxInfo'); $file = request()->file('image'); if ($file) { $fileData = Storage::uploadImg($file, 'avatar'); $avatar = isset($fileData['file']) ? $fileData['file'] : ''; } if (empty($avatar)) { showJson(1004, 3004); } $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : ''; $nowAddress = $nowAddress ? explode(' ', $nowAddress) : []; $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : ''; $homeAddress = $homeAddress ? explode(' ', $homeAddress) : []; $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0; $year = $birthday ? date('Y', $birthday) : 0; $age = $year ? date('Y', time()) - $year : 0; $profileData = [ 'userid' => $this->userId, 'height' => isset($params['height']) ? floatval($params['height']) : 0, 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0, 'age' => $age, 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '', 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '', 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '', 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '', 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '', 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '', 'married' => isset($params['married']) ? intval($params['married']) : 0, 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '', ]; Db::startTrans(); if (UserProfile::checkProfile($this->userId)) { $profileData['updated_at'] = date('Y-m-d H:i:s'); $res = UserProfile::saveData(['userid' => $this->userId], $profileData); } else { $res = UserProfile::insertGetId($profileData); } if (!$res) { Db::rollback(); showJson(1004, 2104); } $memberData = [ 'real_name' => isset($params['realname']) ? trim($params['realname']) : '', 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '', 'mobile' => $mobile, 'birthday' => $birthday, 'sex' => $sex, 'is_reg_profile' => 1, ]; if ($avatar) { $memberData['avatar'] = $avatar; } //PRedis::set('members:reg:info:' . $this->userId, $memberData, 3600); if (!Member::saveData(['id' => $this->userId], $memberData)) { Db::rollback(); showJson(1004, 2104); } // 操作日志 UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '完善信息注册']); Db::commit(); // 进入资源库(手机号注册) PoolModel::distribute(0, $this->userId, 4); // 更新缓存 $userInfo = Member::getInfo(['id' => $this->userId]); session('userInfo', $userInfo); showJson(1005, 1008); } catch (\Exception $exception) { PRedis::set('members:reg:error:' . $this->userId, $exception, 6 * 3600); showJson(1004, 2136); } } /** * 完善资料 * @throws \think\Exception * @throws \think\exception\PDOException */ public function setProfileTest() { try { $params = input(); $userId = input('uid', 0); $validate = new MemberValidate(); PRedis::set('members:reg:params:' . $this->userId, ['info' => $this->userInfo, 'params' => $params], 3600); if (!$validate->scene('reg')->check($params)) { showJson(1004, $validate->getError()); } $mobile = isset($params['mobile']) ? trim($params['mobile']) : ''; $code = isset($params['code']) ? trim($params['code']) : ''; $result = Sms::checkCode($mobile, $code); if (!$userId && $result !== true) { //showJson(1004, $result); } if (empty($this->userId)) { showJson(1004, 2009); } $sex = isset($params['sex']) ? intval($params['sex']) : 0; if (!in_array($sex, [1, 2])) { showJson(1004, 2023); } // 头像 $avatar = ''; $wxInfo = session('wxInfo'); $file = request()->file('image'); if ($file) { $fileData = Storage::uploadImg($file, 'avatar', false, false); if (!is_array($fileData)) { showJson(1004, $fileData ? $fileData : 3004); } $avatar = isset($fileData['file']) ? $fileData['file'] : ''; } if (empty($avatar)) { showJson(1004, 3004); } PRedis::set('members:reg:params2:' . $this->userId, $params, 3600); $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : ''; $nowAddress = $nowAddress ? explode(' ', $nowAddress) : []; $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : ''; $homeAddress = $homeAddress ? explode(' ', $homeAddress) : []; $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0; $year = $birthday ? date('Y', $birthday) : 0; $age = $year ? date('Y', time()) - $year : 0; $profileData = [ 'userid' => $this->userId, 'height' => isset($params['height']) ? floatval($params['height']) : 0, 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0, 'age' => $age, 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '', 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '', 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '', 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '', 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '', 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '', 'married' => isset($params['married']) ? intval($params['married']) : 0, 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '', ]; PRedis::set('members:reg:params3:' . $this->userId, $params, 3600); Db::startTrans(); PRedis::set('members:reg:profile:' . $this->userId, $profileData, 3600); if (UserProfile::checkProfile($this->userId)) { $profileData['updated_at'] = date('Y-m-d H:i:s'); $res = UserProfile::saveData(['userid' => $this->userId], $profileData); } else { $res = UserProfile::insertGetId($profileData); } if (!$res) { Db::rollback(); showJson(1004, 2104); } $memberData = [ 'real_name' => isset($params['realname']) ? trim($params['realname']) : '', 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '', 'mobile' => $mobile, 'birthday' => $birthday, 'sex' => $sex, 'is_reg_profile' => 1, ]; if ($avatar) { $memberData['avatar'] = $avatar; } PRedis::set('members:reg:info:' . $this->userId, $memberData, 3600); if (!Member::saveData(['id' => $this->userId], $memberData)) { Db::rollback(); showJson(1004, 2104); } showJson(1005, 1008); exit; // 操作日志 UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '完善信息注册']); Db::commit(); // 更新缓存 $userInfo = Member::getInfo(['id' => $this->userId]); session('userInfo', $userInfo); showJson(1005, 1008); } catch (\Exception $exception) { PRedis::set('members:reg:error:' . $this->userId, $exception, 6 * 3600); showJson(1004, 2136); } } /** * 保存资料 */ public function saveInfo() { $params = input(); $validate = new MemberValidate(); if (!$validate->scene('info')->check($params)) { showJson(1004, $validate->getError()); } $newMobile = isset($params['mobile']) ? trim($params['mobile']) : ''; $mobile = isset($this->userInfo['mobile']) ? $this->userInfo['mobile'] : ''; if ($newMobile && $newMobile != $mobile) { $code = isset($params['code']) ? trim($params['code']) : ''; $result = Sms::checkCode($newMobile, $code); if ($result !== true) { showJson(1004, $result); } // 验证手机号码是否被使用 $id = Member::where(['mobile' => $newMobile])->value('id'); if ($id && $id != $this->userId) { showJson(1004, 2001); } } $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : ''; $nowAddress = $nowAddress ? explode(' ', $nowAddress) : []; $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : ''; $homeAddress = $homeAddress ? explode(' ', $homeAddress) : []; $birthday = isset($params['birthday']) ? strtotime($params['birthday']) : 0; $year = $birthday ? date('Y', $birthday) : 0; $age = $year ? date('Y', time()) - $year : 0; $info = [ 'userid' => $this->userId, 'age' => $age, 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0, 'height' => isset($params['height']) ? floatval($params['height']) : 0, 'salary' => isset($params['salary']) ? intval($params['salary']) : 0, 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '', 'education' => isset($params['education']) ? intval($params['education']) : 0, 'company' => isset($params['company']) ? trim($params['company']) : '', 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '', 'property' => isset($params['property']) ? intval($params['property']) : 0, 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '', 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '', 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '', 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '', 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '', 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '', 'married' => isset($params['married']) ? intval($params['married']) : 0, 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '', 'qq' => isset($params['qq']) ? trim($params['qq']) : '', ]; Db::startTrans(); if (UserProfile::checkProfile($this->userId)) { $profileData['updated_at'] = date('Y-m-d H:i:s'); $res = UserProfile::saveData(['userid' => $this->userId], $info); } else { $res = UserProfile::insertGetId($info); } if (!$res) { Db::rollback(); showJson(1004, 2104); } $memberData = [ 'real_name' => isset($params['realname']) ? trim($params['realname']) : '', 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '', 'birthday' => $birthday, 'sex' => isset($params['sex']) ? intval($params['sex']) : 0, ]; if ($newMobile && $mobile != $newMobile) { $memberData['mobile'] = $newMobile; } if (!Member::saveData(['id' => $this->userId], $memberData)) { Db::rollback(); showJson(1004, 2104); } Db::commit(); showJson(1005, 2029); } /** * 获取资料 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getProfile() { $info = []; $type = input('type', 1); switch ($type) { case 1: $photolistArr = []; $photolist = UserProfile::where(['userid' => $this->userId])->value('photolist'); $photolists = $photolist ? explode(',', $photolist) : []; $info['photolist'] = $photolist ? $photolist : ''; foreach ($photolists as $k => $val) { $photolistArr[$k]['file'] = $val; $photolistArr[$k]['preview'] = $val ? cmf_get_image_preview_url($val) : ''; } $info['photolists'] = $photolistArr; break; default: $field = 'userid,introduce,introduce_img,brief,brief,family,family_img,hobby,hobby_img,purpose,purpose_img,cause,cause_img,expect,tags,expect_img'; $info = UserProfile::where(['userid' => $this->userId])->field($field)->find(); $info = $info ? $info->toArray() : []; if (isset($info['introduce_img'])) { $info['introduce_img_preview'] = $info['introduce_img'] ? cmf_get_image_preview_url($info['introduce_img']) : ''; } if (isset($info['family_img'])) { $info['family_img_preview'] = $info['family_img'] ? cmf_get_image_preview_url($info['family_img']) : ''; } if (isset($info['hobby_img'])) { $info['hobby_img_preview'] = $info['hobby_img'] ? cmf_get_image_preview_url($info['hobby_img']) : ''; } if (isset($info['purpose_img'])) { $info['purpose_img_preview'] = $info['purpose_img'] ? cmf_get_image_preview_url($info['purpose_img']) : ''; } if (isset($info['cause_img'])) { $info['cause_img_preview'] = $info['cause_img'] ? cmf_get_image_preview_url($info['cause_img']) : ''; } if (isset($info['expect_img'])) { $info['expect_img_preview'] = $info['expect_img'] ? cmf_get_image_preview_url($info['expect_img']) : ''; } if (isset($info['tags'])) { $info['tags'] = $info['tags'] ? explode(',', $info['tags']) : []; } break; } showJson(1005, 1008, $info); } /* * 头像 * */ public function setAvatar() { $avatar = ''; $file = request()->file('image'); if ($file) { $fileData = Storage::uploadImg($file, 'avatar'); $avatar = isset($fileData['file']) ? $fileData['file'] : ''; } if (empty($avatar)) { showJson(1004, 3007); } // 保存 $idcardCheck = UserProfile::where(['userid' => $this->userId])->value('idcard_check'); $oldAvatar = Member::where(['id' => $this->userId])->value('avatar'); $data = $idcardCheck == 2? ['avatar_confirm'=> $avatar,'avatar_confirm_status'=> 2] : ['avatar' => $avatar,'avatar_confirm_status'=> 1]; if (!Member::saveData(['id' => $this->userId], $data)) { showJson(1004, 2030); } if ($idcardCheck != 2 && file_exists('upload/' . $oldAvatar)) { @unlink('upload/' . $oldAvatar); $paths = explode('_', basename($oldAvatar)); $filename = end($paths); $filename = 'upload/' . dirname($oldAvatar) . '/' . $filename; if ($filename && file_exists($filename)) { @unlink($filename); } } showJson(1005, $idcardCheck==2? 2051 : 2050); } /** * 保存资料 */ public function saveProfile() { $info = []; $img = input('img', ''); $params = input(); // 需要先完成身份认证 if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } // 学历证明照片 $file = request()->file('image'); if ($file) { $fileData = Storage::uploadImg($file, 'profile'); $img = isset($fileData['file']) ? $fileData['file'] : ''; $oldImg = isset($params['img']) ? $params['img'] : ''; if ($img && $oldImg) { @unlink('upload/' . $oldImg); } } if (isset($params['photolist'])) { $info['photolist'] = trim($params['photolist']); } if (isset($params['introduce'])) { $info['introduce'] = trim($params['introduce']); $info['introduce_img'] = $img; } if (isset($params['family'])) { $info['family'] = trim($params['family']); $info['family_img'] = $img; } if (isset($params['hobby'])) { $info['hobby'] = trim($params['hobby']); $info['hobby_img'] = $img; } if (isset($params['purpose'])) { $info['purpose'] = trim($params['purpose']); $info['purpose_img'] = $img; } if (isset($params['cause'])) { $info['cause'] = trim($params['cause']); $info['cause_img'] = $img; } if (isset($params['expect'])) { $info['expect'] = trim($params['expect']); $info['expect_img'] = $img; } // 标签 if (isset($params['tags'])) { $info['tags'] = trim($params['tags']); } if (!UserProfile::saveData(['userid' => $this->userId], $info)) { showJson(1004, 2030); } // 奖励 UserProfile::profileAward($this->userId); showJson(1005, 2029); } /** * 获取主页信息 */ public function getHomeInfo() { $id = input('id', 0); $cid = input('cid', 0); $type = input('type', 1); // 基础信息 $userId = $id ? $id : $this->userId; $myInfo = Member::getHomeInfo($userId, '', $type); // 访问记录 $isHeart = isset($myInfo['is_heart'])? $myInfo['is_heart'] : 0; $status = isset($myInfo['user_status'])? $myInfo['user_status'] : 0; $profileReg = isset($myInfo['is_reg_profile'])? $myInfo['is_reg_profile'] : 0; if($myInfo && ($isHeart==1 && $status ==1 && $profileReg==1) && $type == 4){ Member::makeUserAccess($userId, $this->userId); } $cUserInfo = []; $cInfo = []; if ($cid <= 0 && $id) { $cid = UserContactLog::where(['user_id' => $this->userId, 'contact_uid' => $id]) ->where('status', 'in', [1, 2, 3]) ->value('id'); if ($cid <= 0) { $cid = UserContactLog::where(['contact_uid' => $this->userId, 'user_id' => $id]) ->where('status', 'in', [1, 2, 3]) ->value('id'); } } if ($cid > 0) { // 认识记录 $cInfo = UserContactLog::where(['id' => $cid])->where('status', 'in', [1, 2, 3])->field('id,user_id,contact_uid,is_read,status')->find(); $cUid = isset($cInfo['contact_uid']) ? intval($cInfo['contact_uid']) : 0; $status = isset($cInfo['status']) ? intval($cInfo['status']) : 0; if ($cUid) { // 被申请方查看,更新申请微信阅读状态 if ($cUid == $this->userId) { UserContactLog::where(['id' => $cid])->update(['is_read' => 1]); } // 想认识的人的信息 $field = 'm.id,m.user_nickname,m.avatar,m.real_name,up.wechat_code,up.qq'; $cUserInfo = Member::getHomeInfo($cUid, $field, 2); // 未确认认识的不展示联系方式 if ($status != 2 && $cUserInfo) { $cUserInfo['wechat_code'] = ''; $cUserInfo['qq'] = ''; } } } //PRedis::set('test:' . $userId, ['homeInfo' => $myInfo, 'cUserInfo' => $cUserInfo, 'cInfo' => $cInfo], 600); showJson(1005, 1008, ['homeInfo' => $myInfo, 'cUserInfo' => $cUserInfo, 'cInfo' => $cInfo]); } /** * 单身推荐列表 */ public function getRecommendList() { $params = input(); $pageSize = input('pageSize', 12); $type = input('type', 1); $uid = input('uid', 0); $refresh = input('refresh', false); $userId = $uid ? $uid : $this->userId; if ($type == 1) { $params['user_id'] = $userId; $dataList = Member::getRecommendList($params, $pageSize); Member::visitCount($userId, 'match'); } else { $dataList = Member::getHeartList($userId, '', $refresh); Member::visitCount($userId, 'heart'); } showJson(1005, 1001, $dataList); } /** * 获取首页置顶列表 */ public function getTopList(){ $params = input(); $pageSize = input('pageSize', 12); $type = input('type', 1); $params['user_id'] = $this->userId; $dataList = Member::getTopList($params, $pageSize); showJson(1005, 1001, $dataList); } /** * 设置隐私 */ public function setPrivacy() { $type = input('type', 1); $value = input('value', 0); $reset = input('reset', 0); if (!in_array($type, [1, 2, 3])) { showJson(1004, 2129); } $types = [1 => 'show_graduate', 2 => 'show_company']; if ($type == 3) { if ($value == 1) { if(!UserProfile::checkUserProfile($this->userId)){ showJson(1006,2045, ['url'=> Wechat::makeRedirectUrl(url('/weixin/member/profile','','',true))]); } Member::where(['id' => $this->userId, 'user_type' => 2]) ->update(['is_heart' => 1]); // 操作日志 UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "取消隐身模式"]); showJson(1005, 2036); } // 扣除爱心账户 $accountConfig = cmf_get_option('account_config'); $hiddenPay = isset($accountConfig['hidden_pay']) ? intval($accountConfig['hidden_pay']) : 0; $hiddenPay = $hiddenPay ? $hiddenPay : 10; $memberInfo = Member::where(['id' => $this->userId, 'user_type' => 2])->field('redheart,vip_auth,vip_expire,is_heart,invisible_time')->find(); $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0; $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0; $isVip = $vipAuth && $vipExpire>=time()? true : false; $isHeart = isset($memberInfo['is_heart']) ? intval($memberInfo['is_heart']) : 0; $invisibleTime = isset($memberInfo['invisible_time']) ? intval($memberInfo['invisible_time']) : 0; if ($reset != 1 && $invisibleTime >= time() - 7 * 24 * 3600) { showJson(1004, lang($isVip? 'invisible_vip' : 'invisible', ['num'=> $hiddenPay,'date' => date('Y-m-d', $invisibleTime)])); } if ($isHeart == 2 && $value == 0) { showJson(1004, 2034); } // 扣除爱心隐身 Db::startTrans(); if ($reset == 1 && !$isVip) { $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0; if ($redheart < $hiddenPay) { showJson(1004, 2137); } if (!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $hiddenPay)) { Db::rollback(); showJson(1004, 2031); } // 账户明细 $accountData = [ 'user_id' => $this->userId, 'type' => 2, 'account_type' => 1, 'change_type' => 2, 'money' => $hiddenPay, 'balance' => $redheart, 'remark' => "付费设置隐身模式【{$this->userId}】扣除{$hiddenPay}个爱心", 'created_at' => date('Y-m-d H:i:s'), 'status' => 2, ]; PRedis::set('accounts:privacy:' . $this->userId, $accountData, 600); if (!AccountLog::insertGetId($accountData)) { Db::rollback(); return false; } } // 更新设置隐身模式 Member::where(['id' => $this->userId, 'user_type' => 2]) ->update(['is_heart' => 2, 'invisible_time' => time()]); // 操作日志 UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "设置隐身模式"]); Db::commit(); showJson(1005, 2035); } else { $field = $types[$type]; if (!UserProfile::saveData(['userid' => $this->userId], [$field => $value])) { showJson(1004, 2131); } } showJson(1005, 2130); } /** * 设置微信号 */ public function setWechat(){ $params = input(); $validate = new MemberValidate(); if (!$validate->scene('wechat')->check($params)) { showJson(1004, $validate->getError()); } // 验证 $this->checkUser(); if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } $cacheKey = "cache:wechat:account:{$this->userId}"; if(PRedis::get($cacheKey)){ showJson(1004, 2049); } $wechatCode = input('wechat_code',''); if(UserProfile::where(['userid'=> $this->userId])->update(['wechat_code'=>$wechatCode,'updated_at'=>date('Y-m-d H:i:s')])){ PRedis::set($cacheKey, ['params'=> $params], 300); showJson(1005, 2047); }else{ showJson(1004,2048); } } /** * 关注用户 */ public function collect() { // 验证 $this->checkUser(); if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } $id = input('id'); $opType = input('type', 1); $result = Member::collect($this->userId, $id, $opType); if ($result === true) { showJson(1005, $opType == 1 ? 2106 : 2108); } else { showJson(1004, $result); } } /** * 获取关注用户/收藏活动列表 */ public function getCollectList() { $params = input(); $pageSize = input('pageSize', 12); $type = input('type', 1); $dataList = []; if ($type == 1) { $dataList = UserCollect::getUserList($this->userId, $params, $pageSize); } else if ($type == 2) { $dataList = UserCollect::getFollowUserList($this->userId, $params, $pageSize); } showJson(1005, 1001, $dataList); } /** * 获取申请微信消息列表 */ public function getMessageList() { $params = input(); $pageSize = input('pageSize', 12); $dataList = Member::getMessageList($this->userId, $params, $pageSize); showJson(1005, 1001, $dataList); } /** * 获取申请微信消息详情 */ public function getMessageInfo() { $id = input('id', 0); $info = Member::getMessageInfo($id, $this->userId); showJson(1005, 1001, $info); } /** * 认证 */ public function authSubmit() { // 验证 $this->checkUser(); $params = input(); $scene = isset($params['scene']) ? trim($params['scene']) : ''; $scene = in_array($scene, ['idcard', 'education', 'position']) ? $scene : 'idcard'; $validate = new MemberValidate(); if (!$validate->scene($scene)->check($params)) { showJson(1004, $validate->getError()); } if ($scene != 'idcard' && UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } // 处理 switch ($scene) { case 'idcard': // 身份证认证 $idcard = isset($params['idcard']) ? trim($params['idcard']) : ''; $realname = isset($params['realname'])? trim($params['realname']) : ''; $profileData = [ 'idcard' => $idcard, 'front_idcard' => isset($params['front_idcard']) ? trim($params['front_idcard']) : '', 'back_idcard' => isset($params['back_idcard']) ? trim($params['back_idcard']) : '', 'idcard_type' => isset($params['idcard_type']) ? intval($params['idcard_type']) : 1, 'idcard_check' => 1, ]; // 验证身份证号是否被使用 $checkId = UserProfile::where(['idcard' => $idcard]) ->where('userid', 'not in', $this->userId) ->value('id'); if ($checkId) { showJson(1004, 2128); } // 身份证照片 if (empty($profileData['front_idcard'])) { showJson(1004, 2024); } if (empty($profileData['back_idcard'])) { showJson(1004, 2025); } Db::startTrans(); if (!Member::saveData(['id' => $this->userId], ['real_name' => $realname])) { Db::rollback(); showJson(1004, 2026); } // 在线验证是否通过 $profileData['idcard_online_check'] = 0; if (UserProfile::checkProfile($this->userId)) { $profileData['updated_at'] = date('Y-m-d H:i:s'); $res = UserProfile::saveData(['userid' => $this->userId], $profileData); } else { $res = UserProfile::insertGetId($profileData); } if (!$res) { Db::rollback(); showJson(1004, 2026); } // 操作日志 UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交身份证认证']); Db::commit(); showJson(1005, 2027); break; case 'education': // 学历认证 $educationType = isset($params['education_type']) ? intval($params['education_type']) : 0; $profileData = [ 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '', 'education' => isset($params['education']) ? trim($params['education']) : '', 'education_img' => isset($params['education_img']) ? trim($params['education_img']) : '', 'education_code' => isset($params['education_code']) ? trim($params['education_code']) : '', 'education_type' => $educationType, 'education_check' => 1, ]; $siteInfo = cmf_get_site_info(); $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用'; // 学历证明照片 if ($educationType != 2){ $file = request()->file('image1'); if ($file) { $fileData = Storage::uploadImg($file, 'education_img'); $educationImg = isset($fileData['file']) ? $fileData['file'] : ''; $profileData['education_img'] = $waterTxt ? Storage::imageWater($educationImg, $waterTxt) : $educationImg; } if (empty($profileData['education_img'])) { showJson(1004, 2028); } } Db::startTrans(); if (UserProfile::checkProfile($this->userId)) { $profileData['updated_at'] = date('Y-m-d H:i:s'); $res = UserProfile::saveData(['userid' => $this->userId], $profileData); } else { $res = UserProfile::insertGetId($profileData); } if (!$res) { Db::rollback(); showJson(1004, 2026); } // 操作日志 UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交学历认证']); Db::commit(); showJson(1005, 2027); break; case 'position': // 职位认证 $profileData = [ 'company' => isset($params['company']) ? trim($params['company']) : '', 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '', 'position_img' => isset($params['position_img']) ? trim($params['position_img']) : '', 'position_type' => isset($params['position_type']) ? intval($params['position_type']) : 0, 'position_hide' => isset($params['position_hide']) ? intval($params['position_hide']) : 0, 'position_check' => 1, ]; $siteInfo = cmf_get_site_info(); $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用'; // 职位证明照片 $file = request()->file('image1'); if ($file) { $fileData = Storage::uploadImg($file, 'position_img', false, false); $positionImg = isset($fileData['file']) ? $fileData['file'] : ''; $profileData['position_img'] = $waterTxt ? Storage::imageWater($positionImg, $waterTxt) : $positionImg; } //PRedis::set('test:auth:' . $this->userId, ['file' => $file, 'data' => $fileData, 'profile' => $profileData], 600); if (empty($profileData['position_img'])) { showJson(1004, 2033); } Db::startTrans(); if (UserProfile::checkProfile($this->userId)) { $profileData['updated_at'] = date('Y-m-d H:i:s'); $res = UserProfile::saveData(['userid' => $this->userId], $profileData); } else { $res = UserProfile::insertGetId($profileData); } if (!$res) { Db::rollback(); showJson(1004, 2026); } // 操作日志 UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交职业认证']); Db::commit(); showJson(1005, 2027); break; } showJson(1004, 2009); } /** * 在线认证 */ public function authCheck(){ // 验证 $this->checkUser(); $params = input(); $validate = new MemberValidate(); if (!$validate->scene('idcard')->check($params)) { showJson(1004, $validate->getError()); } // 验证身份证号是否被使用 $idcard = isset($params['idcard'])? trim($params['idcard']) : ''; $checkId = UserProfile::where(['idcard' => $idcard]) ->where('userid', 'not in', $this->userId) ->whereIn('idcard_check',[1,2]) ->value('id'); if ($checkId) { showJson(1004, 2128); } $result = ZimFace::check($this->userId,$params); $data = isset($result['result'])? $result['result'] : []; $code = isset($result['code']) && $result['code']? $result['code'] : 'error'; $msg = isset($result['msg']) && $result['msg']? $result['msg'] : '验证错误'; showJson($code, $msg, $data); } /** * 加入怦然心动 */ public function joinHeart() { // 验证 $this->checkUser(); if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } if (!UserProfile::checkUserProfile($this->userId)) { showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]); } $isHeart = input('is_heart', 2); if (!in_array($isHeart, [1, 2])) { showJson(1004, 2111); } $result = Member::where(['id' => $this->userId]) ->update(['updated_at' => date('Y-m-d H:i:s'), 'is_heart' => $isHeart]); if ($result) { UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => $isHeart == 1 ? '加入怦然心动' : '取消加入怦然心动']); showJson(1005, $isHeart == 1 ? 5017 : 5019); } else { showJson(1004, $isHeart == 1 ? 5018 : 5020); } } /** * 设置用户推荐条件 */ public function setConditions() { // 验证 $this->checkUser(); if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } $params = input(); PRedis::set('test:conditions:' . $this->userId, $params, 600); $res = Member::setMemberConditions($this->userId, $params); if ($res) { UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => '设置推荐条件']); showJson(1005, 1008); } else { showJson(1004, 1009); } } /** * 获取推荐条件 */ public function getConditions() { $conditions = Member::getMemberConditions($this->userId); showJson(1005, 1008, $conditions); } /** * 获取我的活动列表 */ public function getActivityList() { $params = input(); $pageSize = input('pageSize', 12); $params['user_id'] = $this->userId; $dataList = Activity::getMemberActivityList($params, $pageSize); showJson(1005, 1001, $dataList); } /** * 爱心充值 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function doRecharge() { // 验证 $this->checkUser(); $money = input('money', 0); $num = input('num', 0); $mealId = input('meal_id', 0); if (empty($money) || empty($num)) { showJson(1004, 4001); } if(empty($mealId)){ showJson(1004, 4006); } $mealInfo = HeartMeal::where(['id'=> $mealId,'status'=> 1])->find(); $money = isset($mealInfo['price'])? $mealInfo['price'] : 0; $giveNum = isset($mealInfo['give'])? $mealInfo['give'] : 0; if(empty($mealInfo)){ showJson(1004, 4007); } if($mealInfo['heart']<=0 || $mealInfo['price']<=0){ showJson(1004, 4008); } // if($mealInfo['limit_buy']>0){ $rechargeNum = db('user_recharge_log')->where(['user_id'=> $this->userId,'type'=>1,'source_id'=> $mealId,'status'=>2]) ->count('id'); if($rechargeNum>= $mealInfo['limit_buy']){ showJson(1004, lang(4009,['num'=>$mealInfo['limit_buy']])); } } if($mealId<=0){ $accountConfig = $siteInfo = cmf_get_option('account_config'); $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0; $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1; if ($minRecharge && $num < $minRecharge) { showJson(1004, '最低充值数量为:' . $minRecharge . '个'); } $realMoney = moneyFormat($num * $chargeRate, 2); if ($realMoney != $money) { showJson(1004, '支付金额计算错误:' . $realMoney); } }else{ $num = intval($mealInfo['heart']); $money = $mealInfo['price']; } $orderSn = makeTradeNo('RH', $this->userId); $memberInfo = Member::where(['id' => $this->userId])->field('openid,redheart')->find(); $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0; $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : ''; $log = [ 'order_sn' => $orderSn, 'source_id' => $mealId, 'money' => intval($num), 'give_num' => intval($giveNum), 'pay_money' => $money, 'user_id' => $this->userId, 'balance' => $redheart, 'remark' => "爱心充值:{$num}个".($giveNum? "赠送{$giveNum}个":'').",合计:{$money}元", 'created_at' => date('Y-m-d H:i:s') ]; $orderId = db('user_recharge_log')->insertGetId($log); if ($orderId) { // 获取OPENID if (empty($openid)) { showJson(1004, 2010); } $order = [ 'orderNo' => $orderSn, 'amount' => $money, 'openid' => $openid, 'body' => '爱心充值订单支付', ]; $params = Wechat::jsapiUnifiedorder($order, 'recharge'); PRedis::set('orders:recharge:redheart:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600); $code = isset($params['code']) ? $params['code'] : ''; if ($code == 1004) { showJson(1004, $params['message']); } // 更新订单参数 unset($params['prepay_id']); showJson(1005, 4004, $params); } else { showJson(1004, 4005); } } /** * 想认识 */ public function doContact() { // 验证 $this->checkUser(); $id = input('id', 0); $remark = input('remark', ''); if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } // 完善个人信息 if (!UserProfile::checkUserProfile($this->userId)) { showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]); } // 隐身不可申请 $type = input('type', 1); $isHeart = Member::where(['id' => $this->userId])->value('is_heart'); if ($isHeart != 1 && $type != 2) { showJson(1006, 2037, ['type' => 'check']); } $res = Member::contactUser($this->userId, $id, $remark); if (is_array($res)) { showJson(1005, 1008); } else if ($res == 2103) { $referer = request()->server('HTTP_REFERER'); $rebackurl = $referer ? $referer : url('/weixin/match/index', '', '', true); showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/index/entry?rebackurl=' . $rebackurl, '', '', true))]); } else if ($res == 2121) { showJson(1006, $res ? $res : 1009, ['url' => '/weixin/member/invite']); } else { showJson(1004, $res ? $res : 1009); } } /** * 邀请认证 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function inviteAuth(){ // 验证 $this->checkUser(); $uid = input('uid', 0); $type = input('type', 1); if($this->userId == $uid){ showJson(1004, 2009); } $info = Member::where(['id' => $this->userId, 'user_status'=> 1])->field('user_nickname,openid,vip_auth,vip_expire')->find(); if(empty($info)){ showJson(1004, 2140); } $nickname = isset($info['user_nickname'])? $info['user_nickname'] : ''; $memberInfo = Member::where(['id' => $uid, 'user_status'=> 1])->field('user_nickname,openid,vip_auth,vip_expire')->find(); if(empty($memberInfo)){ showJson(1004, 2140); } $cacheKey = 'messages:inviteAuth:' . $this->userId . '_' . $uid.'_'.$type; if(PRedis::get($cacheKey)){ showJson(1004, 2141); } $nickname1 = isset($memberInfo['user_nickname'])? $memberInfo['user_nickname'] : ''; $openid = isset($memberInfo['openid'])? $memberInfo['openid'] : ''; $typeNames = [1=>'实名认证',2=>'工作认证',3=>'学历认证']; if(empty($openid)){ showJson(1004, 2009); } $params = [ 'title' => "您好亲{$nickname1},用户{$nickname}邀请您完成认证", 'remark' => "完成认证,可以让更多人认识你哦!", 'type' => 'contact_confirm', 'keywords' => [ 'keyword1' => [ 'value' => isset($typeNames[$type])? $typeNames[$type] : '认证', 'color' => '#173177', ], 'keyword2' => [ 'value' => '邀请认证', 'color' => '#173177', ], ], 'url' => url("/weixin/auth/".($type==1? 'idcard': ($type==2? 'position':'education')), '', '', true), ]; PRedis::set($cacheKey, ['info' => $info, 'data' => $memberInfo, 'params' => $params], 6*3600); Wechat::sendTplMsg($openid, $params); showJson(1005, 1008); } /** * 认识审核确认 */ public function contactConfirm() { // 验证 $this->checkUser(); $cid = input('cid', 0); $status = input('status', 2); if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } $res = Member::contactConfirm($this->userId, $cid, $status); if (is_array($res)) { showJson(1005, 1008); } else { showJson(1004, $res ? $res : 1009); } } /** * 套餐列表 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function mealList() { $type = input('type', 0); showJson(1005, 1001, Meals::getList($type)); } /** * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function heartMeals(){ showJson(1005, 1001, HeartMeal::getList()); } /** * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function signMeals(){ showJson(1005, 1001, SignMeal::getList()); } /** * 购买VIP套餐 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function buyVip() { // 验证 $this->checkUser(); $mealId = input('mealId', 0); $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price,num')->find(); if (empty($mealId) || empty($mealInfo)) { showJson(1004, 7001); } $mealTime = isset($mealInfo['time']) ? $mealInfo['time'] : 0; $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0; $mealNum = isset($mealInfo['num']) ? $mealInfo['num'] : 0; if (empty($mealTime)) { showJson(1004, 7002); } if (empty($mealPrice)) { showJson(1004, 7003); } if ($mealNum<=0) { showJson(1004, 7006); } $orderSn = makeTradeNo('VP', $this->userId); $memberInfo = Member::where(['id' => $this->userId])->field('openid,vip_auth,vip_expire,vip_num')->find(); $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0; $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0; $vipNum = isset($memberInfo['vip_num']) ? intval($memberInfo['vip_num']) : 0; $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : ''; $expireText = $vipExpire > time() && $vipAuth ? ',原先' . date('Y-m-d H:i:s', $vipExpire) . '到期' : ',原先未开通'; if($vipExpire>time() && $vipNum>0){ showJson(1004, '您还有'.$vipNum.'次申请微信机会未使用完,请先使用完再续购'); } $log = [ 'order_sn' => $orderSn, 'money' => $mealTime, 'type' => 4, 'pay_money' => $mealPrice, 'user_id' => $this->userId, 'balance' => 0, 'use_num' => $mealNum, 'remark' => "购买VIP套餐[ID:{$mealId}]:会员续费{$mealTime}个月可使用{$mealNum}次{$expireText}", 'created_at' => date('Y-m-d H:i:s') ]; $orderId = db('user_recharge_log')->insertGetId($log); if ($orderId) { // 获取OPENID if (empty($openid)) { showJson(1004, 2010); } $order = [ 'orderNo' => $orderSn, 'amount' => $mealPrice, 'openid' => $openid, 'body' => $vipAuth ? '续费' . $mealInfo['name'] . '订单支付' : '购买' . $mealInfo['name'] . '订单支付', ]; $params = Wechat::jsapiUnifiedorder($order, 'vip'); PRedis::set('orders:recharge:vip:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600); $code = isset($params['code']) ? $params['code'] : ''; if ($code == 1004) { showJson(1004, $params['message']); } // 更新订单参数 unset($params['prepay_id']); showJson(1005, 7004, $params); } else { showJson(1004, 7005); } } /** * 购买人工服务 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function handPay() { // 验证 $this->checkUser(); $mealId = input('mealId', 0); $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find(); if (empty($mealId) || empty($mealInfo)) { showJson(1004, 7001); } $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0; if (empty($mealPrice)) { showJson(1004, 7003); } $orderSn = makeTradeNo('HP', $this->userId); $log = [ 'order_sn' => $orderSn, 'money' => $mealPrice, 'type' => 5, 'pay_money' => $mealPrice, 'user_id' => $this->userId, 'balance' => 0, 'remark' => "购买人工牵服务[ID:{$mealId}]:支付{$mealPrice}元", 'created_at' => date('Y-m-d H:i:s') ]; $orderId = db('user_recharge_log')->insertGetId($log); $memberInfo = Member::where(['id' => $this->userId])->field('openid')->find(); $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : ''; if ($orderId) { // 获取OPENID if (empty($openid)) { showJson(1004, 2010); } $order = [ 'orderNo' => $orderSn, 'amount' => $mealPrice, 'openid' => $openid, 'body' => '购买' . $mealInfo['name'] . '服务订单支付', ]; $params = Wechat::jsapiUnifiedorder($order, 'hand'); PRedis::set('orders:recharge:hand:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600); $code = isset($params['code']) ? $params['code'] : ''; if ($code == 1004) { showJson(1004, $params['message']); } // 更新订单参数 unset($params['prepay_id']); showJson(1005, 7004, $params); } else { showJson(1004, 7005); } } /** * 举报信息提交 */ public function complainSubmit() { $uid = input('uid', 0); $type = input('type', 0); if (empty($uid)) { showJson(1004, 8001); } if (empty($type)) { showJson(1004, 8002); } // 是否已经提交过 if (Complain::where(['uid' => $this->userId, 'c_uid' => $uid])->where('created_time', '>=', time() - 7 * 24 * 3600)->value('id')) { showJson(1004, 8005); } // 举报数据 $params = [ 'uid' => $this->userId, 'c_uid' => $uid, 'remark' => htmlspecialchars(input('remark', '')), 'type' => $type, ]; // 照片 $file = request()->file('image'); if ($file) { $fileData = Storage::uploadImg($file, 'complain', false, false); $image = isset($fileData['file']) ? $fileData['file'] : ''; $params['image'] = $image; } // 保存数据 if ($id = Complain::saveData($params)) { showJson(1005, 8003, $id); } else { showJson(1004, 8004); } } /** * 用户反馈建议提交 */ public function adviceSubmit() { $type = input('type', 0); if (empty($type)) { showJson(1004, 8009); } // 是否已经提交过 if (Advice::where(['uid' => $this->userId, 'type' => $type])->where('created_time', '>=', time() - 3 * 24 * 3600)->value('id')) { showJson(1004, 8006); } // 数据 $params = [ 'uid' => $this->userId, 'remark' => htmlspecialchars(input('remark', '')), 'type' => $type, ]; // $file = request()->file('image'); if ($file) { $fileData = Storage::uploadImg($file, 'complain', false, false); $image = isset($fileData['file']) ? $fileData['file'] : ''; $params['image'] = $image; } // 保存数据 if ($id = Advice::saveData($params)) { showJson(1005, 8007, $id); } else { showJson(1004, 8008); } } /** * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function complainList() { $type = input('type', 2); $pageSize = input('pageSize', 30); showJson(1005, 1001, Member::getComplainList($type, $pageSize)); } /** * 坐标转换地址 */ public function getLocationAddress() { $locationType = 'wgs84ll'; $apiUrl = config('api.locationApi'); $siteInfo = $siteInfo = cmf_get_site_info(); $ak = isset($siteInfo['map_key']) ? trim($siteInfo['map_key']) : ''; $uid = input('uid', 0); $lat = input('lat', ''); $lng = input('lng', ''); $type = input('type', 1); if (empty($lat) || empty($lng)) { showJson(1004, 1002); } $apiUrl = sprintf($apiUrl, $ak, $locationType, "{$lat},{$lng}"); $data = cmf_curl_get($apiUrl); $data = $data ? json_decode($data, true) : []; $data = isset($data['result']) ? $data['result'] : []; $addressData = isset($data['addressComponent']) ? $data['addressComponent'] : []; $province = isset($addressData['province']) ? $addressData['province'] : ''; $city = isset($addressData['city']) ? $addressData['city'] : ''; $district = isset($addressData['district']) ? $addressData['district'] : ''; $location = isset($data['location']) ? $data['location'] : []; $latNew = isset($location['lat']) ? round($location['lat'], 6) : 0; $lngNew = isset($location['lng']) ? round($location['lng'], 6) : 0; if (empty($data) || empty($latNew) || empty($lngNew)) { showJson(1004, 8204); } // 更新位置数据 $cacheKey = "cache:location:u_{$this->userId}"; $updateData = ['lat' => $latNew, 'lng' => $lngNew, 'address' => "{$province},{$city},{$district}"]; if (!PRedis::get($cacheKey)) { Member::where(['id' => $this->userId, 'user_type' => 2])->update($updateData); PRedis::set($cacheKey, ['uid' => $this->userId, 'data' => $data, 'update' => $updateData, 'lat' => $latNew, 'lng' => $lngNew, 'date' => date('Y-m-d H:i:s')], 5); } if ($type == 1 && $uid) { $distance = ''; $userInfo = Member::where(['id' => $uid])->field('lat,lng,address')->find(); $lat1 = isset($userInfo['lat']) ? $userInfo['lat'] : 0; $lng1 = isset($userInfo['lng']) ? $userInfo['lng'] : 0; $address = isset($userInfo['address']) ? $userInfo['address'] : ''; $address = $address ? explode(',', $address) : ''; $district = isset($address[2]) ? $address[2] : ''; if ($lat1 > 0 && $lng1 > 0) { $distance = getDistance($lngNew, $latNew, $lng1, $lat1, 1); $distance = $distance >= 1000 ? round($distance / 1000, 2) . 'km' : ($distance? $distance . 'm' : ''); } showJson(1005, 8202, ['location' => $data, 'distance' => $distance, 'other' => $userInfo, 'address' => $address, 'district' => $district]); } showJson(1005, 8202, ['location' => $data]); } /** * 注销账号 * @throws \think\Exception * @throws \think\exception\PDOException */ public function logout() { // 验证扣除账号 $accountConfig = $siteInfo = cmf_get_option('account_config'); $logoutPay = isset($accountConfig['logout_pay']) ? floatval($accountConfig['logout_pay']) : 0; $memberInfo['logout_pay'] = $logoutPay > 0 ? $logoutPay : 1; $memberInfo = Member::where(['id' => $this->userId]) ->field('id,redheart,user_nickname,user_status') ->find(); $memberInfo = $memberInfo? $memberInfo->toArray() : []; $redheart = isset($memberInfo['redheart'])? $memberInfo['redheart'] : 0; $nickname = isset($memberInfo['user_nickname'])? $memberInfo['user_nickname'] : ''; $userStatus = isset($memberInfo['user_status'])? $memberInfo['user_status'] : 0; if($userStatus == -1){ showJson(1004, 1124); } if($redheart < $logoutPay){ showJson(1004, lang(1125,['pay'=> $logoutPay])); } DB::startTrans(); if(!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $logoutPay)){ DB::rollback(); showJson(1004, 2031); } // 账户明细 $data = [ 'user_id'=> $this->userId, 'type'=> 2, 'account_type'=> 1, 'change_type'=> 2, 'money'=> $logoutPay, 'balance'=> $redheart, 'remark'=> '用户【'.$nickname.'】注销扣除'.$logoutPay.'颗爱心', 'created_at'=> date('Y-m-d H:i:s'), 'status'=> 2 ]; if(!AccountLog::insertGetId($data)){ Db::rollback(); showJson(1004, 8306); } Db::commit(); // 注销信息 Member::where(['id' => $this->userId, 'user_type' => 2]) ->update(['user_status' => -1, 'vip_auth' => 0, 'is_heart' => 0,'catch_time'=> date('Y-m-d H:i:s'), 'vip_expire' => 0, 'is_reg_profile' => 2, 'is_tuijian' => 0]); // 进入资源库 PoolModel::distribute(0, $this->userId, 6); $cacheKey = "weixin:auth:" . session('openid'); PRedis::del($cacheKey); session('userInfo', null); session('openid', null); showJson(1005, 1001); } /** * 认证记录 * @throws \think\Exception\DbException */ public function getAuthNotice(){ $dataList = \app\weixin\service\Member::getAuthNotices(); showJson(1005, 1001, $dataList); } /** * 获取用户访问记录 */ public function getUserAccess(){ $pageSize = input('pageSize', 30); $dataList = Member::getUserAccess($this->userId, $pageSize); showJson(1005, 1001, $dataList); } /** * 解锁访问用户信息 */ public function unlock(){ $uid = input('uid', 0); $cuid = input('cuid', 0); if(empty($uid) || empty($cuid)){ showJson(1004,1012); } if($uid != $this->userId || ($uid == $cuid)){ showJson(1004,8301); } if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) { showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]); } $res = Member::catchUnlock($uid, $cuid); if (is_array($res)) { showJson(1005, 8302); } else { showJson(1004, $res ? $res : 8303); } } /** * 签到 * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function sign(){ // 验证 $this->checkUser(); $params = input(); $res = SignMeal::catchSign($this->userId, $params); if (is_array($res)) { showJson(1005, 2146); }else { showJson(1004, $res ? $res : 2147); } } public function setSign(){ PRedis::set("caches:signs:close:".$this->userId.'_'.date('Ymd'),date('Y-m-d H:i:s'), 86400); showJson(1005, 2146); } }