MemberController.php 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  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_type,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_type' => isset($params['idcard_type']) ? intval($params['idcard_type']) : 1,
  837. 'idcard_check' => 1,
  838. ];
  839. // 验证身份证号是否被使用
  840. $checkId = UserProfile::where(['idcard' => $idcard])
  841. ->where('userid', 'not in', $this->userId)
  842. ->value('id');
  843. if ($checkId) {
  844. showJson(1004, 2128);
  845. }
  846. // 身份证照片
  847. if (empty($profileData['front_idcard'])) {
  848. showJson(1004, 2024);
  849. }
  850. if (empty($profileData['back_idcard'])) {
  851. showJson(1004, 2025);
  852. }
  853. Db::startTrans();
  854. if (!Member::saveData(['id' => $this->userId], ['real_name' => $realname])) {
  855. Db::rollback();
  856. showJson(1004, 2026);
  857. }
  858. // 在线验证是否通过
  859. $profileData['idcard_online_check'] = 0;
  860. if (UserProfile::checkProfile($this->userId)) {
  861. $profileData['updated_at'] = date('Y-m-d H:i:s');
  862. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  863. } else {
  864. $res = UserProfile::insertGetId($profileData);
  865. }
  866. if (!$res) {
  867. Db::rollback();
  868. showJson(1004, 2026);
  869. }
  870. // 操作日志
  871. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交身份证认证']);
  872. Db::commit();
  873. showJson(1005, 2027);
  874. break;
  875. case 'education': // 学历认证
  876. $educationType = isset($params['education_type']) ? intval($params['education_type']) : 0;
  877. $profileData = [
  878. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  879. 'education' => isset($params['education']) ? trim($params['education']) : '',
  880. 'education_img' => isset($params['education_img']) ? trim($params['education_img']) : '',
  881. 'education_code' => isset($params['education_code']) ? trim($params['education_code']) : '',
  882. 'education_type' => $educationType,
  883. 'education_check' => 1,
  884. ];
  885. $siteInfo = cmf_get_site_info();
  886. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  887. // 学历证明照片
  888. if ($educationType != 2){
  889. $file = request()->file('image1');
  890. if ($file) {
  891. $fileData = Storage::uploadImg($file, 'education_img');
  892. $educationImg = isset($fileData['file']) ? $fileData['file'] : '';
  893. $profileData['education_img'] = $waterTxt ? Storage::imageWater($educationImg, $waterTxt) : $educationImg;
  894. }
  895. if (empty($profileData['education_img'])) {
  896. showJson(1004, 2028);
  897. }
  898. }
  899. Db::startTrans();
  900. if (UserProfile::checkProfile($this->userId)) {
  901. $profileData['updated_at'] = date('Y-m-d H:i:s');
  902. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  903. } else {
  904. $res = UserProfile::insertGetId($profileData);
  905. }
  906. if (!$res) {
  907. Db::rollback();
  908. showJson(1004, 2026);
  909. }
  910. // 操作日志
  911. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交学历认证']);
  912. Db::commit();
  913. showJson(1005, 2027);
  914. break;
  915. case 'position': // 职位认证
  916. $profileData = [
  917. 'company' => isset($params['company']) ? trim($params['company']) : '',
  918. 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '',
  919. 'position_img' => isset($params['position_img']) ? trim($params['position_img']) : '',
  920. 'position_type' => isset($params['position_type']) ? intval($params['position_type']) : 0,
  921. 'position_hide' => isset($params['position_hide']) ? intval($params['position_hide']) : 0,
  922. 'position_check' => 1,
  923. ];
  924. $siteInfo = cmf_get_site_info();
  925. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  926. // 职位证明照片
  927. $file = request()->file('image1');
  928. if ($file) {
  929. $fileData = Storage::uploadImg($file, 'position_img', false, false);
  930. $positionImg = isset($fileData['file']) ? $fileData['file'] : '';
  931. $profileData['position_img'] = $waterTxt ? Storage::imageWater($positionImg, $waterTxt) : $positionImg;
  932. }
  933. //PRedis::set('test:auth:' . $this->userId, ['file' => $file, 'data' => $fileData, 'profile' => $profileData], 600);
  934. if (empty($profileData['position_img'])) {
  935. showJson(1004, 2033);
  936. }
  937. Db::startTrans();
  938. if (UserProfile::checkProfile($this->userId)) {
  939. $profileData['updated_at'] = date('Y-m-d H:i:s');
  940. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  941. } else {
  942. $res = UserProfile::insertGetId($profileData);
  943. }
  944. if (!$res) {
  945. Db::rollback();
  946. showJson(1004, 2026);
  947. }
  948. // 操作日志
  949. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交职业认证']);
  950. Db::commit();
  951. showJson(1005, 2027);
  952. break;
  953. }
  954. showJson(1004, 2009);
  955. }
  956. /**
  957. * 在线认证
  958. */
  959. public function authCheck(){
  960. // 验证
  961. $this->checkUser();
  962. $params = input();
  963. $validate = new MemberValidate();
  964. if (!$validate->scene('idcard')->check($params)) {
  965. showJson(1004, $validate->getError());
  966. }
  967. // 验证身份证号是否被使用
  968. $idcard = isset($params['idcard'])? trim($params['idcard']) : '';
  969. $checkId = UserProfile::where(['idcard' => $idcard])
  970. ->where('userid', 'not in', $this->userId)
  971. ->whereIn('idcard_check',[1,2])
  972. ->value('id');
  973. if ($checkId) {
  974. showJson(1004, 2128);
  975. }
  976. $result = FaceAuth::getToken($this->userId,$params);
  977. $data = isset($result['result'])? $result['result'] : [];
  978. $code = isset($result['code']) && $result['code']? $result['code'] : 'error';
  979. $msg = isset($result['msg']) && $result['msg']? $result['msg'] : '验证错误';
  980. showJson($code, $msg, $data);
  981. }
  982. /**
  983. * 加入怦然心动
  984. */
  985. public function joinHeart()
  986. {
  987. // 验证
  988. $this->checkUser();
  989. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  990. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  991. }
  992. if (!UserProfile::checkUserProfile($this->userId)) {
  993. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  994. }
  995. $isHeart = input('is_heart', 2);
  996. if (!in_array($isHeart, [1, 2])) {
  997. showJson(1004, 2111);
  998. }
  999. $result = Member::where(['id' => $this->userId])
  1000. ->update(['updated_at' => date('Y-m-d H:i:s'), 'is_heart' => $isHeart]);
  1001. if ($result) {
  1002. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => $isHeart == 1 ? '加入怦然心动' : '取消加入怦然心动']);
  1003. showJson(1005, $isHeart == 1 ? 5017 : 5019);
  1004. } else {
  1005. showJson(1004, $isHeart == 1 ? 5018 : 5020);
  1006. }
  1007. }
  1008. /**
  1009. * 设置用户推荐条件
  1010. */
  1011. public function setConditions()
  1012. {
  1013. // 验证
  1014. $this->checkUser();
  1015. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1016. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1017. }
  1018. $params = input();
  1019. PRedis::set('test:conditions:' . $this->userId, $params, 600);
  1020. $res = Member::setMemberConditions($this->userId, $params);
  1021. if ($res) {
  1022. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => '设置推荐条件']);
  1023. showJson(1005, 1008);
  1024. } else {
  1025. showJson(1004, 1009);
  1026. }
  1027. }
  1028. /**
  1029. * 获取推荐条件
  1030. */
  1031. public function getConditions()
  1032. {
  1033. $conditions = Member::getMemberConditions($this->userId);
  1034. showJson(1005, 1008, $conditions);
  1035. }
  1036. /**
  1037. * 获取我的活动列表
  1038. */
  1039. public function getActivityList()
  1040. {
  1041. $params = input();
  1042. $pageSize = input('pageSize', 12);
  1043. $params['user_id'] = $this->userId;
  1044. $dataList = Activity::getMemberActivityList($params, $pageSize);
  1045. showJson(1005, 1001, $dataList);
  1046. }
  1047. /**
  1048. * 爱心充值
  1049. * @throws \think\db\exception\DataNotFoundException
  1050. * @throws \think\db\exception\ModelNotFoundException
  1051. * @throws \think\exception\DbException
  1052. */
  1053. public function doRecharge()
  1054. {
  1055. // 验证
  1056. $this->checkUser();
  1057. $money = input('money', 0);
  1058. $num = input('num', 0);
  1059. if (empty($money) || empty($num)) {
  1060. showJson(1004, 4001);
  1061. }
  1062. $accountConfig = $siteInfo = cmf_get_option('account_config');
  1063. $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
  1064. $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
  1065. if ($minRecharge && $num < $minRecharge) {
  1066. showJson(1004, '最低充值数量为:' . $minRecharge . '个');
  1067. }
  1068. $realMoney = moneyFormat($num * $chargeRate, 2);
  1069. if ($realMoney != $money) {
  1070. showJson(1004, '支付金额计算错误:' . $realMoney);
  1071. }
  1072. $orderSn = makeTradeNo('RH', $this->userId);
  1073. $memberInfo = Member::where(['id' => $this->userId])->field('openid,redheart')->find();
  1074. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  1075. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1076. $log = [
  1077. 'order_sn' => $orderSn,
  1078. 'money' => $num,
  1079. 'pay_money' => $money,
  1080. 'user_id' => $this->userId,
  1081. 'balance' => $redheart,
  1082. 'remark' => "爱心充值:{$num}个,合计:{$money}元",
  1083. 'created_at' => date('Y-m-d H:i:s')
  1084. ];
  1085. $orderId = db('user_recharge_log')->insertGetId($log);
  1086. if ($orderId) {
  1087. // 获取OPENID
  1088. if (empty($openid)) {
  1089. showJson(1004, 2010);
  1090. }
  1091. $order = [
  1092. 'orderNo' => $orderSn,
  1093. 'amount' => $money,
  1094. 'openid' => $openid,
  1095. 'body' => '爱心充值订单支付',
  1096. ];
  1097. $params = Wechat::jsapiUnifiedorder($order, 'recharge');
  1098. PRedis::set('orders:recharge:redheart:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1099. $code = isset($params['code']) ? $params['code'] : '';
  1100. if ($code == 1004) {
  1101. showJson(1004, $params['message']);
  1102. }
  1103. // 更新订单参数
  1104. unset($params['prepay_id']);
  1105. showJson(1005, 4004, $params);
  1106. } else {
  1107. showJson(1004, 4005);
  1108. }
  1109. }
  1110. /**
  1111. * 想认识
  1112. */
  1113. public function doContact()
  1114. {
  1115. // 验证
  1116. $this->checkUser();
  1117. $id = input('id', 0);
  1118. $remark = input('remark', '');
  1119. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1120. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1121. }
  1122. // 完善个人信息
  1123. if (!UserProfile::checkUserProfile($this->userId)) {
  1124. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  1125. }
  1126. // 隐身不可申请
  1127. $type = input('type', 1);
  1128. $isHeart = Member::where(['id' => $this->userId])->value('is_heart');
  1129. if ($isHeart != 1 && $type != 2) {
  1130. showJson(1006, 2037, ['type' => 'check']);
  1131. }
  1132. $res = Member::contactUser($this->userId, $id, $remark);
  1133. if (is_array($res)) {
  1134. showJson(1005, 1008);
  1135. } else if ($res == 2103) {
  1136. $referer = request()->server('HTTP_REFERER');
  1137. $rebackurl = $referer ? $referer : url('/weixin/match/index', '', '', true);
  1138. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/index/entry?rebackurl=' . $rebackurl, '', '', true))]);
  1139. } else if ($res == 2121) {
  1140. showJson(1006, $res ? $res : 1009, ['url' => '/weixin/member/invite']);
  1141. } else {
  1142. showJson(1004, $res ? $res : 1009);
  1143. }
  1144. }
  1145. /**
  1146. * 认识审核确认
  1147. */
  1148. public function contactConfirm()
  1149. {
  1150. // 验证
  1151. $this->checkUser();
  1152. $cid = input('cid', 0);
  1153. $status = input('status', 2);
  1154. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1155. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1156. }
  1157. $res = Member::contactConfirm($this->userId, $cid, $status);
  1158. if (is_array($res)) {
  1159. showJson(1005, 1008);
  1160. } else {
  1161. showJson(1004, $res ? $res : 1009);
  1162. }
  1163. }
  1164. /**
  1165. * 套餐列表
  1166. * @throws \think\db\exception\DataNotFoundException
  1167. * @throws \think\db\exception\ModelNotFoundException
  1168. * @throws \think\exception\DbException
  1169. */
  1170. public function mealList()
  1171. {
  1172. $type = input('type', 0);
  1173. showJson(1005, 1001, Meals::getList($type));
  1174. }
  1175. /**
  1176. * 购买VIP套餐
  1177. * @throws \think\db\exception\DataNotFoundException
  1178. * @throws \think\db\exception\ModelNotFoundException
  1179. * @throws \think\exception\DbException
  1180. */
  1181. public function buyVip()
  1182. {
  1183. // 验证
  1184. $this->checkUser();
  1185. $mealId = input('mealId', 0);
  1186. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1187. if (empty($mealId) || empty($mealInfo)) {
  1188. showJson(1004, 7001);
  1189. }
  1190. $mealTime = isset($mealInfo['time']) ? $mealInfo['time'] : 0;
  1191. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1192. if (empty($mealTime)) {
  1193. showJson(1004, 7002);
  1194. }
  1195. if (empty($mealPrice)) {
  1196. showJson(1004, 7003);
  1197. }
  1198. $orderSn = makeTradeNo('VP', $this->userId);
  1199. $memberInfo = Member::where(['id' => $this->userId])->field('openid,vip_auth,vip_expire')->find();
  1200. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  1201. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  1202. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1203. $expireText = $vipExpire > time() && $vipAuth ? ',原先' . date('Y-m-d H:i:s', $vipExpire) . '到期' : ',原先未开通';
  1204. $log = [
  1205. 'order_sn' => $orderSn,
  1206. 'money' => $mealTime,
  1207. 'type' => 4,
  1208. 'pay_money' => $mealPrice,
  1209. 'user_id' => $this->userId,
  1210. 'balance' => 0,
  1211. 'remark' => "购买VIP套餐[ID:{$mealId}]:会员续费{$mealTime}个月{$expireText}",
  1212. 'created_at' => date('Y-m-d H:i:s')
  1213. ];
  1214. $orderId = db('user_recharge_log')->insertGetId($log);
  1215. if ($orderId) {
  1216. // 获取OPENID
  1217. if (empty($openid)) {
  1218. showJson(1004, 2010);
  1219. }
  1220. $order = [
  1221. 'orderNo' => $orderSn,
  1222. 'amount' => $mealPrice,
  1223. 'openid' => $openid,
  1224. 'body' => $vipAuth ? '续费' . $mealInfo['name'] . '订单支付' : '购买' . $mealInfo['name'] . '订单支付',
  1225. ];
  1226. $params = Wechat::jsapiUnifiedorder($order, 'vip');
  1227. PRedis::set('orders:recharge:vip:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1228. $code = isset($params['code']) ? $params['code'] : '';
  1229. if ($code == 1004) {
  1230. showJson(1004, $params['message']);
  1231. }
  1232. // 更新订单参数
  1233. unset($params['prepay_id']);
  1234. showJson(1005, 7004, $params);
  1235. } else {
  1236. showJson(1004, 7005);
  1237. }
  1238. }
  1239. /**
  1240. * 购买人工服务
  1241. * @throws \think\db\exception\DataNotFoundException
  1242. * @throws \think\db\exception\ModelNotFoundException
  1243. * @throws \think\exception\DbException
  1244. */
  1245. public function handPay()
  1246. {
  1247. // 验证
  1248. $this->checkUser();
  1249. $mealId = input('mealId', 0);
  1250. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1251. if (empty($mealId) || empty($mealInfo)) {
  1252. showJson(1004, 7001);
  1253. }
  1254. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1255. if (empty($mealPrice)) {
  1256. showJson(1004, 7003);
  1257. }
  1258. $orderSn = makeTradeNo('HP', $this->userId);
  1259. $log = [
  1260. 'order_sn' => $orderSn,
  1261. 'money' => $mealPrice,
  1262. 'type' => 5,
  1263. 'pay_money' => $mealPrice,
  1264. 'user_id' => $this->userId,
  1265. 'balance' => 0,
  1266. 'remark' => "购买人工牵服务[ID:{$mealId}]:支付{$mealPrice}元",
  1267. 'created_at' => date('Y-m-d H:i:s')
  1268. ];
  1269. $orderId = db('user_recharge_log')->insertGetId($log);
  1270. $memberInfo = Member::where(['id' => $this->userId])->field('openid')->find();
  1271. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1272. if ($orderId) {
  1273. // 获取OPENID
  1274. if (empty($openid)) {
  1275. showJson(1004, 2010);
  1276. }
  1277. $order = [
  1278. 'orderNo' => $orderSn,
  1279. 'amount' => $mealPrice,
  1280. 'openid' => $openid,
  1281. 'body' => '购买' . $mealInfo['name'] . '服务订单支付',
  1282. ];
  1283. $params = Wechat::jsapiUnifiedorder($order, 'hand');
  1284. PRedis::set('orders:recharge:hand:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1285. $code = isset($params['code']) ? $params['code'] : '';
  1286. if ($code == 1004) {
  1287. showJson(1004, $params['message']);
  1288. }
  1289. // 更新订单参数
  1290. unset($params['prepay_id']);
  1291. showJson(1005, 7004, $params);
  1292. } else {
  1293. showJson(1004, 7005);
  1294. }
  1295. }
  1296. /**
  1297. * 举报信息提交
  1298. */
  1299. public function complainSubmit()
  1300. {
  1301. $uid = input('uid', 0);
  1302. $type = input('type', 0);
  1303. if (empty($uid)) {
  1304. showJson(1004, 8001);
  1305. }
  1306. if (empty($type)) {
  1307. showJson(1004, 8002);
  1308. }
  1309. // 是否已经提交过
  1310. if (Complain::where(['uid' => $this->userId, 'c_uid' => $uid])->where('created_time', '>=', time() - 7 * 24 * 3600)->value('id')) {
  1311. showJson(1004, 8005);
  1312. }
  1313. // 举报数据
  1314. $params = [
  1315. 'uid' => $this->userId,
  1316. 'c_uid' => $uid,
  1317. 'remark' => htmlspecialchars(input('remark', '')),
  1318. 'type' => $type,
  1319. ];
  1320. // 照片
  1321. $file = request()->file('image');
  1322. if ($file) {
  1323. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1324. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1325. $params['image'] = $image;
  1326. }
  1327. // 保存数据
  1328. if ($id = Complain::saveData($params)) {
  1329. showJson(1005, 8003, $id);
  1330. } else {
  1331. showJson(1004, 8004);
  1332. }
  1333. }
  1334. /**
  1335. * 用户反馈建议提交
  1336. */
  1337. public function adviceSubmit()
  1338. {
  1339. $type = input('type', 0);
  1340. if (empty($type)) {
  1341. showJson(1004, 8009);
  1342. }
  1343. // 是否已经提交过
  1344. if (Advice::where(['uid' => $this->userId, 'type' => $type])->where('created_time', '>=', time() - 3 * 24 * 3600)->value('id')) {
  1345. showJson(1004, 8006);
  1346. }
  1347. // 数据
  1348. $params = [
  1349. 'uid' => $this->userId,
  1350. 'remark' => htmlspecialchars(input('remark', '')),
  1351. 'type' => $type,
  1352. ];
  1353. //
  1354. $file = request()->file('image');
  1355. if ($file) {
  1356. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1357. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1358. $params['image'] = $image;
  1359. }
  1360. // 保存数据
  1361. if ($id = Advice::saveData($params)) {
  1362. showJson(1005, 8007, $id);
  1363. } else {
  1364. showJson(1004, 8008);
  1365. }
  1366. }
  1367. /**
  1368. * @throws \think\db\exception\DataNotFoundException
  1369. * @throws \think\db\exception\ModelNotFoundException
  1370. * @throws \think\exception\DbException
  1371. */
  1372. public function complainList()
  1373. {
  1374. $type = input('type', 2);
  1375. $pageSize = input('pageSize', 30);
  1376. showJson(1005, 1001, Member::getComplainList($type, $pageSize));
  1377. }
  1378. /**
  1379. * 坐标转换地址
  1380. */
  1381. public function getLocationAddress()
  1382. {
  1383. $locationType = 'wgs84ll';
  1384. $apiUrl = config('api.locationApi');
  1385. $siteInfo = $siteInfo = cmf_get_site_info();
  1386. $ak = isset($siteInfo['map_key']) ? trim($siteInfo['map_key']) : '';
  1387. $uid = input('uid', 0);
  1388. $lat = input('lat', '');
  1389. $lng = input('lng', '');
  1390. $type = input('type', 1);
  1391. if (empty($lat) || empty($lng)) {
  1392. showJson(1004, 1002);
  1393. }
  1394. $apiUrl = sprintf($apiUrl, $ak, $locationType, "{$lat},{$lng}");
  1395. $data = cmf_curl_get($apiUrl);
  1396. $data = $data ? json_decode($data, true) : [];
  1397. $data = isset($data['result']) ? $data['result'] : [];
  1398. $addressData = isset($data['addressComponent']) ? $data['addressComponent'] : [];
  1399. $province = isset($addressData['province']) ? $addressData['province'] : '';
  1400. $city = isset($addressData['city']) ? $addressData['city'] : '';
  1401. $district = isset($addressData['district']) ? $addressData['district'] : '';
  1402. $location = isset($data['location']) ? $data['location'] : [];
  1403. $latNew = isset($location['lat']) ? round($location['lat'], 6) : 0;
  1404. $lngNew = isset($location['lng']) ? round($location['lng'], 6) : 0;
  1405. if (empty($data) || empty($latNew) || empty($lngNew)) {
  1406. showJson(1004, 8204);
  1407. }
  1408. // 更新位置数据
  1409. $cacheKey = "cache:location:u_{$this->userId}";
  1410. $updateData = ['lat' => $latNew, 'lng' => $lngNew, 'address' => "{$province},{$city},{$district}"];
  1411. if (!PRedis::get($cacheKey)) {
  1412. Member::where(['id' => $this->userId, 'user_type' => 2])->update($updateData);
  1413. PRedis::set($cacheKey, ['uid' => $this->userId, 'data' => $data, 'update' => $updateData, 'lat' => $latNew, 'lng' => $lngNew, 'date' => date('Y-m-d H:i:s')], 5);
  1414. }
  1415. if ($type == 1 && $uid) {
  1416. $distance = '';
  1417. $userInfo = Member::where(['id' => $uid])->field('lat,lng,address')->find();
  1418. $lat1 = isset($userInfo['lat']) ? $userInfo['lat'] : 0;
  1419. $lng1 = isset($userInfo['lng']) ? $userInfo['lng'] : 0;
  1420. $address = isset($userInfo['address']) ? $userInfo['address'] : '';
  1421. $address = $address ? explode(',', $address) : '';
  1422. $district = isset($address[2]) ? $address[2] : '';
  1423. if ($lat1 > 0 && $lng1 > 0) {
  1424. $distance = getDistance($lngNew, $latNew, $lng1, $lat1, 1);
  1425. $distance = $distance >= 1000 ? round($distance / 1000, 2) . 'km' : ($distance? $distance . 'm' : '');
  1426. }
  1427. showJson(1005, 8202, ['location' => $data, 'distance' => $distance, 'other' => $userInfo, 'address' => $address, 'district' => $district]);
  1428. }
  1429. showJson(1005, 8202, ['location' => $data]);
  1430. }
  1431. /**
  1432. * 注销账号
  1433. * @throws \think\Exception
  1434. * @throws \think\exception\PDOException
  1435. */
  1436. public function logout()
  1437. {
  1438. // 验证扣除账号
  1439. $accountConfig = $siteInfo = cmf_get_option('account_config');
  1440. $logoutPay = isset($accountConfig['logout_pay']) ? floatval($accountConfig['logout_pay']) : 0;
  1441. $memberInfo['logout_pay'] = $logoutPay > 0 ? $logoutPay : 1;
  1442. $memberInfo = Member::where(['id' => $this->userId])
  1443. ->field('id,redheart,user_nickname,user_status')
  1444. ->find();
  1445. $memberInfo = $memberInfo? $memberInfo->toArray() : [];
  1446. $redheart = isset($memberInfo['redheart'])? $memberInfo['redheart'] : 0;
  1447. $nickname = isset($memberInfo['user_nickname'])? $memberInfo['user_nickname'] : '';
  1448. $userStatus = isset($memberInfo['user_status'])? $memberInfo['user_status'] : 0;
  1449. if($userStatus == -1){
  1450. showJson(1004, 1124);
  1451. }
  1452. if($redheart < $logoutPay){
  1453. showJson(1004, lang(1125,['pay'=> $logoutPay]));
  1454. }
  1455. DB::startTrans();
  1456. if(!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $logoutPay)){
  1457. DB::rollback();
  1458. showJson(1004, 2031);
  1459. }
  1460. // 账户明细
  1461. $data = [
  1462. 'user_id'=> $this->userId,
  1463. 'type'=> 2,
  1464. 'account_type'=> 1,
  1465. 'change_type'=> 2,
  1466. 'money'=> $logoutPay,
  1467. 'balance'=> $redheart,
  1468. 'remark'=> '用户【'.$nickname.'】注销扣除'.$logoutPay.'颗爱心',
  1469. 'created_at'=> date('Y-m-d H:i:s'),
  1470. 'status'=> 2
  1471. ];
  1472. if(!AccountLog::insertGetId($data)){
  1473. Db::rollback();
  1474. showJson(1004, 8306);
  1475. }
  1476. Db::commit();
  1477. // 注销信息
  1478. Member::where(['id' => $this->userId, 'user_type' => 2])
  1479. ->update(['user_status' => -1, 'vip_auth' => 0, 'is_heart' => 0, 'vip_expire' => 0, 'is_reg_profile' => 2, 'is_tuijian' => 0]);
  1480. $cacheKey = "weixin:auth:" . session('openid');
  1481. PRedis::del($cacheKey);
  1482. session('userInfo', null);
  1483. session('openid', null);
  1484. showJson(1005, 1001);
  1485. }
  1486. /**
  1487. * 认证记录
  1488. * @throws \think\Exception\DbException
  1489. */
  1490. public function getAuthNotice(){
  1491. $dataList = \app\weixin\service\Member::getAuthNotices();
  1492. showJson(1005, 1001, $dataList);
  1493. }
  1494. /**
  1495. * 获取用户访问记录
  1496. */
  1497. public function getUserAccess(){
  1498. $pageSize = input('pageSize', 30);
  1499. $dataList = Member::getUserAccess($this->userId, $pageSize);
  1500. showJson(1005, 1001, $dataList);
  1501. }
  1502. /**
  1503. * 解锁访问用户信息
  1504. */
  1505. public function unlock(){
  1506. $uid = input('uid', 0);
  1507. $cuid = input('cuid', 0);
  1508. if(empty($uid) || empty($cuid)){
  1509. showJson(1004,1012);
  1510. }
  1511. if($uid != $this->userId || ($uid == $cuid)){
  1512. showJson(1004,8301);
  1513. }
  1514. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1515. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1516. }
  1517. $res = Member::catchUnlock($uid, $cuid);
  1518. if (is_array($res)) {
  1519. showJson(1005, 8302);
  1520. } else {
  1521. showJson(1004, $res ? $res : 8303);
  1522. }
  1523. }
  1524. }