User.php 37 KB

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