MemberController.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  1. <?php
  2. /**
  3. * 会员中心模块
  4. * @author wesmiler
  5. */
  6. namespace app\api\controller;
  7. use app\weixin\model\Advice;
  8. use app\weixin\model\Complain;
  9. use app\weixin\service\FaceAuth;
  10. use app\weixin\service\IdnAuth;
  11. use function AlibabaCloud\Client\value;
  12. use app\weixin\model\AccountLog;
  13. use app\weixin\model\Meals;
  14. use app\weixin\model\Member;
  15. use app\weixin\model\Storage;
  16. use app\weixin\model\UserCollect;
  17. use app\weixin\model\UserContactLog;
  18. use app\weixin\model\UserLog;
  19. use app\weixin\model\UserProfile;
  20. use app\weixin\model\Wechat;
  21. use app\weixin\service\PRedis;
  22. use app\weixin\service\Sms;
  23. use app\weixin\service\Activity;
  24. use app\weixin\validate\MemberValidate;
  25. use think\Db;
  26. class MemberController extends BaseController
  27. {
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. $userStatus = isset($this->userInfo['user_status']) ? intval($this->userInfo['user_status']) : 0;
  32. $freezingChoose = isset($this->userInfo['freezing_choose']) ? intval($this->userInfo['freezing_choose']) : 0;
  33. if ($this->userInfo && $userStatus != 1) {
  34. if ($userStatus == -1) {
  35. showJson(1006, 1016, ['url' => 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg3ODEzNjMzMQ==&scene=124#wechat_redirect']);
  36. }
  37. $uncheck = input('uncheck', 0);
  38. $action = request()->action();
  39. if (!in_array($action, ['getRecommendList']) && (($action == 'getInfo' || $action == 'getHomeInfo') && !$uncheck)) {
  40. showJson(1006, $freezingChoose > 0 ? 1020 + $freezingChoose : 1011, ['url' => url('/weixin/page/custom', '', '', true)]);
  41. }
  42. }
  43. }
  44. /**
  45. * 获取有用户信息
  46. */
  47. public function getInfo()
  48. {
  49. $type = input('type', 0);
  50. $id = input('id', 0); // 当前浏览的用户ID
  51. $userId = $this->userId;
  52. $memberInfo = Member::getInfo(['id' => $userId]);
  53. if ($type == 1) {
  54. Member::visitCount($this->userId, 'center');
  55. } else if ($type == 8) {
  56. Member::visitCount($this->userId, 'home');
  57. }
  58. // 冻结
  59. $userStatus = isset($memberInfo['user_status']) ? intval($memberInfo['user_status']) : 0;
  60. if ((!in_array($type, [1, 8])) && $userStatus != 1 && $type != 1) {
  61. showJson(1006, 2102, ['url' => url('/weixin/page/custom', '', '', true)]);
  62. }
  63. // VIP有效状态和时间
  64. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  65. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  66. if ($vipAuth && $vipExpire >= time()) {
  67. $memberInfo['vip_auth'] = 1;
  68. $memberInfo['vip_expire'] = date('Y-m-d', $vipExpire);
  69. if ($vipExpire <= time() + 86400 * 2) {
  70. $memberInfo['vip_expire_near'] = 1;
  71. }
  72. } else {
  73. $memberInfo['vip_auth'] = 0;
  74. $memberInfo['vip_expire'] = '';
  75. $memberInfo['vip_expire_near'] = 0;
  76. }
  77. if ($memberInfo) {
  78. $memberInfo['avatar'] = $memberInfo['avatar'] ? cmf_get_image_preview_url($memberInfo['avatar']) : '';
  79. if (isset($memberInfo['mobile'])) {
  80. $memberInfo['mobile'] = $memberInfo['mobile'] ? formatStr($memberInfo['mobile']) : '';
  81. }
  82. if ($type == 1) {
  83. $memberInfo['collectCount'] = UserCollect::getUserCount($userId, $memberInfo['vip_auth']);
  84. $memberInfo['rechargeCount'] = Member::getRechargeCount($userId);
  85. $memberInfo['messageCount'] = Member::getMessageTotal($userId, ['type' => 1, 'status' => 2]);
  86. $memberInfo['accessCount'] = Member::getAccessCount($userId);
  87. }
  88. if ($type == 2) {
  89. $qrcodeData = Wechat::makeQrcode($userId, $userId);
  90. $memberInfo['qrcode'] = isset($qrcodeData['qrcode']) ? $qrcodeData['qrcode'] : '';
  91. $memberInfo['invite_count'] = Member::getInviteCount($userId);
  92. $memberInfo['profile_complete'] = UserProfile::checkUserProfile($userId) ? 1 : 0;
  93. // $memberInfo['avatar'] = Wechat::loadImage($memberInfo['avatar'],'avatar');
  94. }
  95. if ($type == 3) {
  96. $accountConfig = $siteInfo = cmf_get_option('account_config');
  97. $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
  98. $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
  99. $memberInfo['charge_rate'] = $chargeRate > 0 ? $chargeRate : 1;
  100. $memberInfo['min_recharge'] = $minRecharge ? $minRecharge : 1;
  101. }
  102. // 是否已经认证
  103. if ($type == 2 || $type == 4 || $type == 1) {
  104. $field = 'idcard_check,education_check,position_check';
  105. $authData = UserProfile::where(['userid' => $userId])
  106. ->field($field)
  107. ->find();
  108. $memberInfo['is_auth'] = 0;
  109. $memberInfo['idcard_check'] = isset($authData['idcard_check']) ? intval($authData['idcard_check']) : 0;
  110. $memberInfo['education_check'] = isset($authData['education_check']) ? intval($authData['education_check']) : 0;
  111. $memberInfo['position_check'] = isset($authData['position_check']) ? intval($authData['position_check']) : 0;
  112. if ($memberInfo['idcard_check'] == 2 && $memberInfo['education_check'] == 2 && $memberInfo['position_check'] == 2) {
  113. $memberInfo['is_auth'] = 1;
  114. }
  115. }
  116. // 认证数据
  117. if ($type == 5) {
  118. $field = 'idcard,front_idcard,back_idcard,idcard_fail,idcard_check,idcard_online_check';
  119. $authData = UserProfile::where(['userid' => $userId])
  120. ->field($field)
  121. ->find();
  122. $authData = $authData ? $authData : [];
  123. $authData['realname'] = isset($memberInfo['real_name']) ? trim($memberInfo['real_name']) : '';
  124. $authData['front_idcard_preview'] = isset($authData['front_idcard']) ? cmf_get_image_preview_url($authData['front_idcard']) : '';
  125. $authData['back_idcard_preview'] = isset($authData['back_idcard']) ? cmf_get_image_preview_url($authData['back_idcard']) : '';
  126. $authData['idcard_check'] = isset($authData['idcard_check']) ? $authData['idcard_check'] : 0;
  127. $memberInfo['authInfo'] = $authData;
  128. }
  129. if ($type == 6) {
  130. $field = 'graduate,education,education_img,education_fail,education_check,education_code,education_type';
  131. $authData = UserProfile::where(['userid' => $userId])
  132. ->field($field)
  133. ->find();
  134. $authData['education_img_preview'] = isset($authData['education_img']) ? cmf_get_image_preview_url($authData['education_img']) : '';
  135. $authData['education_check'] = isset($authData['education_check']) ? $authData['education_check'] : 0;
  136. $memberInfo['authInfo'] = $authData ? $authData : [];
  137. }
  138. if ($type == 7) {
  139. $field = 'company,occupation,position_img,position_fail,position_check,position_type,position_hide';
  140. $authData = UserProfile::where(['userid' => $userId])
  141. ->field($field)
  142. ->find();
  143. $authData['position_img_preview'] = isset($authData['position_img']) ? cmf_get_image_preview_url($authData['position_img']) : '';
  144. $authData['position_check'] = isset($authData['position_check']) ? $authData['position_check'] : 0;
  145. $memberInfo['authInfo'] = $authData ? $authData : [];
  146. }
  147. // 验证是否已经收藏过
  148. $memberInfo['is_collect'] = 0;
  149. if ($id && UserCollect::checkCollect($userId, $id)) {
  150. $memberInfo['is_collect'] = 1;
  151. }
  152. // 收藏剩余有效时间
  153. if (isset($memberInfo['collect_expire'])) {
  154. $memberInfo['collect_expire'] = intval($memberInfo['collect_expire']) - time();
  155. $memberInfo['collect_expire'] = $memberInfo['collect_expire'] > 0 ? $memberInfo['collect_expire'] : 0;
  156. }
  157. if ($type == 8) {
  158. $accountConfig = cmf_get_option('account_config');
  159. $contactPay = isset($accountConfig['contact_pay']) ? intval($accountConfig['contact_pay']) : 0;
  160. $contactPay = $contactPay ? $contactPay : 1;
  161. $memberInfo['contact_pay'] = $contactPay;
  162. $contactRefundPay = isset($accountConfig['apply_refund_pay']) ? intval($accountConfig['apply_refund_pay']) : 0;
  163. $contactRefundPay = $contactRefundPay ? $contactRefundPay : 3;
  164. $memberInfo['contact_refund_pay'] = $contactRefundPay;
  165. $siteConfig = cmf_get_option('site_info');
  166. $contactTime = isset($siteConfig['contact_time']) ? intval($siteConfig['contact_time']) : 1;
  167. $contactTime = $contactTime ? $contactTime * 24 : 24;
  168. $memberInfo['contact_time'] = $contactTime;
  169. }
  170. if($type == 9){
  171. $accountConfig = cmf_get_option('account_config');
  172. $pay = isset($accountConfig['lock_access_pay']) ? intval($accountConfig['lock_access_pay']) : 0;
  173. $pay = $pay ? $pay : 1;
  174. $memberInfo['lock_access_pay'] = $pay;
  175. }
  176. }
  177. showJson(1005, 1001, $memberInfo);
  178. }
  179. /**
  180. * 完善资料
  181. * @throws \think\Exception
  182. * @throws \think\exception\PDOException
  183. */
  184. public function setProfile()
  185. {
  186. try {
  187. $params = input();
  188. $userId = input('uid', 0);
  189. $validate = new MemberValidate();
  190. if (!$validate->scene('reg')->check($params)) {
  191. showJson(1004, $validate->getError());
  192. }
  193. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  194. $code = isset($params['code']) ? trim($params['code']) : '';
  195. $result = Sms::checkCode($mobile, $code);
  196. if (!$userId && $result !== true) {
  197. showJson(1004, $result);
  198. }
  199. if ($this->userId <= 1) {
  200. showJson(1004, 2009);
  201. }
  202. $sex = isset($params['sex']) ? intval($params['sex']) : 0;
  203. if (!in_array($sex, [1, 2])) {
  204. showJson(1004, 2023);
  205. }
  206. // 头像
  207. $avatar = '';
  208. $wxInfo = session('wxInfo');
  209. $file = request()->file('image');
  210. if ($file) {
  211. $fileData = Storage::uploadImg($file, 'avatar');
  212. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  213. }
  214. if (empty($avatar)) {
  215. showJson(1004, 3004);
  216. }
  217. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  218. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  219. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  220. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  221. $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0;
  222. $year = $birthday ? date('Y', $birthday) : 0;
  223. $age = $year ? date('Y', time()) - $year : 0;
  224. $profileData = [
  225. 'userid' => $this->userId,
  226. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  227. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  228. 'age' => $age,
  229. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  230. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  231. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  232. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  233. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  234. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  235. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  236. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  237. ];
  238. Db::startTrans();
  239. if (UserProfile::checkProfile($this->userId)) {
  240. $profileData['updated_at'] = date('Y-m-d H:i:s');
  241. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  242. } else {
  243. $res = UserProfile::insertGetId($profileData);
  244. }
  245. if (!$res) {
  246. Db::rollback();
  247. showJson(1004, 2104);
  248. }
  249. $memberData = [
  250. 'real_name' => isset($params['realname']) ? trim($params['realname']) : '',
  251. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  252. 'mobile' => $mobile,
  253. 'birthday' => $birthday,
  254. 'sex' => $sex,
  255. 'is_reg_profile' => 1,
  256. ];
  257. if ($avatar) {
  258. $memberData['avatar'] = $avatar;
  259. }
  260. //PRedis::set('members:reg:info:' . $this->userId, $memberData, 3600);
  261. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  262. Db::rollback();
  263. showJson(1004, 2104);
  264. }
  265. // 操作日志
  266. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '完善信息注册']);
  267. Db::commit();
  268. // 更新缓存
  269. $userInfo = Member::getInfo(['id' => $this->userId]);
  270. session('userInfo', $userInfo);
  271. showJson(1005, 1008);
  272. } catch (\Exception $exception) {
  273. PRedis::set('members:reg:error:' . $this->userId, $exception, 6 * 3600);
  274. showJson(1004, 2136);
  275. }
  276. }
  277. /**
  278. * 完善资料
  279. * @throws \think\Exception
  280. * @throws \think\exception\PDOException
  281. */
  282. public function setProfileTest()
  283. {
  284. try {
  285. $params = input();
  286. $userId = input('uid', 0);
  287. $validate = new MemberValidate();
  288. PRedis::set('members:reg:params:' . $this->userId, ['info' => $this->userInfo, 'params' => $params], 3600);
  289. if (!$validate->scene('reg')->check($params)) {
  290. showJson(1004, $validate->getError());
  291. }
  292. $mobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  293. $code = isset($params['code']) ? trim($params['code']) : '';
  294. $result = Sms::checkCode($mobile, $code);
  295. if (!$userId && $result !== true) {
  296. //showJson(1004, $result);
  297. }
  298. if (empty($this->userId)) {
  299. showJson(1004, 2009);
  300. }
  301. $sex = isset($params['sex']) ? intval($params['sex']) : 0;
  302. if (!in_array($sex, [1, 2])) {
  303. showJson(1004, 2023);
  304. }
  305. // 头像
  306. $avatar = '';
  307. $wxInfo = session('wxInfo');
  308. $file = request()->file('image');
  309. if ($file) {
  310. $fileData = Storage::uploadImg($file, 'avatar', false, false);
  311. if (!is_array($fileData)) {
  312. showJson(1004, $fileData ? $fileData : 3004);
  313. }
  314. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  315. }
  316. if (empty($avatar)) {
  317. showJson(1004, 3004);
  318. }
  319. PRedis::set('members:reg:params2:' . $this->userId, $params, 3600);
  320. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  321. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  322. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  323. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  324. $birthday = isset($params['birthday']) ? strtotime(trim($params['birthday'])) : 0;
  325. $year = $birthday ? date('Y', $birthday) : 0;
  326. $age = $year ? date('Y', time()) - $year : 0;
  327. $profileData = [
  328. 'userid' => $this->userId,
  329. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  330. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  331. 'age' => $age,
  332. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  333. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  334. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  335. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  336. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  337. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  338. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  339. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  340. ];
  341. PRedis::set('members:reg:params3:' . $this->userId, $params, 3600);
  342. Db::startTrans();
  343. PRedis::set('members:reg:profile:' . $this->userId, $profileData, 3600);
  344. if (UserProfile::checkProfile($this->userId)) {
  345. $profileData['updated_at'] = date('Y-m-d H:i:s');
  346. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  347. } else {
  348. $res = UserProfile::insertGetId($profileData);
  349. }
  350. if (!$res) {
  351. Db::rollback();
  352. showJson(1004, 2104);
  353. }
  354. $memberData = [
  355. 'real_name' => isset($params['realname']) ? trim($params['realname']) : '',
  356. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  357. 'mobile' => $mobile,
  358. 'birthday' => $birthday,
  359. 'sex' => $sex,
  360. 'is_reg_profile' => 1,
  361. ];
  362. if ($avatar) {
  363. $memberData['avatar'] = $avatar;
  364. }
  365. PRedis::set('members:reg:info:' . $this->userId, $memberData, 3600);
  366. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  367. Db::rollback();
  368. showJson(1004, 2104);
  369. }
  370. showJson(1005, 1008);
  371. exit;
  372. // 操作日志
  373. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '完善信息注册']);
  374. Db::commit();
  375. // 更新缓存
  376. $userInfo = Member::getInfo(['id' => $this->userId]);
  377. session('userInfo', $userInfo);
  378. showJson(1005, 1008);
  379. } catch (\Exception $exception) {
  380. PRedis::set('members:reg:error:' . $this->userId, $exception, 6 * 3600);
  381. showJson(1004, 2136);
  382. }
  383. }
  384. /**
  385. * 保存资料
  386. */
  387. public function saveInfo()
  388. {
  389. $params = input();
  390. $validate = new MemberValidate();
  391. if (!$validate->scene('info')->check($params)) {
  392. showJson(1004, $validate->getError());
  393. }
  394. $newMobile = isset($params['mobile']) ? trim($params['mobile']) : '';
  395. $mobile = isset($this->userInfo['mobile']) ? $this->userInfo['mobile'] : '';
  396. if ($newMobile && $newMobile != $mobile) {
  397. $code = isset($params['code']) ? trim($params['code']) : '';
  398. $result = Sms::checkCode($newMobile, $code);
  399. if ($result !== true) {
  400. showJson(1004, $result);
  401. }
  402. // 验证手机号码是否被使用
  403. $id = Member::where(['mobile' => $newMobile])->value('id');
  404. if ($id && $id != $this->userId) {
  405. showJson(1004, 2001);
  406. }
  407. }
  408. $nowAddress = isset($params['now_address']) ? trim($params['now_address']) : '';
  409. $nowAddress = $nowAddress ? explode(' ', $nowAddress) : [];
  410. $homeAddress = isset($params['home_address']) ? trim($params['home_address']) : '';
  411. $homeAddress = $homeAddress ? explode(' ', $homeAddress) : [];
  412. $birthday = isset($params['birthday']) ? strtotime($params['birthday']) : 0;
  413. $year = $birthday ? date('Y', $birthday) : 0;
  414. $age = $year ? date('Y', time()) - $year : 0;
  415. $info = [
  416. 'userid' => $this->userId,
  417. 'age' => $age,
  418. 'weight' => isset($params['weight']) ? floatval($params['weight']) : 0,
  419. 'height' => isset($params['height']) ? floatval($params['height']) : 0,
  420. 'salary' => isset($params['salary']) ? intval($params['salary']) : 0,
  421. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  422. 'education' => isset($params['education']) ? intval($params['education']) : 0,
  423. 'company' => isset($params['company']) ? trim($params['company']) : '',
  424. 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '',
  425. 'property' => isset($params['property']) ? intval($params['property']) : 0,
  426. 'province' => isset($nowAddress[0]) ? $nowAddress[0] : '',
  427. 'city' => isset($nowAddress[1]) ? $nowAddress[1] : '',
  428. 'district' => isset($nowAddress[2]) ? $nowAddress[2] : '',
  429. 'home_province' => isset($homeAddress[0]) ? $homeAddress[0] : '',
  430. 'home_city' => isset($homeAddress[1]) ? $homeAddress[1] : '',
  431. 'home_district' => isset($homeAddress[2]) ? $homeAddress[2] : '',
  432. 'married' => isset($params['married']) ? intval($params['married']) : 0,
  433. 'wechat_code' => isset($params['wechat_code']) ? trim($params['wechat_code']) : '',
  434. 'qq' => isset($params['qq']) ? trim($params['qq']) : '',
  435. ];
  436. Db::startTrans();
  437. if (UserProfile::checkProfile($this->userId)) {
  438. $profileData['updated_at'] = date('Y-m-d H:i:s');
  439. $res = UserProfile::saveData(['userid' => $this->userId], $info);
  440. } else {
  441. $res = UserProfile::insertGetId($info);
  442. }
  443. if (!$res) {
  444. Db::rollback();
  445. showJson(1004, 2104);
  446. }
  447. $memberData = [
  448. 'real_name' => isset($params['realname']) ? trim($params['realname']) : '',
  449. 'user_nickname' => isset($params['nickname']) ? trim($params['nickname']) : '',
  450. 'birthday' => $birthday,
  451. 'sex' => isset($params['sex']) ? intval($params['sex']) : 0,
  452. ];
  453. if ($newMobile && $mobile != $newMobile) {
  454. $memberData['mobile'] = $newMobile;
  455. }
  456. if (!Member::saveData(['id' => $this->userId], $memberData)) {
  457. Db::rollback();
  458. showJson(1004, 2104);
  459. }
  460. Db::commit();
  461. showJson(1005, 2029);
  462. }
  463. /**
  464. * 获取资料
  465. * @throws \think\db\exception\DataNotFoundException
  466. * @throws \think\db\exception\ModelNotFoundException
  467. * @throws \think\exception\DbException
  468. */
  469. public function getProfile()
  470. {
  471. $info = [];
  472. $type = input('type', 1);
  473. switch ($type) {
  474. case 1:
  475. $photolistArr = [];
  476. $photolist = UserProfile::where(['userid' => $this->userId])->value('photolist');
  477. $photolists = $photolist ? explode(',', $photolist) : [];
  478. $info['photolist'] = $photolist ? $photolist : '';
  479. foreach ($photolists as $k => $val) {
  480. $photolistArr[$k]['file'] = $val;
  481. $photolistArr[$k]['preview'] = $val ? cmf_get_image_preview_url($val) : '';
  482. }
  483. $info['photolists'] = $photolistArr;
  484. break;
  485. default:
  486. $field = 'userid,introduce,introduce_img,brief,brief,family,family_img,hobby,hobby_img,purpose,purpose_img,cause,cause_img,expect,tags,expect_img';
  487. $info = UserProfile::where(['userid' => $this->userId])->field($field)->find();
  488. $info = $info ? $info->toArray() : [];
  489. if (isset($info['introduce_img'])) {
  490. $info['introduce_img_preview'] = $info['introduce_img'] ? cmf_get_image_preview_url($info['introduce_img']) : '';
  491. }
  492. if (isset($info['family_img'])) {
  493. $info['family_img_preview'] = $info['family_img'] ? cmf_get_image_preview_url($info['family_img']) : '';
  494. }
  495. if (isset($info['hobby_img'])) {
  496. $info['hobby_img_preview'] = $info['hobby_img'] ? cmf_get_image_preview_url($info['hobby_img']) : '';
  497. }
  498. if (isset($info['purpose_img'])) {
  499. $info['purpose_img_preview'] = $info['purpose_img'] ? cmf_get_image_preview_url($info['purpose_img']) : '';
  500. }
  501. if (isset($info['cause_img'])) {
  502. $info['cause_img_preview'] = $info['cause_img'] ? cmf_get_image_preview_url($info['cause_img']) : '';
  503. }
  504. if (isset($info['expect_img'])) {
  505. $info['expect_img_preview'] = $info['expect_img'] ? cmf_get_image_preview_url($info['expect_img']) : '';
  506. }
  507. if (isset($info['tags'])) {
  508. $info['tags'] = $info['tags'] ? explode(',', $info['tags']) : [];
  509. }
  510. break;
  511. }
  512. showJson(1005, 1008, $info);
  513. }
  514. /*
  515. * 头像
  516. *
  517. */
  518. public function setAvatar()
  519. {
  520. $avatar = '';
  521. $file = request()->file('image');
  522. if ($file) {
  523. $fileData = Storage::uploadImg($file, 'avatar');
  524. $avatar = isset($fileData['file']) ? $fileData['file'] : '';
  525. }
  526. if (empty($avatar)) {
  527. showJson(1004, 3007);
  528. }
  529. // 保存
  530. $oldAvatar = Member::where(['id' => $this->userId])->value('avatar');
  531. if (!Member::saveData(['id' => $this->userId], ['avatar' => $avatar])) {
  532. showJson(1004, 2030);
  533. }
  534. if (file_exists('upload/' . $oldAvatar)) {
  535. @unlink('upload/' . $oldAvatar);
  536. $paths = explode('_', basename($oldAvatar));
  537. $filename = end($paths);
  538. $filename = 'upload/' . dirname($oldAvatar) . '/' . $filename;
  539. if ($filename && file_exists($filename)) {
  540. @unlink($filename);
  541. }
  542. }
  543. showJson(1005, 2029);
  544. }
  545. /**
  546. * 保存资料
  547. */
  548. public function saveProfile()
  549. {
  550. $info = [];
  551. $img = input('img', '');
  552. $params = input();
  553. // 需要先完成身份认证
  554. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  555. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  556. }
  557. // 学历证明照片
  558. $file = request()->file('image');
  559. if ($file) {
  560. $fileData = Storage::uploadImg($file, 'profile');
  561. $img = isset($fileData['file']) ? $fileData['file'] : '';
  562. $oldImg = isset($params['img']) ? $params['img'] : '';
  563. if ($img && $oldImg) {
  564. @unlink('upload/' . $oldImg);
  565. }
  566. }
  567. if (isset($params['photolist'])) {
  568. $info['photolist'] = trim($params['photolist']);
  569. }
  570. if (isset($params['introduce'])) {
  571. $info['introduce'] = trim($params['introduce']);
  572. $info['introduce_img'] = $img;
  573. }
  574. if (isset($params['family'])) {
  575. $info['family'] = trim($params['family']);
  576. $info['family_img'] = $img;
  577. }
  578. if (isset($params['hobby'])) {
  579. $info['hobby'] = trim($params['hobby']);
  580. $info['hobby_img'] = $img;
  581. }
  582. if (isset($params['purpose'])) {
  583. $info['purpose'] = trim($params['purpose']);
  584. $info['purpose_img'] = $img;
  585. }
  586. if (isset($params['cause'])) {
  587. $info['cause'] = trim($params['cause']);
  588. $info['cause_img'] = $img;
  589. }
  590. if (isset($params['expect'])) {
  591. $info['expect'] = trim($params['expect']);
  592. $info['expect_img'] = $img;
  593. }
  594. // 标签
  595. if (isset($params['tags'])) {
  596. $info['tags'] = trim($params['tags']);
  597. }
  598. if (!UserProfile::saveData(['userid' => $this->userId], $info)) {
  599. showJson(1004, 2030);
  600. }
  601. // 奖励
  602. UserProfile::profileAward($this->userId);
  603. showJson(1005, 2029);
  604. }
  605. /**
  606. * 获取主页信息
  607. */
  608. public function getHomeInfo()
  609. {
  610. $id = input('id', 0);
  611. $cid = input('cid', 0);
  612. $type = input('type', 1);
  613. // 基础信息
  614. $userId = $id ? $id : $this->userId;
  615. $myInfo = Member::getHomeInfo($userId, '', $type);
  616. // 访问记录
  617. if($myInfo && $type == 4){
  618. Member::makeUserAccess($userId, $this->userId);
  619. }
  620. $cUserInfo = [];
  621. $cInfo = [];
  622. if ($cid <= 0 && $id) {
  623. $cid = UserContactLog::where(['user_id' => $this->userId, 'contact_uid' => $id])
  624. ->where('status', 'in', [1, 2, 3])
  625. ->value('id');
  626. if ($cid <= 0) {
  627. $cid = UserContactLog::where(['contact_uid' => $this->userId, 'user_id' => $id])
  628. ->where('status', 'in', [1, 2, 3])
  629. ->value('id');
  630. }
  631. }
  632. if ($cid > 0) {
  633. // 认识记录
  634. $cInfo = UserContactLog::where(['id' => $cid])->where('status', 'in', [1, 2, 3])->field('id,user_id,contact_uid,is_read,status')->find();
  635. $cUid = isset($cInfo['contact_uid']) ? intval($cInfo['contact_uid']) : 0;
  636. $status = isset($cInfo['status']) ? intval($cInfo['status']) : 0;
  637. if ($cUid) {
  638. // 被申请方查看,更新申请微信阅读状态
  639. if ($cUid == $this->userId) {
  640. UserContactLog::where(['id' => $cid])->update(['is_read' => 1]);
  641. }
  642. // 想认识的人的信息
  643. $field = 'm.id,m.user_nickname,m.avatar,m.real_name,up.wechat_code,up.qq';
  644. $cUserInfo = Member::getHomeInfo($cUid, $field, 2);
  645. // 未确认认识的不展示联系方式
  646. if ($status != 2 && $cUserInfo) {
  647. $cUserInfo['wechat_code'] = '';
  648. $cUserInfo['qq'] = '';
  649. }
  650. }
  651. }
  652. //PRedis::set('test:' . $userId, ['homeInfo' => $myInfo, 'cUserInfo' => $cUserInfo, 'cInfo' => $cInfo], 600);
  653. showJson(1005, 1008, ['homeInfo' => $myInfo, 'cUserInfo' => $cUserInfo, 'cInfo' => $cInfo]);
  654. }
  655. /**
  656. * 单身推荐列表
  657. */
  658. public function getRecommendList()
  659. {
  660. $params = input();
  661. $pageSize = input('pageSize', 12);
  662. $type = input('type', 1);
  663. $uid = input('uid', 0);
  664. $refresh = input('refresh', false);
  665. $userId = $uid ? $uid : $this->userId;
  666. if ($type == 1) {
  667. $params['user_id'] = $userId;
  668. $dataList = Member::getRecommendList($params, $pageSize);
  669. Member::visitCount($userId, 'match');
  670. } else {
  671. $dataList = Member::getHeartList($userId, '', $refresh);
  672. Member::visitCount($userId, 'heart');
  673. }
  674. showJson(1005, 1001, $dataList);
  675. }
  676. /**
  677. * 设置隐私
  678. */
  679. public function setPrivacy()
  680. {
  681. $type = input('type', 1);
  682. $value = input('value', 0);
  683. $reset = input('reset', 0);
  684. if (!in_array($type, [1, 2, 3])) {
  685. showJson(1004, 2129);
  686. }
  687. $types = [1 => 'show_graduate', 2 => 'show_company'];
  688. if ($type == 3) {
  689. if ($value == 1) {
  690. if(!UserProfile::checkUserProfile($this->userId)){
  691. showJson(1006,2045, ['url'=> Wechat::makeRedirectUrl(url('/weixin/member/profile','','',true))]);
  692. }
  693. Member::where(['id' => $this->userId, 'user_type' => 2])
  694. ->update(['is_heart' => 1]);
  695. // 操作日志
  696. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "取消隐身模式"]);
  697. showJson(1005, 2036);
  698. }
  699. $memberInfo = Member::where(['id' => $this->userId, 'user_type' => 2])->field('redheart,is_heart,invisible_time')->find();
  700. $isHeart = isset($memberInfo['is_heart']) ? intval($memberInfo['is_heart']) : 0;
  701. $invisibleTime = isset($memberInfo['invisible_time']) ? intval($memberInfo['invisible_time']) : 0;
  702. if ($reset != 1 && $invisibleTime >= time() - 7 * 24 * 3600) {
  703. showJson(1004, lang('invisible', ['date' => date('Y-m-d', $invisibleTime)]));
  704. }
  705. if ($isHeart == 2 && $value == 0) {
  706. showJson(1004, 2034);
  707. }
  708. // 扣除爱心隐身
  709. Db::startTrans();
  710. if ($reset == 1) {
  711. // 扣除爱心账户
  712. $accountConfig = cmf_get_option('account_config');
  713. $hiddenPay = isset($accountConfig['hidden_pay']) ? intval($accountConfig['hidden_pay']) : 0;
  714. $hiddenPay = $hiddenPay ? $hiddenPay : 10;
  715. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  716. if ($redheart < $hiddenPay) {
  717. showJson(1004, 2137);
  718. }
  719. if (!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $hiddenPay)) {
  720. Db::rollback();
  721. showJson(1004, 2031);
  722. }
  723. // 账户明细
  724. $accountData = [
  725. 'user_id' => $this->userId,
  726. 'type' => 2,
  727. 'account_type' => 1,
  728. 'change_type' => 2,
  729. 'money' => $hiddenPay,
  730. 'balance' => $redheart,
  731. 'remark' => "付费设置隐身模式【{$this->userId}】扣除{$hiddenPay}个爱心",
  732. 'created_at' => date('Y-m-d H:i:s'),
  733. 'status' => 2,
  734. ];
  735. PRedis::set('accounts:privacy:' . $this->userId, $accountData, 600);
  736. if (!AccountLog::insertGetId($accountData)) {
  737. Db::rollback();
  738. return false;
  739. }
  740. }
  741. // 更新设置隐身模式
  742. Member::where(['id' => $this->userId, 'user_type' => 2])
  743. ->update(['is_heart' => 2, 'invisible_time' => time()]);
  744. // 操作日志
  745. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "设置隐身模式"]);
  746. Db::commit();
  747. showJson(1005, 2035);
  748. } else {
  749. $field = $types[$type];
  750. if (!UserProfile::saveData(['userid' => $this->userId], [$field => $value])) {
  751. showJson(1004, 2131);
  752. }
  753. }
  754. showJson(1005, 2130);
  755. }
  756. /**
  757. * 关注用户
  758. */
  759. public function collect()
  760. {
  761. // 验证
  762. $this->checkUser();
  763. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  764. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  765. }
  766. $id = input('id');
  767. $opType = input('type', 1);
  768. $result = Member::collect($this->userId, $id, $opType);
  769. if ($result === true) {
  770. showJson(1005, $opType == 1 ? 2106 : 2108);
  771. } else {
  772. showJson(1004, $result);
  773. }
  774. }
  775. /**
  776. * 获取关注用户/收藏活动列表
  777. */
  778. public function getCollectList()
  779. {
  780. $params = input();
  781. $pageSize = input('pageSize', 12);
  782. $type = input('type', 1);
  783. $dataList = [];
  784. if ($type == 1) {
  785. $dataList = UserCollect::getUserList($this->userId, $params, $pageSize);
  786. } else if ($type == 2) {
  787. $dataList = UserCollect::getFollowUserList($this->userId, $params, $pageSize);
  788. }
  789. showJson(1005, 1001, $dataList);
  790. }
  791. /**
  792. * 获取申请微信消息列表
  793. */
  794. public function getMessageList()
  795. {
  796. $params = input();
  797. $pageSize = input('pageSize', 12);
  798. $dataList = Member::getMessageList($this->userId, $params, $pageSize);
  799. showJson(1005, 1001, $dataList);
  800. }
  801. /**
  802. * 获取申请微信消息详情
  803. */
  804. public function getMessageInfo()
  805. {
  806. $id = input('id', 0);
  807. $info = Member::getMessageInfo($id, $this->userId);
  808. showJson(1005, 1001, $info);
  809. }
  810. /**
  811. * 认证
  812. */
  813. public function authSubmit()
  814. {
  815. // 验证
  816. $this->checkUser();
  817. $params = input();
  818. $scene = isset($params['scene']) ? trim($params['scene']) : '';
  819. $scene = in_array($scene, ['idcard', 'education', 'position']) ? $scene : 'idcard';
  820. $validate = new MemberValidate();
  821. if (!$validate->scene($scene)->check($params)) {
  822. showJson(1004, $validate->getError());
  823. }
  824. if ($scene != 'idcard' && UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  825. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  826. }
  827. // 处理
  828. switch ($scene) {
  829. case 'idcard': // 身份证认证
  830. $idcard = isset($params['idcard']) ? trim($params['idcard']) : '';
  831. $realname = isset($params['realname'])? trim($params['realname']) : '';
  832. $profileData = [
  833. 'idcard' => $idcard,
  834. 'front_idcard' => isset($params['front_idcard']) ? trim($params['front_idcard']) : '',
  835. 'back_idcard' => isset($params['back_idcard']) ? trim($params['back_idcard']) : '',
  836. 'idcard_check' => 1,
  837. ];
  838. // 验证身份证号是否被使用
  839. $checkId = UserProfile::where(['idcard' => $idcard])
  840. ->where('userid', 'not in', $this->userId)
  841. ->value('id');
  842. if ($checkId) {
  843. showJson(1004, 2128);
  844. }
  845. // 在线验证
  846. $checkData = IdnAuth::check($realname, $idcard);
  847. $code = isset($checkData['code'])? $checkData['code'] : '';
  848. $msg = isset($checkData['msg'])? $checkData['msg'] : '';
  849. if($code != 'success' && (empty($profileData['front_idcard']) || empty($profileData['back_idcard']))){
  850. showJson(1004, $msg? $msg : 2138);
  851. }
  852. // 身份证照片
  853. /*if (empty($profileData['front_idcard'])) {
  854. showJson(1004, 2024);
  855. }
  856. if (empty($profileData['back_idcard'])) {
  857. showJson(1004, 2025);
  858. }*/
  859. Db::startTrans();
  860. if (!Member::saveData(['id' => $this->userId], ['real_name' => $realname])) {
  861. Db::rollback();
  862. showJson(1004, 2026);
  863. }
  864. // 在线验证是否通过
  865. $profileData['idcard_online_check'] = $code == 'success'? 1 : 0;
  866. if (UserProfile::checkProfile($this->userId)) {
  867. $profileData['updated_at'] = date('Y-m-d H:i:s');
  868. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  869. } else {
  870. $res = UserProfile::insertGetId($profileData);
  871. }
  872. if (!$res) {
  873. Db::rollback();
  874. showJson(1004, 2026);
  875. }
  876. // 操作日志
  877. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交身份证认证']);
  878. Db::commit();
  879. showJson(1005, 2027);
  880. break;
  881. case 'education': // 学历认证
  882. $profileData = [
  883. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  884. 'education' => isset($params['education']) ? trim($params['education']) : '',
  885. 'education_img' => isset($params['education_img']) ? trim($params['education_img']) : '',
  886. 'education_code' => isset($params['education_code']) ? trim($params['education_code']) : '',
  887. 'education_type' => isset($params['education_type']) ? intval($params['education_type']) : 0,
  888. 'education_check' => 1,
  889. ];
  890. $siteInfo = cmf_get_site_info();
  891. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  892. // 学历证明照片
  893. $file = request()->file('image1');
  894. if ($file) {
  895. $fileData = Storage::uploadImg($file, 'education_img');
  896. $educationImg = isset($fileData['file']) ? $fileData['file'] : '';
  897. $profileData['education_img'] = $waterTxt ? Storage::imageWater($educationImg, $waterTxt) : $educationImg;
  898. }
  899. if (empty($profileData['education_img'])) {
  900. showJson(1004, 2028);
  901. }
  902. Db::startTrans();
  903. if (UserProfile::checkProfile($this->userId)) {
  904. $profileData['updated_at'] = date('Y-m-d H:i:s');
  905. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  906. } else {
  907. $res = UserProfile::insertGetId($profileData);
  908. }
  909. if (!$res) {
  910. Db::rollback();
  911. showJson(1004, 2026);
  912. }
  913. // 操作日志
  914. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交学历认证']);
  915. Db::commit();
  916. showJson(1005, 2027);
  917. break;
  918. case 'position': // 职位认证
  919. $profileData = [
  920. 'company' => isset($params['company']) ? trim($params['company']) : '',
  921. 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '',
  922. 'position_img' => isset($params['position_img']) ? trim($params['position_img']) : '',
  923. 'position_type' => isset($params['position_type']) ? intval($params['position_type']) : 0,
  924. 'position_hide' => isset($params['position_hide']) ? intval($params['position_hide']) : 0,
  925. 'position_check' => 1,
  926. ];
  927. $siteInfo = cmf_get_site_info();
  928. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  929. // 职位证明照片
  930. $file = request()->file('image1');
  931. if ($file) {
  932. $fileData = Storage::uploadImg($file, 'position_img', false, false);
  933. $positionImg = isset($fileData['file']) ? $fileData['file'] : '';
  934. $profileData['position_img'] = $waterTxt ? Storage::imageWater($positionImg, $waterTxt) : $positionImg;
  935. }
  936. //PRedis::set('test:auth:' . $this->userId, ['file' => $file, 'data' => $fileData, 'profile' => $profileData], 600);
  937. if (empty($profileData['position_img'])) {
  938. showJson(1004, 2033);
  939. }
  940. Db::startTrans();
  941. if (UserProfile::checkProfile($this->userId)) {
  942. $profileData['updated_at'] = date('Y-m-d H:i:s');
  943. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  944. } else {
  945. $res = UserProfile::insertGetId($profileData);
  946. }
  947. if (!$res) {
  948. Db::rollback();
  949. showJson(1004, 2026);
  950. }
  951. // 操作日志
  952. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交职业认证']);
  953. Db::commit();
  954. showJson(1005, 2027);
  955. break;
  956. }
  957. showJson(1004, 2009);
  958. }
  959. /**
  960. * 在线认证
  961. */
  962. public function authCheck(){
  963. // 验证
  964. $this->checkUser();
  965. $params = input();
  966. $validate = new MemberValidate();
  967. if (!$validate->scene('idcard')->check($params)) {
  968. showJson(1004, $validate->getError());
  969. }
  970. $result = FaceAuth::getToken($this->userId,$params);
  971. $data = isset($result['result'])? $result['result'] : [];
  972. $code = isset($result['code']) && $result['code']? $result['code'] : 'error';
  973. $msg = isset($result['msg']) && $result['msg']? $result['msg'] : '验证错误';
  974. showJson($code, $msg, $data);
  975. }
  976. /**
  977. * 加入怦然心动
  978. */
  979. public function joinHeart()
  980. {
  981. // 验证
  982. $this->checkUser();
  983. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  984. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  985. }
  986. if (!UserProfile::checkUserProfile($this->userId)) {
  987. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  988. }
  989. $isHeart = input('is_heart', 2);
  990. if (!in_array($isHeart, [1, 2])) {
  991. showJson(1004, 2111);
  992. }
  993. $result = Member::where(['id' => $this->userId])
  994. ->update(['updated_at' => date('Y-m-d H:i:s'), 'is_heart' => $isHeart]);
  995. if ($result) {
  996. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => $isHeart == 1 ? '加入怦然心动' : '取消加入怦然心动']);
  997. showJson(1005, $isHeart == 1 ? 5017 : 5019);
  998. } else {
  999. showJson(1004, $isHeart == 1 ? 5018 : 5020);
  1000. }
  1001. }
  1002. /**
  1003. * 设置用户推荐条件
  1004. */
  1005. public function setConditions()
  1006. {
  1007. // 验证
  1008. $this->checkUser();
  1009. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1010. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1011. }
  1012. $params = input();
  1013. PRedis::set('test:conditions:' . $this->userId, $params, 600);
  1014. $res = Member::setMemberConditions($this->userId, $params);
  1015. if ($res) {
  1016. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => '设置推荐条件']);
  1017. showJson(1005, 1008);
  1018. } else {
  1019. showJson(1004, 1009);
  1020. }
  1021. }
  1022. /**
  1023. * 获取推荐条件
  1024. */
  1025. public function getConditions()
  1026. {
  1027. $conditions = Member::getMemberConditions($this->userId);
  1028. showJson(1005, 1008, $conditions);
  1029. }
  1030. /**
  1031. * 获取我的活动列表
  1032. */
  1033. public function getActivityList()
  1034. {
  1035. $params = input();
  1036. $pageSize = input('pageSize', 12);
  1037. $params['user_id'] = $this->userId;
  1038. $dataList = Activity::getMemberActivityList($params, $pageSize);
  1039. showJson(1005, 1001, $dataList);
  1040. }
  1041. /**
  1042. * 爱心充值
  1043. * @throws \think\db\exception\DataNotFoundException
  1044. * @throws \think\db\exception\ModelNotFoundException
  1045. * @throws \think\exception\DbException
  1046. */
  1047. public function doRecharge()
  1048. {
  1049. // 验证
  1050. $this->checkUser();
  1051. $money = input('money', 0);
  1052. $num = input('num', 0);
  1053. if (empty($money) || empty($num)) {
  1054. showJson(1004, 4001);
  1055. }
  1056. $accountConfig = $siteInfo = cmf_get_option('account_config');
  1057. $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
  1058. $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
  1059. if ($minRecharge && $num < $minRecharge) {
  1060. showJson(1004, '最低充值数量为:' . $minRecharge . '个');
  1061. }
  1062. $realMoney = moneyFormat($num * $chargeRate, 2);
  1063. if ($realMoney != $money) {
  1064. showJson(1004, '支付金额计算错误:' . $realMoney);
  1065. }
  1066. $orderSn = makeTradeNo('RH', $this->userId);
  1067. $memberInfo = Member::where(['id' => $this->userId])->field('openid,redheart')->find();
  1068. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  1069. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1070. $log = [
  1071. 'order_sn' => $orderSn,
  1072. 'money' => $num,
  1073. 'pay_money' => $money,
  1074. 'user_id' => $this->userId,
  1075. 'balance' => $redheart,
  1076. 'remark' => "爱心充值:{$num}个,合计:{$money}元",
  1077. 'created_at' => date('Y-m-d H:i:s')
  1078. ];
  1079. $orderId = db('user_recharge_log')->insertGetId($log);
  1080. if ($orderId) {
  1081. // 获取OPENID
  1082. if (empty($openid)) {
  1083. showJson(1004, 2010);
  1084. }
  1085. $order = [
  1086. 'orderNo' => $orderSn,
  1087. 'amount' => $money,
  1088. 'openid' => $openid,
  1089. 'body' => '爱心充值订单支付',
  1090. ];
  1091. $params = Wechat::jsapiUnifiedorder($order, 'recharge');
  1092. PRedis::set('orders:recharge:redheart:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1093. $code = isset($params['code']) ? $params['code'] : '';
  1094. if ($code == 1004) {
  1095. showJson(1004, $params['message']);
  1096. }
  1097. // 更新订单参数
  1098. unset($params['prepay_id']);
  1099. showJson(1005, 4004, $params);
  1100. } else {
  1101. showJson(1004, 4005);
  1102. }
  1103. }
  1104. /**
  1105. * 想认识
  1106. */
  1107. public function doContact()
  1108. {
  1109. // 验证
  1110. $this->checkUser();
  1111. $id = input('id', 0);
  1112. $remark = input('remark', '');
  1113. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1114. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1115. }
  1116. // 完善个人信息
  1117. if (!UserProfile::checkUserProfile($this->userId)) {
  1118. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  1119. }
  1120. // 隐身不可申请
  1121. $type = input('type', 1);
  1122. $isHeart = Member::where(['id' => $this->userId])->value('is_heart');
  1123. if ($isHeart != 1 && $type != 2) {
  1124. showJson(1006, 2037, ['type' => 'check']);
  1125. }
  1126. $res = Member::contactUser($this->userId, $id, $remark);
  1127. if (is_array($res)) {
  1128. showJson(1005, 1008);
  1129. } else if ($res == 2103) {
  1130. $referer = request()->server('HTTP_REFERER');
  1131. $rebackurl = $referer ? $referer : url('/weixin/match/index', '', '', true);
  1132. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/index/entry?rebackurl=' . $rebackurl, '', '', true))]);
  1133. } else if ($res == 2121) {
  1134. showJson(1006, $res ? $res : 1009, ['url' => '/weixin/member/invite']);
  1135. } else {
  1136. showJson(1004, $res ? $res : 1009);
  1137. }
  1138. }
  1139. /**
  1140. * 认识审核确认
  1141. */
  1142. public function contactConfirm()
  1143. {
  1144. // 验证
  1145. $this->checkUser();
  1146. $cid = input('cid', 0);
  1147. $status = input('status', 2);
  1148. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1149. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1150. }
  1151. $res = Member::contactConfirm($this->userId, $cid, $status);
  1152. if (is_array($res)) {
  1153. showJson(1005, 1008);
  1154. } else {
  1155. showJson(1004, $res ? $res : 1009);
  1156. }
  1157. }
  1158. /**
  1159. * 套餐列表
  1160. * @throws \think\db\exception\DataNotFoundException
  1161. * @throws \think\db\exception\ModelNotFoundException
  1162. * @throws \think\exception\DbException
  1163. */
  1164. public function mealList()
  1165. {
  1166. $type = input('type', 0);
  1167. showJson(1005, 1001, Meals::getList($type));
  1168. }
  1169. /**
  1170. * 购买VIP套餐
  1171. * @throws \think\db\exception\DataNotFoundException
  1172. * @throws \think\db\exception\ModelNotFoundException
  1173. * @throws \think\exception\DbException
  1174. */
  1175. public function buyVip()
  1176. {
  1177. // 验证
  1178. $this->checkUser();
  1179. $mealId = input('mealId', 0);
  1180. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1181. if (empty($mealId) || empty($mealInfo)) {
  1182. showJson(1004, 7001);
  1183. }
  1184. $mealTime = isset($mealInfo['time']) ? $mealInfo['time'] : 0;
  1185. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1186. if (empty($mealTime)) {
  1187. showJson(1004, 7002);
  1188. }
  1189. if (empty($mealPrice)) {
  1190. showJson(1004, 7003);
  1191. }
  1192. $orderSn = makeTradeNo('VP', $this->userId);
  1193. $memberInfo = Member::where(['id' => $this->userId])->field('openid,vip_auth,vip_expire')->find();
  1194. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  1195. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  1196. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1197. $expireText = $vipExpire > time() && $vipAuth ? ',原先' . date('Y-m-d H:i:s', $vipExpire) . '到期' : ',原先未开通';
  1198. $log = [
  1199. 'order_sn' => $orderSn,
  1200. 'money' => $mealTime,
  1201. 'type' => 4,
  1202. 'pay_money' => $mealPrice,
  1203. 'user_id' => $this->userId,
  1204. 'balance' => 0,
  1205. 'remark' => "购买VIP套餐[ID:{$mealId}]:会员续费{$mealTime}个月{$expireText}",
  1206. 'created_at' => date('Y-m-d H:i:s')
  1207. ];
  1208. $orderId = db('user_recharge_log')->insertGetId($log);
  1209. if ($orderId) {
  1210. // 获取OPENID
  1211. if (empty($openid)) {
  1212. showJson(1004, 2010);
  1213. }
  1214. $order = [
  1215. 'orderNo' => $orderSn,
  1216. 'amount' => $mealPrice,
  1217. 'openid' => $openid,
  1218. 'body' => $vipAuth ? '续费' . $mealInfo['name'] . '订单支付' : '购买' . $mealInfo['name'] . '订单支付',
  1219. ];
  1220. $params = Wechat::jsapiUnifiedorder($order, 'vip');
  1221. PRedis::set('orders:recharge:vip:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1222. $code = isset($params['code']) ? $params['code'] : '';
  1223. if ($code == 1004) {
  1224. showJson(1004, $params['message']);
  1225. }
  1226. // 更新订单参数
  1227. unset($params['prepay_id']);
  1228. showJson(1005, 7004, $params);
  1229. } else {
  1230. showJson(1004, 7005);
  1231. }
  1232. }
  1233. /**
  1234. * 购买人工服务
  1235. * @throws \think\db\exception\DataNotFoundException
  1236. * @throws \think\db\exception\ModelNotFoundException
  1237. * @throws \think\exception\DbException
  1238. */
  1239. public function handPay()
  1240. {
  1241. // 验证
  1242. $this->checkUser();
  1243. $mealId = input('mealId', 0);
  1244. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1245. if (empty($mealId) || empty($mealInfo)) {
  1246. showJson(1004, 7001);
  1247. }
  1248. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1249. if (empty($mealPrice)) {
  1250. showJson(1004, 7003);
  1251. }
  1252. $orderSn = makeTradeNo('HP', $this->userId);
  1253. $log = [
  1254. 'order_sn' => $orderSn,
  1255. 'money' => $mealPrice,
  1256. 'type' => 5,
  1257. 'pay_money' => $mealPrice,
  1258. 'user_id' => $this->userId,
  1259. 'balance' => 0,
  1260. 'remark' => "购买人工牵服务[ID:{$mealId}]:支付{$mealPrice}元",
  1261. 'created_at' => date('Y-m-d H:i:s')
  1262. ];
  1263. $orderId = db('user_recharge_log')->insertGetId($log);
  1264. $memberInfo = Member::where(['id' => $this->userId])->field('openid')->find();
  1265. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1266. if ($orderId) {
  1267. // 获取OPENID
  1268. if (empty($openid)) {
  1269. showJson(1004, 2010);
  1270. }
  1271. $order = [
  1272. 'orderNo' => $orderSn,
  1273. 'amount' => $mealPrice,
  1274. 'openid' => $openid,
  1275. 'body' => '购买' . $mealInfo['name'] . '服务订单支付',
  1276. ];
  1277. $params = Wechat::jsapiUnifiedorder($order, 'hand');
  1278. PRedis::set('orders:recharge:hand:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1279. $code = isset($params['code']) ? $params['code'] : '';
  1280. if ($code == 1004) {
  1281. showJson(1004, $params['message']);
  1282. }
  1283. // 更新订单参数
  1284. unset($params['prepay_id']);
  1285. showJson(1005, 7004, $params);
  1286. } else {
  1287. showJson(1004, 7005);
  1288. }
  1289. }
  1290. /**
  1291. * 举报信息提交
  1292. */
  1293. public function complainSubmit()
  1294. {
  1295. $uid = input('uid', 0);
  1296. $type = input('type', 0);
  1297. if (empty($uid)) {
  1298. showJson(1004, 8001);
  1299. }
  1300. if (empty($type)) {
  1301. showJson(1004, 8002);
  1302. }
  1303. // 是否已经提交过
  1304. if (Complain::where(['uid' => $this->userId, 'c_uid' => $uid])->where('created_time', '>=', time() - 7 * 24 * 3600)->value('id')) {
  1305. showJson(1004, 8005);
  1306. }
  1307. // 举报数据
  1308. $params = [
  1309. 'uid' => $this->userId,
  1310. 'c_uid' => $uid,
  1311. 'remark' => htmlspecialchars(input('remark', '')),
  1312. 'type' => $type,
  1313. ];
  1314. // 照片
  1315. $file = request()->file('image');
  1316. if ($file) {
  1317. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1318. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1319. $params['image'] = $image;
  1320. }
  1321. // 保存数据
  1322. if ($id = Complain::saveData($params)) {
  1323. showJson(1005, 8003, $id);
  1324. } else {
  1325. showJson(1004, 8004);
  1326. }
  1327. }
  1328. /**
  1329. * 用户反馈建议提交
  1330. */
  1331. public function adviceSubmit()
  1332. {
  1333. $type = input('type', 0);
  1334. if (empty($type)) {
  1335. showJson(1004, 8009);
  1336. }
  1337. // 是否已经提交过
  1338. if (Advice::where(['uid' => $this->userId, 'type' => $type])->where('created_time', '>=', time() - 3 * 24 * 3600)->value('id')) {
  1339. showJson(1004, 8006);
  1340. }
  1341. // 数据
  1342. $params = [
  1343. 'uid' => $this->userId,
  1344. 'remark' => htmlspecialchars(input('remark', '')),
  1345. 'type' => $type,
  1346. ];
  1347. //
  1348. $file = request()->file('image');
  1349. if ($file) {
  1350. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1351. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1352. $params['image'] = $image;
  1353. }
  1354. // 保存数据
  1355. if ($id = Advice::saveData($params)) {
  1356. showJson(1005, 8007, $id);
  1357. } else {
  1358. showJson(1004, 8008);
  1359. }
  1360. }
  1361. /**
  1362. * @throws \think\db\exception\DataNotFoundException
  1363. * @throws \think\db\exception\ModelNotFoundException
  1364. * @throws \think\exception\DbException
  1365. */
  1366. public function complainList()
  1367. {
  1368. $type = input('type', 2);
  1369. $pageSize = input('pageSize', 30);
  1370. showJson(1005, 1001, Member::getComplainList($type, $pageSize));
  1371. }
  1372. /**
  1373. * 坐标转换地址
  1374. */
  1375. public function getLocationAddress()
  1376. {
  1377. $locationType = 'wgs84ll';
  1378. $apiUrl = config('api.locationApi');
  1379. $siteInfo = $siteInfo = cmf_get_site_info();
  1380. $ak = isset($siteInfo['map_key']) ? trim($siteInfo['map_key']) : '';
  1381. $uid = input('uid', 0);
  1382. $lat = input('lat', '');
  1383. $lng = input('lng', '');
  1384. $type = input('type', 1);
  1385. if (empty($lat) || empty($lng)) {
  1386. showJson(1004, 1002);
  1387. }
  1388. $apiUrl = sprintf($apiUrl, $ak, $locationType, "{$lat},{$lng}");
  1389. $data = cmf_curl_get($apiUrl);
  1390. $data = $data ? json_decode($data, true) : [];
  1391. $data = isset($data['result']) ? $data['result'] : [];
  1392. $addressData = isset($data['addressComponent']) ? $data['addressComponent'] : [];
  1393. $province = isset($addressData['province']) ? $addressData['province'] : '';
  1394. $city = isset($addressData['city']) ? $addressData['city'] : '';
  1395. $district = isset($addressData['district']) ? $addressData['district'] : '';
  1396. $location = isset($data['location']) ? $data['location'] : [];
  1397. $latNew = isset($location['lat']) ? round($location['lat'], 6) : 0;
  1398. $lngNew = isset($location['lng']) ? round($location['lng'], 6) : 0;
  1399. if (empty($data) || empty($latNew) || empty($lngNew)) {
  1400. showJson(1004, 8204);
  1401. }
  1402. // 更新位置数据
  1403. $cacheKey = "cache:location:u_{$this->userId}";
  1404. $updateData = ['lat' => $latNew, 'lng' => $lngNew, 'address' => "{$province},{$city},{$district}"];
  1405. if (!PRedis::get($cacheKey)) {
  1406. Member::where(['id' => $this->userId, 'user_type' => 2])->update($updateData);
  1407. PRedis::set($cacheKey, ['uid' => $this->userId, 'data' => $data, 'update' => $updateData, 'lat' => $latNew, 'lng' => $lngNew, 'date' => date('Y-m-d H:i:s')], 5);
  1408. }
  1409. if ($type == 1 && $uid) {
  1410. $distance = '';
  1411. $userInfo = Member::where(['id' => $uid])->field('lat,lng,address')->find();
  1412. $lat1 = isset($userInfo['lat']) ? $userInfo['lat'] : 0;
  1413. $lng1 = isset($userInfo['lng']) ? $userInfo['lng'] : 0;
  1414. $address = isset($userInfo['address']) ? $userInfo['address'] : '';
  1415. $address = $address ? explode(',', $address) : '';
  1416. $district = isset($address[2]) ? $address[2] : '';
  1417. if ($lat1 > 0 && $lng1 > 0) {
  1418. $distance = getDistance($lngNew, $latNew, $lng1, $lat1, 1);
  1419. $distance = $distance >= 1000 ? round($distance / 1000, 2) . 'km' : ($distance? $distance . 'm' : '');
  1420. }
  1421. showJson(1005, 8202, ['location' => $data, 'distance' => $distance, 'other' => $userInfo, 'address' => $address, 'district' => $district]);
  1422. }
  1423. showJson(1005, 8202, ['location' => $data]);
  1424. }
  1425. /**
  1426. * 注销账号
  1427. * @throws \think\Exception
  1428. * @throws \think\exception\PDOException
  1429. */
  1430. public function logout()
  1431. {
  1432. // 验证扣除账号
  1433. $accountConfig = $siteInfo = cmf_get_option('account_config');
  1434. $logoutPay = isset($accountConfig['logout_pay']) ? floatval($accountConfig['logout_pay']) : 0;
  1435. $memberInfo['logout_pay'] = $logoutPay > 0 ? $logoutPay : 1;
  1436. $memberInfo = Member::where(['id' => $this->userId])
  1437. ->field('id,redheart,user_nickname,user_status')
  1438. ->find();
  1439. $memberInfo = $memberInfo? $memberInfo->toArray() : [];
  1440. $redheart = isset($memberInfo['redheart'])? $memberInfo['redheart'] : 0;
  1441. $nickname = isset($memberInfo['user_nickname'])? $memberInfo['user_nickname'] : '';
  1442. $userStatus = isset($memberInfo['user_status'])? $memberInfo['user_status'] : 0;
  1443. if($userStatus == -1){
  1444. showJson(1004, 1124);
  1445. }
  1446. if($redheart < $logoutPay){
  1447. showJson(1004, 1125);
  1448. }
  1449. DB::startTrans();
  1450. if(!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $logoutPay)){
  1451. DB::rollback();
  1452. showJson(1004, 2031);
  1453. }
  1454. // 账户明细
  1455. $data = [
  1456. 'user_id'=> $this->userId,
  1457. 'type'=> 2,
  1458. 'account_type'=> 1,
  1459. 'change_type'=> 2,
  1460. 'money'=> $logoutPay,
  1461. 'balance'=> $redheart,
  1462. 'remark'=> '用户【'.$nickname.'】注销扣除'.$logoutPay.'颗爱心',
  1463. 'created_at'=> date('Y-m-d H:i:s'),
  1464. 'status'=> 2
  1465. ];
  1466. if(!AccountLog::insertGetId($data)){
  1467. Db::rollback();
  1468. showJson(1004, 8306);
  1469. }
  1470. Db::commit();
  1471. // 注销信息
  1472. Member::where(['id' => $this->userId, 'user_type' => 2])
  1473. ->update(['user_status' => -1, 'vip_auth' => 0, 'is_heart' => 0, 'vip_expire' => 0, 'is_reg_profile' => 2, 'is_tuijian' => 0]);
  1474. $cacheKey = "weixin:auth:" . session('openid');
  1475. PRedis::del($cacheKey);
  1476. session('userInfo', null);
  1477. session('openid', null);
  1478. showJson(1005, 1001);
  1479. }
  1480. /**
  1481. * 认证记录
  1482. * @throws \think\Exception\DbException
  1483. */
  1484. public function getAuthNotice(){
  1485. $dataList = \app\weixin\service\Member::getAuthNotices();
  1486. showJson(1005, 1001, $dataList);
  1487. }
  1488. /**
  1489. * 获取用户访问记录
  1490. */
  1491. public function getUserAccess(){
  1492. $pageSize = input('pageSize', 30);
  1493. $dataList = Member::getUserAccess($this->userId, $pageSize);
  1494. showJson(1005, 1001, $dataList);
  1495. }
  1496. /**
  1497. * 解锁访问用户信息
  1498. */
  1499. public function unlock(){
  1500. $uid = input('uid', 0);
  1501. $cuid = input('cuid', 0);
  1502. if(empty($uid) || empty($cuid)){
  1503. showJson(1004,1012);
  1504. }
  1505. if($uid != $this->userId || ($uid == $cuid)){
  1506. showJson(1004,8301);
  1507. }
  1508. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1509. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1510. }
  1511. $res = Member::catchUnlock($uid, $cuid);
  1512. if (is_array($res)) {
  1513. showJson(1005, 8302);
  1514. } else {
  1515. showJson(1004, $res ? $res : 8303);
  1516. }
  1517. }
  1518. }