User.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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 app\common\service\UserService;
  7. use fast\Random;
  8. use think\Validate;
  9. use miniprogram\wxBizDataCrypt;
  10. use onlogin\onlogin;
  11. use think\Db;
  12. /**
  13. * 会员接口
  14. */
  15. class User extends Api
  16. {
  17. protected $noNeedLogin = ['login', 'onLogin', 'mobilelogin', 'register', 'resetpwd', 'changemobile', 'third', 'getUserOpenid', 'wxMiniProgramLogin','getNickName','wechatlogin'];
  18. protected $noNeedRight = '*';
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. }
  23. /**
  24. * 会员中心
  25. */
  26. public function index()
  27. {
  28. $this->success('', ['welcome' => $this->auth->nickname]);
  29. }
  30. /**
  31. * 会员登录
  32. *
  33. * @param string $account 账号
  34. * @param string $password 密码
  35. */
  36. public function login()
  37. {
  38. $account = $this->request->request('account');
  39. $password = $this->request->request('password');
  40. if (!$account || !$password) {
  41. $this->error(__('Invalid parameters'));
  42. }
  43. $ret = $this->auth->login($account, $password);
  44. if ($ret) {
  45. $data = ['userinfo' => $this->auth->getUserinfo()];
  46. $this->success(__('Logged in successful'), $data);
  47. } else {
  48. $this->error($this->auth->getError());
  49. }
  50. }
  51. /**
  52. * 手机验证码登录
  53. *
  54. * @param string $mobile 手机号
  55. * @param string $captcha 验证码
  56. */
  57. public function mobilelogin()
  58. {
  59. $mobile = $this->request->request('mobile');
  60. $captcha = $this->request->request('captcha');
  61. if (!$mobile || !$captcha) {
  62. $this->error(__('Invalid parameters'));
  63. }
  64. if (!Validate::regex($mobile, "^1\d{10}$")) {
  65. $this->error(__('Mobile is incorrect'));
  66. }
  67. if (!Sms::check($mobile, $captcha, 'mobilelogin') && $captcha != '1212') {
  68. $this->error(__('Captcha is incorrect'));
  69. }
  70. $user = \app\common\model\User::getByMobile($mobile);
  71. if ($user) {
  72. if ($user->status != 'normal') {
  73. $this->error(__('Account is locked'));
  74. }
  75. //如果已经有账号则直接登录
  76. $is_register = 0;
  77. $ret = $this->auth->direct($user->id);
  78. } else {
  79. $is_register = 1;
  80. $ret = $this->auth->register($mobile, Random::alnum(), $mobile, []);
  81. }
  82. if ($ret) {
  83. Sms::flush($mobile, 'mobilelogin');
  84. $data = ['is_register' => $is_register, '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. public function bindUser()
  94. {
  95. $invite_no = $this->request->request('invite_no'); // 邀请码
  96. if (!$invite_no) {
  97. $this->error("请输入邀请码!");
  98. }
  99. $user_id = $this->auth->id;
  100. // 查询邀请码用户信息
  101. $inviteUserInfo = \app\common\model\User::where(["invite_no" => $invite_no])->find();
  102. if (!$inviteUserInfo) $this->error("查询不到该邀请码用户信息!");
  103. if ($inviteUserInfo->id == $user_id) $this->error("不能邀请自己哦!");
  104. if ($inviteUserInfo->is_auth != 2) $this->error("该邀请码用户尚未完成实名认证");
  105. $res = \app\common\model\User::update(["pre_userid" => $inviteUserInfo->id,"bindtime" => time()], ["id" => $user_id]);
  106. if ($res) {
  107. $this->success("恭喜,绑定成功!");
  108. } else {
  109. $this->success("网络繁忙,请稍后重试!");
  110. }
  111. }
  112. /**
  113. * 注册会员
  114. *
  115. * @param string $username 用户名
  116. * @param string $password 密码
  117. * @param string $email 邮箱
  118. * @param string $mobile 手机号
  119. * @param string $code 验证码
  120. */
  121. public function register()
  122. {
  123. $username = $this->request->request('username');
  124. $password = $this->request->request('password');
  125. $mobile = $this->request->request('mobile');
  126. $code = $this->request->request('code');
  127. if (!$username || !$password) {
  128. $this->error(__('Invalid parameters'));
  129. }
  130. if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  131. $this->error(__('Mobile is incorrect'));
  132. }
  133. // $ret = Sms::check($mobile, $code, 'register');
  134. // if (!$ret) {
  135. // $this->error(__('Captcha is incorrect'));
  136. // }
  137. $ret = $this->auth->register($username, $password, $mobile, []);
  138. if ($ret) {
  139. $data = ['userinfo' => $this->auth->getUserinfo()];
  140. $this->success(__('Sign up successful'), $data);
  141. } else {
  142. $this->error($this->auth->getError());
  143. }
  144. }
  145. /**
  146. * 退出登录
  147. */
  148. public function logout()
  149. {
  150. $this->auth->logout();
  151. $this->success(__('Logout successful'));
  152. }
  153. /**
  154. * 修改会员个人信息
  155. *
  156. * @param string $avatar 头像地址
  157. * @param string $username 用户名
  158. * @param string $nickname 昵称
  159. * @param string $bio 个人简介
  160. */
  161. public function profile()
  162. {
  163. $user = $this->auth->getUser();
  164. $username = $this->request->request('username');
  165. $nickname = $this->request->request('nickname');
  166. $bio = $this->request->request('bio');
  167. $avatar = $this->request->request('avatar', '', 'trim,strip_tags,htmlspecialchars');
  168. if ($username) {
  169. $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
  170. if ($exists) {
  171. $this->error(__('Username already exists'));
  172. }
  173. $user->username = $username;
  174. }
  175. if ($nickname) {
  176. $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
  177. if ($exists) {
  178. $this->error(__('Nickname already exists'));
  179. }
  180. $user->nickname = $nickname;
  181. }
  182. $user->bio = $bio;
  183. $user->avatar = $avatar;
  184. $user->save();
  185. $this->success();
  186. }
  187. /**
  188. * 修改手机号
  189. *
  190. * @param string $mobile 手机号
  191. * @param string $captcha 验证码
  192. */
  193. public function changemobile()
  194. {
  195. $user = $this->auth->getUser();
  196. $mobile = $this->request->request('mobile');
  197. $captcha = $this->request->request('captcha');
  198. if (!$mobile || !$captcha) {
  199. $this->error(__('Invalid parameters'));
  200. }
  201. if (!Validate::regex($mobile, "^1\d{10}$")) {
  202. $this->error(__('Mobile is incorrect'));
  203. }
  204. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  205. $this->error(__('Mobile already exists'));
  206. }
  207. $result = Sms::check($mobile, $captcha, 'changeMobile');
  208. if (!$result) {
  209. $this->error(__('Captcha is incorrect'));
  210. }
  211. $verification = $user->verification;
  212. $verification->mobile = 1;
  213. $user->verification = $verification;
  214. $user->mobile = $mobile;
  215. $user->save();
  216. Sms::flush($mobile, 'changeMobile');
  217. $this->success("手机号更换成功!");
  218. }
  219. /**
  220. * 第三方登录
  221. *
  222. * @param string $platform 平台名称
  223. * @param string $code Code码
  224. */
  225. public function third()
  226. {
  227. $url = url('user/index');
  228. $platform = $this->request->request("platform");
  229. $code = $this->request->request("code");
  230. $config = get_addon_config('third');
  231. if (!$config || !isset($config[$platform])) {
  232. $this->error(__('Invalid parameters'));
  233. }
  234. $app = new \addons\third\library\Application($config);
  235. //通过code换access_token和绑定会员
  236. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  237. if ($result) {
  238. $loginret = \addons\third\library\Service::connect($platform, $result);
  239. if ($loginret) {
  240. $data = [
  241. 'userinfo' => $this->auth->getUserinfo(),
  242. 'thirdinfo' => $result
  243. ];
  244. $this->success(__('Logged in successful'), $data);
  245. }
  246. }
  247. $this->error(__('Operation failed'), $url);
  248. }
  249. /**
  250. * 重置密码
  251. *
  252. * @param string $mobile 手机号
  253. * @param string $newpassword 新密码
  254. * @param string $captcha 验证码
  255. */
  256. public function resetpwd()
  257. {
  258. $type = $this->request->request("type");
  259. $mobile = $this->request->request("mobile");
  260. $email = $this->request->request("email");
  261. $newpassword = $this->request->request("newpassword");
  262. $captcha = $this->request->request("captcha");
  263. if (!$newpassword || !$captcha) {
  264. $this->error(__('Invalid parameters'));
  265. }
  266. if ($type == 'mobile') {
  267. if (!Validate::regex($mobile, "^1\d{10}$")) {
  268. $this->error(__('Mobile is incorrect'));
  269. }
  270. $user = \app\common\model\User::getByMobile($mobile);
  271. if (!$user) {
  272. $this->error(__('User not found'));
  273. }
  274. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  275. if (!$ret) {
  276. $this->error(__('Captcha is incorrect'));
  277. }
  278. Sms::flush($mobile, 'resetpwd');
  279. } else {
  280. if (!Validate::is($email, "email")) {
  281. $this->error(__('Email is incorrect'));
  282. }
  283. $user = \app\common\model\User::getByEmail($email);
  284. if (!$user) {
  285. $this->error(__('User not found'));
  286. }
  287. $ret = Ems::check($email, $captcha, 'resetpwd');
  288. if (!$ret) {
  289. $this->error(__('Captcha is incorrect'));
  290. }
  291. Ems::flush($email, 'resetpwd');
  292. }
  293. //模拟一次登录
  294. $this->auth->direct($user->id);
  295. $ret = $this->auth->changepwd($newpassword, '', true);
  296. if ($ret) {
  297. $this->success(__('Reset password successful'));
  298. } else {
  299. $this->error($this->auth->getError());
  300. }
  301. }
  302. /**
  303. * 设置密码
  304. * @param string $newpassword 新密码
  305. * @param string $newpassword 新密码
  306. */
  307. public function setpwd()
  308. {
  309. $params = $this->request->param();
  310. $validate = new \app\api\validate\User();
  311. $result = $validate->scene('setPwd')->check($params);
  312. if (!$result) {
  313. $this->error($validate->getError());
  314. }
  315. $ret = $this->auth->changepwd($params['password'], '', true);
  316. if ($ret) {
  317. $this->success(__('Set password successful'));
  318. } else {
  319. $this->error($this->auth->getError());
  320. }
  321. }
  322. /**
  323. * 修改密码
  324. *
  325. * @param string $mobile 手机号
  326. * @param string $newpassword 新密码
  327. * @param string $captcha 验证码
  328. */
  329. public function changepwd()
  330. {
  331. $params = $this->request->param();
  332. $validate = new \app\api\validate\User();
  333. $result = $validate->scene('changePwd')->check($params);
  334. if (!$result) {
  335. $this->error($validate->getError());
  336. }
  337. $mobile = $this->request->request("mobile");
  338. $newpassword = $this->request->request("password");
  339. $captcha = $this->request->request("captcha");
  340. $user = \app\common\model\User::getByMobile($mobile);
  341. if (!$user) {
  342. $this->error(__('User not found'));
  343. }
  344. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  345. if (!$ret) {
  346. $this->error(__('Captcha is incorrect'));
  347. }
  348. Sms::flush($mobile, 'resetpwd');
  349. $ret = $this->auth->changepwd($newpassword, '', true);
  350. if ($ret) {
  351. $this->success(__('Change password successful'));
  352. } else {
  353. $this->error($this->auth->getError());
  354. }
  355. }
  356. /**
  357. * 获取用户openid
  358. */
  359. public function getUserOpenid()
  360. {
  361. $code = $this->request->param('code');// code值
  362. if (!$code) {
  363. $this->error(__('Invalid parameters'));
  364. }
  365. $config = config("wxMiniProgram");
  366. $getopenid = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $config["appid"] . "&secret=" . $config["secret"] . "&js_code=" . $code . "&grant_type=authorization_code";
  367. $openidInfo = $this->getJson($getopenid);
  368. if (!isset($openidInfo["openid"])) {
  369. $this->error("用户openid获取失败", $openidInfo);
  370. }
  371. // 获取的结果存入数据库
  372. $sessionkeyModel = new \app\common\model\UserSessionkey();
  373. if ($sessionkeyModel->where(["openid" => $openidInfo["openid"]])->find()) {
  374. $update = [];
  375. $update["sessionkey"] = $openidInfo["session_key"];
  376. $res = $sessionkeyModel->update($update, ["openid" => $openidInfo["openid"]]);
  377. } else {
  378. $insert = [];
  379. $insert["sessionkey"] = $openidInfo["session_key"];
  380. $insert["openid"] = $openidInfo["openid"];
  381. $insert["createtime"] = time();
  382. $res = $sessionkeyModel->insert($insert);
  383. }
  384. if ($res) {
  385. $this->success("获取成功!", $openidInfo);
  386. } else {
  387. $this->error("获取失败!");
  388. }
  389. }
  390. /**
  391. * 微信小程序登录
  392. */
  393. public function wxMiniProgramLogin()
  394. {
  395. $openid = $this->request->param('openid');// openid值
  396. $encryptedData = $this->request->param('encryptedData');// 加密数据
  397. $iv = $this->request->param('iv');// 加密算法
  398. $signature = $this->request->param('signature');// 签名验证
  399. $rawData = $this->request->param('rawData');// 签名验证
  400. $logintype = $this->request->param('loginType', 1);// 登录方式:1=手机号,2=微信授权openid
  401. if (!$openid || !$encryptedData || !$iv) {
  402. $this->error(__('Invalid parameters'));
  403. }
  404. $encryptedData = urldecode($encryptedData);
  405. $config = config("wxMiniProgram");
  406. // 获取openid和sessionkey
  407. $sessionkeyModel = new \app\common\model\UserSessionkey();
  408. $openidInfo = $sessionkeyModel->where(["openid" => $openid])->find();
  409. $openid = $openidInfo['openid'];
  410. $session_key = $openidInfo['sessionkey'];
  411. // // 数据签名校验
  412. // $signature2 = sha1($rawData . $session_key);
  413. // if ($signature != $signature2) {
  414. // $this->error(__('数据签名验证失败'));
  415. // }
  416. // 根据加密数据和加密算法获取用户信息
  417. $pc = new WXBizDataCrypt($config["appid"], $session_key);
  418. $data = "";
  419. $errCode = $pc->decryptData($encryptedData, $iv, $data);
  420. if ($errCode == 0) {
  421. $data = json_decode($data, true);
  422. // 用户登录逻辑 === 开始
  423. $userModel = new \app\common\model\User();
  424. $auth = \app\common\library\Auth::instance();
  425. if ($logintype == 1) { // 手机号登录
  426. $userInfo = $userModel->where(["mobile" => $data["purePhoneNumber"]])->find();
  427. // 用户信息不存在时使用
  428. $extend = ["mobile" => $data["purePhoneNumber"]];
  429. } else { // 微信授权openid登录
  430. $userInfo = $userModel->where(["openid" => $openid])->find();
  431. // 用户信息不存在时使用
  432. $extend = [
  433. 'openid' => $data['openId'],
  434. 'nickname' => $data['nickName'],
  435. 'avatar' => $data['avatarUrl'],
  436. 'gender' => $data['gender'],
  437. ];
  438. }
  439. // 判断用户是否已经存在
  440. if ($userInfo) { // 登录
  441. $user = \app\common\model\User::get($userInfo["id"]);
  442. if (!$user) {
  443. $this->error("网络错误!请稍后重试");
  444. }
  445. $user->save(["logintime" => time()]);
  446. $res = $auth->direct($user->id);
  447. $is_register = 0;
  448. } else { // 注册
  449. // 先随机一个用户名,随后再变更为u+数字id
  450. $username = Random::alnum(20);
  451. $password = Random::alnum(6);
  452. Db::startTrans();
  453. try {
  454. // 默认注册一个会员
  455. $result = $auth->register($username, $password, "", $extend);
  456. if (!$result) {
  457. return false;
  458. }
  459. $user = $auth->getUser();
  460. $fields = ['username' => 'u' . $user->id];
  461. // 更新会员资料
  462. $user = \app\common\model\User::get($user->id);
  463. $user->save($fields);
  464. Db::commit();
  465. } catch (PDOException $e) {
  466. Db::rollback();
  467. $auth->logout();
  468. return false;
  469. }
  470. // 写入登录Cookies和Token
  471. $res = $auth->direct($user->id);
  472. $is_register = 1;
  473. }
  474. $userInfo = $auth->getUserinfo();
  475. $userInfo["is_register"] = $is_register;
  476. if ($res) {
  477. $this->success("登录成功!", $userInfo);
  478. } else {
  479. $this->error("登录失败!");
  480. }
  481. // 用户登录逻辑 === 结束
  482. } else {
  483. $this->error("解密失败!", ["code" => $errCode]);
  484. }
  485. }
  486. /**
  487. * json 请求
  488. * @param $url
  489. * @return mixed
  490. */
  491. private function getJson($url)
  492. {
  493. $ch = curl_init();
  494. curl_setopt($ch, CURLOPT_URL, $url);
  495. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  496. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  497. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  498. $output = curl_exec($ch);
  499. curl_close($ch);
  500. return json_decode($output, true);
  501. }
  502. /**
  503. * 运营商一键登录
  504. */
  505. public function onLogin()
  506. {
  507. $accessToken = $this->request->param('accessToken');// 运营商预取号获取到的token
  508. $token = $this->request->param('tokenT');// 易盾返回的token
  509. if (!$accessToken || !$token) {
  510. $this->error("参数获取失败!");
  511. }
  512. $params = array(
  513. // 运营商预取号获取到的token
  514. "accessToken" => $accessToken,
  515. // 易盾返回的token
  516. "token" => $token
  517. );
  518. // 获取密钥配置
  519. $configInfo = config("onLogin");
  520. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  521. $ret = $onlogin->check($params);
  522. // $ret = [];
  523. // $ret["code"] = 200;
  524. // $ret["msg"] = "ok";
  525. // $ret["data"] = [
  526. // "phone" => "17574504021",
  527. // "resultCode" => 0
  528. // ];
  529. if ($ret["code"] == 200) {
  530. $data = $ret["data"];
  531. $phone = $data["phone"];
  532. if (empty($phone)) {
  533. // 取号失败,建议进行二次验证,例如短信验证码
  534. $this->error("取号登录失败,请用验证码方式登录!");
  535. } else {
  536. // 取号成功, 执行登录等流程
  537. // 用户登录逻辑 === 开始
  538. $userModel = new \app\common\model\User();
  539. $auth = \app\common\library\Auth::instance();
  540. $userInfo = $userModel->where(["mobile" => $phone])->find();
  541. // 用户信息不存在时使用
  542. $extend = ["mobile" => $phone];
  543. // 判断用户是否已经存在
  544. if ($userInfo) { // 登录
  545. $user = \app\common\model\User::get($userInfo["id"]);
  546. if (!$user) {
  547. $this->error("网络错误!请稍后重试");
  548. }
  549. if ($user->status != 'normal') {
  550. $this->error(__('Account is locked'));
  551. }
  552. $user->save(["logintime" => time()]);
  553. $res = $auth->direct($user->id);
  554. $is_register = 0;
  555. } else { // 注册
  556. // 先随机一个用户名,随后再变更为u+数字id
  557. $username = Random::alnum(20);
  558. $password = Random::alnum(6);
  559. Db::startTrans();
  560. try {
  561. // 默认注册一个会员
  562. $result = $auth->register($username, $password, "", $extend);
  563. if (!$result) {
  564. return false;
  565. }
  566. $user = $auth->getUser();
  567. $fields = ['username' => 'u' . $user->id];
  568. // 更新会员资料
  569. $user = \app\common\model\User::get($user->id);
  570. $user->save($fields);
  571. Db::commit();
  572. } catch (PDOException $e) {
  573. Db::rollback();
  574. $auth->logout();
  575. return false;
  576. }
  577. // 写入登录Cookies和Token
  578. $res = $auth->direct($user->id);
  579. $is_register = 1;
  580. }
  581. $userInfo["userinfo"] = $auth->getUserinfo();
  582. $userInfo["is_register"] = $is_register;
  583. if ($res) {
  584. $this->success("登录成功!", $userInfo);
  585. } else {
  586. $this->error("登录失败!");
  587. }
  588. // 用户登录逻辑 === 结束
  589. }
  590. } else {
  591. $this->error("登录失败,请用验证码方式登录!");
  592. }
  593. }
  594. /**
  595. * 注销账号
  596. *
  597. * @param string $mobile 手机号
  598. * @param string $captcha 验证码
  599. */
  600. public function cancleUser()
  601. {
  602. $user = $this->auth->getUser();
  603. $user->status = "cancel";
  604. $user->save();
  605. $this->success("账号注销成功!");
  606. }
  607. /**
  608. * 用户举报
  609. *
  610. * @param string $mobile 手机号
  611. * @param string $captcha 验证码
  612. */
  613. public function report()
  614. {
  615. $type = $this->request->param('type');// 类型描述
  616. $content = $this->request->param('content');// 内容
  617. $images = $this->request->param('images');// 图片
  618. $ruser_id = $this->request->param('ruser_id');// 被举报用户ID
  619. if (!$type || !$content || !$images || !$ruser_id) {
  620. $this->error("请完成举报内容!");
  621. }
  622. $user_id = $this->auth->id;
  623. $data = [];
  624. $data["user_id"] = $user_id;
  625. $data["ruser_id"] = $ruser_id;
  626. $data["type"] = $type;
  627. $data["content"] = $content;
  628. $data["images"] = $images;
  629. $data["createtime"] = time();
  630. $res = \app\common\model\UserReport::insert($data);
  631. if ($res) {
  632. $this->success("举报内容提交成功!");
  633. } else {
  634. $this->error("网络错误,请稍后重试!");
  635. }
  636. }
  637. /**
  638. * 获取昵称
  639. * @return string
  640. */
  641. public function getNickName()
  642. {
  643. $nicheng_tou = array('快乐的', '冷静的', '醉熏的', '潇洒的', '糊涂的', '积极的', '冷酷的', '深情的', '粗暴的', '温柔的', '可爱的', '愉快的', '义气的', '认真的', '威武的', '帅气的', '传统的', '潇洒的', '漂亮的', '自然的', '专一的', '听话的', '昏睡的', '狂野的', '等待的', '搞怪的', '幽默的', '魁梧的', '活泼的', '开心的', '高兴的', '超帅的', '留胡子的', '坦率的', '直率的', '轻松的', '痴情的', '完美的', '精明的', '无聊的', '有魅力的', '丰富的', '繁荣的', '饱满的', '炙热的', '暴躁的', '碧蓝的', '俊逸的', '英勇的', '健忘的', '故意的', '无心的', '土豪的', '朴实的', '兴奋的', '幸福的', '淡定的', '不安的', '阔达的', '孤独的', '独特的', '疯狂的', '时尚的', '落后的', '风趣的', '忧伤的', '大胆的', '爱笑的', '矮小的', '健康的', '合适的', '玩命的', '沉默的', '斯文的', '香蕉', '苹果', '鲤鱼', '鳗鱼', '任性的', '细心的', '粗心的', '大意的', '甜甜的', '酷酷的', '健壮的', '英俊的', '霸气的', '阳光的', '默默的', '大力的', '孝顺的', '忧虑的', '着急的', '紧张的', '善良的', '凶狠的', '害怕的', '重要的', '危机的', '欢喜的', '欣慰的', '满意的', '跳跃的', '诚心的', '称心的', '如意的', '怡然的', '娇气的', '无奈的', '无语的', '激动的', '愤怒的', '美好的', '感动的', '激情的', '激昂的', '震动的', '虚拟的', '超级的', '寒冷的', '精明的', '明理的', '犹豫的', '忧郁的', '寂寞的', '奋斗的', '勤奋的', '现代的', '过时的', '稳重的', '热情的', '含蓄的', '开放的', '无辜的', '多情的', '纯真的', '拉长的', '热心的', '从容的', '体贴的', '风中的', '曾经的', '追寻的', '儒雅的', '优雅的', '开朗的', '外向的', '内向的', '清爽的', '文艺的', '长情的', '平常的', '单身的', '伶俐的', '高大的', '懦弱的', '柔弱的', '爱笑的', '乐观的', '耍酷的', '酷炫的', '神勇的', '年轻的', '唠叨的', '瘦瘦的', '无情的', '包容的', '顺心的', '畅快的', '舒适的', '靓丽的', '负责的', '背后的', '简单的', '谦让的', '彩色的', '缥缈的', '欢呼的', '生动的', '复杂的', '慈祥的', '仁爱的', '魔幻的', '虚幻的', '淡然的', '受伤的', '雪白的', '高高的', '糟糕的', '顺利的', '闪闪的', '羞涩的', '缓慢的', '迅速的', '优秀的', '聪明的', '含糊的', '俏皮的', '淡淡的', '坚强的', '平淡的', '欣喜的', '能干的', '灵巧的', '友好的', '机智的', '机灵的', '正直的', '谨慎的', '俭朴的', '殷勤的', '虚心的', '辛勤的', '自觉的', '无私的', '无限的', '踏实的', '老实的', '现实的', '可靠的', '务实的', '拼搏的', '个性的', '粗犷的', '活力的', '成就的', '勤劳的', '单纯的', '落寞的', '朴素的', '悲凉的', '忧心的', '洁净的', '清秀的', '自由的', '小巧的', '单薄的', '贪玩的', '刻苦的', '干净的', '壮观的', '和谐的', '文静的', '调皮的', '害羞的', '安详的', '自信的', '端庄的', '坚定的', '美满的', '舒心的', '温暖的', '专注的', '勤恳的', '美丽的', '腼腆的', '优美的', '甜美的', '甜蜜的', '整齐的', '动人的', '典雅的', '尊敬的', '舒服的', '妩媚的', '秀丽的', '喜悦的', '甜美的', '彪壮的', '强健的', '大方的', '俊秀的', '聪慧的', '迷人的', '陶醉的', '悦耳的', '动听的', '明亮的', '结实的', '魁梧的', '标致的', '清脆的', '敏感的', '光亮的', '大气的', '老迟到的', '知性的', '冷傲的', '呆萌的', '野性的', '隐形的', '笑点低的', '微笑的', '笨笨的', '难过的', '沉静的', '火星上的', '失眠的', '安静的', '纯情的', '要减肥的', '迷路的', '烂漫的', '哭泣的', '贤惠的', '苗条的', '温婉的', '发嗲的', '会撒娇的', '贪玩的', '执着的', '眯眯眼的', '花痴的', '想人陪的', '眼睛大的', '高贵的', '傲娇的', '心灵美的', '爱撒娇的', '细腻的', '天真的', '怕黑的', '感性的', '飘逸的', '怕孤独的', '忐忑的', '高挑的', '傻傻的', '冷艳的', '爱听歌的', '还单身的', '怕孤单的', '懵懂的');
  644. $nicheng_wei = array('嚓茶', '凉面', '便当', '毛豆', '花生', '可乐', '灯泡', '哈密瓜', '野狼', '背包', '眼神', '缘分', '雪碧', '人生', '牛排', '蚂蚁', '飞鸟', '灰狼', '斑马', '汉堡', '悟空', '巨人', '绿茶', '自行车', '保温杯', '大碗', '墨镜', '魔镜', '煎饼', '月饼', '月亮', '星星', '芝麻', '啤酒', '玫瑰', '大叔', '小伙', '哈密瓜,数据线', '太阳', '树叶', '芹菜', '黄蜂', '蜜粉', '蜜蜂', '信封', '西装', '外套', '裙子', '大象', '猫咪', '母鸡', '路灯', '蓝天', '白云', '星月', '彩虹', '微笑', '摩托', '板栗', '高山', '大地', '大树', '电灯胆', '砖头', '楼房', '水池', '鸡翅', '蜻蜓', '红牛', '咖啡', '机器猫', '枕头', '大船', '诺言', '钢笔', '刺猬', '天空', '飞机', '大炮', '冬天', '洋葱', '春天', '夏天', '秋天', '冬日', '航空', '毛衣', '豌豆', '黑米', '玉米', '眼睛', '老鼠', '白羊', '帅哥', '美女', '季节', '鲜花', '服饰', '裙子', '白开水', '秀发', '大山', '火车', '汽车', '歌曲', '舞蹈', '老师', '导师', '方盒', '大米', '麦片', '水杯', '水壶', '手套', '鞋子', '自行车', '鼠标', '手机', '电脑', '书本', '奇迹', '身影', '香烟', '夕阳', '台灯', '宝贝', '未来', '皮带', '钥匙', '心锁', '故事', '花瓣', '滑板', '画笔', '画板', '学姐', '店员', '电源', '饼干', '宝马', '过客', '大白', '时光', '石头', '钻石', '河马', '犀牛', '西牛', '绿草', '抽屉', '柜子', '往事', '寒风', '路人', '橘子', '耳机', '鸵鸟', '朋友', '苗条', '铅笔', '钢笔', '硬币', '热狗', '大侠', '御姐', '萝莉', '毛巾', '期待', '盼望', '白昼', '黑夜', '大门', '黑裤', '钢铁侠', '哑铃', '板凳', '枫叶', '荷花', '乌龟', '仙人掌', '衬衫', '大神', '草丛', '早晨', '心情', '茉莉', '流沙', '蜗牛', '战斗机', '冥王星', '猎豹', '棒球', '篮球', '乐曲', '电话', '网络', '世界', '中心', '鱼', '鸡', '狗', '老虎', '鸭子', '雨', '羽毛', '翅膀', '外套', '火', '丝袜', '书包', '钢笔', '冷风', '八宝粥', '烤鸡', '大雁', '音响', '招牌', '胡萝卜', '冰棍', '帽子', '菠萝', '蛋挞', '香水', '泥猴桃', '吐司', '溪流', '黄豆', '樱桃', '小鸽子', '小蝴蝶', '爆米花', '花卷', '小鸭子', '小海豚', '日记本', '小熊猫', '小懒猪', '小懒虫', '荔枝', '镜子', '曲奇', '金针菇', '小松鼠', '小虾米', '酒窝', '紫菜', '金鱼', '柚子', '果汁', '百褶裙', '项链', '帆布鞋', '火龙果', '奇异果', '煎蛋', '唇彩', '小土豆', '高跟鞋', '戒指', '雪糕', '睫毛', '铃铛', '手链', '香氛', '红酒', '月光', '酸奶', '银耳汤', '咖啡豆', '小蜜蜂', '小蚂蚁', '蜡烛', '棉花糖', '向日葵', '水蜜桃', '小蝴蝶', '小刺猬', '小丸子', '指甲油', '康乃馨', '糖豆', '薯片', '口红', '超短裙', '乌冬面', '冰淇淋', '棒棒糖', '长颈鹿', '豆芽', '发箍', '发卡', '发夹', '发带', '铃铛', '小馒头', '小笼包', '小甜瓜', '冬瓜', '香菇', '小兔子', '含羞草', '短靴', '睫毛膏', '小蘑菇', '跳跳糖', '小白菜', '草莓', '柠檬', '月饼', '百合', '纸鹤', '小天鹅', '云朵', '芒果', '面包', '海燕', '小猫咪', '龙猫', '唇膏', '鞋垫', '羊', '黑猫', '白猫', '万宝路', '金毛', '山水', '音响');
  645. $nicheng = $nicheng_tou[array_rand($nicheng_tou, 1)] . $nicheng_wei[array_rand($nicheng_wei, 1)] . rand(0,99);
  646. $result['nickname'] = $nicheng; //输出生成的昵称
  647. $this->success('获取成功',$result);
  648. }
  649. //微信登录
  650. public function wechatlogin(){
  651. // $nickname = input('nickname','');
  652. // $avatar = input('avatar','');
  653. $gender = input('gender',1);
  654. $wechat_openid = input('openid','');
  655. if (!$wechat_openid) {
  656. $this->error(__('Invalid parameters'));
  657. }
  658. // if($gender != 1){
  659. // $gender = 0;
  660. // }
  661. $user = \app\common\model\User::getByOpenid($wechat_openid);
  662. if ($user) {
  663. if ($user->status != 1) {
  664. $this->error(__('Account is locked'));
  665. }
  666. if ($user->frozentime > time()) {
  667. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  668. }
  669. //如果已经有账号则直接登录
  670. $ret = $this->auth->direct($user->id);
  671. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
  672. /*if($user->gender == 1 && $user->gh_id == 0){
  673. $this->firstopen_send($user->id);
  674. }*/
  675. } else {
  676. // $this->success('选择性别', ['code' => 5]);
  677. // if (!$nickname || !$avatar) {
  678. // $this->error(__('Invalid parameters'));
  679. // }
  680. $reg_data = [
  681. // 'nickname'=>$nickname,
  682. // 'avatar'=>$avatar,
  683. // 'gender'=>$gender,
  684. 'register_from' => input('register_from',''),
  685. 'gender' => $gender,
  686. ];
  687. $ret = $this->auth->openid_register($wechat_openid,$reg_data);
  688. //亿米
  689. /*if(input('register_from','') == 'xiaomi'){
  690. $this->yimi_advert();
  691. }*/
  692. }
  693. if ($ret) {
  694. $data = ['userinfo' => $this->auth->getUserinfo()];
  695. $this->success(__('Logged in successful'), $data);
  696. } else {
  697. $this->error($this->auth->getError());
  698. }
  699. }
  700. //获取openid
  701. public function getopenid() {
  702. //code
  703. $code = $this->request->post('code', '', 'trim');// code值
  704. if (!$code) {
  705. $this->error(__('Invalid parameters'));
  706. }
  707. $config = config('wxMiniProgram');
  708. $getopenid_url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
  709. $openidInfo = httpRequest($getopenid_url, 'GET');//$this->getJson($getopenid_url);
  710. $openidInfo = json_decode($openidInfo,true);
  711. if(!isset($openidInfo['openid'])) {
  712. $this->error('用户openid获取失败', $openidInfo);
  713. }
  714. $user = Db::name('user')->where('mini_openid',$openidInfo['openid'])->find();
  715. //$openidInfo['mobile'] = isset($user['mobile']) ? $user['mobile'] : '';
  716. $this->success('获取成功', $openidInfo);
  717. }
  718. //生成海报
  719. public function createposter() {
  720. // $image = input('image', '', 'trim');
  721. // if (!$image) {
  722. // $this->error('您的网络开小差啦~');
  723. // }
  724. $image = config('site.intro_imges');
  725. $haibao = $this->haibao($this->auth->id,['invite_no'=>$this->auth->invite_no, 'background' => $image]);
  726. return $haibao;
  727. // $this->success('success', $haibao);
  728. }
  729. //海报
  730. public function haibao($player_id,$data){
  731. //下载页二维码,没必要保留
  732. $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
  733. $params = [
  734. 'text' => $httpStr.'/index/index/appdownload?code=' . $data['invite_no'],
  735. 'size' => 90,
  736. 'logo' => false,
  737. 'label' => false,
  738. 'padding' => 0,
  739. ];
  740. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  741. $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
  742. mk_dir($qrcode_path);
  743. $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
  744. $qrCode->writeFile($download_qrcode);
  745. //海报
  746. $result['url'] = $this->createhaibao($download_qrcode,$player_id,$data);
  747. $this->success('获取成功',$result);
  748. }
  749. public function createhaibao($download_qrcode,$player_id,$sub_data){
  750. //二维码
  751. $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
  752. $download_qrcode= $httpStr.'/'.$download_qrcode;
  753. $data = [
  754. /*[
  755. "left" => "15px",
  756. "top" => "400px",
  757. "type" => "img",
  758. "width" => "58px",
  759. "height" => "58px",
  760. "src" => one_domain_image($this->auth->avatar),
  761. ],
  762. [
  763. "left" => "81px",
  764. "top" => "400px",
  765. "type" => "nickname",
  766. "width" => "80px",
  767. "height" => "24px",
  768. "size" => "12px",
  769. "color" => "#000",
  770. "content" => $this->auth->nickname
  771. ],
  772. [
  773. "left" => "81px",
  774. "top" => "400px",
  775. "type" => "nickname",
  776. "width" => "80px",
  777. "height" => "24px",
  778. "size" => "12px",
  779. "color" => "#000",
  780. "content" => $this->auth->invite_no
  781. ],*/
  782. [
  783. "left" => "18px",
  784. "top" => "410px",
  785. "type" => "text",
  786. "width" => "80px",
  787. "height" => "24px",
  788. "size" => "16px",
  789. "color" => "#123354",
  790. "content" => 'GG语音'
  791. ],
  792. [
  793. "left" => "18px",
  794. "top" => "445px",
  795. "type" => "text",
  796. "width" => "80px",
  797. "height" => "24px",
  798. "size" => "10px",
  799. "color" => "#123354",
  800. "content" => '更多现金奖励等你来拿'
  801. ],
  802. [
  803. "left" => "210px",
  804. "top" => "385px",
  805. "type" => "img",
  806. "width" => "95px",
  807. "height" => "95px",
  808. "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  809. ]
  810. ];
  811. $data = json_encode($data, 320);
  812. $poster = [
  813. 'id' => $player_id,
  814. 'title' => 'GG语音',
  815. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  816. 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
  817. 'data' => $data,
  818. 'status' => 'normal',
  819. 'weigh' => 0,
  820. 'createtime' => 1653993709,
  821. 'updatetime' => 1653994259,
  822. ];
  823. $image = new \addons\poster\library\Image();
  824. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  825. if (!$imgurl) {
  826. $this->error('生成海报出错');
  827. }
  828. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  829. return $httpStr.'/' . $imgurl;
  830. }
  831. //申请真人认证
  832. public function realauth()
  833. {
  834. try {
  835. $realName = $this->request->param('real_name',0);
  836. $idCard = $this->request->param('id_card',0);
  837. if ($this->auth->is_auth == 2) {
  838. $this->error('您已经真人认证过了~');
  839. }
  840. if (empty($realName)) {
  841. throw new Exception('请输入姓名');
  842. }
  843. if (empty($idCard)) {
  844. throw new Exception('请输入身份证号');
  845. }
  846. $userService = new UserService();
  847. $faceParams = [
  848. 'real_name' => $realName,
  849. 'id_card' => $idCard,
  850. ];
  851. $res = $userService->faceAuth($faceParams);echo '<pre>';var_dump($res);exit;
  852. if (!$res['status']) {
  853. $this->error('您的网络开小差啦5~');
  854. }
  855. $rs = json_decode($res['data'], true);
  856. if (!$rs || $rs['code'] != 0) {
  857. $this->error('您的网络开小差啦6~');
  858. }
  859. $user_auth = [
  860. 'user_id' => $this->auth->id,
  861. 'realname' => $realName,
  862. 'idcard' => $idCard,
  863. 'certify_id' => $rs['result']['faceId'],
  864. 'out_trade_no' => $data['orderNo'],
  865. 'status' => 0,
  866. 'createtime' => time(),
  867. 'updatetime' => time()
  868. ];
  869. //开启事务
  870. Db::startTrans();
  871. //查询是否认证过
  872. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  873. if ($info) {
  874. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  875. } else {
  876. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  877. }
  878. if (!$auth_rs) {
  879. Db::rollback();
  880. $this->error('您的网络开小差啦7~');
  881. }
  882. //修改用户表认证状态
  883. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
  884. if ($user_rs === false) {
  885. Db::rollback();
  886. $this->error('您的网络开小差啦8~');
  887. }
  888. Db::commit();
  889. $return_data = [
  890. 'face_id' => $user_auth['certify_id'],
  891. 'order_no' => $user_auth['out_trade_no'],
  892. 'user_id' => (string)$this->auth->id,
  893. 'nonce' => $sign_data['nonce'],
  894. 'sign' => $sign
  895. ];
  896. $this->success('success', $return_data);
  897. } catch (Exception $e) {
  898. $this->error($e->getMessage());
  899. }
  900. }
  901. //查询真人认证结果
  902. public function getrealauthresult() {
  903. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  904. if (!$user_auth) {
  905. $this->success('尚未认证');
  906. }
  907. if ($user_auth['status'] == 1) {
  908. $this->success('真人认证通过');
  909. }
  910. if (!$user_auth['certify_id']) {
  911. $this->success('请先进行真人认证');
  912. }
  913. //获取token
  914. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  915. $token_result = file_get_contents($token_url);
  916. if (!$token_result) {
  917. $this->error('您的网络开小差啦1~');
  918. }
  919. $token_result = json_decode($token_result, true);
  920. if ($token_result['code'] != 0) {
  921. $this->error('您的网络开小差啦2~');
  922. }
  923. $token = $token_result['access_token'];
  924. //获取签名鉴权参数ticket
  925. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  926. $ticket_result = file_get_contents($ticket_url);
  927. if (!$ticket_result) {
  928. $this->error('您的网络开小差啦3~');
  929. }
  930. $ticket_result = json_decode($ticket_result, true);
  931. if ($ticket_result['code'] != 0) {
  932. $this->error('您的网络开小差啦4~');
  933. }
  934. $ticket = $ticket_result['tickets'][0]['value'];
  935. //获取签名
  936. $sign_data = [
  937. 'wbappid' => config('tencent_yun')['secret_id'],
  938. 'orderNo' => $user_auth['out_trade_no'],
  939. 'version' => '1.0.0',
  940. 'ticket' => $ticket,
  941. 'nonce' => Random::alnum(32)
  942. ];//p($sign_data);
  943. asort($sign_data); //p($sign_data);//排序
  944. $sign_string = join('', $sign_data);//p($sign_string);
  945. $sign = sha1($sign_string);//p($sign);
  946. //人脸核身结果查询
  947. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  948. $data = [
  949. 'appId' => config('tencent_yun')['secret_id'],
  950. 'version' => '1.0.0',
  951. 'nonce' => $sign_data['nonce'],
  952. 'orderNo' => $user_auth['out_trade_no'],
  953. 'sign' => $sign
  954. ];
  955. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  956. if (!$rs) {
  957. $this->error('您的网络开小差啦5~');
  958. }
  959. $rs = json_decode($rs, true);
  960. if (!$rs || $rs['code'] != 0) {
  961. $this->error($rs['msg']);
  962. }
  963. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  964. $edit_data['status'] = 1;
  965. $msg = '真人认证成功';
  966. } else {
  967. $edit_data['status'] = 2;
  968. $edit_data['certify_id'] = '';
  969. $edit_data['out_trade_no'] = '';
  970. $msg = '真人认证失败';
  971. }
  972. $edit_data['updatetime'] = time();
  973. //开启事务
  974. Db::startTrans();
  975. //修改认证信息
  976. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  977. if (!$result) {
  978. Db::rollback();
  979. $this->error('查询认证结果失败2');
  980. }
  981. //修改用户信息
  982. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
  983. if (!$rs) {
  984. Db::rollback();
  985. $this->error('查询认证结果失败3');
  986. }
  987. if ($edit_data['status'] == 1) { //通过
  988. //tag任务赠送金币
  989. //真人认证奖励
  990. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
  991. if($task_rs === false){
  992. Db::rollback();
  993. $this->error('完成任务赠送奖励失败');
  994. }
  995. //系统消息
  996. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  997. } else {
  998. //系统消息
  999. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  1000. }
  1001. Db::commit();
  1002. $this->success($msg);
  1003. }
  1004. }