User.php 37 KB

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