User.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Ems;
  5. use app\common\library\Sms;
  6. use fast\Random;
  7. use think\Validate;
  8. use think\Db;
  9. use think\Cache;
  10. use Redis;
  11. use AlibabaCloud\Client\AlibabaCloud;
  12. use AlibabaCloud\Client\Exception\ClientException;
  13. use AlibabaCloud\Client\Exception\ServerException;
  14. /**
  15. * 会员接口
  16. */
  17. class User extends Api
  18. {
  19. protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third','onLogin'];
  20. protected $noNeedRight = '*';
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. }
  25. /**
  26. * 会员中心
  27. */
  28. public function index()
  29. {
  30. $this->success('', ['welcome' => $this->auth->nickname]);
  31. }
  32. /**
  33. * 会员登录
  34. *
  35. * @param string $account 账号
  36. * @param string $password 密码
  37. */
  38. public function login()
  39. {
  40. $account = $this->request->request('account');
  41. $password = $this->request->request('password');
  42. if (!$account || !$password) {
  43. $this->error(__('Invalid parameters'));
  44. }
  45. $ret = $this->auth->login($account, $password);
  46. if ($ret) {
  47. $data = ['userinfo' => $this->auth->getUserinfo()];
  48. $this->success(__('Logged in successful'), $data);
  49. } else {
  50. $this->error($this->auth->getError());
  51. }
  52. }
  53. /**
  54. * 手机验证码登录
  55. *
  56. * @param string $mobile 手机号
  57. * @param string $captcha 验证码
  58. */
  59. public function mobilelogin()
  60. {
  61. $mobile = $this->request->request('mobile');
  62. $captcha = $this->request->request('captcha');
  63. if (!$mobile || !$captcha) {
  64. $this->error(__('Invalid parameters'));
  65. }
  66. if (!Validate::regex($mobile, "^1\d{10}$")) {
  67. $this->error(__('Mobile is incorrect'));
  68. }
  69. if (!Sms::check($mobile, $captcha, 'login')) {
  70. $this->error(__('Captcha is incorrect'));
  71. }
  72. $user = \app\common\model\User::getByMobile($mobile);
  73. if ($user) {
  74. if ($user->status != 'normal') {
  75. $this->error(__('Account is locked'));
  76. }
  77. //如果已经有账号则直接登录
  78. $ret = $this->auth->direct($user->id);
  79. } else {
  80. $ret = $this->auth->register($mobile, Random::alnum(), $mobile, []);
  81. }
  82. if ($ret) {
  83. Sms::flush($mobile, 'login');
  84. $data = ['userinfo' => $this->auth->getUserinfo()];
  85. $this->success(__('Logged in successful'), $data);
  86. } else {
  87. $this->error($this->auth->getError());
  88. }
  89. }
  90. /**
  91. * 注册会员
  92. *
  93. * @param string $username 用户名
  94. * @param string $password 密码
  95. * @param string $email 邮箱
  96. * @param string $mobile 手机号
  97. * @param string $code 验证码
  98. */
  99. public function register()
  100. {
  101. $username = $this->request->request('username');
  102. $password = $this->request->request('password');
  103. $email = $this->request->request('email');
  104. $mobile = $this->request->request('mobile');
  105. $code = $this->request->request('code');
  106. if (!$username || !$password) {
  107. $this->error(__('Invalid parameters'));
  108. }
  109. if ($email && !Validate::is($email, "email")) {
  110. $this->error(__('Email is incorrect'));
  111. }
  112. if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  113. $this->error(__('Mobile is incorrect'));
  114. }
  115. $ret = Sms::check($mobile, $code, 'register');
  116. if (!$ret) {
  117. $this->error(__('Captcha is incorrect'));
  118. }
  119. $ret = $this->auth->register($username, $password, $email, $mobile, []);
  120. if ($ret) {
  121. $data = ['userinfo' => $this->auth->getUserinfo()];
  122. $this->success(__('Sign up successful'), $data);
  123. } else {
  124. $this->error($this->auth->getError());
  125. }
  126. }
  127. /**
  128. * 退出登录
  129. */
  130. public function logout()
  131. {
  132. $this->auth->logout();
  133. $this->success(__('Logout successful'));
  134. }
  135. /**
  136. * 修改邮箱
  137. *
  138. * @param string $email 邮箱
  139. * @param string $captcha 验证码
  140. */
  141. public function changeemail()
  142. {
  143. $user = $this->auth->getUser();
  144. $email = $this->request->post('email');
  145. $captcha = $this->request->request('captcha');
  146. if (!$email || !$captcha) {
  147. $this->error(__('Invalid parameters'));
  148. }
  149. if (!Validate::is($email, "email")) {
  150. $this->error(__('Email is incorrect'));
  151. }
  152. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  153. $this->error(__('Email already exists'));
  154. }
  155. $result = Ems::check($email, $captcha, 'changeemail');
  156. if (!$result) {
  157. $this->error(__('Captcha is incorrect'));
  158. }
  159. $verification = $user->verification;
  160. $verification->email = 1;
  161. $user->verification = $verification;
  162. $user->email = $email;
  163. $user->save();
  164. Ems::flush($email, 'changeemail');
  165. $this->success();
  166. }
  167. /**
  168. * 修改手机号
  169. *
  170. * @param string $mobile 手机号
  171. * @param string $captcha 验证码
  172. */
  173. public function changemobile()
  174. {
  175. $user = $this->auth->getUser();
  176. $mobile = $this->request->request('mobile');
  177. $captcha = $this->request->request('captcha');
  178. if (!$mobile || !$captcha) {
  179. $this->error(__('Invalid parameters'));
  180. }
  181. if (!Validate::regex($mobile, "^1\d{10}$")) {
  182. $this->error(__('Mobile is incorrect'));
  183. }
  184. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  185. $this->error(__('Mobile already exists'));
  186. }
  187. $result = Sms::check($mobile, $captcha, 'changemobile');
  188. if (!$result) {
  189. $this->error(__('Captcha is incorrect'));
  190. }
  191. $verification = $user->verification;
  192. $verification->mobile = 1;
  193. $user->verification = $verification;
  194. $user->mobile = $mobile;
  195. $user->save();
  196. Sms::flush($mobile, 'changemobile');
  197. $this->success();
  198. }
  199. /**
  200. * 第三方登录
  201. *
  202. * @param string $platform 平台名称
  203. * @param string $code Code码
  204. */
  205. public function third()
  206. {
  207. $url = url('user/index');
  208. $platform = $this->request->request("platform");
  209. $code = $this->request->request("code");
  210. $config = get_addon_config('third');
  211. if (!$config || !isset($config[$platform])) {
  212. $this->error(__('Invalid parameters'));
  213. }
  214. $app = new \addons\third\library\Application($config);
  215. //通过code换access_token和绑定会员
  216. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  217. if ($result) {
  218. $loginret = \addons\third\library\Service::connect($platform, $result);
  219. if ($loginret) {
  220. $data = [
  221. 'userinfo' => $this->auth->getUserinfo(),
  222. 'thirdinfo' => $result
  223. ];
  224. $this->success(__('Logged in successful'), $data);
  225. }
  226. }
  227. $this->error(__('Operation failed'), $url);
  228. }
  229. /**
  230. * 重置密码
  231. *
  232. * @param string $mobile 手机号
  233. * @param string $newpassword 新密码
  234. * @param string $captcha 验证码
  235. */
  236. public function resetpwd()
  237. {
  238. $type = $this->request->request("type");
  239. $mobile = $this->request->request("mobile");
  240. $email = $this->request->request("email");
  241. $newpassword = $this->request->request("newpassword");
  242. $captcha = $this->request->request("captcha");
  243. if (!$newpassword || !$captcha) {
  244. $this->error(__('Invalid parameters'));
  245. }
  246. if ($type == 'mobile') {
  247. if (!Validate::regex($mobile, "^1\d{10}$")) {
  248. $this->error(__('Mobile is incorrect'));
  249. }
  250. $user = \app\common\model\User::getByMobile($mobile);
  251. if (!$user) {
  252. $this->error(__('User not found'));
  253. }
  254. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  255. if (!$ret) {
  256. $this->error(__('Captcha is incorrect'));
  257. }
  258. Sms::flush($mobile, 'resetpwd');
  259. } else {
  260. if (!Validate::is($email, "email")) {
  261. $this->error(__('Email is incorrect'));
  262. }
  263. $user = \app\common\model\User::getByEmail($email);
  264. if (!$user) {
  265. $this->error(__('User not found'));
  266. }
  267. $ret = Ems::check($email, $captcha, 'resetpwd');
  268. if (!$ret) {
  269. $this->error(__('Captcha is incorrect'));
  270. }
  271. Ems::flush($email, 'resetpwd');
  272. }
  273. //模拟一次登录
  274. $this->auth->direct($user->id);
  275. $ret = $this->auth->changepwd($newpassword, '', true);
  276. if ($ret) {
  277. $this->success(__('Reset password successful'));
  278. } else {
  279. $this->error($this->auth->getError());
  280. }
  281. }
  282. /**
  283. * 运营商一键登录
  284. */
  285. public function onLogin() {
  286. $token = $this->request->param('token');// 易盾返回的token
  287. // 判断登录token是否有效
  288. if (!$token) {
  289. //如果token为空就返回
  290. $this->error('token不能为空,请重试');
  291. } else {
  292. //调用getPhone方法并且将token传给getPhone
  293. $res = $this->getPhone($token);
  294. //如果返回的状态为1说明是注册过的用户
  295. if ($res['state'] == 1) {
  296. $phone = $res['phone'];
  297. // 用户登录逻辑 === 开始
  298. $userModel = new \app\common\model\User();
  299. $auth = \app\common\library\Auth::instance();
  300. $userInfo = $userModel->where(["mobile"=>$phone])->find();
  301. // 判断用户是否已经存在
  302. if($userInfo) { // 登录
  303. $user = \app\common\model\User::get($userInfo["id"]);
  304. if (!$user) {
  305. $this->error("网络错误!请稍后重试");
  306. }
  307. $user->save(["logintime"=>time()]);
  308. $res_login = $auth->direct($user->id);
  309. } else { // 注册
  310. // 先随机一个用户名,随后再变更为u+数字id
  311. $username = Random::alnum(20);
  312. $password = Random::alnum(6);
  313. // 获取默认头像和昵称
  314. $nickname = array_column(\app\admin\model\website\Nickname::select(),'content');
  315. $avatar = array_column(\app\admin\model\website\Avatar::select(),'content');
  316. $extend = [
  317. 'nickname'=>$nickname[rand(0,count($nickname)-1)],
  318. 'avatar'=>$avatar[rand(0,count($avatar)-1)],
  319. "mobile"=>$phone
  320. ];
  321. Db::startTrans();
  322. try {
  323. // 默认注册一个会员
  324. $result = $auth->register($username, $password, "", $extend);
  325. if (!$result) {
  326. return false;
  327. }
  328. $user = $auth->getUser();
  329. $fields = ['username' => 'u' . $user->id];
  330. // 更新会员资料
  331. $user = \app\common\model\User::get($user->id);
  332. $user->save($fields);
  333. Db::commit();
  334. } catch (PDOException $e) {
  335. Db::rollback();
  336. $auth->logout();
  337. return false;
  338. }
  339. // 写入登录Cookies和Token
  340. $res_login = $auth->direct($user->id);
  341. }
  342. $userInfo = $auth->getUserinfo();
  343. if($res_login) {
  344. $this->success("登录成功!",['userinfo' => $userInfo]);
  345. } else {
  346. $this->error("登录失败!");
  347. }
  348. // 用户登录逻辑 === 结束
  349. } else {
  350. //如果没有注册过就返回注册状态
  351. $this->error($res['msg']);
  352. }
  353. }
  354. }
  355. /*
  356. * 根据token换取手机号码
  357. */
  358. public function getPhone($token) {
  359. $config = config('onLogin');
  360. AlibabaCloud::accessKeyClient($config['phone_access_key'], $config['phone_access_secret'])
  361. ->regionId('cn-hangzhou')
  362. ->asDefaultClient();
  363. try {
  364. $result = AlibabaCloud::rpc()
  365. ->product('Dypnsapi')
  366. ->scheme('https')// https | http
  367. ->version('2017-05-25')
  368. ->action('GetMobile')
  369. ->method('POST')
  370. ->host('dypnsapi.aliyuncs.com')
  371. ->options([
  372. 'query' => [
  373. 'RegionId' => "cn-hangzhou",
  374. 'AccessToken' => $token
  375. ],
  376. ])
  377. ->request();
  378. // 将返回的结果转化为数组
  379. $result = $result->toArray();
  380. //判断当前数组不为空
  381. if (isset($result['GetMobileResultDTO']['Mobile'])) {
  382. // token不为空返回手机号码
  383. $phone = $result['GetMobileResultDTO']['Mobile'];
  384. $res = [
  385. 'state' => 1,
  386. 'phone' => $phone
  387. ];
  388. return $res;
  389. } else {
  390. //如果token为空
  391. $res = [
  392. 'state' => 0,
  393. 'msg' => 'token无效'
  394. ];
  395. return $res;
  396. }
  397. } catch (ClientException $e) {//有异常就抛出异常
  398. // 客户端错误
  399. $res = [
  400. 'state' => 101,
  401. 'msg' => '注册失败'
  402. ];
  403. return $res;
  404. } catch (ServerException $e) {
  405. // 服务端错误
  406. $res = [
  407. 'state' => 101,
  408. 'msg' => '注册失败'
  409. ];
  410. return $res;
  411. }
  412. }
  413. /**
  414. * 修改会员个人信息
  415. * 头像,昵称,性别,
  416. */
  417. public function userAvatar()
  418. {
  419. $user = $this->auth->getUser();
  420. $gender = $this->request->request('gender'); // 性别:1=男,-1=女
  421. $nickname_auth = $this->request->request('nickname');
  422. $avatar_auth = $this->request->request('avatar');
  423. if (!$gender && !$nickname_auth && !$avatar_auth) $this->error('参数为空!');
  424. // 随机获取昵称和头像
  425. if(!$user->nickname && !$nickname_auth) {
  426. $nicknameList = \app\admin\model\website\Nickname::select();//得到总条数
  427. $nicknameArr = [];
  428. if($nicknameList) foreach($nicknameList as $k => $v) {
  429. $nicknameArr[] = $v['content'];
  430. }
  431. $user->nickname = $nicknameArr[array_rand($nicknameArr,1)];
  432. }
  433. if(!$user->avatar && !$avatar_auth) {
  434. $avatarList = \app\admin\model\website\Avatar::select();//得到总条数
  435. $avatarArr = [];
  436. if($avatarList) foreach($avatarList as $k => $v) {
  437. $avatarArr[] = $v['content'];
  438. }
  439. $user->avatar = $avatarArr[array_rand($avatarArr,1)];
  440. }
  441. Db::startTrans();
  442. try {
  443. $res1 = true;
  444. if ($nickname_auth) {
  445. if($nickname_auth == $user->nickname) {
  446. $this->error(__('与原昵称相同无需修改!'));
  447. }
  448. $user->nickname_auth = $nickname_auth;
  449. // 添加昵称修改申请表
  450. if(\app\common\model\NicknameAuth::where(["status"=>0,"user_id"=>$this->auth->id])->find()) $this->error("昵称已在审核中!请勿重复申请");
  451. $data = [];
  452. $data['user_id'] = $this->auth->id;
  453. $data['nickname'] = $nickname_auth;
  454. $data['old_nickname'] = $user->nickname;
  455. $data['createtime'] = time();
  456. $res1 = \app\common\model\NicknameAuth::insert($data);
  457. }
  458. if($avatar_auth) {
  459. $user->avatar_auth = $avatar_auth;
  460. // 添加头像修改申请表
  461. if(\app\common\model\AvatarAuth::where(["status"=>0,"user_id"=>$this->auth->id])->find()) $this->error("头像已在审核中!请勿重复申请");
  462. $data = [];
  463. $data['user_id'] = $this->auth->id;
  464. $data['avatar'] = $avatar_auth;
  465. $data['old_avatar'] = $user->avatar;
  466. $data['createtime'] = time();
  467. $res1 = \app\common\model\AvatarAuth::insert($data);
  468. }
  469. $gender && $user->gender = $gender;
  470. $res2 = $user->save();
  471. if($res1 && $res2 !== false) {
  472. Db::commit();
  473. delUserInfo($this->auth->id);
  474. $this->success("修改成功!昵称审核中");
  475. }
  476. } catch (PDOException $e) {
  477. Db::rollback();
  478. $this->error("修改失败!");
  479. }
  480. }
  481. /**
  482. * 修改会员个人信息
  483. * 城市,年龄,收入
  484. */
  485. public function userCity() {
  486. $user = $this->auth->getUser();
  487. $province = $this->request->request('province'); // 省
  488. $city = $this->request->request('city'); // 市
  489. $district = $this->request->request('district'); // 区
  490. $birthday = $this->request->request('birthday');
  491. $age = $this->request->request('age');
  492. $constellation = $this->request->request('constellation'); // 星座
  493. $income = $this->request->request('income');
  494. if ((!$province || !$city || !$district) && $age < 3 && !$income) $this->error('年龄太小了哦!');
  495. $province && $user->province = $province;
  496. $city && $user->city = $city;
  497. $district && $user->district = $district;
  498. $province && $user->province_name = \app\common\model\Area::getNameFromId($province);
  499. $city && $user->city_name = \app\common\model\Area::getNameFromId($city);
  500. $district && $user->district_name = \app\common\model\Area::getNameFromId($district);
  501. $age >= 3 && $user->age = $age;
  502. $constellation && $user->constellation = $constellation;
  503. $birthday && $user->birthday = $birthday;
  504. $income && $user->income = $income;
  505. $user->save();
  506. delUserInfo($this->auth->id);
  507. $this->success("修改成功!");
  508. }
  509. /**
  510. * 修改会员个人信息
  511. * 期望对象
  512. */
  513. public function userExpect() {
  514. $user = $this->auth->getUser();
  515. $expect = $this->request->request('expect'); // 期望对象,格式:1,2,3
  516. if (!$expect) $this->error('参数为空!');
  517. $user->expect_ids = $expect;
  518. $user->save();
  519. delUserInfo($user->id);
  520. $this->success("修改成功!");
  521. }
  522. /**
  523. * 修改会员个人信息
  524. * 最后登录的经纬度
  525. */
  526. public function userLnglat() {
  527. $user = $this->auth->getUser();
  528. $lng = $this->request->request('lng'); // 经度
  529. $lat = $this->request->request('lat'); // 纬度
  530. if (!$lng || !$lat) $this->error('参数缺失!');
  531. $user->lng = $lng;
  532. $user->lat = $lat;
  533. $user->save();
  534. $this->success("修改成功!");
  535. }
  536. /**
  537. * 修改会员个人信息
  538. * 环信注册id
  539. */
  540. public function userEmcid() {
  541. $user = $this->auth->getUser();
  542. $emcid = $this->request->request('emcid'); // 环信注册ID
  543. $user->emcid = $emcid;
  544. $user->save();
  545. $this->success("修改成功!");
  546. }
  547. /**
  548. * 修改会员个人信息
  549. * 爱好,职业,微信,交友宣言
  550. */
  551. public function userhoppy() {
  552. $user = $this->auth->getUser();
  553. $hobby_ids = $this->request->request('hobby_ids'); // 爱好
  554. $profession = $this->request->request('profession'); // 职业(传汉字即可)
  555. $wechat = $this->request->request('wechat'); // 微信号
  556. $declaration = $this->request->request('declaration'); // 交友宣言
  557. if (!$hobby_ids && !$profession && !$wechat && !$declaration) $this->error('参数为空!');
  558. Db::startTrans();
  559. try {
  560. $hobby_ids && $user->hobby_ids = $hobby_ids;
  561. $profession && $user->profession = $profession;
  562. if($wechat) {
  563. if($user->wechat_time + 30*86400 > time()) {
  564. $this->error('微信号每月最多修改一次哦!');
  565. }
  566. $user->wechat_auth = $wechat;
  567. // 添加微信号修改申请表
  568. if(\app\common\model\WechatAuth::where(["status"=>0,"user_id"=>$this->auth->id])->find()) $this->error("微信号已在审核中!请勿重复申请");
  569. $data = [];
  570. $data['user_id'] = $this->auth->id;
  571. $data['wechat'] = $wechat;
  572. $data['old_wechat'] = $user->wechat;
  573. $data['createtime'] = time();
  574. $res1 = \app\common\model\WechatAuth::insert($data);
  575. $user->wechat_time = time();
  576. } else {
  577. $res1 = true;
  578. }
  579. if($declaration) {
  580. if (iconv_strlen($declaration, 'utf-8') > 64) {
  581. $this->error('交友宣言最多64位哦!');
  582. }
  583. $user->declaration_auth = $declaration;
  584. // 添加交友宣言修改申请表
  585. if(\app\common\model\DeclarationAuth::where(["status"=>0,"user_id"=>$this->auth->id])->find()) $this->error("交友宣言已在审核中!请勿重复申请");
  586. $data = [];
  587. $data['user_id'] = $this->auth->id;
  588. $data['declaration'] = $declaration;
  589. $data['old_declaration'] = $user->declaration;
  590. $data['createtime'] = time();
  591. $res3 = \app\common\model\DeclarationAuth::insert($data);
  592. } else {
  593. $res3 = true;
  594. }
  595. // $declaration && $user->declaration = $declaration;
  596. $res2 = $user->save();
  597. if($res1 && $res2 && $res3) {
  598. Db::commit();
  599. delUserInfo($this->auth->id);
  600. if($wechat) {
  601. $this->success("微信号修改申请已提交,请耐心等待审核!");
  602. } elseif ($declaration) {
  603. $this->success("交友宣言修改申请已提交,请耐心等待审核!");
  604. } else {
  605. $this->success("修改成功!");
  606. }
  607. }
  608. } catch (PDOException $e) {
  609. Db::rollback();
  610. $this->error("修改失败!");
  611. }
  612. }
  613. /**
  614. * 实名认证
  615. */
  616. public function authApply() {
  617. $realname = $this->request->request('realname'); // 真实姓名
  618. $idcard = $this->request->request('idcard'); // 身份证号
  619. $zimage = $this->request->request('zimage'); // 身份证正面照
  620. $fimage = $this->request->request('fimage'); // 身份证反面照
  621. if (!$zimage || !$fimage) {
  622. $this->error(__('Invalid parameters'));
  623. }
  624. $userauthModel = new \app\common\model\UserAuth();
  625. $data = [];
  626. $data["user_id"] = $this->auth->id;
  627. if($userauthModel->where($data)->where(['status'=>['in',[0,1]]])->find()) $this->error('您已经申请过了,请勿重复操作!');
  628. $data["idcard"] = $idcard;
  629. $data["realname"] = $realname;
  630. $zimage && $data["zimage"] = $zimage;
  631. $fimage && $data["fimage"] = $fimage;
  632. $data["status"] = 0;
  633. $data["updatetime"] = time();
  634. $data["createtime"] = time();
  635. $res = $userauthModel->insertGetId($data);
  636. \app\common\model\User::update(['is_auth'=>1],["id"=>$this->auth->id]);
  637. if($res) {
  638. $this->success("实名认证申请提交成功,请耐心等待审核");
  639. } else {
  640. $this->error("网络错误,请稍后重试");
  641. }
  642. }
  643. /**
  644. * 加入黑名单
  645. */
  646. public function addBlacklist() {
  647. $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
  648. if (!$black_user_id) {
  649. $this->error(__('Invalid parameters'));
  650. }
  651. $user_id = $this->auth->id;
  652. if($user_id == $black_user_id) {
  653. $this->error(__('为何拉黑自己呢?'));
  654. }
  655. $userblacklistModel = new \app\common\model\UserBlacklist();
  656. $data = [];
  657. $data["user_id"] = $user_id;
  658. $data["black_user_id"] = $black_user_id;
  659. if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
  660. $data["createtime"] = time();
  661. $res = $userblacklistModel->insertGetId($data);
  662. if($res) {
  663. $this->success("加入成功!");
  664. } else {
  665. $this->error("网络错误,请稍后重试");
  666. }
  667. }
  668. /**
  669. * 获取黑名单用户
  670. */
  671. public function getBlacklist() {
  672. $page = $this->request->request('page',1); // 分页
  673. $pageNum = $this->request->request('pageNum',10); // 分页
  674. // 分页搜索构建
  675. $pageStart = ($page-1)*$pageNum;
  676. $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
  677. $where = [];
  678. $where["a.user_id"] = $this->auth->id;
  679. $list = $userblacklistModel->alias("a")
  680. ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.age,u.gender,u.constellation,u.hobby_ids,u.profession")
  681. ->join("hx_user u","u.id = a.black_user_id")
  682. ->where($where)
  683. ->limit($pageStart,$pageNum)
  684. ->select();
  685. if($list) {
  686. foreach($list as $k => $v) {
  687. $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
  688. }
  689. $this->success("获取成功!",$list);
  690. } else {
  691. $this->success("数据为空",[]);
  692. }
  693. }
  694. /**
  695. * 移除用户黑名单
  696. */
  697. public function removeUserBlack() {
  698. $id = $this->request->request('id'); // 黑名单ID
  699. if (!$id) {
  700. $this->error(__('Invalid parameters'));
  701. }
  702. $userblacklistModel = new \app\common\model\UserBlacklist();
  703. $where = [];
  704. $where["id"] = $id;
  705. $info = $userblacklistModel->where($where)->find();
  706. if($info['user_id'] != $this->auth->id) $this->error("无权限!");
  707. $res = $userblacklistModel->where($where)->delete();
  708. if($res) {
  709. $this->success("移除成功!",$res);
  710. } else {
  711. $this->error("网络错误,请稍后重试!");
  712. }
  713. }
  714. /**
  715. * 举报用户
  716. */
  717. public function addReport() {
  718. $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
  719. $content = $this->request->request('content'); // 举报内容
  720. $type_id = $this->request->request('type_id'); // 举报类型
  721. $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
  722. if (!$ruser_id) {
  723. $this->error(__('Invalid parameters'));
  724. }
  725. $userreportModel = new \app\common\model\UserReport();
  726. $data = [];
  727. $data["user_id"] = $this->auth->id;
  728. $data["ruser_id"] = $ruser_id;
  729. $data["type_id"] = $type_id;
  730. $data["content"] = $content;
  731. $data["image"] = $image;
  732. $data["createtime"] = time();
  733. $res = $userreportModel->insertGetId($data);
  734. if($res) {
  735. $this->success("举报成功!");
  736. } else {
  737. $this->error("网络错误,请稍后重试");
  738. }
  739. }
  740. /**
  741. * 剩余特权次数
  742. * @return int|mixed
  743. */
  744. public function getFateCount() {
  745. $fate_count = \app\common\model\User::getViewCount($this->auth->id);
  746. $this->success("获取成功!",$fate_count);
  747. }
  748. /**
  749. * 添加有眼缘
  750. */
  751. public function addFate() {
  752. $fate_user_id = $this->request->request('fate_user_id'); // 被眼缘用户ID
  753. if (!$fate_user_id) {
  754. $this->error(__('Invalid parameters'));
  755. }
  756. $user_id = $this->auth->id;
  757. if($fate_user_id == $user_id) {
  758. $this->error("不需要添加自己为有眼缘哦!");
  759. }
  760. $user = \app\common\model\User::get($user_id);
  761. // 查看当前用户剩余次数
  762. $view_count = \app\common\model\User::getViewCount($user_id);
  763. if($view_count <= 0) {
  764. $this->error(__('可查看次数不够了哦!',[],100));
  765. } else {
  766. Db::startTrans();
  767. try {
  768. $user->view_count = $user->view_count - 1;
  769. $res1 = $user->save();
  770. // 添加眼缘记录
  771. $data = [];
  772. $data['user_id'] = $user_id;
  773. $data['fate_user_id'] = $fate_user_id;
  774. if(\app\common\model\UserFate::where($data)->find()) {
  775. $this->error("已经添加眼缘啦!");
  776. }
  777. $data['createtime'] = time();
  778. $res2 = \app\common\model\UserFate::insert($data);
  779. // 添加返利
  780. if($user->is_goddess == 1) {
  781. $memo = '被查看有眼缘获得收益!';
  782. $profit = config('site.fate') * config('site.goddessProfitRate') * 0.01;
  783. } else {
  784. $memo = '被查看有眼缘获得收益!';
  785. $profit = config('site.fate') * config('site.userProfitRate') * 0.01;
  786. }
  787. if($profit >= 0.01 && $fate_user_id > 0) {
  788. $res3 = \app\common\model\User::profit($profit,$fate_user_id,$memo);
  789. } else {
  790. $res3 = true;
  791. }
  792. if($res1 && $res2 && $res3) {
  793. Db::commit();
  794. $fate_user_info = \app\common\model\User::where(['id'=>$fate_user_id])->find();
  795. $title = '眼缘提醒!';
  796. $content = $fate_user_info->nickname.': 等你很久了,终于来了。希望你可以眼缘这里找到有趣的灵魂。无论白天还是深夜,无论快乐还是寂寞,始终有人陪你~';
  797. \app\common\model\SysMsg::sendSysMsg($fate_user_id,6,$title,$content);
  798. $this->success("眼缘添加成功!");
  799. }
  800. } catch (PDOException $e) {
  801. Db::rollback();
  802. $this->error("添加失败!");
  803. }
  804. }
  805. }
  806. /**
  807. * 获取有眼缘列表
  808. */
  809. public function getFate() {
  810. $page = $this->request->request('page',1); // 分页
  811. $pageNum = $this->request->request('pageNum',10); // 分页
  812. // 分页搜索构建
  813. $pageStart = ($page-1)*$pageNum;
  814. $user_id = $this->auth->id;
  815. $where = [];
  816. $where['a.user_id'] = $user_id;
  817. $res = \app\common\model\UserFate::alias("a")
  818. ->field("a.id,u.id as user_id,u.avatar,u.nickname,u.age,u.constellation,u.hobby_ids,u.profession,u.wechat")
  819. ->join("hx_user u","u.id = a.fate_user_id")
  820. ->where($where)
  821. ->order("a.createtime",'desc')
  822. ->limit($pageStart,$pageNum)
  823. ->select();
  824. if($res) foreach($res as $k => $v) {
  825. $res[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
  826. }
  827. $this->success("获取成功!",$res);
  828. }
  829. /**
  830. * 获取用户个人信息
  831. */
  832. public function getUserInfo() {
  833. $user_id = $this->request->request('user_id',0); // 用户ID
  834. if(!$user_id) {
  835. $this->error('参数缺失!');
  836. }
  837. // // redis
  838. // $redis = new Redis();
  839. // $redisconfig = config("redis");
  840. // $redis->connect($redisconfig["host"], $redisconfig["port"]);
  841. // $userInfo = decodeArray($redis->hGetAll('userInfo_'.$user_id));
  842. //
  843. // if(!$userInfo){
  844. // 获取用户信息
  845. $field = 'id,avatar,nickname,is_goddess,is_auth,recharge_auth,vipStatus(vip_duetime) as is_vip,age,lng,lat,city_name,district_name,constellation,hobby_ids,profession,declaration,wechat,income';
  846. $userInfo = \app\common\model\User::field($field)->where(['id'=>$user_id])->find();
  847. $userInfo['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($userInfo['hobby_ids']);
  848. // 获取是否有眼缘
  849. $userInfo['is_fate'] = \app\common\model\User::getIsView($user_id,$this->auth->id);
  850. // 获取地区
  851. $userInfo['address'] = \app\common\model\Eyemargin::getDistanceTxt($userInfo['lng'],$userInfo['lat'],$this->auth->lng,$this->auth->lat,$userInfo['city_name'],$userInfo['district_name']);
  852. // 微信号
  853. if(!$userInfo['wechat']) {
  854. $userInfo['wechat'] = '暂未设置微信号!';
  855. } elseif(!$userInfo['is_fate']) {
  856. $userInfo['wechat'] = '******';
  857. }
  858. // 获取已有标签以及数量
  859. $userInfo['tagUser'] = \app\common\model\TagUser::alias('a')
  860. ->field('a.id,t.name,a.number')
  861. ->join('hx_tag t','t.id = a.tag_id','left')
  862. ->where(['a.user_id'=>$user_id])
  863. ->select();
  864. // $userInfo = $userInfo->toArray();
  865. // $redis->hMSet('userInfo_'.$user_id,encodeArray($userInfo));
  866. // }
  867. $this->success("获取成功!",$userInfo);
  868. }
  869. /**
  870. * 获取我的个人信息
  871. */
  872. public function getMyInfo() {
  873. $user_id = $this->auth->id;
  874. // redis
  875. // $redis = new Redis();
  876. // $redisconfig = config("redis");
  877. // $redis->connect($redisconfig["host"], $redisconfig["port"]);
  878. // $userInfo = decodeArray($redis->hGetAll('userInfo_'.$user_id));
  879. //
  880. // if(!$userInfo){
  881. // 获取用户信息
  882. $field = 'id,avatar,avatar_auth,gender,nickname,nickname_auth,is_goddess,is_auth,vipStatus(vip_duetime) as is_vip,vip_duetime,age,city_name,district_name,constellation,hobby_ids,expect_ids,profession,declaration,declaration_auth,money,wechat,wechat_auth,pre_user_id';
  883. $userInfo = \app\common\model\User::field($field)->where(['id'=>$user_id])->find();
  884. $userInfo['vip_duetime'] = $userInfo['vip_duetime']?date('Y-m-d',$userInfo['vip_duetime']):"";
  885. if($userInfo['pre_user_id']>0) {
  886. $userInfo['pre_invite_no'] = \app\common\model\User::where(['id'=>$userInfo['pre_user_id']])->value("invite_no");
  887. } else {
  888. $userInfo['pre_invite_no'] = "";
  889. }
  890. // 获取我喜欢的统计
  891. $userInfo['ilike_count'] = \app\common\model\UserLike::where(['fans_id'=>$user_id])->count();
  892. $userInfo['likeme_count'] = \app\common\model\UserLike::where(['user_id'=>$user_id])->count();
  893. $userInfo['fate_count'] = \app\common\model\UserFate::where(['user_id'=>$user_id])->count();
  894. $userInfo['money_count'] = $userInfo['money'];
  895. $userInfo['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($userInfo['hobby_ids']);
  896. $userInfo['expect_ids'] = $userInfo['expect_ids']?explode(",",$userInfo['expect_ids']):[];
  897. $userInfo['nickname_auth_stauts'] = \app\common\model\NicknameAuth::getAuthStatus($userInfo['id'],$userInfo['nickname_auth']);
  898. $userInfo['avatar_auth_stauts'] = \app\common\model\AvatarAuth::getAuthStatus($userInfo['id'],$userInfo['avatar_auth']);
  899. $userInfo['wechat_auth_stauts'] = \app\common\model\WechatAuth::getAuthStatus($userInfo['id'],$userInfo['wechat_auth']);
  900. $userInfo['declaration_auth_stauts'] = $userInfo['declaration_auth'] !== '' ? \app\common\model\DeclarationAuth::getAuthStatus($userInfo['id'],$userInfo['declaration_auth']) : 1;
  901. // $userInfo = $userInfo->toArray();
  902. // $redis->hMSet('userInfo_'.$user_id,encodeArray($userInfo));
  903. // }
  904. $this->success("获取成功!",$userInfo);
  905. }
  906. /**
  907. * 获取动态/我的动态
  908. * @throws \think\db\exception\DataNotFoundException
  909. * @throws \think\db\exception\ModelNotFoundException
  910. * @throws \think\exception\DbException
  911. */
  912. public function getUserEyemagin() {
  913. $user_id = $this->request->request('user_id',0); // 用户ID
  914. $page = $this->request->request('page',1); // 分页
  915. $pageNum = $this->request->request('pageNum',10); // 分页
  916. // 分页搜索构建
  917. $pageStart = ($page-1)*$pageNum;
  918. $where = [];
  919. if($user_id > 0) {
  920. $where['a.user_id'] = $user_id;
  921. $where['a.status'] = 1;
  922. } else {
  923. $user_id = $this->auth->id;
  924. $where['a.user_id'] = $user_id;
  925. $where['a.status'] = ['in',[0,1]];
  926. }
  927. $field = "a.*,u.avatar,u.city_name,u.district_name,u.nickname,u.is_goddess,u.is_auth,vipStatus(u.vip_duetime) as is_vip,
  928. u.age,u.constellation,u.hobby_ids,u.profession,u.declaration,u.lng,u.lat";
  929. $list = \app\common\model\Eyemargin::alias("a")
  930. ->field($field)
  931. ->join("user u","a.user_id = u.id")
  932. ->where($where)
  933. ->limit($pageStart,$pageNum)
  934. ->order("a.createtime desc")
  935. ->select();
  936. if($list) foreach($list as $k => $v) {
  937. // 计算距离
  938. $list[$k]['distance'] = \app\common\model\Eyemargin::getDistance($v['lng'],$v['lat'],$this->auth->lng,$this->auth->lat);
  939. $list[$k]['distance_txt'] = \app\common\model\Eyemargin::getDistanceTxt($v['lng'],$v['lat'],$this->auth->lng,$this->auth->lat,$v['city_name'],$v['district_name']);
  940. $list[$k]['right_info'] = \app\common\model\Eyemargin::getIsView($v['user_id'],$user_id);
  941. $v['cover'] || $list[$k]['cover'] = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].'/assets/img/video_cover.jpeg';
  942. $v['hobby_ids'] || $list[$k]['hobby_ids'] = [];
  943. $v['profession'] || $list[$k]['profession'] = '';
  944. $v['music'] || $list[$k]['music'] = '';
  945. $v['video'] || $list[$k]['video'] = '';
  946. }
  947. $this->success("获取成功!",$list);
  948. }
  949. /**
  950. * 获取我的个人基本信息
  951. */
  952. public function getMyBaseInfo() {
  953. $user_id = $this->auth->id;
  954. // redis
  955. // $redis = new Redis();
  956. // $redisconfig = config("redis");
  957. // $redis->connect($redisconfig["host"], $redisconfig["port"]);
  958. // $userInfo = decodeArray($redis->hGetAll('userInfo_'.$user_id));
  959. // if(!$userInfo){
  960. // 获取用户信息
  961. $field = 'id,avatar,nickname,gender,age,city_name,district_name,constellation,hobby_ids,profession,declaration,wechat,income';
  962. $userInfo = \app\common\model\User::field($field)->where(['id'=>$user_id])->find();
  963. $userInfo['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($userInfo['hobby_ids']);
  964. // 获取已有标签以及数量
  965. $userInfo['tagUser'] = \app\common\model\TagUser::alias('a')
  966. ->field('a.id,t.name,a.number')
  967. ->join('hx_tag t','t.id = a.tag_id','left')
  968. ->where(['a.user_id'=>$user_id])
  969. ->select();
  970. $userInfo = $userInfo->toArray();
  971. // $redis->hMSet('userInfo_'.$user_id,encodeArray($userInfo));
  972. // }
  973. $this->success("获取成功!",$userInfo);
  974. }
  975. /**
  976. * 为用户添加标签
  977. */
  978. public function setUserTag() {
  979. $tag_id = $this->request->request('tag_id',0); // 标签ID
  980. $fate_user_id = $this->request->request('fate_user_id',0); // 有眼缘用户ID
  981. if(!$tag_id || !$fate_user_id) {
  982. $this->error('参数缺失!');
  983. }
  984. if(!\app\common\model\Tag::where(['id'=>$tag_id])->find()) {
  985. $this->error('标签不存在!');
  986. }
  987. $user_id = $this->auth->id;
  988. $is_fate = \app\common\model\User::getIsView($fate_user_id,$user_id);
  989. if(!$is_fate) $this->error('您需要先获取微信号才能添加标签');
  990. $tag_user_log = \app\common\model\TagUserLog::where(['user_id'=>$user_id,'fate_user_id'=>$fate_user_id,'tag_id'=>$tag_id])->find();
  991. if($tag_user_log) {
  992. $this->error('您已经为ta添加过此标签了');
  993. }
  994. Db::startTrans();
  995. try {
  996. // 添加记录
  997. $data = [];
  998. $data['user_id'] = $user_id;
  999. $data['fate_user_id'] = $fate_user_id;
  1000. $data['tag_id'] = $tag_id;
  1001. $data['createtime'] = time();
  1002. $res1 = \app\common\model\TagUserLog::insert($data);
  1003. // 修改标签数量
  1004. $where = [];
  1005. $where['user_id'] = $fate_user_id;
  1006. $where['tag_id'] = $tag_id;
  1007. $tag_user = \app\common\model\TagUser::where($where)->find();
  1008. if($tag_user) {
  1009. $tag_user->number = $tag_user->number + 1;
  1010. $res2 = $tag_user->save();
  1011. } else {
  1012. $data = [];
  1013. $data['user_id'] = $fate_user_id;
  1014. $data['tag_id'] = $tag_id;
  1015. $data['number'] = 1;
  1016. $data['createtime'] = time();
  1017. $res2 = \app\common\model\TagUser::insert($data);
  1018. }
  1019. if($res1 && $res2) {
  1020. Db::commit();
  1021. delUserInfo($fate_user_id);
  1022. $this->success("标签添加成功!");
  1023. }
  1024. } catch (PDOException $e) {
  1025. Db::rollback();
  1026. $this->error("修改失败!");
  1027. }
  1028. }
  1029. /**
  1030. * 绑定用户
  1031. */
  1032. public function bindUser() {
  1033. $invite_no = $this->request->request('invite_no'); // 邀请码
  1034. if(!$invite_no) {
  1035. $this->error("请输入邀请码!");
  1036. }
  1037. $user_id = $this->auth->id;
  1038. // 查询邀请码用户信息
  1039. $inviteUserInfo = \app\common\model\User::where(["invite_no"=>$invite_no])->find();
  1040. if(!$inviteUserInfo) $this->error("查询不到该邀请码用户信息!");
  1041. // 判断是否已经绑定过
  1042. $my_pre_user_id = \app\common\model\User::where(["id"=>$user_id])->value("pre_user_id");
  1043. if($my_pre_user_id > 0) {
  1044. $this->error(__('您已绑定过,不可重复绑定!'));
  1045. }
  1046. if($user_id == $inviteUserInfo->id) {
  1047. $this->error(__('不能绑定自己哦?'));
  1048. }
  1049. // 判断当前用户是否实名认证
  1050. $userAuthInfo = \app\common\model\UserAuth::userIsAuth($this->auth->id);
  1051. if($userAuthInfo['status'] == 0) $this->error($userAuthInfo['msg']);
  1052. $res = \app\common\model\User::update(["pre_user_id"=>$inviteUserInfo->id,'invite_time'=>time()],["id"=>$user_id]);
  1053. if($res) {
  1054. $this->success("恭喜,绑定成功!");
  1055. } else {
  1056. $this->error("网络繁忙,请稍后重试!");
  1057. }
  1058. }
  1059. /**
  1060. * 添加银行卡
  1061. */
  1062. public function addBank() {
  1063. $user_name = $this->request->request('user_name'); //真实姓名
  1064. $bank_name= $this->request->request('bank_name'); //银行名称
  1065. $bank_no = $this->request->request('bank_no'); //银行卡号
  1066. if (!$user_name || !$bank_name || !$bank_no) {
  1067. $this->error(__('Invalid parameters'));
  1068. }
  1069. $bankModel = new \app\common\model\UserBank();
  1070. $where = [];
  1071. $where["user_id"] = $this->auth->id;
  1072. $where["bank_no"] = $bank_no;
  1073. $bankInfo = $bankModel->where($where)->find();
  1074. if($bankInfo) {
  1075. $this->error('该银行卡已经添加过了!');
  1076. }
  1077. $data = [];
  1078. $data["user_id"] = $this->auth->id;
  1079. $data["user_name"] = $user_name;
  1080. $data["bank_name"] = $bank_name;
  1081. $data["bank_no"] = $bank_no;
  1082. $data["createtime"] = time();
  1083. $id = $bankModel->insertGetId($data);
  1084. if($id > 0) {
  1085. $this->success('添加成功!');
  1086. } else {
  1087. $this->error('添加失败!');
  1088. }
  1089. }
  1090. /**
  1091. * 获取银行卡信息
  1092. */
  1093. public function bankInfo() {
  1094. $bankModel = new \app\common\model\UserBank();
  1095. $where = [];
  1096. $where["user_id"] = $this->auth->id;
  1097. $bankInfo = $bankModel->where($where)->find();
  1098. $bankInfo['bank_no'] && $bankInfo['bank_no'] = substr_replace($bankInfo['bank_no'],'********','0','8');
  1099. $this->success('获取成功!',$bankInfo);
  1100. }
  1101. /**
  1102. * 删除银行卡
  1103. */
  1104. public function bankDel() {
  1105. $bankModel = new \app\common\model\UserBank();
  1106. $where = [];
  1107. $where["user_id"] = $this->auth->id;
  1108. $bankInfo = $bankModel->where($where)->delete();
  1109. if($bankInfo) {
  1110. $this->success('删除成功!');
  1111. } else {
  1112. $this->error('删除失败!');
  1113. }
  1114. }
  1115. /**
  1116. * 获取会员开通配置信息
  1117. */
  1118. public function getVipConfig() {
  1119. $res = [];
  1120. $res['user_info'] = \app\common\model\User::field('id,nickname,avatar,vipStatus(vip_duetime) as is_vip,vip_duetime')->where(['id'=>$this->auth->id])->find();
  1121. $res['user_info']['vip_duetime'] = $res['user_info']['vip_duetime']?date('Y-m-d',$res['user_info']['vip_duetime']):"";
  1122. $res['vip_config'] = \app\admin\model\vip\Config::order("weight","desc")->select();
  1123. $this->success("获取成功!",$res);
  1124. }
  1125. /**
  1126. * 设置首页推荐
  1127. */
  1128. public function setEyemaginToMain() {
  1129. $fate_id = $this->request->request('fate_id'); //动态ID
  1130. if (!$fate_id) {
  1131. $this->error(__('Invalid parameters'));
  1132. }
  1133. $user_id = $this->auth->id;
  1134. $fateInfo = \app\common\model\Eyemargin::get($fate_id);
  1135. if($fateInfo->user_id != $user_id) $this->error('抱歉,您无权限操作!');
  1136. // 判断动态是否在审核中
  1137. if($fateInfo->status != 1) $this->error('当前动态状态不允许设置为推荐!');
  1138. Db::startTrans();
  1139. try {
  1140. // 先取消掉所有的推荐
  1141. $res1 = \app\common\model\Eyemargin::update(['is_main'=>0],['user_id'=>$user_id]);
  1142. $res2 = \app\common\model\Eyemargin::update(['is_main'=>1],['id'=>$fate_id]);
  1143. if($res1 && $res2) {
  1144. Db::commit();
  1145. $this->success("设置成功!");
  1146. }
  1147. } catch (PDOException $e) {
  1148. Db::rollback();
  1149. $this->error("设置失败!");
  1150. }
  1151. }
  1152. /**
  1153. * 删除动态
  1154. */
  1155. public function delEyemagin() {
  1156. $fate_id = $this->request->request('fate_id'); //动态ID
  1157. if (!$fate_id) {
  1158. $this->error(__('Invalid parameters'));
  1159. }
  1160. $user_id = $this->auth->id;
  1161. $fateInfo = \app\common\model\Eyemargin::get($fate_id);
  1162. if($fateInfo->user_id != $user_id) $this->error('抱歉,您无权限操作!');
  1163. $res = \app\common\model\Eyemargin::where(['id'=>$fate_id])->delete();
  1164. if($res) {
  1165. $this->success("删除成功!");
  1166. } else {
  1167. $this->error("删除失败!");
  1168. }
  1169. }
  1170. /**
  1171. * 获取第一条系统消息
  1172. */
  1173. public function getFirstSysMsg() {
  1174. $user_id = $this->auth->id;
  1175. $res = [];
  1176. $res['msg_content'] = \app\common\model\SysMsg::where(['user_id'=>$user_id])->order('createtime','desc')->value('title');
  1177. $res['msg_count'] = \app\common\model\SysMsg::where(['user_id'=>$user_id,'is_read'=>0])->count();
  1178. $this->success("获取成功!",$res);
  1179. }
  1180. /**
  1181. * 获取系统消息列表
  1182. */
  1183. public function getSysMsg() {
  1184. $page = $this->request->request('page',1); // 分页
  1185. $pageNum = $this->request->request('pageNum',10); // 分页
  1186. // 分页搜索构建
  1187. $pageStart = ($page-1)*$pageNum;
  1188. $user_id = $this->auth->id;
  1189. $sysMsgList = \app\common\model\SysMsg::where(['user_id'=>$user_id])->order('createtime','desc')->limit($pageStart,$pageNum)->select();
  1190. if($sysMsgList) {
  1191. // 标记所有消息已读1
  1192. \app\common\model\SysMsg::update(['is_read'=>1],['user_id'=>$user_id]);
  1193. }
  1194. $this->success("获取成功!",$sysMsgList);
  1195. }
  1196. /**
  1197. * 获取实名认证信息
  1198. */
  1199. public function getAuthInfo() {
  1200. $user_id = $this->auth->id;
  1201. // 判断当前用户是否实名认证
  1202. $userAuthInfo = \app\common\model\UserAuth::where(["user_id"=>$user_id])->find();
  1203. $res = [];
  1204. $res['status'] = 2;
  1205. $res['msg'] = "已实名!";
  1206. $res['data'] = $userAuthInfo;
  1207. if($userAuthInfo) {
  1208. if($userAuthInfo->status == 0) {
  1209. $res['status'] = 1;
  1210. $res['msg'] = "审核中!";
  1211. } elseif($userAuthInfo->status == 2) {
  1212. $res['status'] = -1;
  1213. $res['msg'] = "审核未通过!";
  1214. }
  1215. } else {
  1216. $res['status'] = 0;
  1217. $res['msg'] = "请先申请实名认证!";
  1218. $res['data'] = [];
  1219. }
  1220. $res['recharge_auth'] = \app\common\model\User::where(['id'=>$user_id])->value("recharge_auth");
  1221. $this->success("获取成功!",$res);
  1222. }
  1223. }