MemberController.php 57 KB

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