| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996 |
- <?php
- /**
- * 会员中心模块
- * @author wesmiler
- */
- namespace app\api\controller;
- use app\user\model\PoolModel;
- use app\weixin\model\Advice;
- use app\weixin\model\Complain;
- use app\weixin\model\HeartMeal;
- use app\weixin\model\SignMeal;
- use app\weixin\service\FaceAuth;
- use app\weixin\service\ZimFace;
- use app\weixin\service\IdnAuth;
- use function AlibabaCloud\Client\value;
- use app\weixin\model\AccountLog;
- use app\weixin\model\Meals;
- use app\weixin\model\Member;
- use app\weixin\model\Storage;
- use app\weixin\model\UserCollect;
- use app\weixin\model\UserContactLog;
- use app\weixin\model\UserLog;
- use app\weixin\model\UserProfile;
- use app\weixin\model\Wechat;
- use app\weixin\service\PRedis;
- use app\weixin\service\Sms;
- use app\weixin\service\Activity;
- use app\weixin\validate\MemberValidate;
- use think\Db;
- class MemberController extends BaseController
- {
- public function __construct()
- {
- parent::__construct();
- $userStatus = isset($this->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);
- }
- }
|