MemberController.php 75 KB

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