User.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. if ($v['eye_type'] == 2) {
  947. $album = explode(',', $v['album']);
  948. foreach ($album as &$vv) {
  949. $vv = $vv . config('oss.img_watermark');
  950. }
  951. $list[$k]['album'] = join(',', $album);
  952. }
  953. }
  954. $this->success("获取成功!",$list);
  955. }
  956. /**
  957. * 获取我的个人基本信息
  958. */
  959. public function getMyBaseInfo() {
  960. $user_id = $this->auth->id;
  961. // redis
  962. // $redis = new Redis();
  963. // $redisconfig = config("redis");
  964. // $redis->connect($redisconfig["host"], $redisconfig["port"]);
  965. // $userInfo = decodeArray($redis->hGetAll('userInfo_'.$user_id));
  966. // if(!$userInfo){
  967. // 获取用户信息
  968. $field = 'id,avatar,nickname,gender,age,city_name,district_name,constellation,hobby_ids,profession,declaration,wechat,income';
  969. $userInfo = \app\common\model\User::field($field)->where(['id'=>$user_id])->find();
  970. $userInfo['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($userInfo['hobby_ids']);
  971. // 获取已有标签以及数量
  972. $userInfo['tagUser'] = \app\common\model\TagUser::alias('a')
  973. ->field('a.id,t.name,a.number')
  974. ->join('hx_tag t','t.id = a.tag_id','left')
  975. ->where(['a.user_id'=>$user_id])
  976. ->select();
  977. $userInfo = $userInfo->toArray();
  978. // $redis->hMSet('userInfo_'.$user_id,encodeArray($userInfo));
  979. // }
  980. $this->success("获取成功!",$userInfo);
  981. }
  982. /**
  983. * 为用户添加标签
  984. */
  985. public function setUserTag() {
  986. $tag_id = $this->request->request('tag_id',0); // 标签ID
  987. $fate_user_id = $this->request->request('fate_user_id',0); // 有眼缘用户ID
  988. if(!$tag_id || !$fate_user_id) {
  989. $this->error('参数缺失!');
  990. }
  991. if(!\app\common\model\Tag::where(['id'=>$tag_id])->find()) {
  992. $this->error('标签不存在!');
  993. }
  994. $user_id = $this->auth->id;
  995. $is_fate = \app\common\model\User::getIsView($fate_user_id,$user_id);
  996. if(!$is_fate) $this->error('您需要先获取微信号才能添加标签');
  997. $tag_user_log = \app\common\model\TagUserLog::where(['user_id'=>$user_id,'fate_user_id'=>$fate_user_id,'tag_id'=>$tag_id])->find();
  998. if($tag_user_log) {
  999. $this->error('您已经为ta添加过此标签了');
  1000. }
  1001. Db::startTrans();
  1002. try {
  1003. // 添加记录
  1004. $data = [];
  1005. $data['user_id'] = $user_id;
  1006. $data['fate_user_id'] = $fate_user_id;
  1007. $data['tag_id'] = $tag_id;
  1008. $data['createtime'] = time();
  1009. $res1 = \app\common\model\TagUserLog::insert($data);
  1010. // 修改标签数量
  1011. $where = [];
  1012. $where['user_id'] = $fate_user_id;
  1013. $where['tag_id'] = $tag_id;
  1014. $tag_user = \app\common\model\TagUser::where($where)->find();
  1015. if($tag_user) {
  1016. $tag_user->number = $tag_user->number + 1;
  1017. $res2 = $tag_user->save();
  1018. } else {
  1019. $data = [];
  1020. $data['user_id'] = $fate_user_id;
  1021. $data['tag_id'] = $tag_id;
  1022. $data['number'] = 1;
  1023. $data['createtime'] = time();
  1024. $res2 = \app\common\model\TagUser::insert($data);
  1025. }
  1026. if($res1 && $res2) {
  1027. Db::commit();
  1028. delUserInfo($fate_user_id);
  1029. $this->success("标签添加成功!");
  1030. }
  1031. } catch (PDOException $e) {
  1032. Db::rollback();
  1033. $this->error("修改失败!");
  1034. }
  1035. }
  1036. /**
  1037. * 绑定用户
  1038. */
  1039. public function bindUser() {
  1040. $invite_no = $this->request->request('invite_no'); // 邀请码
  1041. if(!$invite_no) {
  1042. $this->error("请输入邀请码!");
  1043. }
  1044. $user_id = $this->auth->id;
  1045. // 查询邀请码用户信息
  1046. $inviteUserInfo = \app\common\model\User::where(["invite_no"=>$invite_no])->find();
  1047. if(!$inviteUserInfo) $this->error("查询不到该邀请码用户信息!");
  1048. // 判断是否已经绑定过
  1049. $my_pre_user_id = \app\common\model\User::where(["id"=>$user_id])->value("pre_user_id");
  1050. if($my_pre_user_id > 0) {
  1051. $this->error(__('您已绑定过,不可重复绑定!'));
  1052. }
  1053. if($user_id == $inviteUserInfo->id) {
  1054. $this->error(__('不能绑定自己哦?'));
  1055. }
  1056. // 判断当前用户是否实名认证
  1057. $userAuthInfo = \app\common\model\UserAuth::userIsAuth($this->auth->id);
  1058. if($userAuthInfo['status'] == 0) $this->error($userAuthInfo['msg']);
  1059. $res = \app\common\model\User::update(["pre_user_id"=>$inviteUserInfo->id,'invite_time'=>time()],["id"=>$user_id]);
  1060. if($res) {
  1061. $this->success("恭喜,绑定成功!");
  1062. } else {
  1063. $this->error("网络繁忙,请稍后重试!");
  1064. }
  1065. }
  1066. /**
  1067. * 添加银行卡
  1068. */
  1069. public function addBank() {
  1070. $user_name = $this->request->request('user_name'); //真实姓名
  1071. $bank_name= $this->request->request('bank_name'); //银行名称
  1072. $bank_no = $this->request->request('bank_no'); //银行卡号
  1073. if (!$user_name || !$bank_name || !$bank_no) {
  1074. $this->error(__('Invalid parameters'));
  1075. }
  1076. $bankModel = new \app\common\model\UserBank();
  1077. $where = [];
  1078. $where["user_id"] = $this->auth->id;
  1079. $where["bank_no"] = $bank_no;
  1080. $bankInfo = $bankModel->where($where)->find();
  1081. if($bankInfo) {
  1082. $this->error('该银行卡已经添加过了!');
  1083. }
  1084. $data = [];
  1085. $data["user_id"] = $this->auth->id;
  1086. $data["user_name"] = $user_name;
  1087. $data["bank_name"] = $bank_name;
  1088. $data["bank_no"] = $bank_no;
  1089. $data["createtime"] = time();
  1090. $id = $bankModel->insertGetId($data);
  1091. if($id > 0) {
  1092. $this->success('添加成功!');
  1093. } else {
  1094. $this->error('添加失败!');
  1095. }
  1096. }
  1097. /**
  1098. * 获取银行卡信息
  1099. */
  1100. public function bankInfo() {
  1101. $bankModel = new \app\common\model\UserBank();
  1102. $where = [];
  1103. $where["user_id"] = $this->auth->id;
  1104. $bankInfo = $bankModel->where($where)->find();
  1105. $bankInfo['bank_no'] && $bankInfo['bank_no'] = substr_replace($bankInfo['bank_no'],'********','0','8');
  1106. $this->success('获取成功!',$bankInfo);
  1107. }
  1108. /**
  1109. * 删除银行卡
  1110. */
  1111. public function bankDel() {
  1112. $bankModel = new \app\common\model\UserBank();
  1113. $where = [];
  1114. $where["user_id"] = $this->auth->id;
  1115. $bankInfo = $bankModel->where($where)->delete();
  1116. if($bankInfo) {
  1117. $this->success('删除成功!');
  1118. } else {
  1119. $this->error('删除失败!');
  1120. }
  1121. }
  1122. /**
  1123. * 获取会员开通配置信息
  1124. */
  1125. public function getVipConfig() {
  1126. $res = [];
  1127. $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();
  1128. $res['user_info']['vip_duetime'] = $res['user_info']['vip_duetime']?date('Y-m-d',$res['user_info']['vip_duetime']):"";
  1129. $res['vip_config'] = \app\admin\model\vip\Config::order("weight","desc")->select();
  1130. $this->success("获取成功!",$res);
  1131. }
  1132. /**
  1133. * 设置首页推荐
  1134. */
  1135. public function setEyemaginToMain() {
  1136. $fate_id = $this->request->request('fate_id'); //动态ID
  1137. if (!$fate_id) {
  1138. $this->error(__('Invalid parameters'));
  1139. }
  1140. $user_id = $this->auth->id;
  1141. $fateInfo = \app\common\model\Eyemargin::get($fate_id);
  1142. if($fateInfo->user_id != $user_id) $this->error('抱歉,您无权限操作!');
  1143. // 判断动态是否在审核中
  1144. if($fateInfo->status != 1) $this->error('当前动态状态不允许设置为推荐!');
  1145. Db::startTrans();
  1146. try {
  1147. // 先取消掉所有的推荐
  1148. $res1 = \app\common\model\Eyemargin::update(['is_main'=>0],['user_id'=>$user_id]);
  1149. $res2 = \app\common\model\Eyemargin::update(['is_main'=>1],['id'=>$fate_id]);
  1150. if($res1 && $res2) {
  1151. Db::commit();
  1152. $this->success("设置成功!");
  1153. }
  1154. } catch (PDOException $e) {
  1155. Db::rollback();
  1156. $this->error("设置失败!");
  1157. }
  1158. }
  1159. /**
  1160. * 删除动态
  1161. */
  1162. public function delEyemagin() {
  1163. $fate_id = $this->request->request('fate_id'); //动态ID
  1164. if (!$fate_id) {
  1165. $this->error(__('Invalid parameters'));
  1166. }
  1167. $user_id = $this->auth->id;
  1168. $fateInfo = \app\common\model\Eyemargin::get($fate_id);
  1169. if($fateInfo->user_id != $user_id) $this->error('抱歉,您无权限操作!');
  1170. $res = \app\common\model\Eyemargin::where(['id'=>$fate_id])->delete();
  1171. if($res) {
  1172. $this->success("删除成功!");
  1173. } else {
  1174. $this->error("删除失败!");
  1175. }
  1176. }
  1177. /**
  1178. * 获取第一条系统消息
  1179. */
  1180. public function getFirstSysMsg() {
  1181. $user_id = $this->auth->id;
  1182. $res = [];
  1183. $res['msg_content'] = \app\common\model\SysMsg::where(['user_id'=>$user_id])->order('createtime','desc')->value('title');
  1184. $res['msg_count'] = \app\common\model\SysMsg::where(['user_id'=>$user_id,'is_read'=>0])->count();
  1185. $this->success("获取成功!",$res);
  1186. }
  1187. /**
  1188. * 获取系统消息列表
  1189. */
  1190. public function getSysMsg() {
  1191. $page = $this->request->request('page',1); // 分页
  1192. $pageNum = $this->request->request('pageNum',10); // 分页
  1193. // 分页搜索构建
  1194. $pageStart = ($page-1)*$pageNum;
  1195. $user_id = $this->auth->id;
  1196. $sysMsgList = \app\common\model\SysMsg::where(['user_id'=>$user_id])->order('createtime','desc')->limit($pageStart,$pageNum)->select();
  1197. if($sysMsgList) {
  1198. // 标记所有消息已读1
  1199. \app\common\model\SysMsg::update(['is_read'=>1],['user_id'=>$user_id]);
  1200. }
  1201. $this->success("获取成功!",$sysMsgList);
  1202. }
  1203. /**
  1204. * 获取实名认证信息
  1205. */
  1206. public function getAuthInfo() {
  1207. $user_id = $this->auth->id;
  1208. // 判断当前用户是否实名认证
  1209. $userAuthInfo = \app\common\model\UserAuth::where(["user_id"=>$user_id])->find();
  1210. $res = [];
  1211. $res['status'] = 2;
  1212. $res['msg'] = "已实名!";
  1213. $res['data'] = $userAuthInfo;
  1214. if($userAuthInfo) {
  1215. if($userAuthInfo->status == 0) {
  1216. $res['status'] = 1;
  1217. $res['msg'] = "审核中!";
  1218. } elseif($userAuthInfo->status == 2) {
  1219. $res['status'] = -1;
  1220. $res['msg'] = "审核未通过!";
  1221. }
  1222. } else {
  1223. $res['status'] = 0;
  1224. $res['msg'] = "请先申请实名认证!";
  1225. $res['data'] = [];
  1226. }
  1227. $res['recharge_auth'] = \app\common\model\User::where(['id'=>$user_id])->value("recharge_auth");
  1228. $this->success("获取成功!",$res);
  1229. }
  1230. }