MemberController.php 77 KB

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