MemberController.php 72 KB

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