MemberController.php 76 KB

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