MemberController.php 75 KB

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