| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977 |
- <?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;
- $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;
- 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;
- }
- }
- // 更新登录时间
- if(!PRedis::get("members:login")){
- Member::where(['id'=> $this->userId])->update(['last_login_time'=> time()]);
- PRedis::set("members:login", $this->userId, rand(300, 600));
- }
- 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')->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);
- }
- }
- /**
- * 举报信息提交
- */
- 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]);
- $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);
- }
- }
|