MemberController.php 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388
  1. <?php
  2. /**
  3. * 会员中心模块
  4. * @author wesmiler
  5. */
  6. namespace app\api\controller;
  7. use app\user\model\PoolModel;
  8. use app\user\model\UserModel;
  9. use app\weixin\model\Advice;
  10. use app\weixin\model\Channels;
  11. use app\weixin\model\Complain;
  12. use app\weixin\model\HeartMeal;
  13. use app\weixin\model\SignMeal;
  14. use app\weixin\service\FaceAuth;
  15. use app\weixin\service\ZimFace;
  16. use app\weixin\service\IdnAuth;
  17. use function AlibabaCloud\Client\value;
  18. use app\weixin\model\AccountLog;
  19. use app\weixin\model\Meals;
  20. use app\weixin\model\Member;
  21. use app\weixin\model\Storage;
  22. use app\weixin\model\UserCollect;
  23. use app\weixin\model\UserContactLog;
  24. use app\weixin\model\UserLog;
  25. use app\weixin\model\UserProfile;
  26. use app\weixin\model\Wechat;
  27. use app\weixin\service\PRedis;
  28. use app\weixin\service\Sms;
  29. use app\weixin\service\Activity;
  30. use app\weixin\validate\MemberValidate;
  31. use think\Db;
  32. class MemberController extends BaseController
  33. {
  34. public function __construct()
  35. {
  36. parent::__construct();
  37. $userStatus = isset($this->userInfo['user_status']) ? intval($this->userInfo['user_status']) : 0;
  38. $freezingChoose = isset($this->userInfo['freezing_choose']) ? intval($this->userInfo['freezing_choose']) : 0;
  39. $action = request()->action();
  40. if ($this->userInfo && $userStatus != 1 && $action != 'loginbymobile') {
  41. if ($userStatus == -1) {
  42. showJson(1006, 1016, ['url' => 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg3ODEzNjMzMQ==&scene=124#wechat_redirect']);
  43. }
  44. $uncheck = input('uncheck', 0);
  45. if (!in_array($action, ['getrecommendlist']) && (($action == 'getinfo' || $action == 'gethomeinfo') && !$uncheck)) {
  46. showJson(1006, $freezingChoose > 0 ? 1020 + $freezingChoose : 1011, ['url' => url('/weixin/page/custom', '', '', true)]);
  47. }
  48. }
  49. }
  50. /**
  51. * 获取有用户信息
  52. */
  53. public function getInfo()
  54. {
  55. $type = input('type', 0);
  56. $id = input('id', 0); // 当前浏览的用户ID
  57. $userId = $this->userId;
  58. $cacheKey = "caches:member:temp:{$userId}_{$type}";
  59. $memberInfo = PRedis::get($cacheKey);
  60. if($memberInfo){
  61. showJson(1005, 1001, $memberInfo);
  62. }
  63. $memberInfo = Member::getInfo(['id' => $userId]);
  64. if ($type == 1) {
  65. Member::visitCount($this->userId, 'center');
  66. } else if ($type == 8) {
  67. Member::visitCount($this->userId, 'home');
  68. }
  69. // 冻结
  70. $userStatus = isset($memberInfo['user_status']) ? intval($memberInfo['user_status']) : 0;
  71. if ((!in_array($type, [1, 8])) && $userStatus != 1 && $type != 1) {
  72. showJson(1006, 2102, ['url' => url('/weixin/page/custom', '', '', true)]);
  73. }
  74. // VIP有效状态和时间
  75. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  76. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  77. $vipTime = isset($memberInfo['vip_time']) && $memberInfo['vip_time']? strtotime($memberInfo['vip_time']) : 0;
  78. $memberInfo['vip_type'] = 1; // 默认老VIP
  79. if($vipTime > strtotime('2022-04-21 00:00:00')){
  80. $memberInfo['vip_type'] = 2;
  81. }
  82. if ($vipAuth && $vipExpire >= time()) {
  83. $memberInfo['vip_auth'] = 1;
  84. $memberInfo['vip_expire'] = date('Y-m-d', $vipExpire);
  85. if ($vipExpire <= time() + 86400 * 2) {
  86. $memberInfo['vip_expire_near'] = 1;
  87. }
  88. } else {
  89. $memberInfo['vip_auth'] = 0;
  90. $memberInfo['vip_expire'] = '';
  91. $memberInfo['vip_expire_near'] = 0;
  92. }
  93. if ($memberInfo) {
  94. $memberInfo['avatar'] = isset($memberInfo['avatar']) && $memberInfo['avatar'] ? cmf_get_image_preview_url($memberInfo['avatar']) : '';
  95. if ($type == 1) {
  96. $memberInfo['collectCount'] = UserCollect::getUserCount($userId, $memberInfo['vip_auth']);
  97. $memberInfo['rechargeCount'] = Member::getRechargeCount($userId);
  98. $memberInfo['messageCount'] = Member::getMessageTotal($userId, ['type' => 1, 'status' => 2]);
  99. $memberInfo['accessCount'] = Member::getAccessCount($userId);
  100. // 手机验证是否已经到了需要验证时间
  101. $memberInfo['verify_mobile'] = 0;
  102. $siteInfo = cmf_get_option('site_info');
  103. $memberInfo['verify_mobile_status'] = isset($siteInfo['verify_mobile_status'])? intval($siteInfo['verify_mobile_status']) : 2;
  104. $verifyTime = isset($memberInfo['verify_mobile_expired'])? $memberInfo['verify_mobile_expired'] : '';
  105. if($verifyTime <= date('Y-m-d H:i:s')){
  106. $memberInfo['verify_mobile'] = 1;
  107. }
  108. }
  109. if ($type == 2) {
  110. $qrcodeData = Wechat::makeQrcode($userId, $userId);
  111. $memberInfo['qrcode'] = isset($qrcodeData['qrcode']) ? $qrcodeData['qrcode'] : '';
  112. $memberInfo['invite_count'] = Member::getInviteCount($userId);
  113. $memberInfo['profile_complete'] = UserProfile::checkUserProfile($userId) ? 1 : 0;
  114. }else{
  115. if (isset($memberInfo['mobile'])) {
  116. $memberInfo['mobile'] = $memberInfo['mobile'] ? formatStr($memberInfo['mobile']) : '';
  117. }
  118. }
  119. if($type == 1 || $type == 2){
  120. $memberInfo['signed'] = 0;
  121. $showSign = PRedis::get("caches:signs:close:".$this->userId.'_'.date('Ymd'));
  122. $memberInfo['showSign'] = $showSign? 0 : 1;
  123. $signDay = isset($memberInfo['sign_day'])? $memberInfo['sign_day'] : 1;
  124. $signAt = isset($memberInfo['sign_at'])? $memberInfo['sign_at'] : '';
  125. if($signDay && (empty($signAt) || $signAt <= date('Y-m-d', strtotime(date('Y-m-d')) - 86400))){
  126. $memberInfo['sign_day'] = 0;
  127. $memberInfo['sign_at'] = '';
  128. }else if($signDay && (empty($signAt) || $signAt >= date('Y-m-d'))){
  129. $memberInfo['signed'] = 1;
  130. }else if($signDay && $signDay>=7 && $signAt <= date('Y-m-d')){
  131. $memberInfo['sign_day'] = 0;
  132. $memberInfo['sign_at'] = '';
  133. }
  134. }
  135. if ($type == 3) {
  136. $accountConfig = cmf_get_option('account_config');
  137. $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
  138. $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
  139. $memberInfo['charge_rate'] = $chargeRate > 0 ? $chargeRate : 1;
  140. $memberInfo['min_recharge'] = $minRecharge ? $minRecharge : 1;
  141. $clearData = Member::getSignReadheart($userId);
  142. $signClear = isset($clearData['sign_clear'])? $clearData['sign_clear'] : 0;
  143. $signTotal = isset($clearData['sign_total'])? $clearData['sign_total'] : 0;
  144. $memberInfo['redheart_temp'] = $memberInfo['redheart'];
  145. // $memberInfo['redheart'] = $memberInfo['redheart']>$signClear? $memberInfo['redheart'] - $signClear : 0;
  146. $memberInfo['redheart_forever'] = $memberInfo['redheart']>$signTotal? $memberInfo['redheart'] - $signTotal : 0;
  147. $memberInfo['clearData'] = $clearData;
  148. }
  149. // 是否已经认证
  150. if ($type == 2 || $type == 4 || $type == 1) {
  151. $field = 'idcard_check,education_check,position_check,wechat_code';
  152. $authData = UserProfile::where(['userid' => $userId])
  153. ->field($field)
  154. ->find();
  155. $memberInfo['is_auth'] = 0;
  156. $memberInfo['idcard_check'] = isset($authData['idcard_check']) ? intval($authData['idcard_check']) : 0;
  157. $memberInfo['education_check'] = isset($authData['education_check']) ? intval($authData['education_check']) : 0;
  158. $memberInfo['position_check'] = isset($authData['position_check']) ? intval($authData['position_check']) : 0;
  159. $memberInfo['wechat_code'] = isset($authData['wechat_code']) ? $authData['wechat_code'] : '';
  160. if ($memberInfo['idcard_check'] == 2 && $memberInfo['education_check'] == 2 && $memberInfo['position_check'] == 2) {
  161. $memberInfo['is_auth'] = 1;
  162. }
  163. }
  164. // 认证数据
  165. if ($type == 5) {
  166. $field = 'idcard,front_idcard,back_idcard,idcard_fail,idcard_check,idcard_type,idcard_online_check';
  167. $authData = UserProfile::where(['userid' => $userId])
  168. ->field($field)
  169. ->find();
  170. $authData = $authData ? $authData : [];
  171. $authData['realname'] = isset($memberInfo['real_name']) ? trim($memberInfo['real_name']) : '';
  172. $authData['front_idcard_preview'] = isset($authData['front_idcard']) ? cmf_get_image_preview_url($authData['front_idcard']) : '';
  173. $authData['back_idcard_preview'] = isset($authData['back_idcard']) ? cmf_get_image_preview_url($authData['back_idcard']) : '';
  174. $authData['idcard_check'] = isset($authData['idcard_check']) ? $authData['idcard_check'] : 0;
  175. $memberInfo['authInfo'] = $authData;
  176. }
  177. if ($type == 6) {
  178. $field = 'graduate,education,education_img,education_fail,education_check,education_code,education_type';
  179. $authData = UserProfile::where(['userid' => $userId])
  180. ->field($field)
  181. ->find();
  182. $authData['education_img_preview'] = isset($authData['education_img']) ? cmf_get_image_preview_url($authData['education_img']) : '';
  183. $authData['education_check'] = isset($authData['education_check']) ? $authData['education_check'] : 0;
  184. $memberInfo['authInfo'] = $authData ? $authData : [];
  185. }
  186. if ($type == 7) {
  187. $field = 'company,occupation,position_img,position_fail,position_check,position_type,position_hide';
  188. $authData = UserProfile::where(['userid' => $userId])
  189. ->field($field)
  190. ->find();
  191. $authData['position_img_preview'] = isset($authData['position_img']) ? cmf_get_image_preview_url($authData['position_img']) : '';
  192. $authData['position_check'] = isset($authData['position_check']) ? $authData['position_check'] : 0;
  193. $memberInfo['authInfo'] = $authData ? $authData : [];
  194. }
  195. // 验证是否已经收藏过
  196. $memberInfo['is_collect'] = 0;
  197. if ($id && UserCollect::checkCollect($userId, $id)) {
  198. $memberInfo['is_collect'] = 1;
  199. }
  200. // 收藏剩余有效时间
  201. if (isset($memberInfo['collect_expire'])) {
  202. $memberInfo['collect_expire'] = intval($memberInfo['collect_expire']) - time();
  203. $memberInfo['collect_expire'] = $memberInfo['collect_expire'] > 0 ? $memberInfo['collect_expire'] : 0;
  204. }
  205. if ($type == 8) {
  206. $accountConfig = cmf_get_option('account_config');
  207. $contactPay = isset($accountConfig['contact_pay']) ? intval($accountConfig['contact_pay']) : 0;
  208. $contactPay = $contactPay ? $contactPay : 1;
  209. $memberInfo['contact_pay'] = $contactPay;
  210. $contactRefundPay = isset($accountConfig['apply_refund_pay']) ? intval($accountConfig['apply_refund_pay']) : 0;
  211. $contactRefundPay = $contactRefundPay ? $contactRefundPay : 3;
  212. $memberInfo['contact_refund_pay'] = $contactRefundPay;
  213. $siteConfig = cmf_get_option('site_info');
  214. $contactTime = isset($siteConfig['contact_time']) ? intval($siteConfig['contact_time']) : 1;
  215. $contactTime = $contactTime ? $contactTime * 24 : 24;
  216. $memberInfo['contact_time'] = $contactTime;
  217. $regAward = isset($siteConfig['invite_award_redheart'])? $siteConfig['invite_award_redheart'] : 0;
  218. $idcardAward = isset($siteConfig['idcard_invite_award_redheart'])? $siteConfig['idcard_invite_award_redheart'] : 0;
  219. $educationAward = isset($siteConfig['education_invite_award_redheart'])? $siteConfig['education_invite_award_redheart'] : 0;
  220. $positionAward = isset($siteConfig['position_invite_award_redheart'])? $siteConfig['position_invite_award_redheart'] : 0;
  221. $memberInfo['share_invite_award'] = intval($regAward + $idcardAward + $educationAward + $positionAward);
  222. }
  223. if($type == 9){
  224. $accountConfig = cmf_get_option('account_config');
  225. $pay = isset($accountConfig['lock_access_pay']) ? intval($accountConfig['lock_access_pay']) : 0;
  226. $pay = $pay ? $pay : 1;
  227. $memberInfo['lock_access_pay'] = $memberInfo['vip_auth']==1? 0 : $pay;
  228. }
  229. }
  230. PRedis::set($cacheKey, $memberInfo, rand(2,5));
  231. showJson(1005, 1001, $memberInfo);
  232. }
  233. /**
  234. * 手机号绑定注册/登录
  235. * @throws \think\Exception
  236. * @throws \think\db\exception\DataNotFoundException
  237. * @throws \think\db\exception\ModelNotFoundException
  238. * @throws \think\exception\DbException
  239. * @throws \think\exception\PDOException
  240. */
  241. public function loginByMobile()
  242. {
  243. $params = input();
  244. $userId = input('uid', 0);
  245. $validate = new MemberValidate();
  246. if (!$validate->scene('login')->check($params)) {
  247. showJson(1004, $validate->getError());
  248. }
  249. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  250. $code = isset($params['code']) ? trim($params['code']) : '';
  251. $result = Sms::checkCode($mobile, $code,'login');
  252. if ($code != '1122' && !$userId && $result !== true) {
  253. showJson(1004, $result);
  254. }
  255. // 验证是否完善资料注册
  256. $openid = isset($params['openid']) ? trim($params['openid']) : '';
  257. if(empty($openid)){
  258. showJson(1006, 1016, ['url' => 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg3ODEzNjMzMQ==&scene=124#wechat_redirect']);
  259. }
  260. $info = Member::where(['openid'=>$openid])->field('id,user_status,mobile,is_reg_profile,user_type')->find();
  261. $isRegProfile = isset($info['is_reg_profile'])? $info['is_reg_profile'] : 2;
  262. $oldMobile = isset($info['mobile'])? $info['mobile'] : '';
  263. $status = isset($info['user_status'])? $info['user_status'] : 0;
  264. $siteInfo = cmf_get_option('site_info');
  265. $verifyMobileTime = isset($siteInfo['verify_mobile_time'])? intval($siteInfo['verify_mobile_time']) : 0;
  266. $verifyMobileTime = $verifyMobileTime? $verifyMobileTime : 7;
  267. if($info && $status==1){
  268. if($oldMobile != $mobile){
  269. $data = [
  270. 'mobile'=> $mobile,
  271. 'verify_mobile_expired' => date('Y-m-d H:i:s', time() + $verifyMobileTime * 86400),
  272. ];
  273. Member::where(['id'=> $this->userId])->update($data);
  274. }
  275. session('openid', $openid);
  276. session('userInfo', []);
  277. showJson(1005, 1001, ['is_profile'=> $isRegProfile]);
  278. }
  279. // 注册
  280. $sex = isset($params['sex']) ? intval($params['sex']) : 0;
  281. $isMedia = isset($params['is_media'])? intval($params['is_media']) : 0;
  282. $password = $isMedia==1? 'sg6688' : '123456';
  283. $userPass = cmf_password($password);
  284. $memberData = [
  285. 'openid' => $openid,
  286. 'real_name' => isset($params['real_name']) ? trim($params['real_name']) : '',
  287. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  288. 'mobile' => $mobile,
  289. 'sex' => $sex,
  290. 'user_type' => 2,
  291. 'user_login' => $mobile,
  292. 'user_pass' => $userPass,
  293. 'pay_password' => $userPass,
  294. 'verify_mobile_expired' => date('Y-m-d H:i:s', time() + $verifyMobileTime * 86400),
  295. 'last_login_ip' => get_client_ip(),
  296. 'last_login_time' => time(),
  297. 'create_time' => time(),
  298. 'is_media' => $isMedia,
  299. ];
  300. $parentId = isset($params['parent_id']) ? intval($params['parent_id']) : 0;
  301. if($parentId){
  302. $inviteIsMedia = Member::where(['id' => $parentId, 'user_type' => 2])
  303. ->value('is_media');
  304. if($inviteIsMedia==1){
  305. $memberData['invite_type'] = 1;
  306. }
  307. }
  308. Db::startTrans();
  309. if (!$userId = Member::insertGetId($memberData)) {
  310. Db::rollback();
  311. showJson(1004, 2003);
  312. }
  313. if($userId && $isMedia==1 && !Db::name('RoleUser')->insert(["role_id" => 14, "user_id" => $userId])){
  314. Db::rollback();
  315. showJson(1004, 2003);
  316. }
  317. Db::commit();
  318. session('openid', $openid);
  319. session('userInfo', []);
  320. showJson(1005, 2002, ['uid'=> $userId,'is_profile'=> 2]);
  321. }
  322. /**
  323. * 新注册
  324. * @throws \think\Exception
  325. * @throws \think\exception\PDOException
  326. */
  327. public function register()
  328. {
  329. try {
  330. $params = input();
  331. $validate = new MemberValidate();
  332. if (!$validate->scene('new_reg')->check($params)) {
  333. showJson(1004, $validate->getError());
  334. }
  335. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  336. $code = isset($params['code']) ? trim($params['code']) : '';
  337. $result = Sms::checkCode($mobile, $code,'new_reg');
  338. if ($code != '1122' && $result !== true) {
  339. showJson(1004, $result);
  340. }
  341. $sex = isset($params['sex']) ? intval($params['sex']) : 0;
  342. if (!in_array($sex, [1, 2])) {
  343. showJson(1004, 2023);
  344. }
  345. // 新注册
  346. $shareId = isset($params['share_id'])? intval($params['share_id']) : 0;
  347. if($shareId>0 && !Channels::where(['id'=> $shareId,'status'=>1])->value('id')){
  348. showJson(1004, '渠道码无效');
  349. }
  350. $isVip = isset($params['is_vip'])? intval($params['is_vip']) : 0;
  351. $id = Member::where(['mobile' => $mobile,'user_type'=>2])
  352. ->where('user_status','>=',0)
  353. ->value('id');
  354. if($id>0){
  355. showJson(1004, '已经注册');
  356. }
  357. if($isVip<=0 && $shareId<=0){
  358. showJson(1004, '渠道参数错误');
  359. }
  360. // 头像
  361. $avatar = '';
  362. $file = request()->file('image');
  363. if ($file) {
  364. $fileData = Storage::uploadImg($file, 'avatar');
  365. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  366. }
  367. if (empty($avatar)) {
  368. showJson(1004, 3004);
  369. }
  370. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  371. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  372. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  373. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  374. $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0;
  375. $year = $birthday ? date('Y', $birthday) : 0;
  376. $age = $year ? date('Y', time()) - $year : 0;
  377. // 手机号验证时间
  378. $siteInfo = cmf_get_option('site_info');
  379. $verifyMobileTime = isset($siteInfo['verify_mobile_time'])? intval($siteInfo['verify_mobile_time']) : 0;
  380. $verifyMobileTime = $verifyMobileTime? $verifyMobileTime : 7;
  381. $realname = isset($params['real_name']) ? trim($params['real_name']) : '';
  382. $isMedia = isset($params['is_media'])? intval($params['is_media']) : 0;
  383. $password = $isMedia==1? 'sg6688' : '123456';
  384. $userPass = cmf_password($password);
  385. $inviteType = $isVip? 2 : ($shareId?3: 0);
  386. $memberData = [
  387. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : uniqid('U'),
  388. 'mobile' => $mobile,
  389. 'user_login' => $mobile,
  390. 'user_pass' => $userPass,
  391. 'pay_password' => $userPass,
  392. 'verify_mobile_expired' => date('Y-m-d H:i:s', time() + $verifyMobileTime * 86400),
  393. 'birthday' => $birthday,
  394. 'sex' => $sex,
  395. 'user_type' => 2,
  396. 'is_reg_profile' => 1,
  397. 'profile_at'=> date('Y-m-d H:i:s'),
  398. 'is_media' => $isMedia,
  399. 'share_id' => $shareId,
  400. ];
  401. if($realname){
  402. $memberData['real_name'] = $realname;
  403. }
  404. if ($avatar) {
  405. $memberData['avatar'] = $avatar;
  406. }
  407. if($inviteType){
  408. $memberData['invite_type'] = $inviteType;
  409. }
  410. // VIP 授权
  411. $openid = isset($params['openid'])? $params['openid'] : session('openid');
  412. if($openid){
  413. $this->userId = Member::where(['openid' => $openid,'is_reg_profile'=>1,'user_type'=>2])
  414. ->where('user_status','>=',0)
  415. ->order('id')
  416. ->value('id');
  417. }
  418. if($this->userId){
  419. if($openid){
  420. $memberData['openid'] = $openid;
  421. }
  422. if (!Member::saveData(['id'=> $this->userId],$memberData)) {
  423. Db::rollback();
  424. showJson(1004, 2052);
  425. }
  426. }else{
  427. $memberData['create_time'] = time();
  428. if($openid){
  429. $memberData['openid'] = $openid;
  430. }
  431. if (!$this->userId = Member::insertGetId($memberData)) {
  432. Db::rollback();
  433. showJson(1004, 2052);
  434. }
  435. }
  436. $profileData = [
  437. 'age' => $age,
  438. 'userid' => $this->userId,
  439. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  440. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  441. 'salary' => isset($params['salary']) ? intval($params['salary']) : 0,
  442. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  443. 'education' => isset($params['education']) ? intval($params['education']) : 0,
  444. 'company' => isset($params['company']) ? trim($params['company']) : '',
  445. 'occupation' => isset($params['position']) ? trim($params['position']) : '',
  446. 'property' => isset($params['property']) ? intval($params['property']) : 0,
  447. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  448. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  449. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  450. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  451. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  452. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  453. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  454. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  455. 'qq' => isset($params['qq']) ? trim($params['qq']) : '',
  456. ];
  457. Db::startTrans();
  458. PRedis::set("caches:member:reg_{$mobile}", ['data'=>$profileData,'params'=> $params], 600);
  459. if (UserProfile::checkProfile($this->userId)) {
  460. $profileData['updated_at'] = date('Y-m-d H:i:s');
  461. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  462. } else {
  463. $res = UserProfile::insertGetId($profileData);
  464. }
  465. if (!$res) {
  466. Db::rollback();
  467. showJson(1004, 2052);
  468. }
  469. // 操作日志
  470. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '渠道注册']);
  471. Db::commit();
  472. // VIP定制注册
  473. if($isVip==1){
  474. PoolModel::distribute(0, $this->userId, 5,-1,true);
  475. }else{
  476. // 进入资源库(手机号注册)
  477. PoolModel::distribute(0, $this->userId, 4);
  478. }
  479. // 渠道码统计
  480. if($shareId>0){
  481. Channels::where(['id'=> $shareId])->setInc('share_count',1);
  482. }
  483. // 更新缓存
  484. $userInfo = Member::getInfo(['id' => $this->userId]);
  485. session('userInfo', $userInfo);
  486. showJson(1005, 2005);
  487. } catch (\Exception $exception) {
  488. PRedis::set('members:reg:error:' . $this->userId, $exception->getMessage(), 6 * 3600);
  489. showJson(1004, 2136);
  490. }
  491. }
  492. /**
  493. * 注册完善资料
  494. * @throws \think\Exception
  495. * @throws \think\exception\PDOException
  496. */
  497. public function setProfile()
  498. {
  499. try {
  500. $params = input();
  501. $validate = new MemberValidate();
  502. if (!$validate->scene('reg')->check($params)) {
  503. showJson(1004, $validate->getError());
  504. }
  505. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  506. if ($this->userId <= 1) {
  507. showJson(1004, 2009);
  508. }
  509. $sex = isset($params['sex']) ? intval($params['sex']) : 0;
  510. if (!in_array($sex, [1, 2])) {
  511. showJson(1004, 2023);
  512. }
  513. // 头像
  514. $avatar = '';
  515. $file = request()->file('image');
  516. if ($file) {
  517. $fileData = Storage::uploadImg($file, 'avatar');
  518. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  519. }
  520. // 相亲卡渠道码
  521. $shareId = isset($params['ssid'])? intval($params['ssid']) : session('ssid');
  522. if($shareId>0 && !Channels::where(['id'=> $shareId,'status'=>1])->value('id')){
  523. $shareId = 0;
  524. }
  525. if (empty($avatar)) {
  526. showJson(1004, 3004);
  527. }
  528. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  529. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  530. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  531. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  532. $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0;
  533. $year = $birthday ? date('Y', $birthday) : 0;
  534. $age = $year ? date('Y', time()) - $year : 0;
  535. $profileData = [
  536. 'age' => $age,
  537. 'userid' => $this->userId,
  538. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  539. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  540. 'salary' => isset($params['salary']) ? intval($params['salary']) : 0,
  541. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  542. 'education' => isset($params['education']) ? intval($params['education']) : 0,
  543. 'company' => isset($params['company']) ? trim($params['company']) : '',
  544. 'occupation' => isset($params['position']) ? trim($params['position']) : '',
  545. 'property' => isset($params['property']) ? intval($params['property']) : 0,
  546. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  547. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  548. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  549. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  550. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  551. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  552. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  553. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  554. 'qq' => isset($params['qq']) ? trim($params['qq']) : '',
  555. ];
  556. Db::startTrans();
  557. PRedis::set("caches:member:reg_{$mobile}", ['data'=>$profileData,'params'=> $params], 600);
  558. if (UserProfile::checkProfile($this->userId)) {
  559. $profileData['updated_at'] = date('Y-m-d H:i:s');
  560. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  561. } else {
  562. $res = UserProfile::insertGetId($profileData);
  563. }
  564. if (!$res) {
  565. Db::rollback();
  566. showJson(1004, 2052);
  567. }
  568. // 手机号验证时间
  569. $siteInfo = cmf_get_option('site_info');
  570. $verifyMobileTime = isset($siteInfo['verify_mobile_time'])? intval($siteInfo['verify_mobile_time']) : 0;
  571. $verifyMobileTime = $verifyMobileTime? $verifyMobileTime : 7;
  572. $realname = isset($params['realname']) ? trim($params['realname']) : '';
  573. $isMedia = isset($params['is_media'])? intval($params['is_media']) : 0;
  574. $password = $isMedia==1? 'sg6688' : '123456';
  575. $userPass = cmf_password($password);
  576. $inviteType = $shareId?3: 0;
  577. $memberData = [
  578. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  579. 'mobile' => $mobile,
  580. 'user_login' => $mobile,
  581. 'user_pass' => $userPass,
  582. 'pay_password' => $userPass,
  583. 'verify_mobile_expired' => date('Y-m-d H:i:s', time() + $verifyMobileTime * 86400),
  584. 'birthday' => $birthday,
  585. 'sex' => $sex,
  586. 'is_reg_profile' => 1,
  587. 'profile_at'=> date('Y-m-d H:i:s'),
  588. 'is_media' => $isMedia,
  589. 'share_id' => $shareId,
  590. ];
  591. if($realname){
  592. $memberData['real_name'] = $realname;
  593. }
  594. if ($avatar) {
  595. $memberData['avatar'] = $avatar;
  596. }
  597. if($inviteType){
  598. $memberData['invite_type'] = $inviteType;
  599. }
  600. //PRedis::set('members:reg:info:' . $this->userId, $memberData, 3600);
  601. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  602. Db::rollback();
  603. showJson(1004, 2052);
  604. }
  605. // 新媒体账号
  606. if($isMedia>0){
  607. // 添加后台登录权限
  608. if(!Db::name('RoleUser')->where(["role_id" => 14, "user_id" => $this->userId])->value('id')){
  609. Db::name('RoleUser')->insert(["role_id" => 14, "user_id" => $this->userId]);
  610. }
  611. }
  612. // 操作日志
  613. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '完善信息注册']);
  614. Db::commit();
  615. // 进入资源库(手机号注册)
  616. PoolModel::distribute(0, $this->userId, 4);
  617. // 渠道码统计
  618. if($shareId>0){
  619. Channels::where(['id'=> $shareId])->setInc('share_count',1);
  620. }
  621. // 更新缓存
  622. $userInfo = Member::getInfo(['id' => $this->userId]);
  623. session('userInfo', $userInfo);
  624. showJson(1005, 2005);
  625. } catch (\Exception $exception) {
  626. PRedis::set('members:reg:error:' . $this->userId, $exception->getMessage(), 6 * 3600);
  627. showJson(1004, 2136);
  628. }
  629. }
  630. /**
  631. * 完善资料
  632. * @throws \think\Exception
  633. * @throws \think\exception\PDOException
  634. */
  635. public function setProfileTest()
  636. {
  637. try {
  638. $params = input();
  639. $userId = input('uid', 0);
  640. $validate = new MemberValidate();
  641. PRedis::set('members:reg:params:' . $this->userId, ['info' => $this->userInfo, 'params' => $params], 3600);
  642. if (!$validate->scene('reg')->check($params)) {
  643. showJson(1004, $validate->getError());
  644. }
  645. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  646. $code = isset($params['code']) ? trim($params['code']) : '';
  647. $result = Sms::checkCode($mobile, $code);
  648. if (!$userId && $result !== true) {
  649. //showJson(1004, $result);
  650. }
  651. if (empty($this->userId)) {
  652. showJson(1004, 2009);
  653. }
  654. $sex = isset($params['sex']) ? intval($params['sex']) : 0;
  655. if (!in_array($sex, [1, 2])) {
  656. showJson(1004, 2023);
  657. }
  658. // 头像
  659. $avatar = '';
  660. $wxInfo = session('wxInfo');
  661. $file = request()->file('image');
  662. if ($file) {
  663. $fileData = Storage::uploadImg($file, 'avatar', false, false);
  664. if (!is_array($fileData)) {
  665. showJson(1004, $fileData ? $fileData : 3004);
  666. }
  667. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  668. }
  669. if (empty($avatar)) {
  670. showJson(1004, 3004);
  671. }
  672. PRedis::set('members:reg:params2:' . $this->userId, $params, 3600);
  673. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  674. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  675. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  676. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  677. $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0;
  678. $year = $birthday ? date('Y', $birthday) : 0;
  679. $age = $year ? date('Y', time()) - $year : 0;
  680. $profileData = [
  681. 'userid' => $this->userId,
  682. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  683. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  684. 'age' => $age,
  685. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  686. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  687. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  688. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  689. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  690. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  691. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  692. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  693. ];
  694. PRedis::set('members:reg:params3:' . $this->userId, $params, 3600);
  695. Db::startTrans();
  696. PRedis::set('members:reg:profile:' . $this->userId, $profileData, 3600);
  697. if (UserProfile::checkProfile($this->userId)) {
  698. $profileData['updated_at'] = date('Y-m-d H:i:s');
  699. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  700. } else {
  701. $res = UserProfile::insertGetId($profileData);
  702. }
  703. if (!$res) {
  704. Db::rollback();
  705. showJson(1004, 2104);
  706. }
  707. $memberData = [
  708. 'real_name' => isset($params['realname']) ? trim($params['realname']) : '',
  709. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  710. 'mobile' => $mobile,
  711. 'birthday' => $birthday,
  712. 'sex' => $sex,
  713. 'is_reg_profile' => 1,
  714. ];
  715. if ($avatar) {
  716. $memberData['avatar'] = $avatar;
  717. }
  718. PRedis::set('members:reg:info:' . $this->userId, $memberData, 3600);
  719. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  720. Db::rollback();
  721. showJson(1004, 2104);
  722. }
  723. showJson(1005, 1008);
  724. exit;
  725. // 操作日志
  726. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '完善信息注册']);
  727. Db::commit();
  728. // 更新缓存
  729. $userInfo = Member::getInfo(['id' => $this->userId]);
  730. session('userInfo', $userInfo);
  731. showJson(1005, 1008);
  732. } catch (\Exception $exception) {
  733. PRedis::set('members:reg:error:' . $this->userId, $exception, 6 * 3600);
  734. showJson(1004, 2136);
  735. }
  736. }
  737. /**
  738. * 保存资料
  739. */
  740. public function saveInfo()
  741. {
  742. $params = input();
  743. $validate = new MemberValidate();
  744. if (!$validate->scene('info')->check($params)) {
  745. showJson(1004, $validate->getError());
  746. }
  747. $newMobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  748. $mobile = isset($this->userInfo['mobile']) ? $this->userInfo['mobile'] : '';
  749. if ($newMobile && $newMobile != $mobile) {
  750. $code = isset($params['code']) ? trim($params['code']) : '';
  751. $result = Sms::checkCode($newMobile, $code);
  752. if ($result !== true) {
  753. showJson(1004, $result);
  754. }
  755. // 验证手机号码是否被使用
  756. $id = Member::where(['mobile' => $newMobile])->value('id');
  757. if ($id && $id != $this->userId) {
  758. showJson(1004, 2001);
  759. }
  760. }
  761. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  762. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  763. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  764. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  765. $birthday = isset($params['birthday']) ? strtotime($params['birthday']) : 0;
  766. $year = $birthday ? date('Y', $birthday) : 0;
  767. $age = $year ? date('Y', time()) - $year : 0;
  768. $info = [
  769. 'userid' => $this->userId,
  770. 'age' => $age,
  771. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  772. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  773. 'salary' => isset($params['salary']) ? intval($params['salary']) : 0,
  774. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  775. 'education' => isset($params['education']) ? intval($params['education']) : 0,
  776. 'company' => isset($params['company']) ? trim($params['company']) : '',
  777. 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '',
  778. 'property' => isset($params['property']) ? intval($params['property']) : 0,
  779. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  780. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  781. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  782. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  783. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  784. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  785. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  786. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  787. 'qq' => isset($params['qq']) ? trim($params['qq']) : '',
  788. ];
  789. Db::startTrans();
  790. if (UserProfile::checkProfile($this->userId)) {
  791. $profileData['updated_at'] = date('Y-m-d H:i:s');
  792. $res = UserProfile::saveData(['userid' => $this->userId], $info);
  793. } else {
  794. $res = UserProfile::insertGetId($info);
  795. }
  796. if (!$res) {
  797. Db::rollback();
  798. showJson(1004, 2030);
  799. }
  800. $memberData = [
  801. 'real_name' => isset($params['realname']) ? trim($params['realname']) : '',
  802. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  803. 'birthday' => $birthday,
  804. 'sex' => isset($params['sex']) ? intval($params['sex']) : 0,
  805. ];
  806. if ($newMobile && $mobile != $newMobile) {
  807. $memberData['mobile'] = $newMobile;
  808. }
  809. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  810. Db::rollback();
  811. showJson(1004, 2104);
  812. }
  813. Db::commit();
  814. showJson(1005, 2029);
  815. }
  816. /**
  817. * 获取资料
  818. * @throws \think\db\exception\DataNotFoundException
  819. * @throws \think\db\exception\ModelNotFoundException
  820. * @throws \think\exception\DbException
  821. */
  822. public function getProfile()
  823. {
  824. $info = [];
  825. $type = input('type', 1);
  826. switch ($type) {
  827. case 1:
  828. $photolistArr = [];
  829. $photolist = UserProfile::where(['userid' => $this->userId])->value('photolist');
  830. $photolists = $photolist ? explode(',', $photolist) : [];
  831. $info['photolist'] = $photolist ? $photolist : '';
  832. foreach ($photolists as $k => $val) {
  833. $photolistArr[$k]['file'] = $val;
  834. $photolistArr[$k]['preview'] = $val ? cmf_get_image_preview_url($val) : '';
  835. }
  836. $info['photolists'] = $photolistArr;
  837. break;
  838. default:
  839. $field = 'userid,introduce,introduce_img,brief,brief,family,family_img,hobby,hobby_img,purpose,purpose_img,cause,cause_img,expect,tags,expect_img';
  840. $info = UserProfile::where(['userid' => $this->userId])->field($field)->find();
  841. $info = $info ? $info->toArray() : [];
  842. if (isset($info['introduce_img'])) {
  843. $info['introduce_img_preview'] = $info['introduce_img'] ? cmf_get_image_preview_url($info['introduce_img']) : '';
  844. }
  845. if (isset($info['family_img'])) {
  846. $info['family_img_preview'] = $info['family_img'] ? cmf_get_image_preview_url($info['family_img']) : '';
  847. }
  848. if (isset($info['hobby_img'])) {
  849. $info['hobby_img_preview'] = $info['hobby_img'] ? cmf_get_image_preview_url($info['hobby_img']) : '';
  850. }
  851. if (isset($info['purpose_img'])) {
  852. $info['purpose_img_preview'] = $info['purpose_img'] ? cmf_get_image_preview_url($info['purpose_img']) : '';
  853. }
  854. if (isset($info['cause_img'])) {
  855. $info['cause_img_preview'] = $info['cause_img'] ? cmf_get_image_preview_url($info['cause_img']) : '';
  856. }
  857. if (isset($info['expect_img'])) {
  858. $info['expect_img_preview'] = $info['expect_img'] ? cmf_get_image_preview_url($info['expect_img']) : '';
  859. }
  860. if (isset($info['tags'])) {
  861. $info['tags'] = $info['tags'] ? explode(',', $info['tags']) : [];
  862. }
  863. break;
  864. }
  865. showJson(1005, 1008, $info);
  866. }
  867. /*
  868. * 头像
  869. *
  870. */
  871. public function setAvatar()
  872. {
  873. $avatar = '';
  874. $file = request()->file('image');
  875. if ($file) {
  876. $fileData = Storage::uploadImg($file, 'avatar');
  877. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  878. }
  879. if (empty($avatar)) {
  880. showJson(1004, 3007);
  881. }
  882. // 保存
  883. $idcardCheck = UserProfile::where(['userid' => $this->userId])->value('idcard_check');
  884. $oldAvatar = Member::where(['id' => $this->userId])->value('avatar');
  885. $data = $idcardCheck == 2? ['avatar_confirm'=> $avatar,'avatar_confirm_status'=> 2] : ['avatar' => $avatar,'avatar_confirm_status'=> 1];
  886. if (!Member::saveData(['id' => $this->userId], $data)) {
  887. showJson(1004, 2030);
  888. }
  889. if ($idcardCheck != 2 && file_exists('upload/' . $oldAvatar)) {
  890. @unlink('upload/' . $oldAvatar);
  891. $paths = explode('_', basename($oldAvatar));
  892. $filename = end($paths);
  893. $filename = 'upload/' . dirname($oldAvatar) . '/' . $filename;
  894. if ($filename && file_exists($filename)) {
  895. @unlink($filename);
  896. }
  897. }
  898. showJson(1005, $idcardCheck==2? 2051 : 2050);
  899. }
  900. /**
  901. * 保存资料
  902. */
  903. public function saveProfile()
  904. {
  905. $info = [];
  906. $img = input('img', '');
  907. $params = input();
  908. // 需要先完成身份认证
  909. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  910. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  911. }
  912. // 学历证明照片
  913. $file = request()->file('image');
  914. if ($file) {
  915. $fileData = Storage::uploadImg($file, 'profile');
  916. $img = isset($fileData['file']) ? $fileData['file'] : '';
  917. $oldImg = isset($params['img']) ? $params['img'] : '';
  918. if ($img && $oldImg) {
  919. @unlink('upload/' . $oldImg);
  920. }
  921. }
  922. if (isset($params['photolist'])) {
  923. $info['photolist'] = trim($params['photolist']);
  924. }
  925. if (isset($params['introduce'])) {
  926. $info['introduce'] = trim($params['introduce']);
  927. $info['introduce_img'] = $img;
  928. }
  929. if (isset($params['family'])) {
  930. $info['family'] = trim($params['family']);
  931. $info['family_img'] = $img;
  932. }
  933. if (isset($params['hobby'])) {
  934. $info['hobby'] = trim($params['hobby']);
  935. $info['hobby_img'] = $img;
  936. }
  937. if (isset($params['purpose'])) {
  938. $info['purpose'] = trim($params['purpose']);
  939. $info['purpose_img'] = $img;
  940. }
  941. if (isset($params['cause'])) {
  942. $info['cause'] = trim($params['cause']);
  943. $info['cause_img'] = $img;
  944. }
  945. if (isset($params['expect'])) {
  946. $info['expect'] = trim($params['expect']);
  947. $info['expect_img'] = $img;
  948. }
  949. // 标签
  950. if (isset($params['tags'])) {
  951. $info['tags'] = trim($params['tags']);
  952. }
  953. if (!UserProfile::saveData(['userid' => $this->userId], $info)) {
  954. showJson(1004, 2030);
  955. }
  956. // 奖励
  957. UserProfile::profileAward($this->userId);
  958. showJson(1005, 2029);
  959. }
  960. /**
  961. * 获取主页信息
  962. */
  963. public function getHomeInfo()
  964. {
  965. $id = input('id', 0);
  966. $cid = input('cid', 0);
  967. $type = input('type', 1);
  968. // 基础信息
  969. $userId = $id ? $id : $this->userId;
  970. $myInfo = Member::getHomeInfo($userId, '', $type);
  971. // 访问记录
  972. $isHeart = isset($myInfo['is_heart'])? $myInfo['is_heart'] : 0;
  973. $status = isset($myInfo['user_status'])? $myInfo['user_status'] : 0;
  974. $profileReg = isset($myInfo['is_reg_profile'])? $myInfo['is_reg_profile'] : 0;
  975. if($myInfo && ($isHeart==1 && $status ==1 && $profileReg==1) && $type == 4){
  976. Member::makeUserAccess($userId, $this->userId);
  977. }
  978. $cUserInfo = [];
  979. $cInfo = [];
  980. if ($cid <= 0 && $id) {
  981. $cid = UserContactLog::where(['user_id' => $this->userId, 'contact_uid' => $id])
  982. ->where('status', 'in', [1, 2, 3])
  983. ->value('id');
  984. if ($cid <= 0) {
  985. $cid = UserContactLog::where(['contact_uid' => $this->userId, 'user_id' => $id])
  986. ->where('status', 'in', [1, 2, 3])
  987. ->value('id');
  988. }
  989. }
  990. if ($cid > 0) {
  991. // 认识记录
  992. $cInfo = UserContactLog::where(['id' => $cid])->where('status', 'in', [1, 2, 3])->field('id,user_id,contact_uid,is_read,status')->find();
  993. $cUid = isset($cInfo['contact_uid']) ? intval($cInfo['contact_uid']) : 0;
  994. $status = isset($cInfo['status']) ? intval($cInfo['status']) : 0;
  995. if ($cUid) {
  996. // 被申请方查看,更新申请微信阅读状态
  997. if ($cUid == $this->userId) {
  998. UserContactLog::where(['id' => $cid])->update(['is_read' => 1]);
  999. }
  1000. // 想认识的人的信息
  1001. $field = 'm.id,m.user_nickname,m.avatar,m.real_name,up.wechat_code,up.qq';
  1002. $cUserInfo = Member::getHomeInfo($cUid, $field, 2);
  1003. // 未确认认识的不展示联系方式
  1004. if ($status != 2 && $cUserInfo) {
  1005. $cUserInfo['wechat_code'] = '';
  1006. $cUserInfo['qq'] = '';
  1007. }
  1008. }
  1009. }
  1010. //PRedis::set('test:' . $userId, ['homeInfo' => $myInfo, 'cUserInfo' => $cUserInfo, 'cInfo' => $cInfo], 600);
  1011. showJson(1005, 1008, ['homeInfo' => $myInfo, 'cUserInfo' => $cUserInfo, 'cInfo' => $cInfo]);
  1012. }
  1013. /**
  1014. * 单身推荐列表
  1015. */
  1016. public function getRecommendList()
  1017. {
  1018. $params = input();
  1019. $pageSize = input('pageSize', 12);
  1020. $type = input('type', 1);
  1021. $uid = input('uid', 0);
  1022. $refresh = input('refresh', 0);
  1023. $userId = $uid ? $uid : $this->userId;
  1024. if ($type == 1) {
  1025. $params['user_id'] = $userId;
  1026. $dataList = Member::getRecommendList($params, $pageSize);
  1027. Member::visitCount($userId, 'match');
  1028. } else {
  1029. //$userId = $userId == '102712'? 116865: $userId;
  1030. $dataList = Member::getHeartList($userId, '', $refresh);
  1031. Member::visitCount($userId, 'heart');
  1032. }
  1033. if(date('H:i')>='20:00'){
  1034. $time = strtotime(date('Y-m-d 20:00:00'))+86400 - time();
  1035. }else{
  1036. $time = strtotime(date('Y-m-d 20:00:00')) - time();
  1037. }
  1038. showJson(1005, 1001, ['list'=>$dataList,'refresh'=>$refresh,'time'=>$time]);
  1039. }
  1040. /**
  1041. * 获取首页置顶列表
  1042. */
  1043. public function getTopList(){
  1044. $params = input();
  1045. $pageSize = input('pageSize', 12);
  1046. $type = input('type', 1);
  1047. $params['user_id'] = $this->userId;
  1048. $dataList = Member::getTopList($params, $pageSize);
  1049. showJson(1005, 1001, $dataList);
  1050. }
  1051. /**
  1052. * 设置隐私
  1053. */
  1054. public function setPrivacy()
  1055. {
  1056. $type = input('type', 1);
  1057. $value = input('value', 0);
  1058. $reset = input('reset', 0);
  1059. if (!in_array($type, [1, 2, 3])) {
  1060. showJson(1004, 2129);
  1061. }
  1062. $types = [1 => 'show_graduate', 2 => 'show_company'];
  1063. if ($type == 3) {
  1064. if ($value == 1) {
  1065. if(!UserProfile::checkUserProfile($this->userId)){
  1066. showJson(1006,2045, ['url'=> Wechat::makeRedirectUrl(url('/weixin/member/profile','','',true))]);
  1067. }
  1068. Member::where(['id' => $this->userId, 'user_type' => 2])
  1069. ->update(['is_heart' => 1]);
  1070. // 操作日志
  1071. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "取消隐身模式"]);
  1072. showJson(1005, 2036);
  1073. }
  1074. // 扣除爱心账户
  1075. $accountConfig = cmf_get_option('account_config');
  1076. $hiddenPay = isset($accountConfig['hidden_pay']) ? intval($accountConfig['hidden_pay']) : 0;
  1077. $hiddenPay = $hiddenPay ? $hiddenPay : 10;
  1078. $memberInfo = Member::where(['id' => $this->userId, 'user_type' => 2])->field('redheart,vip_auth,vip_expire,is_heart,invisible_time')->find();
  1079. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  1080. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  1081. $isVip = $vipAuth && $vipExpire>=time()? true : false;
  1082. $isHeart = isset($memberInfo['is_heart']) ? intval($memberInfo['is_heart']) : 0;
  1083. $invisibleTime = isset($memberInfo['invisible_time']) ? intval($memberInfo['invisible_time']) : 0;
  1084. if ($reset != 1 && $invisibleTime >= time() - 7 * 24 * 3600) {
  1085. showJson(1004, lang($isVip? 'invisible_vip' : 'invisible', ['num'=> $hiddenPay,'date' => date('Y-m-d', $invisibleTime)]));
  1086. }
  1087. if ($isHeart == 2 && $value == 0) {
  1088. showJson(1004, 2034);
  1089. }
  1090. // 扣除爱心隐身
  1091. Db::startTrans();
  1092. if ($reset == 1 && !$isVip) {
  1093. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  1094. if ($redheart < $hiddenPay) {
  1095. showJson(1004, 2137);
  1096. }
  1097. if (!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $hiddenPay)) {
  1098. Db::rollback();
  1099. showJson(1004, 2031);
  1100. }
  1101. // 账户明细
  1102. $accountData = [
  1103. 'user_id' => $this->userId,
  1104. 'type' => 2,
  1105. 'account_type' => 1,
  1106. 'change_type' => 2,
  1107. 'money' => $hiddenPay,
  1108. 'balance' => $redheart,
  1109. 'remark' => "付费设置隐身模式【{$this->userId}】扣除{$hiddenPay}个爱心",
  1110. 'created_at' => date('Y-m-d H:i:s'),
  1111. 'status' => 2,
  1112. ];
  1113. PRedis::set('accounts:privacy:' . $this->userId, $accountData, 600);
  1114. if (!AccountLog::insertGetId($accountData)) {
  1115. Db::rollback();
  1116. return false;
  1117. }
  1118. }
  1119. // 更新设置隐身模式
  1120. Member::where(['id' => $this->userId, 'user_type' => 2])
  1121. ->update(['is_heart' => 2, 'invisible_time' => time()]);
  1122. // 操作日志
  1123. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "设置隐身模式"]);
  1124. Db::commit();
  1125. showJson(1005, 2035);
  1126. } else {
  1127. $field = $types[$type];
  1128. if (!UserProfile::saveData(['userid' => $this->userId], [$field => $value])) {
  1129. showJson(1004, 2131);
  1130. }
  1131. }
  1132. showJson(1005, 2130);
  1133. }
  1134. /**
  1135. * 设置微信号
  1136. */
  1137. public function setWechat(){
  1138. $params = input();
  1139. $validate = new MemberValidate();
  1140. if (!$validate->scene('wechat')->check($params)) {
  1141. showJson(1004, $validate->getError());
  1142. }
  1143. // 验证
  1144. $this->checkUser();
  1145. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1146. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1147. }
  1148. $cacheKey = "cache:wechat:account:{$this->userId}";
  1149. if(PRedis::get($cacheKey)){
  1150. showJson(1004, 2049);
  1151. }
  1152. $wechatCode = input('wechat_code','');
  1153. if(UserProfile::where(['userid'=> $this->userId])->update(['wechat_code'=>$wechatCode,'updated_at'=>date('Y-m-d H:i:s')])){
  1154. PRedis::set($cacheKey, ['params'=> $params], 300);
  1155. showJson(1005, 2047);
  1156. }else{
  1157. showJson(1004,2048);
  1158. }
  1159. }
  1160. /**
  1161. * 关注用户
  1162. */
  1163. public function collect()
  1164. {
  1165. // 验证
  1166. $this->checkUser();
  1167. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1168. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1169. }
  1170. $id = input('id');
  1171. $opType = input('type', 1);
  1172. $result = Member::collect($this->userId, $id, $opType);
  1173. if ($result === true) {
  1174. showJson(1005, $opType == 1 ? 2106 : 2108);
  1175. } else {
  1176. showJson(1004, $result);
  1177. }
  1178. }
  1179. /**
  1180. * 获取关注用户/收藏活动列表
  1181. */
  1182. public function getCollectList()
  1183. {
  1184. $params = input();
  1185. $pageSize = input('pageSize', 12);
  1186. $type = input('type', 1);
  1187. $dataList = [];
  1188. if ($type == 1) {
  1189. $dataList = UserCollect::getUserList($this->userId, $params, $pageSize);
  1190. } else if ($type == 2) {
  1191. $dataList = UserCollect::getFollowUserList($this->userId, $params, $pageSize);
  1192. }
  1193. showJson(1005, 1001, $dataList);
  1194. }
  1195. /**
  1196. * 获取申请微信消息列表
  1197. */
  1198. public function getMessageList()
  1199. {
  1200. $params = input();
  1201. $pageSize = input('pageSize', 12);
  1202. $dataList = Member::getMessageList($this->userId, $params, $pageSize);
  1203. showJson(1005, 1001, $dataList);
  1204. }
  1205. /**
  1206. * 获取申请微信消息详情
  1207. */
  1208. public function getMessageInfo()
  1209. {
  1210. $id = input('id', 0);
  1211. $info = Member::getMessageInfo($id, $this->userId);
  1212. showJson(1005, 1001, $info);
  1213. }
  1214. /**
  1215. * 认证
  1216. */
  1217. public function authSubmit()
  1218. {
  1219. // 验证
  1220. $this->checkUser();
  1221. $params = input();
  1222. $scene = isset($params['scene']) ? trim($params['scene']) : '';
  1223. $scene = in_array($scene, ['idcard', 'education', 'position']) ? $scene : 'idcard';
  1224. $validate = new MemberValidate();
  1225. if (!$validate->scene($scene)->check($params)) {
  1226. showJson(1004, $validate->getError());
  1227. }
  1228. if ($scene != 'idcard' && UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1229. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1230. }
  1231. // 处理
  1232. switch ($scene) {
  1233. case 'idcard': // 身份证认证
  1234. $idcard = isset($params['idcard']) ? trim($params['idcard']) : '';
  1235. $realname = isset($params['realname'])? trim($params['realname']) : '';
  1236. $profileData = [
  1237. 'idcard' => $idcard,
  1238. 'front_idcard' => isset($params['front_idcard']) ? trim($params['front_idcard']) : '',
  1239. 'back_idcard' => isset($params['back_idcard']) ? trim($params['back_idcard']) : '',
  1240. 'idcard_type' => isset($params['idcard_type']) ? intval($params['idcard_type']) : 1,
  1241. 'idcard_check' => 1,
  1242. ];
  1243. // 验证身份证号是否被使用
  1244. $checkId = UserProfile::where(['idcard' => $idcard])
  1245. ->where('userid', 'not in', $this->userId)
  1246. ->value('id');
  1247. if ($checkId) {
  1248. showJson(1004, 2128);
  1249. }
  1250. // 身份证照片
  1251. if (empty($profileData['front_idcard'])) {
  1252. showJson(1004, 2024);
  1253. }
  1254. if (empty($profileData['back_idcard'])) {
  1255. showJson(1004, 2025);
  1256. }
  1257. Db::startTrans();
  1258. if (!Member::saveData(['id' => $this->userId], ['real_name' => $realname])) {
  1259. Db::rollback();
  1260. showJson(1004, 2026);
  1261. }
  1262. // 在线验证是否通过
  1263. $profileData['idcard_online_check'] = 0;
  1264. if (UserProfile::checkProfile($this->userId)) {
  1265. $profileData['updated_at'] = date('Y-m-d H:i:s');
  1266. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  1267. } else {
  1268. $res = UserProfile::insertGetId($profileData);
  1269. }
  1270. if (!$res) {
  1271. Db::rollback();
  1272. showJson(1004, 2026);
  1273. }
  1274. // 操作日志
  1275. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交身份证认证']);
  1276. Db::commit();
  1277. showJson(1005, 2027);
  1278. break;
  1279. case 'education': // 学历认证
  1280. $educationType = isset($params['education_type']) ? intval($params['education_type']) : 0;
  1281. $profileData = [
  1282. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  1283. 'education' => isset($params['education']) ? trim($params['education']) : '',
  1284. 'education_img' => isset($params['education_img']) ? trim($params['education_img']) : '',
  1285. 'education_code' => isset($params['education_code']) ? trim($params['education_code']) : '',
  1286. 'education_type' => $educationType,
  1287. 'education_check' => 1,
  1288. ];
  1289. $siteInfo = cmf_get_site_info();
  1290. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  1291. // 学历证明照片
  1292. if ($educationType != 2){
  1293. $file = request()->file('image1');
  1294. if ($file) {
  1295. $fileData = Storage::uploadImg($file, 'education_img');
  1296. $educationImg = isset($fileData['file']) ? $fileData['file'] : '';
  1297. $profileData['education_img'] = $waterTxt ? Storage::imageWater($educationImg, $waterTxt) : $educationImg;
  1298. }
  1299. if (empty($profileData['education_img'])) {
  1300. showJson(1004, 2028);
  1301. }
  1302. }
  1303. Db::startTrans();
  1304. if (UserProfile::checkProfile($this->userId)) {
  1305. $profileData['updated_at'] = date('Y-m-d H:i:s');
  1306. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  1307. } else {
  1308. $res = UserProfile::insertGetId($profileData);
  1309. }
  1310. if (!$res) {
  1311. Db::rollback();
  1312. showJson(1004, 2026);
  1313. }
  1314. // 操作日志
  1315. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交学历认证']);
  1316. Db::commit();
  1317. showJson(1005, 2027);
  1318. break;
  1319. case 'position': // 职位认证
  1320. $profileData = [
  1321. 'company' => isset($params['company']) ? trim($params['company']) : '',
  1322. 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '',
  1323. 'position_img' => isset($params['position_img']) ? trim($params['position_img']) : '',
  1324. 'position_type' => isset($params['position_type']) ? intval($params['position_type']) : 0,
  1325. 'position_hide' => isset($params['position_hide']) ? intval($params['position_hide']) : 0,
  1326. 'position_check' => 1,
  1327. ];
  1328. $siteInfo = cmf_get_site_info();
  1329. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  1330. // 职位证明照片
  1331. $file = request()->file('image1');
  1332. if ($file) {
  1333. $fileData = Storage::uploadImg($file, 'position_img', false, false);
  1334. $positionImg = isset($fileData['file']) ? $fileData['file'] : '';
  1335. $profileData['position_img'] = $waterTxt ? Storage::imageWater($positionImg, $waterTxt) : $positionImg;
  1336. }
  1337. //PRedis::set('test:auth:' . $this->userId, ['file' => $file, 'data' => $fileData, 'profile' => $profileData], 600);
  1338. if (empty($profileData['position_img'])) {
  1339. showJson(1004, 2033);
  1340. }
  1341. Db::startTrans();
  1342. if (UserProfile::checkProfile($this->userId)) {
  1343. $profileData['updated_at'] = date('Y-m-d H:i:s');
  1344. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  1345. } else {
  1346. $res = UserProfile::insertGetId($profileData);
  1347. }
  1348. if (!$res) {
  1349. Db::rollback();
  1350. showJson(1004, 2026);
  1351. }
  1352. // 操作日志
  1353. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交职业认证']);
  1354. Db::commit();
  1355. showJson(1005, 2027);
  1356. break;
  1357. }
  1358. showJson(1004, 2009);
  1359. }
  1360. /**
  1361. * 在线认证
  1362. */
  1363. public function authCheck(){
  1364. // 验证
  1365. $this->checkUser();
  1366. $params = input();
  1367. $validate = new MemberValidate();
  1368. if (!$validate->scene('idcard')->check($params)) {
  1369. showJson(1004, $validate->getError());
  1370. }
  1371. // 验证身份证号是否被使用
  1372. $idcard = isset($params['idcard'])? trim($params['idcard']) : '';
  1373. $checkId = UserProfile::where(['idcard' => $idcard])
  1374. ->where('userid', 'not in', $this->userId)
  1375. ->whereIn('idcard_check',[1,2])
  1376. ->value('id');
  1377. if ($checkId) {
  1378. showJson(1004, 2128);
  1379. }
  1380. $result = ZimFace::check($this->userId,$params);
  1381. $data = isset($result['result'])? $result['result'] : [];
  1382. $code = isset($result['code']) && $result['code']? $result['code'] : 'error';
  1383. $msg = isset($result['msg']) && $result['msg']? $result['msg'] : '验证错误';
  1384. showJson($code, $msg, $data);
  1385. }
  1386. /**
  1387. * 加入怦然心动
  1388. */
  1389. public function joinHeart()
  1390. {
  1391. // 验证
  1392. $this->checkUser();
  1393. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1394. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1395. }
  1396. if (!UserProfile::checkUserProfile($this->userId)) {
  1397. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  1398. }
  1399. $isHeart = input('is_heart', 2);
  1400. if (!in_array($isHeart, [1, 2])) {
  1401. showJson(1004, 2111);
  1402. }
  1403. $result = Member::where(['id' => $this->userId])
  1404. ->update(['updated_at' => date('Y-m-d H:i:s'), 'is_heart' => $isHeart]);
  1405. if ($result) {
  1406. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => $isHeart == 1 ? '加入怦然心动' : '取消加入怦然心动']);
  1407. showJson(1005, $isHeart == 1 ? 5017 : 5019);
  1408. } else {
  1409. showJson(1004, $isHeart == 1 ? 5018 : 5020);
  1410. }
  1411. }
  1412. /**
  1413. * 设置用户推荐条件
  1414. */
  1415. public function setConditions()
  1416. {
  1417. // 验证
  1418. $this->checkUser();
  1419. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1420. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1421. }
  1422. $params = input();
  1423. PRedis::set('test:conditions:' . $this->userId, $params, 600);
  1424. $res = Member::setMemberConditions($this->userId, $params);
  1425. if ($res) {
  1426. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => '设置推荐条件']);
  1427. showJson(1005, 1008);
  1428. } else {
  1429. showJson(1004, 1009);
  1430. }
  1431. }
  1432. /**
  1433. * 获取推荐条件
  1434. */
  1435. public function getConditions()
  1436. {
  1437. $conditions = Member::getMemberConditions($this->userId);
  1438. showJson(1005, 1008, $conditions);
  1439. }
  1440. /**
  1441. * 获取我的活动列表
  1442. */
  1443. public function getActivityList()
  1444. {
  1445. $params = input();
  1446. $pageSize = input('pageSize', 12);
  1447. $params['user_id'] = $this->userId;
  1448. $dataList = Activity::getMemberActivityList($params, $pageSize);
  1449. showJson(1005, 1001, $dataList);
  1450. }
  1451. /**
  1452. * 爱心充值
  1453. * @throws \think\db\exception\DataNotFoundException
  1454. * @throws \think\db\exception\ModelNotFoundException
  1455. * @throws \think\exception\DbException
  1456. */
  1457. public function doRecharge()
  1458. {
  1459. // 验证
  1460. $this->checkUser();
  1461. $money = input('money', 0);
  1462. $num = input('num', 0);
  1463. $mealId = input('meal_id', 0);
  1464. if (empty($money) || empty($num)) {
  1465. showJson(1004, 4001);
  1466. }
  1467. if(empty($mealId)){
  1468. showJson(1004, 4006);
  1469. }
  1470. $mealInfo = HeartMeal::where(['id'=> $mealId,'status'=> 1])->find();
  1471. $money = isset($mealInfo['price'])? $mealInfo['price'] : 0;
  1472. $giveNum = isset($mealInfo['give'])? $mealInfo['give'] : 0;
  1473. if(empty($mealInfo)){
  1474. showJson(1004, 4007);
  1475. }
  1476. if($mealInfo['heart']<=0 || $mealInfo['price']<=0){
  1477. showJson(1004, 4008);
  1478. }
  1479. //
  1480. if($mealInfo['limit_buy']>0){
  1481. $rechargeNum = db('user_recharge_log')->where(['user_id'=> $this->userId,'type'=>1,'source_id'=> $mealId,'status'=>2])
  1482. ->count('id');
  1483. if($rechargeNum>= $mealInfo['limit_buy']){
  1484. showJson(1004, lang(4009,['num'=>$mealInfo['limit_buy']]));
  1485. }
  1486. }
  1487. if($mealId<=0){
  1488. $accountConfig = $siteInfo = cmf_get_option('account_config');
  1489. $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
  1490. $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
  1491. if ($minRecharge && $num < $minRecharge) {
  1492. showJson(1004, '最低充值数量为:' . $minRecharge . '个');
  1493. }
  1494. $realMoney = moneyFormat($num * $chargeRate, 2);
  1495. if ($realMoney != $money) {
  1496. showJson(1004, '支付金额计算错误:' . $realMoney);
  1497. }
  1498. }else{
  1499. $num = intval($mealInfo['heart']);
  1500. $money = $mealInfo['price'];
  1501. }
  1502. $orderSn = makeTradeNo('RH', $this->userId);
  1503. $memberInfo = Member::where(['id' => $this->userId])->field('openid,redheart')->find();
  1504. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  1505. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1506. $log = [
  1507. 'order_sn' => $orderSn,
  1508. 'source_id' => $mealId,
  1509. 'money' => intval($num),
  1510. 'give_num' => intval($giveNum),
  1511. 'pay_money' => $money,
  1512. 'user_id' => $this->userId,
  1513. 'balance' => $redheart,
  1514. 'remark' => "爱心充值:{$num}个".($giveNum? "赠送{$giveNum}个":'').",合计:{$money}元",
  1515. 'created_at' => date('Y-m-d H:i:s')
  1516. ];
  1517. $orderId = db('user_recharge_log')->insertGetId($log);
  1518. if ($orderId) {
  1519. // 获取OPENID
  1520. if (empty($openid)) {
  1521. showJson(1004, 2010);
  1522. }
  1523. $order = [
  1524. 'orderNo' => $orderSn,
  1525. 'amount' => $money,
  1526. 'openid' => $openid,
  1527. 'body' => '爱心充值订单支付',
  1528. ];
  1529. $params = Wechat::jsapiUnifiedorder($order, 'recharge');
  1530. PRedis::set('orders:recharge:redheart:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1531. $code = isset($params['code']) ? $params['code'] : '';
  1532. if ($code == 1004) {
  1533. showJson(1004, $params['message']);
  1534. }
  1535. // 更新订单参数
  1536. unset($params['prepay_id']);
  1537. showJson(1005, 4004, $params);
  1538. } else {
  1539. showJson(1004, 4005);
  1540. }
  1541. }
  1542. /**
  1543. * 想认识
  1544. */
  1545. public function doContact()
  1546. {
  1547. // 验证
  1548. $this->checkUser();
  1549. $id = input('id', 0);
  1550. $remark = input('remark', '');
  1551. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1552. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1553. }
  1554. // 完善个人信息
  1555. if (!UserProfile::checkUserProfile($this->userId)) {
  1556. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  1557. }
  1558. // 隐身不可申请
  1559. $type = input('type', 1);
  1560. $isHeart = Member::where(['id' => $this->userId])->value('is_heart');
  1561. if ($isHeart != 1 && $type != 2) {
  1562. showJson(1006, 2037, ['type' => 'check']);
  1563. }
  1564. $res = Member::contactUser($this->userId, $id, $remark);
  1565. if (is_array($res)) {
  1566. showJson(1005, 1008);
  1567. } else if ($res == 2103) {
  1568. $referer = request()->server('HTTP_REFERER');
  1569. $rebackurl = $referer ? $referer : url('/weixin/match/index', '', '', true);
  1570. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/index/entry?rebackurl=' . $rebackurl, '', '', true))]);
  1571. } else if ($res == 2121) {
  1572. showJson(1006, $res ? $res : 1009, ['url' => '/weixin/member/invite']);
  1573. } else {
  1574. showJson(1004, $res ? $res : 1009);
  1575. }
  1576. }
  1577. /**
  1578. * 邀请认证
  1579. * @throws \think\db\exception\DataNotFoundException
  1580. * @throws \think\db\exception\ModelNotFoundException
  1581. * @throws \think\exception\DbException
  1582. */
  1583. public function inviteAuth(){
  1584. // 验证
  1585. $this->checkUser();
  1586. $uid = input('uid', 0);
  1587. $type = input('type', 1);
  1588. if($this->userId == $uid){
  1589. showJson(1004, 2009);
  1590. }
  1591. $info = Member::where(['id' => $this->userId, 'user_status'=> 1])->field('user_nickname,openid,vip_auth,vip_expire')->find();
  1592. if(empty($info)){
  1593. showJson(1004, 2140);
  1594. }
  1595. $nickname = isset($info['user_nickname'])? $info['user_nickname'] : '';
  1596. $memberInfo = Member::where(['id' => $uid, 'user_status'=> 1])->field('user_nickname,openid,vip_auth,vip_expire')->find();
  1597. if(empty($memberInfo)){
  1598. showJson(1004, 2140);
  1599. }
  1600. $cacheKey = 'messages:inviteAuth:' . $this->userId . '_' . $uid.'_'.$type;
  1601. if(PRedis::get($cacheKey)){
  1602. showJson(1004, 2141);
  1603. }
  1604. $nickname1 = isset($memberInfo['user_nickname'])? $memberInfo['user_nickname'] : '';
  1605. $openid = isset($memberInfo['openid'])? $memberInfo['openid'] : '';
  1606. $typeNames = [1=>'实名认证',2=>'工作认证',3=>'学历认证'];
  1607. if(empty($openid)){
  1608. showJson(1004, 2009);
  1609. }
  1610. $params = [
  1611. 'from_user_id'=> $this->userId,
  1612. 'to_user_id'=> $uid,
  1613. 'title' => "您好亲{$nickname1},用户{$nickname}邀请您完成认证",
  1614. 'remark' => "完成认证,可以让更多人认识你哦!",
  1615. 'type' => 'contact_confirm',
  1616. 'keywords' => [
  1617. 'keyword1' => [
  1618. 'value' => isset($typeNames[$type])? $typeNames[$type] : '认证',
  1619. 'color' => '#173177',
  1620. ],
  1621. 'keyword2' => [
  1622. 'value' => '邀请认证',
  1623. 'color' => '#173177',
  1624. ],
  1625. ],
  1626. 'url' => url("/weixin/auth/".($type==1? 'idcard': ($type==2? 'position':'education')), '', '', true),
  1627. ];
  1628. PRedis::set($cacheKey, ['info' => $info, 'data' => $memberInfo, 'params' => $params], 6*3600);
  1629. Wechat::sendTplMsg($openid, $params);
  1630. showJson(1005, 1008);
  1631. }
  1632. /**
  1633. * 认识审核确认
  1634. */
  1635. public function contactConfirm()
  1636. {
  1637. // 验证
  1638. $this->checkUser();
  1639. $cid = input('cid', 0);
  1640. $status = input('status', 2);
  1641. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1642. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1643. }
  1644. $res = Member::contactConfirm($this->userId, $cid, $status);
  1645. if (is_array($res)) {
  1646. showJson(1005, 1008);
  1647. } else {
  1648. showJson(1004, $res ? $res : 1009);
  1649. }
  1650. }
  1651. /**
  1652. * 套餐列表
  1653. * @throws \think\db\exception\DataNotFoundException
  1654. * @throws \think\db\exception\ModelNotFoundException
  1655. * @throws \think\exception\DbException
  1656. */
  1657. public function mealList()
  1658. {
  1659. $type = input('type', 0);
  1660. showJson(1005, 1001, Meals::getList($type));
  1661. }
  1662. /**
  1663. * @throws \think\db\exception\DataNotFoundException
  1664. * @throws \think\db\exception\ModelNotFoundException
  1665. * @throws \think\exception\DbException
  1666. */
  1667. public function heartMeals(){
  1668. showJson(1005, 1001, HeartMeal::getList());
  1669. }
  1670. /**
  1671. * @throws \think\db\exception\DataNotFoundException
  1672. * @throws \think\db\exception\ModelNotFoundException
  1673. * @throws \think\exception\DbException
  1674. */
  1675. public function signMeals(){
  1676. showJson(1005, 1001, SignMeal::getList());
  1677. }
  1678. /**
  1679. * 购买VIP套餐
  1680. * @throws \think\db\exception\DataNotFoundException
  1681. * @throws \think\db\exception\ModelNotFoundException
  1682. * @throws \think\exception\DbException
  1683. */
  1684. public function buyVip()
  1685. {
  1686. // 验证
  1687. $this->checkUser();
  1688. $mealId = input('mealId', 0);
  1689. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price,num')->find();
  1690. if (empty($mealId) || empty($mealInfo)) {
  1691. showJson(1004, 7001);
  1692. }
  1693. $mealTime = isset($mealInfo['time']) ? $mealInfo['time'] : 0;
  1694. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1695. $mealNum = isset($mealInfo['num']) ? $mealInfo['num'] : 0;
  1696. if (empty($mealTime)) {
  1697. showJson(1004, 7002);
  1698. }
  1699. if (empty($mealPrice)) {
  1700. showJson(1004, 7003);
  1701. }
  1702. if ($mealNum<=0) {
  1703. showJson(1004, 7006);
  1704. }
  1705. $orderSn = makeTradeNo('VP', $this->userId);
  1706. $memberInfo = Member::where(['id' => $this->userId])->field('openid,vip_auth,vip_expire,vip_time,vip_num')->find();
  1707. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  1708. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  1709. $vipNum = isset($memberInfo['vip_num']) ? intval($memberInfo['vip_num']) : 0;
  1710. $vipTime = isset($memberInfo['vip_time']) && $memberInfo['vip_time']? strtotime($memberInfo['vip_time']) : 0;
  1711. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1712. $expireText = $vipExpire > time() && $vipAuth ? ',原先' . date('Y-m-d H:i:s', $vipExpire) . '到期' : ',原先未开通';
  1713. /* if($vipExpire>time() && $vipNum>0){
  1714. showJson(1004, '您还有'.$vipNum.'次申请微信机会未使用完,请先使用完再续购');
  1715. }*/
  1716. if(($vipExpire>time() && $vipNum>0) && $vipTime <= strtotime('2022-04-21 00:00:00')){
  1717. showJson(1004, '您是旧会员,当前还未到期不可续费为新会员');
  1718. }
  1719. $log = [
  1720. 'order_sn' => $orderSn,
  1721. 'money' => $mealTime,
  1722. 'type' => 4,
  1723. 'pay_money' => $mealPrice,
  1724. 'user_id' => $this->userId,
  1725. 'balance' => 0,
  1726. 'use_num' => $mealNum,
  1727. 'remark' => "购买VIP套餐[ID:{$mealId}]:会员续费{$mealTime}个月可使用{$mealNum}次{$expireText}",
  1728. 'created_at' => date('Y-m-d H:i:s')
  1729. ];
  1730. $orderId = db('user_recharge_log')->insertGetId($log);
  1731. if ($orderId) {
  1732. // 获取OPENID
  1733. if (empty($openid)) {
  1734. showJson(1004, 2010);
  1735. }
  1736. $order = [
  1737. 'orderNo' => $orderSn,
  1738. 'amount' => $mealPrice,
  1739. 'openid' => $openid,
  1740. 'body' => $vipAuth ? '续费' . $mealInfo['name'] . '订单支付' : '购买' . $mealInfo['name'] . '订单支付',
  1741. ];
  1742. $params = Wechat::jsapiUnifiedorder($order, 'vip');
  1743. PRedis::set('orders:recharge:vip:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1744. $code = isset($params['code']) ? $params['code'] : '';
  1745. if ($code == 1004) {
  1746. showJson(1004, $params['message']);
  1747. }
  1748. // 更新订单参数
  1749. unset($params['prepay_id']);
  1750. showJson(1005, 7004, $params);
  1751. } else {
  1752. showJson(1004, 7005);
  1753. }
  1754. }
  1755. /**
  1756. * 购买人工服务
  1757. * @throws \think\db\exception\DataNotFoundException
  1758. * @throws \think\db\exception\ModelNotFoundException
  1759. * @throws \think\exception\DbException
  1760. */
  1761. public function handPay()
  1762. {
  1763. // 验证
  1764. $this->checkUser();
  1765. $mealId = input('mealId', 0);
  1766. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1767. if (empty($mealId) || empty($mealInfo)) {
  1768. showJson(1004, 7001);
  1769. }
  1770. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1771. if (empty($mealPrice)) {
  1772. showJson(1004, 7003);
  1773. }
  1774. $orderSn = makeTradeNo('HP', $this->userId);
  1775. $log = [
  1776. 'order_sn' => $orderSn,
  1777. 'money' => $mealPrice,
  1778. 'type' => 5,
  1779. 'pay_money' => $mealPrice,
  1780. 'user_id' => $this->userId,
  1781. 'balance' => 0,
  1782. 'remark' => "购买人工牵服务[ID:{$mealId}]:支付{$mealPrice}元",
  1783. 'created_at' => date('Y-m-d H:i:s')
  1784. ];
  1785. $orderId = db('user_recharge_log')->insertGetId($log);
  1786. $memberInfo = Member::where(['id' => $this->userId])->field('openid')->find();
  1787. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1788. if ($orderId) {
  1789. // 获取OPENID
  1790. if (empty($openid)) {
  1791. showJson(1004, 2010);
  1792. }
  1793. $order = [
  1794. 'orderNo' => $orderSn,
  1795. 'amount' => $mealPrice,
  1796. 'openid' => $openid,
  1797. 'body' => '购买' . $mealInfo['name'] . '服务订单支付',
  1798. ];
  1799. $params = Wechat::jsapiUnifiedorder($order, 'hand');
  1800. PRedis::set('orders:recharge:hand:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1801. $code = isset($params['code']) ? $params['code'] : '';
  1802. if ($code == 1004) {
  1803. showJson(1004, $params['message']);
  1804. }
  1805. // 更新订单参数
  1806. unset($params['prepay_id']);
  1807. showJson(1005, 7004, $params);
  1808. } else {
  1809. showJson(1004, 7005);
  1810. }
  1811. }
  1812. /**
  1813. * 举报信息提交
  1814. */
  1815. public function complainSubmit()
  1816. {
  1817. $uid = input('uid', 0);
  1818. $type = input('type', 0);
  1819. if (empty($uid)) {
  1820. showJson(1004, 8001);
  1821. }
  1822. if (empty($type)) {
  1823. showJson(1004, 8002);
  1824. }
  1825. // 是否已经提交过
  1826. if (Complain::where(['uid' => $this->userId, 'c_uid' => $uid])->where('created_time', '>=', time() - 7 * 24 * 3600)->value('id')) {
  1827. showJson(1004, 8005);
  1828. }
  1829. // 举报数据
  1830. $params = [
  1831. 'uid' => $this->userId,
  1832. 'c_uid' => $uid,
  1833. 'remark' => htmlspecialchars(input('remark', '')),
  1834. 'type' => $type,
  1835. ];
  1836. // 照片
  1837. $file = request()->file('image');
  1838. if ($file) {
  1839. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1840. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1841. $params['image'] = $image;
  1842. }
  1843. // 保存数据
  1844. if ($id = Complain::saveData($params)) {
  1845. showJson(1005, 8003, $id);
  1846. } else {
  1847. showJson(1004, 8004);
  1848. }
  1849. }
  1850. /**
  1851. * 用户反馈建议提交
  1852. */
  1853. public function adviceSubmit()
  1854. {
  1855. $type = input('type', 0);
  1856. if (empty($type)) {
  1857. showJson(1004, 8009);
  1858. }
  1859. // 是否已经提交过
  1860. if (Advice::where(['uid' => $this->userId, 'type' => $type])->where('created_time', '>=', time() - 3 * 24 * 3600)->value('id')) {
  1861. showJson(1004, 8006);
  1862. }
  1863. // 数据
  1864. $params = [
  1865. 'uid' => $this->userId,
  1866. 'remark' => htmlspecialchars(input('remark', '')),
  1867. 'type' => $type,
  1868. ];
  1869. //
  1870. $file = request()->file('image');
  1871. if ($file) {
  1872. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1873. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1874. $params['image'] = $image;
  1875. }
  1876. // 保存数据
  1877. if ($id = Advice::saveData($params)) {
  1878. showJson(1005, 8007, $id);
  1879. } else {
  1880. showJson(1004, 8008);
  1881. }
  1882. }
  1883. /**
  1884. * @throws \think\db\exception\DataNotFoundException
  1885. * @throws \think\db\exception\ModelNotFoundException
  1886. * @throws \think\exception\DbException
  1887. */
  1888. public function complainList()
  1889. {
  1890. $type = input('type', 2);
  1891. $pageSize = input('pageSize', 30);
  1892. showJson(1005, 1001, Member::getComplainList($type, $pageSize));
  1893. }
  1894. /**
  1895. * 坐标转换地址
  1896. */
  1897. public function getLocationAddress()
  1898. {
  1899. $locationType = 'wgs84ll';
  1900. $apiUrl = config('api.locationApi');
  1901. $siteInfo = $siteInfo = cmf_get_site_info();
  1902. $ak = isset($siteInfo['map_key']) ? trim($siteInfo['map_key']) : '';
  1903. $uid = input('uid', 0);
  1904. $lat = input('lat', '');
  1905. $lng = input('lng', '');
  1906. $type = input('type', 1);
  1907. if (empty($lat) || empty($lng)) {
  1908. showJson(1004, 1002);
  1909. }
  1910. $mapCacheKey = "cache:location:{$ak}:".$this->userId;
  1911. if(PRedis::get($mapCacheKey)){
  1912. showJson(1002, 1002);
  1913. }
  1914. $apiUrl = sprintf($apiUrl, $ak, $locationType, "{$lat},{$lng}");
  1915. $data = cmf_curl_get($apiUrl);
  1916. $data = $data ? json_decode($data, true) : [];
  1917. $data = isset($data['result']) ? $data['result'] : [];
  1918. $addressData = isset($data['addressComponent']) ? $data['addressComponent'] : [];
  1919. $province = isset($addressData['province']) ? $addressData['province'] : '';
  1920. $city = isset($addressData['city']) ? $addressData['city'] : '';
  1921. $district = isset($addressData['district']) ? $addressData['district'] : '';
  1922. $location = isset($data['location']) ? $data['location'] : [];
  1923. $latNew = isset($location['lat']) ? round($location['lat'], 6) : 0;
  1924. $lngNew = isset($location['lng']) ? round($location['lng'], 6) : 0;
  1925. if (empty($data) || empty($latNew) || empty($lngNew)) {
  1926. showJson(1004, 8204);
  1927. }
  1928. // 缓存6小时更新一次
  1929. PRedis::set($mapCacheKey, ['uid'=> $this->userId,'result'=> $data], 6 * 3600);
  1930. // 更新位置数据
  1931. $cacheKey = "cache:location:u_{$this->userId}";
  1932. $updateData = ['lat' => $latNew, 'lng' => $lngNew, 'address' => "{$province},{$city},{$district}"];
  1933. if (!PRedis::get($cacheKey)) {
  1934. Member::where(['id' => $this->userId, 'user_type' => 2])->update($updateData);
  1935. PRedis::set($cacheKey, ['uid' => $this->userId, 'data' => $data, 'update' => $updateData, 'lat' => $latNew, 'lng' => $lngNew, 'date' => date('Y-m-d H:i:s')], 5);
  1936. }
  1937. if ($type == 1 && $uid) {
  1938. $distance = '';
  1939. $userInfo = Member::where(['id' => $uid])->field('lat,lng,address')->find();
  1940. $lat1 = isset($userInfo['lat']) ? $userInfo['lat'] : 0;
  1941. $lng1 = isset($userInfo['lng']) ? $userInfo['lng'] : 0;
  1942. $address = isset($userInfo['address']) ? $userInfo['address'] : '';
  1943. $address = $address ? explode(',', $address) : '';
  1944. $district = isset($address[2]) ? $address[2] : '';
  1945. if ($lat1 > 0 && $lng1 > 0) {
  1946. $distance = getDistance($lngNew, $latNew, $lng1, $lat1, 1);
  1947. $distance = $distance >= 1000 ? round($distance / 1000, 2) . 'km' : ($distance? $distance . 'm' : '');
  1948. }
  1949. showJson(1005, 8202, ['location' => $data, 'distance' => $distance, 'other' => $userInfo, 'address' => $address, 'district' => $district]);
  1950. }
  1951. showJson(1005, 8202, ['location' => $data]);
  1952. }
  1953. /**
  1954. * 注销账号
  1955. * @throws \think\Exception
  1956. * @throws \think\exception\PDOException
  1957. */
  1958. public function logout()
  1959. {
  1960. // 验证扣除账号
  1961. $accountConfig = $siteInfo = cmf_get_option('account_config');
  1962. $logoutPay = isset($accountConfig['logout_pay']) ? floatval($accountConfig['logout_pay']) : 0;
  1963. $memberInfo['logout_pay'] = $logoutPay > 0 ? $logoutPay : 1;
  1964. $memberInfo = Member::where(['id' => $this->userId])
  1965. ->field('id,redheart,user_nickname,user_status')
  1966. ->find();
  1967. $memberInfo = $memberInfo? $memberInfo->toArray() : [];
  1968. $redheart = isset($memberInfo['redheart'])? $memberInfo['redheart'] : 0;
  1969. $nickname = isset($memberInfo['user_nickname'])? $memberInfo['user_nickname'] : '';
  1970. $userStatus = isset($memberInfo['user_status'])? $memberInfo['user_status'] : 0;
  1971. if($userStatus == -1){
  1972. showJson(1004, 1124);
  1973. }
  1974. if($redheart < $logoutPay){
  1975. showJson(1004, lang(1125,['pay'=> $logoutPay]));
  1976. }
  1977. DB::startTrans();
  1978. if(!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $logoutPay)){
  1979. DB::rollback();
  1980. showJson(1004, 2031);
  1981. }
  1982. // 账户明细
  1983. $data = [
  1984. 'user_id'=> $this->userId,
  1985. 'type'=> 2,
  1986. 'account_type'=> 1,
  1987. 'change_type'=> 2,
  1988. 'money'=> $logoutPay,
  1989. 'balance'=> $redheart,
  1990. 'remark'=> '用户【'.$nickname.'】注销扣除'.$logoutPay.'颗爱心',
  1991. 'created_at'=> date('Y-m-d H:i:s'),
  1992. 'status'=> 2
  1993. ];
  1994. if(!AccountLog::insertGetId($data)){
  1995. Db::rollback();
  1996. showJson(1004, 8306);
  1997. }
  1998. Db::commit();
  1999. // 注销信息
  2000. Member::where(['id' => $this->userId, 'user_type' => 2])
  2001. ->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]);
  2002. // 进入资源库
  2003. PoolModel::distribute(0, $this->userId, 6);
  2004. $cacheKey = "weixin:auth:" . session('openid');
  2005. PRedis::del($cacheKey);
  2006. session('userInfo', null);
  2007. session('openid', null);
  2008. showJson(1005, 1001);
  2009. }
  2010. /**
  2011. * 认证记录
  2012. * @throws \think\Exception\DbException
  2013. */
  2014. public function getAuthNotice(){
  2015. $dataList = \app\weixin\service\Member::getAuthNotices();
  2016. showJson(1005, 1001, $dataList);
  2017. }
  2018. /**
  2019. * 获取用户访问记录
  2020. */
  2021. public function getUserAccess(){
  2022. $pageSize = input('pageSize', 30);
  2023. $dataList = Member::getUserAccess($this->userId, $pageSize);
  2024. showJson(1005, 1001, $dataList);
  2025. }
  2026. /**
  2027. * 解锁访问用户信息
  2028. */
  2029. public function unlock(){
  2030. $uid = input('uid', 0);
  2031. $cuid = input('cuid', 0);
  2032. if(empty($uid) || empty($cuid)){
  2033. showJson(1004,1012);
  2034. }
  2035. if($uid != $this->userId || ($uid == $cuid)){
  2036. showJson(1004,8301);
  2037. }
  2038. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  2039. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  2040. }
  2041. $res = Member::catchUnlock($uid, $cuid);
  2042. if (is_array($res)) {
  2043. showJson(1005, 8302);
  2044. } else {
  2045. showJson(1004, $res ? $res : 8303);
  2046. }
  2047. }
  2048. /**
  2049. * 签到
  2050. * @throws \think\Exception
  2051. * @throws \think\db\exception\DataNotFoundException
  2052. * @throws \think\db\exception\ModelNotFoundException
  2053. * @throws \think\exception\DbException
  2054. * @throws \think\exception\PDOException
  2055. */
  2056. public function sign(){
  2057. // 验证
  2058. $this->checkUser();
  2059. $params = input();
  2060. $res = SignMeal::catchSign($this->userId, $params);
  2061. if (is_array($res)) {
  2062. showJson(1005, 2146);
  2063. }else {
  2064. showJson(1004, $res ? $res : 2147);
  2065. }
  2066. }
  2067. /**
  2068. * 关闭签到
  2069. */
  2070. public function setSign(){
  2071. PRedis::set("caches:signs:close:".$this->userId.'_'.date('Ymd'),date('Y-m-d H:i:s'), 86400);
  2072. showJson(1005, 2146);
  2073. }
  2074. /**
  2075. * 重新验证手机号
  2076. */
  2077. public function verifyMobile(){
  2078. $params = $this->request->param();
  2079. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  2080. $code = isset($params['code']) ? trim($params['code']) : '';
  2081. $result = Sms::checkCode($mobile, $code,'verify');
  2082. if ( $result !== true) {
  2083. showJson(1004, $result);
  2084. }
  2085. $siteInfo = cmf_get_option('site_info');
  2086. $verifyMobileTime = isset($siteInfo['verify_mobile_time'])? intval($siteInfo['verify_mobile_time']) : 0;
  2087. $verifyMobileTime = $verifyMobileTime? $verifyMobileTime : 7;
  2088. $info = Member::where(['id'=> $this->userId,'user_type'=>2])->field(['id,mobile,verify_mobile_expired,user_status'])->find();
  2089. if(empty($info)){
  2090. showJson(1004, 2013);
  2091. }
  2092. if($info['user_status'] != 1){
  2093. showJson(1004, 1017);
  2094. }
  2095. $verifyMobileExpired = date('Y-m-d H:i:s', time() + $verifyMobileTime*86400);
  2096. if(Member::where(['id'=> $this->userId,'user_type'=>2])->update(['mobile'=> $mobile, 'verify_mobile_expired'=>$verifyMobileExpired])){
  2097. showJson(1005, 2053);
  2098. }
  2099. showJson(1004, 1009);
  2100. }
  2101. }