MemberController.php 75 KB

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