MemberController.php 57 KB

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