MemberController.php 76 KB

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