MemberController.php 63 KB

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