MemberController.php 74 KB

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