MemberController.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  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. if(!UserProfile::checkUserProfile($this->userId)){
  682. showJson(1007,1005, ['url'=> Wechat::makeRedirectUrl(url('/weixin/member/profile','','',true))]);
  683. }
  684. showJson(1005, 2036);
  685. }
  686. $memberInfo = Member::where(['id' => $this->userId, 'user_type' => 2])->field('redheart,is_heart,invisible_time')->find();
  687. $isHeart = isset($memberInfo['is_heart']) ? intval($memberInfo['is_heart']) : 0;
  688. $invisibleTime = isset($memberInfo['invisible_time']) ? intval($memberInfo['invisible_time']) : 0;
  689. if ($reset != 1 && $invisibleTime >= time() - 7 * 24 * 3600) {
  690. showJson(1004, lang('invisible', ['date' => date('Y-m-d', $invisibleTime)]));
  691. }
  692. if ($isHeart == 2 && $value == 0) {
  693. showJson(1004, 2034);
  694. }
  695. // 扣除爱心隐身
  696. Db::startTrans();
  697. if ($reset == 1) {
  698. // 扣除爱心账户
  699. $accountConfig = cmf_get_option('account_config');
  700. $hiddenPay = isset($accountConfig['hidden_pay']) ? intval($accountConfig['hidden_pay']) : 0;
  701. $hiddenPay = $hiddenPay ? $hiddenPay : 10;
  702. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  703. if ($redheart < $hiddenPay) {
  704. showJson(1004, 2137);
  705. }
  706. if (!Member::where(['id' => $this->userId, 'user_type' => 2])->setDec('redheart', $hiddenPay)) {
  707. Db::rollback();
  708. showJson(1004, 2031);
  709. }
  710. // 账户明细
  711. $accountData = [
  712. 'user_id' => $this->userId,
  713. 'type' => 2,
  714. 'account_type' => 1,
  715. 'change_type' => 2,
  716. 'money' => $hiddenPay,
  717. 'balance' => $redheart,
  718. 'remark' => "付费设置隐身模式【{$this->userId}】扣除{$hiddenPay}个爱心",
  719. 'created_at' => date('Y-m-d H:i:s'),
  720. 'status' => 2,
  721. ];
  722. PRedis::set('accounts:privacy:' . $this->userId, $accountData, 600);
  723. if (!AccountLog::insertGetId($accountData)) {
  724. Db::rollback();
  725. return false;
  726. }
  727. }
  728. // 更新设置隐身模式
  729. Member::where(['id' => $this->userId, 'user_type' => 2])
  730. ->update(['is_heart' => 2, 'invisible_time' => time()]);
  731. // 操作日志
  732. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => "设置隐身模式"]);
  733. Db::commit();
  734. showJson(1005, 2035);
  735. } else {
  736. $field = $types[$type];
  737. if (!UserProfile::saveData(['userid' => $this->userId], [$field => $value])) {
  738. showJson(1004, 2131);
  739. }
  740. }
  741. showJson(1005, 2130);
  742. }
  743. /**
  744. * 关注用户
  745. */
  746. public function collect()
  747. {
  748. // 验证
  749. $this->checkUser();
  750. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  751. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  752. }
  753. $id = input('id');
  754. $opType = input('type', 1);
  755. $result = Member::collect($this->userId, $id, $opType);
  756. if ($result === true) {
  757. showJson(1005, $opType == 1 ? 2106 : 2108);
  758. } else {
  759. showJson(1004, $result);
  760. }
  761. }
  762. /**
  763. * 获取关注用户/收藏活动列表
  764. */
  765. public function getCollectList()
  766. {
  767. $params = input();
  768. $pageSize = input('pageSize', 12);
  769. $type = input('type', 1);
  770. $dataList = [];
  771. if ($type == 1) {
  772. $dataList = UserCollect::getUserList($this->userId, $params, $pageSize);
  773. } else if ($type == 2) {
  774. $dataList = UserCollect::getFollowUserList($this->userId, $params, $pageSize);
  775. }
  776. showJson(1005, 1001, $dataList);
  777. }
  778. /**
  779. * 获取申请微信消息列表
  780. */
  781. public function getMessageList()
  782. {
  783. $params = input();
  784. $pageSize = input('pageSize', 12);
  785. $dataList = Member::getMessageList($this->userId, $params, $pageSize);
  786. showJson(1005, 1001, $dataList);
  787. }
  788. /**
  789. * 获取申请微信消息详情
  790. */
  791. public function getMessageInfo()
  792. {
  793. $id = input('id', 0);
  794. $info = Member::getMessageInfo($id, $this->userId);
  795. showJson(1005, 1001, $info);
  796. }
  797. /**
  798. * 认证
  799. */
  800. public function authSubmit()
  801. {
  802. // 验证
  803. $this->checkUser();
  804. $params = input();
  805. $scene = isset($params['scene']) ? trim($params['scene']) : '';
  806. $scene = in_array($scene, ['idcard', 'education', 'position']) ? $scene : 'idcard';
  807. $validate = new MemberValidate();
  808. if (!$validate->scene($scene)->check($params)) {
  809. showJson(1004, $validate->getError());
  810. }
  811. if ($scene != 'idcard' && UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  812. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  813. }
  814. // 处理
  815. switch ($scene) {
  816. case 'idcard': // 身份证认证
  817. $idcard = isset($params['idcard']) ? trim($params['idcard']) : '';
  818. $profileData = [
  819. 'idcard' => $idcard,
  820. 'front_idcard' => isset($params['front_idcard']) ? trim($params['front_idcard']) : '',
  821. 'back_idcard' => isset($params['back_idcard']) ? trim($params['back_idcard']) : '',
  822. 'idcard_check' => 1,
  823. ];
  824. // 验证身份证号是否被使用
  825. $checkId = UserProfile::where(['idcard' => $idcard])
  826. ->where('userid', 'not in', $this->userId)
  827. ->value('id');
  828. if ($checkId) {
  829. showJson(1004, 2128);
  830. }
  831. // 身份证照片
  832. /*if (isset($_FILES['image1'])) {
  833. $file1 = request()->file('image1');
  834. $fileData = Storage::uploadImg($file1, 'auth');
  835. $frontIdcard = isset($fileData['file']) ? $fileData['file'] : '';
  836. $profileData['front_idcard'] = $waterTxt ? Storage::imageWater($frontIdcard, $waterTxt) : $frontIdcard;
  837. }
  838. //$file2 = isset($_FILES['image2'])? $_FILES['image2'] : null;
  839. $files = request()->file();
  840. if (isset($_FILES['image2'])) {
  841. $file2 = request()->file('image2');
  842. $fileData = Storage::uploadImg($file2, 'auth');
  843. $backIdcard = isset($fileData['file']) ? $fileData['file'] : '';
  844. $profileData['back_idcard'] = $waterTxt ? Storage::imageWater($backIdcard, $waterTxt) : $backIdcard;
  845. }*/
  846. if (empty($profileData['front_idcard'])) {
  847. showJson(1004, 2024);
  848. }
  849. if (empty($profileData['back_idcard'])) {
  850. showJson(1004, 2025);
  851. }
  852. // var_dump($profileData);exit;
  853. Db::startTrans();
  854. if (!Member::saveData(['id' => $this->userId], ['real_name' => trim($params['realname'])])) {
  855. Db::rollback();
  856. showJson(1004, 2026);
  857. }
  858. if (UserProfile::checkProfile($this->userId)) {
  859. $profileData['updated_at'] = date('Y-m-d H:i:s');
  860. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  861. } else {
  862. $res = UserProfile::insertGetId($profileData);
  863. }
  864. if (!$res) {
  865. Db::rollback();
  866. showJson(1004, 2026);
  867. }
  868. // 操作日志
  869. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交身份证认证']);
  870. Db::commit();
  871. showJson(1005, 2027);
  872. break;
  873. case 'education': // 学历认证
  874. $profileData = [
  875. 'graduate' => isset($params['graduate']) ? trim($params['graduate']) : '',
  876. 'education' => isset($params['education']) ? trim($params['education']) : '',
  877. 'education_img' => isset($params['education_img']) ? trim($params['education_img']) : '',
  878. 'education_check' => 1,
  879. ];
  880. $siteInfo = cmf_get_site_info();
  881. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  882. // 学历证明照片
  883. $file = request()->file('image1');
  884. if ($file) {
  885. $fileData = Storage::uploadImg($file, 'education_img');
  886. $educationImg = isset($fileData['file']) ? $fileData['file'] : '';
  887. $profileData['education_img'] = $waterTxt ? Storage::imageWater($educationImg, $waterTxt) : $educationImg;
  888. }
  889. if (empty($profileData['education_img'])) {
  890. showJson(1004, 2028);
  891. }
  892. Db::startTrans();
  893. if (UserProfile::checkProfile($this->userId)) {
  894. $profileData['updated_at'] = date('Y-m-d H:i:s');
  895. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  896. } else {
  897. $res = UserProfile::insertGetId($profileData);
  898. }
  899. if (!$res) {
  900. Db::rollback();
  901. showJson(1004, 2026);
  902. }
  903. // 操作日志
  904. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交学历认证']);
  905. Db::commit();
  906. showJson(1005, 2027);
  907. break;
  908. case 'position': // 职位认证
  909. $profileData = [
  910. 'company' => isset($params['company']) ? trim($params['company']) : '',
  911. 'occupation' => isset($params['occupation']) ? trim($params['occupation']) : '',
  912. 'position_img' => isset($params['position_img']) ? trim($params['position_img']) : '',
  913. 'position_check' => 1,
  914. ];
  915. $siteInfo = cmf_get_site_info();
  916. $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
  917. // 职位证明照片
  918. $file = request()->file('image1');
  919. if ($file) {
  920. $fileData = Storage::uploadImg($file, 'position_img', false, false);
  921. $positionImg = isset($fileData['file']) ? $fileData['file'] : '';
  922. $profileData['position_img'] = $waterTxt ? Storage::imageWater($positionImg, $waterTxt) : $positionImg;
  923. }
  924. //PRedis::set('test:auth:' . $this->userId, ['file' => $file, 'data' => $fileData, 'profile' => $profileData], 600);
  925. if (empty($profileData['position_img'])) {
  926. showJson(1004, 2033);
  927. }
  928. Db::startTrans();
  929. if (UserProfile::checkProfile($this->userId)) {
  930. $profileData['updated_at'] = date('Y-m-d H:i:s');
  931. $res = UserProfile::saveData(['userid' => $this->userId], $profileData);
  932. } else {
  933. $res = UserProfile::insertGetId($profileData);
  934. }
  935. if (!$res) {
  936. Db::rollback();
  937. showJson(1004, 2026);
  938. }
  939. // 操作日志
  940. UserLog::saveLog(['user_id' => $this->userId, 'type' => 1, 'content' => '提交职业认证']);
  941. Db::commit();
  942. showJson(1005, 2027);
  943. break;
  944. }
  945. showJson(1004, 2009);
  946. }
  947. /**
  948. * 加入怦然心动
  949. */
  950. public function joinHeart()
  951. {
  952. // 验证
  953. $this->checkUser();
  954. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  955. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  956. }
  957. if (!UserProfile::checkUserProfile($this->userId)) {
  958. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  959. }
  960. $isHeart = input('is_heart', 2);
  961. if (!in_array($isHeart, [1, 2])) {
  962. showJson(1004, 2111);
  963. }
  964. $result = Member::where(['id' => $this->userId])
  965. ->update(['updated_at' => date('Y-m-d H:i:s'), 'is_heart' => $isHeart]);
  966. if ($result) {
  967. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => $isHeart == 1 ? '加入怦然心动' : '取消加入怦然心动']);
  968. showJson(1005, $isHeart == 1 ? 5017 : 5019);
  969. } else {
  970. showJson(1004, $isHeart == 1 ? 5018 : 5020);
  971. }
  972. }
  973. /**
  974. * 设置用户推荐条件
  975. */
  976. public function setConditions()
  977. {
  978. // 验证
  979. $this->checkUser();
  980. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  981. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  982. }
  983. $params = input();
  984. PRedis::set('test:conditions:' . $this->userId, $params, 600);
  985. $res = Member::setMemberConditions($this->userId, $params);
  986. if ($res) {
  987. UserLog::saveLog(['user_id' => $this->userId, 'type' => 4, 'content' => '设置推荐条件']);
  988. showJson(1005, 1008);
  989. } else {
  990. showJson(1004, 1009);
  991. }
  992. }
  993. /**
  994. * 获取推荐条件
  995. */
  996. public function getConditions()
  997. {
  998. $conditions = Member::getMemberConditions($this->userId);
  999. showJson(1005, 1008, $conditions);
  1000. }
  1001. /**
  1002. * 获取我的活动列表
  1003. */
  1004. public function getActivityList()
  1005. {
  1006. $params = input();
  1007. $pageSize = input('pageSize', 12);
  1008. $params['user_id'] = $this->userId;
  1009. $dataList = Activity::getMemberActivityList($params, $pageSize);
  1010. showJson(1005, 1001, $dataList);
  1011. }
  1012. /**
  1013. * 爱心充值
  1014. * @throws \think\db\exception\DataNotFoundException
  1015. * @throws \think\db\exception\ModelNotFoundException
  1016. * @throws \think\exception\DbException
  1017. */
  1018. public function doRecharge()
  1019. {
  1020. // 验证
  1021. $this->checkUser();
  1022. $money = input('money', 0);
  1023. $num = input('num', 0);
  1024. if (empty($money) || empty($num)) {
  1025. showJson(1004, 4001);
  1026. }
  1027. $accountConfig = $siteInfo = cmf_get_option('account_config');
  1028. $chargeRate = isset($accountConfig['charge_rate']) ? floatval($accountConfig['charge_rate']) : 0;
  1029. $minRecharge = isset($accountConfig['min_recharge']) ? intval($accountConfig['min_recharge']) : 1;
  1030. if ($minRecharge && $num < $minRecharge) {
  1031. showJson(1004, '最低充值数量为:' . $minRecharge . '个');
  1032. }
  1033. $realMoney = moneyFormat($num * $chargeRate, 2);
  1034. if ($realMoney != $money) {
  1035. showJson(1004, '支付金额计算错误:' . $realMoney);
  1036. }
  1037. $orderSn = makeTradeNo('RH', $this->userId);
  1038. $memberInfo = Member::where(['id' => $this->userId])->field('openid,redheart')->find();
  1039. $redheart = isset($memberInfo['redheart']) ? intval($memberInfo['redheart']) : 0;
  1040. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1041. $log = [
  1042. 'order_sn' => $orderSn,
  1043. 'money' => $num,
  1044. 'pay_money' => $money,
  1045. 'user_id' => $this->userId,
  1046. 'balance' => $redheart,
  1047. 'remark' => "爱心充值:{$num}个,合计:{$money}元",
  1048. 'created_at' => date('Y-m-d H:i:s')
  1049. ];
  1050. $orderId = db('user_recharge_log')->insertGetId($log);
  1051. if ($orderId) {
  1052. // 获取OPENID
  1053. if (empty($openid)) {
  1054. showJson(1004, 2010);
  1055. }
  1056. $order = [
  1057. 'orderNo' => $orderSn,
  1058. 'amount' => $money,
  1059. 'openid' => $openid,
  1060. 'body' => '爱心充值订单支付',
  1061. ];
  1062. $params = Wechat::jsapiUnifiedorder($order, 'recharge');
  1063. PRedis::set('orders:recharge:redheart:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1064. $code = isset($params['code']) ? $params['code'] : '';
  1065. if ($code == 1004) {
  1066. showJson(1004, $params['message']);
  1067. }
  1068. // 更新订单参数
  1069. unset($params['prepay_id']);
  1070. showJson(1005, 4004, $params);
  1071. } else {
  1072. showJson(1004, 4005);
  1073. }
  1074. }
  1075. /**
  1076. * 想认识
  1077. */
  1078. public function doContact()
  1079. {
  1080. // 验证
  1081. $this->checkUser();
  1082. $id = input('id', 0);
  1083. $remark = input('remark', '');
  1084. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1085. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1086. }
  1087. // 完善个人信息
  1088. if (!UserProfile::checkUserProfile($this->userId)) {
  1089. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  1090. }
  1091. // 隐身不可申请
  1092. $type = input('type', 1);
  1093. $isHeart = Member::where(['id' => $this->userId])->value('is_heart');
  1094. if ($isHeart != 1 && $type != 2) {
  1095. showJson(1006, 2037, ['type' => 'check']);
  1096. }
  1097. $res = Member::contactUser($this->userId, $id, $remark);
  1098. if (is_array($res)) {
  1099. showJson(1005, 1008);
  1100. } else if ($res == 2103) {
  1101. $referer = request()->server('HTTP_REFERER');
  1102. $rebackurl = $referer ? $referer : url('/weixin/match/index', '', '', true);
  1103. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/index/entry?rebackurl=' . $rebackurl, '', '', true))]);
  1104. } else if ($res == 2121) {
  1105. showJson(1006, $res ? $res : 1009, ['url' => '/weixin/member/invite']);
  1106. } else {
  1107. showJson(1004, $res ? $res : 1009);
  1108. }
  1109. }
  1110. /**
  1111. * 认识审核确认
  1112. */
  1113. public function contactConfirm()
  1114. {
  1115. // 验证
  1116. $this->checkUser();
  1117. $cid = input('cid', 0);
  1118. $status = input('status', 2);
  1119. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  1120. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  1121. }
  1122. $res = Member::contactConfirm($this->userId, $cid, $status);
  1123. if (is_array($res)) {
  1124. showJson(1005, 1008);
  1125. } else {
  1126. showJson(1004, $res ? $res : 1009);
  1127. }
  1128. }
  1129. /**
  1130. * 套餐列表
  1131. * @throws \think\db\exception\DataNotFoundException
  1132. * @throws \think\db\exception\ModelNotFoundException
  1133. * @throws \think\exception\DbException
  1134. */
  1135. public function mealList()
  1136. {
  1137. $type = input('type', 0);
  1138. showJson(1005, 1001, Meals::getList($type));
  1139. }
  1140. /**
  1141. * 购买VIP套餐
  1142. * @throws \think\db\exception\DataNotFoundException
  1143. * @throws \think\db\exception\ModelNotFoundException
  1144. * @throws \think\exception\DbException
  1145. */
  1146. public function buyVip()
  1147. {
  1148. // 验证
  1149. $this->checkUser();
  1150. $mealId = input('mealId', 0);
  1151. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1152. if (empty($mealId) || empty($mealInfo)) {
  1153. showJson(1004, 7001);
  1154. }
  1155. $mealTime = isset($mealInfo['time']) ? $mealInfo['time'] : 0;
  1156. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1157. if (empty($mealTime)) {
  1158. showJson(1004, 7002);
  1159. }
  1160. if (empty($mealPrice)) {
  1161. showJson(1004, 7003);
  1162. }
  1163. $orderSn = makeTradeNo('VP', $this->userId);
  1164. $memberInfo = Member::where(['id' => $this->userId])->field('openid,vip_auth,vip_expire')->find();
  1165. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  1166. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  1167. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1168. $expireText = $vipExpire > time() && $vipAuth ? ',原先' . date('Y-m-d H:i:s', $vipExpire) . '到期' : ',原先未开通';
  1169. $log = [
  1170. 'order_sn' => $orderSn,
  1171. 'money' => $mealTime,
  1172. 'type' => 4,
  1173. 'pay_money' => $mealPrice,
  1174. 'user_id' => $this->userId,
  1175. 'balance' => 0,
  1176. 'remark' => "购买VIP套餐[ID:{$mealId}]:会员续费{$mealTime}个月{$expireText}",
  1177. 'created_at' => date('Y-m-d H:i:s')
  1178. ];
  1179. $orderId = db('user_recharge_log')->insertGetId($log);
  1180. if ($orderId) {
  1181. // 获取OPENID
  1182. if (empty($openid)) {
  1183. showJson(1004, 2010);
  1184. }
  1185. $order = [
  1186. 'orderNo' => $orderSn,
  1187. 'amount' => $mealPrice,
  1188. 'openid' => $openid,
  1189. 'body' => $vipAuth ? '续费' . $mealInfo['name'] . '订单支付' : '购买' . $mealInfo['name'] . '订单支付',
  1190. ];
  1191. $params = Wechat::jsapiUnifiedorder($order, 'vip');
  1192. PRedis::set('orders:recharge:vip:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1193. $code = isset($params['code']) ? $params['code'] : '';
  1194. if ($code == 1004) {
  1195. showJson(1004, $params['message']);
  1196. }
  1197. // 更新订单参数
  1198. unset($params['prepay_id']);
  1199. showJson(1005, 7004, $params);
  1200. } else {
  1201. showJson(1004, 7005);
  1202. }
  1203. }
  1204. /**
  1205. * 购买人工服务
  1206. * @throws \think\db\exception\DataNotFoundException
  1207. * @throws \think\db\exception\ModelNotFoundException
  1208. * @throws \think\exception\DbException
  1209. */
  1210. public function handPay()
  1211. {
  1212. // 验证
  1213. $this->checkUser();
  1214. $mealId = input('mealId', 0);
  1215. $mealInfo = Meals::where(['status' => 1, 'id' => $mealId])->field('id,name,time,price')->find();
  1216. if (empty($mealId) || empty($mealInfo)) {
  1217. showJson(1004, 7001);
  1218. }
  1219. $mealPrice = isset($mealInfo['price']) ? $mealInfo['price'] : 0;
  1220. if (empty($mealPrice)) {
  1221. showJson(1004, 7003);
  1222. }
  1223. $orderSn = makeTradeNo('HP', $this->userId);
  1224. $log = [
  1225. 'order_sn' => $orderSn,
  1226. 'money' => $mealPrice,
  1227. 'type' => 5,
  1228. 'pay_money' => $mealPrice,
  1229. 'user_id' => $this->userId,
  1230. 'balance' => 0,
  1231. 'remark' => "购买人工牵服务[ID:{$mealId}]:支付{$mealPrice}元",
  1232. 'created_at' => date('Y-m-d H:i:s')
  1233. ];
  1234. $orderId = db('user_recharge_log')->insertGetId($log);
  1235. $memberInfo = Member::where(['id' => $this->userId])->field('openid')->find();
  1236. $openid = isset($memberInfo['openid']) ? $memberInfo['openid'] : '';
  1237. if ($orderId) {
  1238. // 获取OPENID
  1239. if (empty($openid)) {
  1240. showJson(1004, 2010);
  1241. }
  1242. $order = [
  1243. 'orderNo' => $orderSn,
  1244. 'amount' => $mealPrice,
  1245. 'openid' => $openid,
  1246. 'body' => '购买' . $mealInfo['name'] . '服务订单支付',
  1247. ];
  1248. $params = Wechat::jsapiUnifiedorder($order, 'hand');
  1249. PRedis::set('orders:recharge:hand:' . $this->userId . '_' . '_' . $orderSn, ['log' => $log, 'order' => $order, 'params' => $params], 600);
  1250. $code = isset($params['code']) ? $params['code'] : '';
  1251. if ($code == 1004) {
  1252. showJson(1004, $params['message']);
  1253. }
  1254. // 更新订单参数
  1255. unset($params['prepay_id']);
  1256. showJson(1005, 7004, $params);
  1257. } else {
  1258. showJson(1004, 7005);
  1259. }
  1260. }
  1261. /**
  1262. * 举报信息提交
  1263. */
  1264. public function complainSubmit()
  1265. {
  1266. $uid = input('uid', 0);
  1267. $type = input('type', 0);
  1268. if (empty($uid)) {
  1269. showJson(1004, 8001);
  1270. }
  1271. if (empty($type)) {
  1272. showJson(1004, 8002);
  1273. }
  1274. // 是否已经提交过
  1275. if (Complain::where(['uid' => $this->userId, 'c_uid' => $uid])->where('created_time', '>=', time() - 7 * 24 * 3600)->value('id')) {
  1276. showJson(1004, 8005);
  1277. }
  1278. // 举报数据
  1279. $params = [
  1280. 'uid' => $this->userId,
  1281. 'c_uid' => $uid,
  1282. 'remark' => htmlspecialchars(input('remark', '')),
  1283. 'type' => $type,
  1284. ];
  1285. // 照片
  1286. $file = request()->file('image');
  1287. if ($file) {
  1288. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1289. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1290. $params['image'] = $image;
  1291. }
  1292. // 保存数据
  1293. if ($id = Complain::saveData($params)) {
  1294. showJson(1005, 8003, $id);
  1295. } else {
  1296. showJson(1004, 8004);
  1297. }
  1298. }
  1299. /**
  1300. * 用户反馈建议提交
  1301. */
  1302. public function adviceSubmit()
  1303. {
  1304. $type = input('type', 0);
  1305. if (empty($type)) {
  1306. showJson(1004, 8009);
  1307. }
  1308. // 是否已经提交过
  1309. if (Advice::where(['uid' => $this->userId, 'type' => $type])->where('created_time', '>=', time() - 3 * 24 * 3600)->value('id')) {
  1310. showJson(1004, 8006);
  1311. }
  1312. // 数据
  1313. $params = [
  1314. 'uid' => $this->userId,
  1315. 'remark' => htmlspecialchars(input('remark', '')),
  1316. 'type' => $type,
  1317. ];
  1318. //
  1319. $file = request()->file('image');
  1320. if ($file) {
  1321. $fileData = Storage::uploadImg($file, 'complain', false, false);
  1322. $image = isset($fileData['file']) ? $fileData['file'] : '';
  1323. $params['image'] = $image;
  1324. }
  1325. // 保存数据
  1326. if ($id = Advice::saveData($params)) {
  1327. showJson(1005, 8007, $id);
  1328. } else {
  1329. showJson(1004, 8008);
  1330. }
  1331. }
  1332. /**
  1333. * @throws \think\db\exception\DataNotFoundException
  1334. * @throws \think\db\exception\ModelNotFoundException
  1335. * @throws \think\exception\DbException
  1336. */
  1337. public function complainList()
  1338. {
  1339. $type = input('type', 1);
  1340. $pageSize = input('pageSize', 30);
  1341. showJson(1005, 1001, Member::getComplainList($type, $pageSize));
  1342. }
  1343. /**
  1344. * 坐标转换地址
  1345. */
  1346. public function getLocationAddress()
  1347. {
  1348. $locationType = 'wgs84ll';
  1349. $apiUrl = config('api.locationApi');
  1350. $siteInfo = $siteInfo = cmf_get_site_info();
  1351. $ak = isset($siteInfo['map_key']) ? trim($siteInfo['map_key']) : '';
  1352. $uid = input('uid', 0);
  1353. $lat = input('lat', '');
  1354. $lng = input('lng', '');
  1355. $type = input('type', 1);
  1356. if (empty($lat) || empty($lng)) {
  1357. showJson(1004, 1002);
  1358. }
  1359. $apiUrl = sprintf($apiUrl, $ak, $locationType, "{$lat},{$lng}");
  1360. $data = cmf_curl_get($apiUrl);
  1361. $data = $data ? json_decode($data, true) : [];
  1362. $data = isset($data['result']) ? $data['result'] : [];
  1363. $addressData = isset($data['addressComponent']) ? $data['addressComponent'] : [];
  1364. $province = isset($addressData['province']) ? $addressData['province'] : '';
  1365. $city = isset($addressData['city']) ? $addressData['city'] : '';
  1366. $district = isset($addressData['district']) ? $addressData['district'] : '';
  1367. $location = isset($data['location']) ? $data['location'] : [];
  1368. $latNew = isset($location['lat']) ? round($location['lat'], 6) : 0;
  1369. $lngNew = isset($location['lng']) ? round($location['lng'], 6) : 0;
  1370. if (empty($data) || empty($latNew) || empty($lngNew)) {
  1371. showJson(1004, 8204);
  1372. }
  1373. // 更新位置数据
  1374. $cacheKey = "cache:location:u_{$this->userId}";
  1375. $updateData = ['lat' => $latNew, 'lng' => $lngNew, 'address' => "{$province},{$city},{$district}"];
  1376. if (!PRedis::get($cacheKey)) {
  1377. Member::where(['id' => $this->userId, 'user_type' => 2])->update($updateData);
  1378. PRedis::set($cacheKey, ['uid' => $this->userId, 'data' => $data, 'update' => $updateData, 'lat' => $latNew, 'lng' => $lngNew, 'date' => date('Y-m-d H:i:s')], 5);
  1379. }
  1380. if ($type == 1 && $uid) {
  1381. $distance = '';
  1382. $userInfo = Member::where(['id' => $uid])->field('lat,lng,address')->find();
  1383. $lat1 = isset($userInfo['lat']) ? $userInfo['lat'] : 0;
  1384. $lng1 = isset($userInfo['lng']) ? $userInfo['lng'] : 0;
  1385. $address = isset($userInfo['address']) ? $userInfo['address'] : '';
  1386. $address = $address ? explode(',', $address) : '';
  1387. $district = isset($address[2]) ? $address[2] : '';
  1388. if ($lat1 > 0 && $lng1 > 0) {
  1389. $distance = getDistance($lngNew, $latNew, $lng1, $lat1, 1);
  1390. $distance = $distance >= 1000 ? round($distance / 1000, 2) . 'km' : ($distance? $distance . 'm' : '');
  1391. }
  1392. showJson(1005, 8202, ['location' => $data, 'distance' => $distance, 'other' => $userInfo, 'address' => $address, 'district' => $district]);
  1393. }
  1394. showJson(1005, 8202, ['location' => $data]);
  1395. }
  1396. /**
  1397. * 注销账号
  1398. * @throws \think\Exception
  1399. * @throws \think\exception\PDOException
  1400. */
  1401. public function logout()
  1402. {
  1403. Member::where(['id' => $this->userId, 'user_type' => 2])
  1404. ->update(['user_status' => -1, 'vip_auth' => 0, 'is_heart' => 0, 'vip_expire' => 0, 'is_reg_profile' => 2, 'is_tuijian' => 0]);
  1405. $cacheKey = "weixin:auth:" . session('openid');
  1406. PRedis::del($cacheKey);
  1407. session('userInfo', null);
  1408. session('openid', null);
  1409. showJson(1005, 1001);
  1410. }
  1411. }