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']); } 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; $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 ($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; 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]); } 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 == 3) { $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; $memberInfo['charge_rate'] = $chargeRate > 0 ? $chargeRate : 1; $memberInfo['min_recharge'] = $minRecharge ? $minRecharge : 1; } // 是否已经认证 if ($type == 2 || $type == 4 || $type == 1) { $field = 'idcard_check,education_check,position_check'; $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; 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'; $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'; $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'; $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; } } 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(); // 更新缓存 $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, '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); } // 保存 $oldAvatar = Member::where(['id' => $this->userId])->value('avatar'); if (!Member::saveData(['id' => $this->userId], ['avatar' => $avatar])) { showJson(1004, 2030); } if (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, 2029); } /** * 保存资料 */ 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); $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 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){ Member::where(['id' => $this->userId,'user_type'=> 2]) ->update(['is_heart'=> 1]); // 操作日志 UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "取消隐身模式"]); showJson(1005, 2036); } $memberInfo = Member::where(['id' => $this->userId,'user_type'=> 2])->field('redheart,is_heart,invisible_time')->find(); $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('invisible',['date'=> date('Y-m-d', $invisibleTime)])); } if($isHeart==2 && $value == 0){ showJson(1004, 2034); } // 扣除爱心隐身 Db::startTrans(); if($reset == 1){ // 扣除爱心账户 $accountConfig = cmf_get_option('account_config'); $hiddenPay = isset($accountConfig['hidden_pay']) ? intval($accountConfig['hidden_pay']) : 0; $hiddenPay = $hiddenPay ? $hiddenPay : 10; $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 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']) : ''; $profileData = [ 'idcard' => $idcard, 'front_idcard' => isset($params['front_idcard']) ? trim($params['front_idcard']) : '', 'back_idcard' => isset($params['back_idcard']) ? trim($params['back_idcard']) : '', 'idcard_check' => 1, ]; // 验证身份证号是否被使用 $checkId = UserProfile::where(['idcard' => $idcard]) ->where('userid', 'not in', $this->userId) ->value('id'); if ($checkId) { showJson(1004, 2128); } // 身份证照片 /*if (isset($_FILES['image1'])) { $file1 = request()->file('image1'); $fileData = Storage::uploadImg($file1, 'auth'); $frontIdcard = isset($fileData['file']) ? $fileData['file'] : ''; $profileData['front_idcard'] = $waterTxt ? Storage::imageWater($frontIdcard, $waterTxt) : $frontIdcard; } //$file2 = isset($_FILES['image2'])? $_FILES['image2'] : null; $files = request()->file(); if (isset($_FILES['image2'])) { $file2 = request()->file('image2'); $fileData = Storage::uploadImg($file2, 'auth'); $backIdcard = isset($fileData['file']) ? $fileData['file'] : ''; $profileData['back_idcard'] = $waterTxt ? Storage::imageWater($backIdcard, $waterTxt) : $backIdcard; }*/ if (empty($profileData['front_idcard'])) { showJson(1004, 2024); } if (empty($profileData['back_idcard'])) { showJson(1004, 2025); } // var_dump($profileData);exit; Db::startTrans(); if (!Member::saveData(['id' => $this->userId], ['real_name' => trim($params['realname'])])) { Db::rollback(); showJson(1004, 2026); } 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': // 学历认证 $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_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, '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_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 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); if (empty($money) || empty($num)) { showJson(1004, 4001); } $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); } $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, 'money' => $num, 'pay_money' => $money, 'user_id' => $this->userId, 'balance' => $redheart, 'remark' => "爱心充值:{$num}个,合计:{$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); } } /** * 认识审核确认 */ 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)); } /** * 购买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')->find(); if (empty($mealId) || empty($mealInfo)) { showJson(1004, 7001); } $mealTime = isset($mealInfo['time'])? $mealInfo['time'] : 0; $mealPrice = isset($mealInfo['price'])? $mealInfo['price'] : 0; if (empty($mealTime)) { showJson(1004, 7002); } if (empty($mealPrice)) { showJson(1004, 7003); } $orderSn = makeTradeNo('VP', $this->userId); $memberInfo = Member::where(['id' => $this->userId])->field('openid,vip_auth,vip_expire')->find(); $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0; $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0; $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : ''; $expireText = $vipExpire>time() && $vipAuth? ',原先'.date('Y-m-d H:i:s', $vipExpire).'到期' : ',原先未开通'; $log = [ 'order_sn' => $orderSn, 'money' => $mealTime, 'type' => 4, 'pay_money' => $mealPrice, 'user_id' => $this->userId, 'balance' => 0, 'remark' => "购买VIP套餐[ID:{$mealId}]:会员续费{$mealTime}个月{$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); } } /** * 注销账号 * @throws \think\Exception * @throws \think\exception\PDOException */ public function logout(){ Member::where(['id' => $this->userId,'user_type'=> 2]) ->update(['user_status'=> -1, 'vip_auth'=> 0,'is_heart'=> 0,'vip_expire'=> 0, 'is_reg_profile'=> 2, 'is_tuijian'=> 0]); $cacheKey = "weixin:auth:".session('openid'); PRedis::del($cacheKey); session('userInfo', null); session('openid', null); showJson(1005,1001); } }