LevelController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. /**
  12. * 会员等级
  13. */
  14. namespace app\appapi\controller;
  15. use cmf\controller\HomeBaseController;
  16. use think\Db;
  17. class LevelController extends HomebaseController {
  18. public function index(){
  19. $data = $this->request->param();
  20. $uid=isset($data['uid']) ? $data['uid']: '';
  21. $token=isset($data['token']) ? $data['token']: '';
  22. $uid=(int)checkNull($uid);
  23. $token=checkNull($token);
  24. $checkToken=checkToken($uid,$token);
  25. if($checkToken==700){
  26. $reason='您的登陆状态失效,请重新登陆!';
  27. $this->assign('reason', $reason);
  28. return $this->fetch(':error');
  29. }
  30. $userinfo=Db::name('user')->field("avatar,consumption,votestotal")->where(["id"=>$uid])->find();
  31. $userinfo['avatar']=get_upload_path($userinfo['avatar']);
  32. $this->assign("userinfo",$userinfo);
  33. /* 用户等级 */
  34. $levelinfo=Db::name("level")->where("level_up>='{$userinfo['consumption']}'")->order("levelid asc")->find();
  35. if(!$levelinfo){
  36. $levelinfo=Db::name("level")->order("levelid desc")->find();
  37. }
  38. $cha=$levelinfo['level_up']+1-$userinfo['consumption'];
  39. if($cha>0)
  40. {
  41. if($levelinfo['level_up']>0){
  42. $baifen=floor($userinfo['consumption']/$levelinfo['level_up']*100);
  43. }else{
  44. $baifen='0';
  45. }
  46. $type="1";
  47. }else{
  48. $baifen=100;
  49. $type="0";
  50. }
  51. $this->assign("baifen",$baifen);
  52. $this->assign("levelinfo",$levelinfo);
  53. $this->assign("cha",$cha);
  54. $this->assign("type",$type);
  55. /* 主播等价 */
  56. $levelinfo_a=Db::name("level_anchor")->where("level_up>='{$userinfo['votestotal']}'")->order("levelid asc")->find();
  57. if(!$levelinfo_a){
  58. $levelinfo_a=Db::name("level_anchor")->order("levelid desc")->find();
  59. }
  60. $cha_a=$levelinfo_a['level_up']+1-$userinfo['votestotal'];
  61. if($cha_a>0)
  62. {
  63. if($levelinfo_a['level_up']>0){
  64. $baifen_a=floor($userinfo['votestotal']/$levelinfo_a['level_up']*100);
  65. }else{
  66. $baifen_a='0';
  67. }
  68. $type_a="1";
  69. }else{
  70. $baifen_a=100;
  71. $type_a="0";
  72. }
  73. $this->assign("cha_a",$cha_a);
  74. $this->assign("type_a",$type_a);
  75. $this->assign("baifen_a",$baifen_a);
  76. $this->assign("levelinfo_a",$levelinfo_a);
  77. return $this->fetch();
  78. }
  79. public function level(){
  80. $list=Db::name("level")->order("levelid asc")->select()->toArray();
  81. foreach($list as $k=>$v){
  82. $list[$k]['level_up']=number_format($v['level_up']);
  83. $list[$k]['thumb']=get_upload_path($v['thumb']);
  84. }
  85. $this->assign("list",$list);
  86. return $this->fetch();
  87. }
  88. public function level_a(){
  89. $list=Db::name("level_anchor")->order("levelid asc")->select()->toArray();
  90. foreach($list as $k=>$v){
  91. $list[$k]['level_up']=number_format($v['level_up']);
  92. $list[$k]['thumb']=get_upload_path($v['thumb']);
  93. }
  94. $this->assign("list",$list);
  95. return $this->fetch();
  96. }
  97. }