MemberController.php 61 KB

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