User.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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\Config;
  8. use think\Validate;
  9. use app\common\library\Token;
  10. use think\Db;
  11. use app\common\model\UserDeviceInfo;
  12. use onlogin\onlogin;
  13. use addons\epay\library\Service;
  14. use addons\epay\library\Wechat;
  15. /**
  16. * 会员接口,登录,注册,修改资料等
  17. */
  18. class User extends Api
  19. {
  20. protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig'];
  21. protected $noNeedRight = '*';
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. if (!Config::get('fastadmin.usercenter')) {
  26. $this->error(__('User center already closed'));
  27. }
  28. }
  29. /**
  30. * 会员中心
  31. */
  32. public function index()
  33. {
  34. $this->success('', ['welcome' => $this->auth->nickname]);
  35. }
  36. /**
  37. * 会员登录
  38. *
  39. * @ApiMethod (POST)
  40. * @param string $account 账号
  41. * @param string $password 密码
  42. */
  43. public function login()
  44. {
  45. $account = input('account');
  46. $password = input('password');
  47. if (!$account || !$password) {
  48. $this->error(__('Invalid parameters'));
  49. }
  50. $ret = $this->auth->login($account, $password);
  51. if ($ret) {
  52. $data = $this->userInfo('return');
  53. $this->success(__('Logged in successful'), $data);
  54. } else {
  55. $this->error($this->auth->getError());
  56. }
  57. }
  58. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次。
  59. private function firstopen_send($oneuser){
  60. //找出公会的人
  61. $map = [
  62. 'gh_id' => ['gt',0],
  63. ];
  64. $ghuser = Db::name('user')->where($map)->orderRaw('rand()')->limit(3)->column('id');
  65. //dump($ghuser);
  66. //随机取出一句话
  67. $oneword = Db::name('plantask_accost')->orderRaw('rand()')->limit(3)->column('title');
  68. //dump($oneword);
  69. $tenim = new \app\common\library\Tenim;
  70. for($i = 0;$i < 3;$i++){
  71. $ghuser_one = isset($ghuser[$i]) ? $ghuser[$i] : $ghuser[array_rand($ghuser)];
  72. $oneword_one = isset($oneword[$i]) ? $oneword[$i] : $oneword[array_rand($oneword)];
  73. $tenim->sendMessageToUser($ghuser_one,$oneuser,$oneword_one);
  74. }
  75. }
  76. /**
  77. * 手机验证码登录
  78. *
  79. * @ApiMethod (POST)
  80. * @param string $mobile 手机号
  81. * @param string $captcha 验证码
  82. */
  83. public function mobilelogin()
  84. {
  85. $mobile = input('mobile');
  86. $captcha = input('captcha');
  87. if (!$mobile || !$captcha) {
  88. $this->error(__('Invalid parameters'));
  89. }
  90. if (!Validate::regex($mobile, "^1\d{10}$")) {
  91. $this->error(__('Mobile is incorrect'));
  92. }
  93. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  94. $this->error(__('Captcha is incorrect'));
  95. }
  96. $user = \app\common\model\User::getByMobile($mobile);
  97. if ($user) {
  98. if ($user->status == -1) {
  99. $this->error('账户已注销');
  100. }
  101. if ($user->status != 1) {
  102. $this->error(__('Account is locked'));
  103. }
  104. //如果已经有账号则直接登录
  105. $ret = $this->auth->direct($user->id);
  106. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
  107. if($user->gender == 1 && $user->gh_id == 0){
  108. $this->firstopen_send($user->id);
  109. }
  110. } else {
  111. $extend = [
  112. 'register_from' => input('register_from',''),
  113. ];
  114. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  115. //亿米
  116. $ua = input('ua','','trim');
  117. $this->yimi_advert($ua);
  118. }
  119. if ($ret) {
  120. Sms::flush($mobile, 'mobilelogin');
  121. $data = $this->userInfo('return');
  122. $this->success(__('Logged in successful'), $data);
  123. } else {
  124. $this->error($this->auth->getError());
  125. }
  126. }
  127. /**
  128. * 注册会员
  129. *
  130. * @ApiMethod (POST)
  131. * @param string $username 用户名
  132. * @param string $password 密码
  133. * @param string $email 邮箱
  134. * @param string $mobile 手机号
  135. * @param string $code 验证码
  136. */
  137. /*public function register()
  138. {
  139. $username = $this->request->post('username');
  140. $password = $this->request->post('password');
  141. $email = $this->request->post('email');
  142. $mobile = $this->request->post('mobile');
  143. $code = $this->request->post('code');
  144. if (!$username || !$password) {
  145. $this->error(__('Invalid parameters'));
  146. }
  147. if ($email && !Validate::is($email, "email")) {
  148. $this->error(__('Email is incorrect'));
  149. }
  150. if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  151. $this->error(__('Mobile is incorrect'));
  152. }
  153. $ret = Sms::check($mobile, $code, 'register');
  154. if (!$ret) {
  155. $this->error(__('Captcha is incorrect'));
  156. }
  157. $ret = $this->auth->register($username, $password, $email, $mobile, []);
  158. if ($ret) {
  159. $data = $this->userInfo('return');
  160. $this->success(__('Sign up successful'), $data);
  161. } else {
  162. $this->error($this->auth->getError());
  163. }
  164. }*/
  165. //微信登录+注册
  166. public function wechatlogin(){
  167. $nickname = input('nickname','');
  168. $avatar = input('avatar','');
  169. $gender = input('gender',1);
  170. $wechat_openid = input('wechat_openid','');
  171. if (!$wechat_openid) {
  172. $this->error(__('Invalid parameters'));
  173. }
  174. if($gender != 1){
  175. $gender = 0;
  176. }
  177. $user = \app\common\model\User::getByOpenid($wechat_openid);
  178. if ($user) {
  179. if ($user->status != 1) {
  180. $this->error(__('Account is locked'));
  181. }
  182. //如果已经有账号则直接登录
  183. $ret = $this->auth->direct($user->id);
  184. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
  185. if($user->gender == 1 && $user->gh_id == 0){
  186. $this->firstopen_send($user->id);
  187. }
  188. } else {
  189. if (!$nickname || !$avatar) {
  190. $this->error(__('Invalid parameters'));
  191. }
  192. $reg_data = [
  193. 'nickname'=>$nickname,
  194. 'avatar'=>$avatar,
  195. 'gender'=>$gender,
  196. 'register_from' => input('register_from',''),
  197. ];
  198. $ret = $this->auth->openid_register($wechat_openid,$reg_data);
  199. //亿米
  200. $ua = input('ua','','trim');
  201. $this->yimi_advert($ua);
  202. }
  203. if ($ret) {
  204. $data = $this->userInfo('return');
  205. $this->success(__('Logged in successful'), $data);
  206. } else {
  207. $this->error($this->auth->getError());
  208. }
  209. }
  210. /**
  211. * 运营商一键登录
  212. */
  213. public function onLogin()
  214. {
  215. $accessToken = input('accessToken');// 运营商预取号获取到的token
  216. $token = input('tokenT');// 易盾返回的token
  217. if (!$accessToken || !$token) {
  218. $this->error("参数获取失败!");
  219. }
  220. $params = array(
  221. // 运营商预取号获取到的token
  222. "accessToken" => $accessToken,
  223. // 易盾返回的token
  224. "token" => $token
  225. );
  226. // 获取密钥配置
  227. $configInfo = config("onLogin");
  228. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  229. $onret = $onlogin->check($params);
  230. // $ret = [];
  231. // $ret["code"] = 200;
  232. // $ret["msg"] = "ok";
  233. // $ret["data"] = [
  234. // "phone" => "17574504021",
  235. // "resultCode" => 0
  236. // ];
  237. if ($onret["code"] == 200) {
  238. $mobile = $onret["data"]["phone"];
  239. if (empty($mobile)) {
  240. // 取号失败,建议进行二次验证,例如短信验证码
  241. $this->error("取号登录失败,请用验证码方式登录!");
  242. } else {
  243. // 取号成功, 执行登录等流程
  244. // 用户登录逻辑 === 开始
  245. $user = \app\common\model\User::getByMobile($mobile);
  246. if ($user) {
  247. if ($user->status != 1) {
  248. $this->error(__('Account is locked'));
  249. }
  250. //如果已经有账号则直接登录
  251. $ret = $this->auth->direct($user->id);
  252. $is_register = 0;
  253. //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
  254. if($user->gender == 1 && $user->gh_id == 0){
  255. $this->firstopen_send($user->id);
  256. }
  257. } else {
  258. $extend = [
  259. 'register_from' => input('register_from',''),
  260. ];
  261. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  262. $is_register = 1;
  263. //亿米
  264. $ua = input('ua','','trim');
  265. $this->yimi_advert($ua);
  266. }
  267. //结果
  268. /*$rs['userinfo'] = $this->auth->getUserinfo();
  269. $rs['is_register'] = $is_register;*/
  270. if ($ret) {
  271. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  272. } else {
  273. $this->error($this->auth->getError());
  274. }
  275. // 用户登录逻辑 === 结束
  276. }
  277. } else {
  278. $this->error("登录失败,请用验证码方式登录!");
  279. }
  280. }
  281. //用户详细资料
  282. public function userInfo($type = 1){
  283. $info = $this->auth->getUserinfo();
  284. if($type == 'return'){
  285. return $info;
  286. }
  287. $this->success(__('success'),$info);
  288. }
  289. //用户邀请信息
  290. public function userintroinfo(){
  291. $intro_num = Db::name('user')->where('intro_uid',$this->auth->id)->count();
  292. $money_sum = Db::name('user_money_log')->where(['user_id'=>$this->auth->id,'log_type'=>63])->sum('change_value');
  293. $user_list = Db::name('user')->field('id,avatar,nickname,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
  294. $rs = [
  295. 'intro_num' => $intro_num,
  296. 'money_sum' => $money_sum,
  297. 'user_list' => $user_list,
  298. ];
  299. $this->success('success',$rs);
  300. }
  301. public function testhaibao(){
  302. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode]);
  303. dump($haibao);
  304. }
  305. //海报
  306. public function haibao($player_id,$data){
  307. //下载页二维码,没必要保留
  308. $params = [
  309. 'text' => config('site.domain_name').'/index/index/appdownload',
  310. 'size' => 90,
  311. 'logo' => false,
  312. 'label' => false,
  313. 'padding' => 0,
  314. ];
  315. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  316. $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
  317. mk_dir($qrcode_path);
  318. $download_qrcode = $qrcode_path.'/download.png';
  319. $qrCode->writeFile($download_qrcode);
  320. //海报
  321. $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
  322. return $haibao;
  323. }
  324. public function createhaibao($download_qrcode,$player_id,$sub_data){
  325. //背景图
  326. $background = config('site.domain_name').'/assets/img/haibao.png';
  327. //海报图片路径
  328. $new_path = 'uploads/hbplayer/'.date("Ymd").'/';
  329. mk_dir($new_path);
  330. $wap_file_name = $new_path .'wap_player_'. $player_id . '.png';
  331. //二维码
  332. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  333. //合成wap图片
  334. $image = new \addons\poster\library\Image2();
  335. $imgurl = $image->createPosterImage($background,$download_qrcode,$sub_data['introcode'],$wap_file_name);
  336. return '/'.$wap_file_name;
  337. }
  338. //申请真人认证
  339. public function apply_real_confirm(){
  340. $avatar = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  341. if(!$avatar){
  342. $this->error('请上传真人头像');
  343. }
  344. Db::startTrans();
  345. $data = [
  346. 'avatar' => $avatar,
  347. 'real_status' => 1,
  348. ];
  349. $rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  350. if($rs === false){
  351. Db::rollback();
  352. $this->error('认证失败');
  353. }
  354. //tag任务赠送金币
  355. //完成本人基本资料 +15金币《所有资料完善,包括真人认证和实名认证》
  356. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,5);
  357. if($task_rs === false){
  358. Db::rollback();
  359. $this->error('完成任务赠送奖励失败');
  360. }
  361. //完成真人头像 +5金币
  362. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,7);
  363. if($task_rs === false){
  364. Db::rollback();
  365. $this->error('完成任务赠送奖励失败');
  366. }
  367. //邀请人拿奖励,男性3元
  368. $intro_money = $this->auth->gender == 1 ? config('site.intro_man_money') : config('site.intro_woman_money');
  369. if($this->auth->idcard_status == 1 && !empty($this->auth->intro_uid) && $intro_money > 0){
  370. $task_rs = model('wallet')->lockChangeAccountRemain($this->auth->intro_uid,'money',$intro_money,63,$remark='');
  371. if($task_rs['status'] === false){
  372. Db::rollback();
  373. $this->error($task_rs['msg']);
  374. }
  375. }
  376. //系统消息
  377. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  378. Db::commit();
  379. $this->success();
  380. }
  381. //实名认证信息
  382. public function idcard_confirm_info(){
  383. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
  384. $this->success('success',$check);
  385. }
  386. //申请私密视频
  387. public function apply_secretvideo(){
  388. $secretvideo = input('secretvideo','');
  389. if(empty($secretvideo)){
  390. $this->error();
  391. }
  392. Db::startTrans();
  393. $check = Db::name('user_secretvideo')->where('user_id',$this->auth->id)->lock(true)->find();
  394. if(!empty($check)){
  395. if($check['status'] == 0){
  396. Db::rollback();
  397. $this->error('您已经提交私密视频,请等待审核');
  398. }
  399. }
  400. $data = [
  401. 'user_id' => $this->auth->id,
  402. 'secretvideo' => $secretvideo,
  403. 'status' => 0,
  404. 'createtime' => time(),
  405. 'updatetime' => time(),
  406. 'audittime' => 0,
  407. 'auditremark' => '',
  408. ];
  409. //更新
  410. $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['secretvideo_status'=>0]);
  411. if(!empty($check)){
  412. $rs = Db::name('user_secretvideo')->where('id',$check['id'])->update($data);
  413. }else{
  414. $rs = Db::name('user_secretvideo')->insertGetId($data);
  415. }
  416. if(!$rs || !$update_rs){
  417. Db::rollback();
  418. $this->error('提交失败');
  419. }
  420. Db::commit();
  421. $this->success('提交成功,请等待审核');
  422. }
  423. //申请实名认证
  424. public function apply_idcard_confirm(){
  425. $truename = input('truename','');
  426. $idcard = input('idcard','');
  427. //$idcard_images = input('idcard_images','');
  428. $alipay_account = input('alipay_account','');
  429. if(empty($truename) || empty($idcard) || empty($alipay_account)){
  430. $this->error('实名认证信息必填');
  431. }
  432. if($this->auth->idcard_status == 1){
  433. $this->error('您已经完成实名认证');
  434. }
  435. if($this->auth->idcard_status == 0){
  436. $this->error('您已经提交实名认证,请等待审核');
  437. }
  438. Db::startTrans();
  439. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->lock(true)->find();
  440. if(!empty($check)){
  441. if($check['status'] == 0){
  442. Db::rollback();
  443. $this->error('您已经提交实名认证,请等待审核');
  444. }
  445. if($check['status'] == 1){
  446. Db::rollback();
  447. $this->error('您已经完成实名认证');
  448. }
  449. }
  450. $data = [
  451. 'user_id' => $this->auth->id,
  452. 'truename' => $truename,
  453. 'idcard' => $idcard,
  454. //'idcard_images' => $idcard_images,
  455. 'alipay_account' => $alipay_account,
  456. 'status' => 0,
  457. 'createtime' => time(),
  458. 'updatetime' => time(),
  459. ];
  460. //更新
  461. $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcard_status'=>0]);
  462. if(!empty($check)){
  463. $rs = Db::name('user_idconfirm')->where('id',$check['id'])->update($data);
  464. }else{
  465. $rs = Db::name('user_idconfirm')->insertGetId($data);
  466. }
  467. if(!$rs || !$update_rs){
  468. Db::rollback();
  469. $this->error('提交失败');
  470. }
  471. Db::commit();
  472. $this->success('提交成功,请等待审核');
  473. }
  474. /**
  475. * 退出登录
  476. * @ApiMethod (POST)
  477. */
  478. public function logout()
  479. {
  480. if (!$this->request->isPost()) {
  481. $this->error(__('Invalid parameters'));
  482. }
  483. //退出im
  484. $tenIm = new Tenim();
  485. $tenIm->loginoutim($this->auth->id);
  486. //修改用户活跃0
  487. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
  488. $this->auth->logout();
  489. $this->success(__('Logout successful'));
  490. }
  491. /**
  492. * 修改会员个人信息
  493. *
  494. * @ApiMethod (POST)
  495. * @param string $avatar 头像地址
  496. * @param string $username 用户名
  497. * @param string $nickname 昵称
  498. * @param string $bio 个人简介
  499. */
  500. public function profile()
  501. {
  502. $field_array = ['nickname','introcode','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo','wechat_account'];
  503. $data = [];
  504. foreach($field_array as $key => $field){
  505. if(!input('?'.$field)){
  506. continue;
  507. }
  508. $newone = input($field);
  509. if($field == 'avatar'){
  510. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  511. }
  512. if($field == 'photo_images'){
  513. $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
  514. }
  515. $data[$field] = $newone;
  516. }
  517. if(isset($data['birthday'])){
  518. $data['birthday'] = strtotime($data['birthday']);
  519. }
  520. if(isset($data['avatar'])){
  521. //$data['real_status'] = -1; //或许应该改成0。性别不能改所以不需要
  522. }
  523. if(isset($data['hobby_ids'])){
  524. $data['hobby_ids'] = implode(',',explode(',',$data['hobby_ids']));
  525. }
  526. if(isset($data['tag_ids'])){
  527. $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
  528. }
  529. if(isset($data['introcode'])){
  530. $intro_user = Db::name('user')->where('introcode',$data['introcode'])->value('id');
  531. if(!$intro_user){
  532. $this->error('不存在的邀请人');
  533. }
  534. unset($data['introcode']);//别人的邀请码,不能改了自己的
  535. $data['intro_uid'] = $intro_user;
  536. }
  537. //dump($data);
  538. if(empty($data)){
  539. $this->error('没有任何改变');
  540. }
  541. //默认头像
  542. //现在没头像,也没穿头像,但是却传了性别
  543. if($this->auth->avatar == config('site.domain_cdnurl').'/avatar.png' && isset($data['gender']) && $data['avatar'] == config('site.domain_cdnurl').'/avatar.png'){
  544. if($data['gender'] == 1){
  545. $data['avatar'] = 'https://meet-1251365327.cos.ap-beijing.myqcloud.com/uploads/20220314/f9277fba97fd76d9ecfc63b506a3674a.png';
  546. }else{
  547. $data['avatar'] = 'https://meet-1251365327.cos.ap-beijing.myqcloud.com/uploads/20220314/5030460c05c86774f60123ffea7b78a1.png';
  548. }
  549. }
  550. //默认头像
  551. Db::startTrans();
  552. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  553. if($update_rs === false){
  554. Db::rollback();
  555. $this->error('修改资料失败');
  556. }
  557. //tag任务赠送金币
  558. //上传头像加5金币
  559. if(isset($data['avatar'])){
  560. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  561. if($task_rs === false){
  562. Db::rollback();
  563. $this->error('完成任务赠送奖励失败');
  564. }
  565. }
  566. //上传本人语音介绍 10金币
  567. if(isset($data['audio_bio'])){
  568. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,6);
  569. if($task_rs === false){
  570. Db::rollback();
  571. $this->error('完成任务赠送奖励失败');
  572. }
  573. }
  574. //上传本人五张照片 10金币
  575. if(isset($data['photo_images']) && count(explode(',',$data['photo_images'])) >= 5){
  576. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,8);
  577. if($task_rs === false){
  578. Db::rollback();
  579. $this->error('完成任务赠送奖励失败');
  580. }
  581. }
  582. //所有资料完成
  583. $user_info = Db::name('user')->where('id',$this->auth->id)->find();
  584. if($user_info['avatar'] && $user_info['nickname'] && $user_info['mobile'] && $user_info['audio_bio'] && $user_info['photo_images']){
  585. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,5);
  586. if($task_rs === false){
  587. Db::rollback();
  588. $this->error('完成任务赠送奖励失败');
  589. }
  590. }
  591. Db::commit();
  592. $this->success();
  593. }
  594. public function set_status_switch(){
  595. }
  596. /*
  597. * 修改用户的坐标
  598. * */
  599. public function change_longlat(){
  600. $longitude = input_post('longitude');
  601. $latitude = input_post('latitude');
  602. $cityname = input_post('cityname');
  603. if(empty($longitude) || empty($latitude) || empty($cityname)){
  604. $this->error();
  605. }
  606. $data = [
  607. 'longitude' => $longitude,
  608. 'latitude' => $latitude,
  609. 'cityname' => $cityname,
  610. ];
  611. Db::name('user')->where('id',$this->auth->id)->update($data);
  612. $this->success();
  613. }
  614. /**
  615. * 修改邮箱
  616. *
  617. * @ApiMethod (POST)
  618. * @param string $email 邮箱
  619. * @param string $captcha 验证码
  620. */
  621. /*public function changeemail()
  622. {
  623. $user = $this->auth->getUser();
  624. $email = $this->request->post('email');
  625. $captcha = $this->request->post('captcha');
  626. if (!$email || !$captcha) {
  627. $this->error(__('Invalid parameters'));
  628. }
  629. if (!Validate::is($email, "email")) {
  630. $this->error(__('Email is incorrect'));
  631. }
  632. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  633. $this->error(__('Email already exists'));
  634. }
  635. $result = Ems::check($email, $captcha, 'changeemail');
  636. if (!$result) {
  637. $this->error(__('Captcha is incorrect'));
  638. }
  639. $verification = $user->verification;
  640. $verification->email = 1;
  641. $user->verification = $verification;
  642. $user->email = $email;
  643. $user->save();
  644. Ems::flush($email, 'changeemail');
  645. $this->success();
  646. }*/
  647. /**
  648. * 修改手机号
  649. *
  650. * @ApiMethod (POST)
  651. * @param string $mobile 手机号
  652. * @param string $captcha 验证码
  653. */
  654. public function changemobile()
  655. {
  656. $user = $this->auth->getUser();
  657. $oldcaptcha = $this->request->request('oldcaptcha');
  658. $mobile = $this->request->request('mobile');
  659. $captcha = $this->request->request('captcha');
  660. if (!$oldcaptcha || !$mobile || !$captcha) {
  661. $this->error(__('Invalid parameters'));
  662. }
  663. if (!Validate::regex($mobile, "^1\d{10}$")) {
  664. $this->error(__('Mobile is incorrect'));
  665. }
  666. if($user->mobile == $mobile){
  667. $this->error('新手机号不能与旧手机号相同');
  668. }
  669. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  670. $this->error(__('Mobile already exist'));
  671. }
  672. $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
  673. if (!$result) {
  674. $this->error(__('Captcha is incorrect'));
  675. }
  676. $result = Sms::check($mobile, $captcha, 'changemobile');
  677. if (!$result) {
  678. $this->error(__('Captcha is incorrect'));
  679. }
  680. $verification = $user->verification;
  681. $verification->mobile = 1;
  682. $user->verification = $verification;
  683. $user->mobile = $mobile;
  684. $user->save();
  685. Sms::flush($user->mobile, 'changemobile');
  686. Sms::flush($mobile, 'changemobile');
  687. $this->success();
  688. }
  689. /**
  690. * 微信注册来的,绑定手机号
  691. *
  692. * @ApiMethod (POST)
  693. * @param string $mobile 手机号
  694. * @param string $captcha 验证码
  695. */
  696. public function bindmobile()
  697. {
  698. $user = $this->auth->getUser();
  699. $mobile = $this->request->request('mobile');
  700. $captcha = $this->request->request('captcha');
  701. if(!empty($this->auth->mobile)){
  702. $this->error('已经绑定了手机号');
  703. }
  704. if (!$mobile || !$captcha) {
  705. $this->error(__('Invalid parameters'));
  706. }
  707. if (!Validate::regex($mobile, "^1\d{10}$")) {
  708. $this->error(__('Mobile is incorrect'));
  709. }
  710. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  711. $this->error('该手机号已被其他用户绑定');
  712. }
  713. $result = Sms::check($mobile, $captcha, 'changemobile');
  714. if (!$result) {
  715. $this->error(__('Captcha is incorrect'));
  716. }
  717. $verification = $user->verification;
  718. $verification->mobile = 1;
  719. $user->verification = $verification;
  720. $user->mobile = $mobile;
  721. $user->save();
  722. Sms::flush($mobile, 'changemobile');
  723. $this->success('success',$this->userInfo('return'));
  724. }
  725. /**
  726. * 微信注册来的,绑定手机号
  727. *
  728. * @ApiMethod (POST)
  729. * @param string $mobile 手机号
  730. * @param string $captcha 验证码
  731. */
  732. public function bindopenid()
  733. {
  734. $user = $this->auth->getUser();
  735. $wechat_openid = $this->request->request('wechat_openid');
  736. if(!empty($this->auth->wechat_openid)){
  737. $this->error('已经绑定了微信号');
  738. }
  739. if (!$wechat_openid) {
  740. $this->error(__('Invalid parameters'));
  741. }
  742. if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
  743. $this->error('该微信号已被其他用户绑定');
  744. }
  745. $user->wechat_openid = $wechat_openid;
  746. $user->save();
  747. $this->success('success',$this->userInfo('return'));
  748. }
  749. /**
  750. * 第三方登录
  751. *
  752. * @ApiMethod (POST)
  753. * @param string $platform 平台名称
  754. * @param string $code Code码
  755. */
  756. /*public function third()
  757. {
  758. $url = url('user/index');
  759. // $platform = $this->request->post("platform");
  760. $platform = 'wechat';
  761. $code = $this->request->post("code");
  762. $config = get_addon_config('third');
  763. if (!$config || !isset($config[$platform])) {
  764. $this->error(__('Invalid parameters'));
  765. }
  766. $app = new \addons\third\library\Application($config);
  767. //通过code换access_token和绑定会员
  768. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  769. if ($result) {
  770. $loginret = \addons\third\library\Service::connect($platform, $result);
  771. if ($loginret) {
  772. $data = [
  773. 'userinfo' => $this->auth->getUserinfo(),
  774. 'thirdinfo' => $result
  775. ];
  776. $this->success(__('Logged in successful'), $data);
  777. }
  778. }
  779. $this->error(__('Operation failed'), $url);
  780. }*/
  781. /**
  782. * 重置密码
  783. *
  784. * @ApiMethod (POST)
  785. * @param string $mobile 手机号
  786. * @param string $newpassword 新密码
  787. * @param string $captcha 验证码
  788. */
  789. public function resetpwd()
  790. {
  791. //$type = input("type");
  792. $type = 'mobile';
  793. $mobile = input("mobile");
  794. $email = input("email");
  795. $newpassword = input("newpassword");
  796. $captcha = input("captcha");
  797. if (!$newpassword || !$captcha) {
  798. $this->error(__('Invalid parameters'));
  799. }
  800. if ($type == 'mobile') {
  801. if (!Validate::regex($mobile, "^1\d{10}$")) {
  802. $this->error(__('Mobile is incorrect'));
  803. }
  804. $user = \app\common\model\User::getByMobile($mobile);
  805. if (!$user) {
  806. $this->error(__('User not found'));
  807. }
  808. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  809. if (!$ret) {
  810. $this->error(__('Captcha is incorrect'));
  811. }
  812. Sms::flush($mobile, 'resetpwd');
  813. } else {
  814. if (!Validate::is($email, "email")) {
  815. $this->error(__('Email is incorrect'));
  816. }
  817. $user = \app\common\model\User::getByEmail($email);
  818. if (!$user) {
  819. $this->error(__('User not found'));
  820. }
  821. $ret = Ems::check($email, $captcha, 'resetpwd');
  822. if (!$ret) {
  823. $this->error(__('Captcha is incorrect'));
  824. }
  825. Ems::flush($email, 'resetpwd');
  826. }
  827. //模拟一次登录
  828. $this->auth->direct($user->id);
  829. $ret = $this->auth->changepwd($newpassword, '', true);
  830. if ($ret) {
  831. $this->success(__('Reset password successful'));
  832. } else {
  833. $this->error($this->auth->getError());
  834. }
  835. }
  836. /**
  837. * 修改密码
  838. *
  839. * @ApiMethod (POST)
  840. * @param string $newpassword 新密码
  841. * @param string $oldpassword 旧密码
  842. */
  843. public function changepwd(){
  844. $newpassword = input('newpassword');
  845. $oldpassword = input('oldpassword','');
  846. if (!$newpassword) {
  847. $this->error(__('Invalid parameters'));
  848. }
  849. if($this->auth->password && empty($oldpassword)){
  850. $this->error('原密码必填');
  851. }
  852. if(empty($this->auth->password)){
  853. $ret = $this->auth->changepwd($newpassword, '', true);
  854. }else{
  855. $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
  856. }
  857. if ($ret) {
  858. $this->success(__('Reset password successful'));
  859. } else {
  860. $this->error($this->auth->getError());
  861. }
  862. }
  863. /**
  864. * 记录当前登陆的设备ID,设备信息,IP等
  865. */
  866. public function changeDeviceIp()
  867. {
  868. // 接口防并发
  869. if (!$this->apiLimit(1, 5000)) {
  870. return ;
  871. }
  872. $user = $this->auth->getUser();
  873. $ip = request()->ip();
  874. $deviceId = $this->request->request('device_id','');
  875. $phoneModel = $this->request->request('phone_model','');
  876. $brand = $this->request->request('brand','');
  877. $apiVersion = $this->request->request('api_version','');
  878. $deviceOs = $this->request->request('device_os','');
  879. if ($ip !== $user->loginip){
  880. $update = [];
  881. $update['id'] = $user->id;
  882. $update['loginip'] = $ip;
  883. \app\common\model\User::update($update);
  884. }
  885. $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
  886. if (empty($userDeviceInfo)){
  887. $userDeviceInfo = new UserDeviceInfo();
  888. $userDeviceInfo->user_id = $user->u_id;
  889. }
  890. $userDeviceInfo->device_os = $deviceOs;
  891. $userDeviceInfo->device_id = $deviceId;
  892. $userDeviceInfo->phone_model = $phoneModel;
  893. $userDeviceInfo->brand = $brand;
  894. $userDeviceInfo->api_version = $apiVersion;
  895. $userDeviceInfo->save();
  896. //首页接口调用,这里不反回信息
  897. // $this->success("更新成功!");
  898. }
  899. //假注销
  900. public function cancleUser(){
  901. if (!$this->request->isPost()) {
  902. $this->error(__('Invalid parameters'));
  903. }
  904. //退出im
  905. $tenIm = new Tenim();
  906. $tenIm->loginoutim($this->auth->id);
  907. Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
  908. $this->auth->logout();
  909. $this->success('注销成功');
  910. }
  911. //修改用户活跃1
  912. public function useractive(){
  913. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 1,'active_time' => time()]);
  914. $this->success('success');
  915. }
  916. //APP 转化数据统计方案(即:APP 上报对接方案): 广告主上报激活数据,亿米平台搭建服务系统关联点击&下载数据和广告主提供的所有激活数据,将激活数据归因到对应广告。
  917. public function yimi_advert($ua = ''){
  918. //http://trail.e.mi.com/global/log?appId={appid}&info={data}&conv_type={convType}&customer_id={customerId}
  919. $api_url = 'http://trail.e.mi.com/global/log?';
  920. $api_url_test = 'http://trail.e.mi.com/global/test?';
  921. //应用id 1453045
  922. //秘钥A(encrypt_key):ZxdIaVHvFqSQYzWD
  923. //秘钥B(sign_key):uaeWeunykLRnkyLw
  924. $sign_key = 'uaeWeunykLRnkyLw'; //真的
  925. $encrypt_key = 'ZxdIaVHvFqSQYzWD';//真的
  926. $appid = '1453045';
  927. $conv_type = 'APP_REGISTER';
  928. $customer_id = '292232';
  929. //推荐模式
  930. /*$imei = md5('imei');
  931. $data = [
  932. 'imei' => '91b9185dba1772851dd02b276a6c969e',
  933. 'oaid' => '5fb96f268628810c',
  934. 'conv_time' => '1504687208890',
  935. 'client_ip' => '127.0.0.1',
  936. 'ua' => 'Dalvik/2.1.0 (Linux; U; Android 11; M2012K11AC Build/RKQ1.200826.002)',
  937. ];*/
  938. //采用模式
  939. if(empty($ua)){
  940. return true;
  941. }
  942. $data = [
  943. 'conv_time' => time().substr(microtime(),2,3),
  944. 'client_ip' => request()->ip(),
  945. 'ua' => $ua,
  946. ];
  947. $data_query = http_build_query($data);
  948. //dump($data_query);
  949. $property = $sign_key.'&'.urlencode($data_query);
  950. //dump($property);
  951. $signature = md5($property);
  952. //dump($signature);
  953. $base_data = $data_query .'&sign='.urlencode($signature);
  954. //echo $base_data;
  955. $info = urlencode(base64_encode($this->xor_enc($base_data, $encrypt_key)));
  956. //dump($info);
  957. $request_url = $api_url.'appId='.$appid.'&info='.$info.'&customer_id='.$customer_id.'&conv_type='.$conv_type;
  958. //echo $request_url;
  959. $result = curl_get($request_url);
  960. //dump($result);
  961. //日志
  962. $log = [
  963. 'param' => $base_data,
  964. 'url' => $request_url,
  965. 'result'=> $result,
  966. 'createtime' => time(),
  967. ];
  968. Db::name('yimi_advert')->insertGetId($log);
  969. return true;
  970. }
  971. //亿米 异或加密,解密
  972. public function xor_enc($str,$key)
  973. {
  974. $crytxt = '';
  975. $keylen = strlen($key);
  976. for($i=0;$i<strlen($str);$i++)
  977. {
  978. $k = $i%$keylen;
  979. $crytxt .= $str[$i] ^ $key[$k];
  980. }
  981. return $crytxt;
  982. }
  983. //公众号获取openid
  984. public function getUserOpenid_gzh(){
  985. $configValue = Service::getConfig('wechat');
  986. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  987. $rs = $wechat->getOpenid();
  988. $this->success('success',$rs);
  989. }
  990. /**
  991. * 微信内H5-JSAPI支付
  992. */
  993. public function jssdkBuildConfig() {
  994. $url = $this->request->request("url");
  995. $configValue = Service::getConfig('wechat');
  996. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  997. $sign = $wechat->getSignPackage(urldecode($url));
  998. $this->success("获取成功!",$sign);
  999. }
  1000. }