MemberController.php 76 KB

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