LevelanchorController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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\admin\controller;
  15. use cmf\controller\AdminBaseController;
  16. use think\Db;
  17. class LevelanchorController extends AdminbaseController {
  18. public function index(){
  19. $lists = Db::name("level_anchor")
  20. ->order("levelid asc")
  21. ->paginate(20);
  22. $lists->each(function($v,$k){
  23. $v['thumb']=get_upload_path($v['thumb']);
  24. $v['thumb_mark']=get_upload_path($v['thumb_mark']);
  25. $v['bg']=get_upload_path($v['bg']);
  26. return $v;
  27. });
  28. $page = $lists->render();
  29. $this->assign('lists', $lists);
  30. $this->assign("page", $page);
  31. return $this->fetch();
  32. }
  33. public function del(){
  34. $id = $this->request->param('id', 0, 'intval');
  35. $rs = DB::name('level_anchor')->where("id={$id}")->delete();
  36. if(!$rs){
  37. $this->error("删除失败!");
  38. }
  39. $this->resetcache();
  40. $this->success("删除成功!",url("levelanchor/index"));
  41. }
  42. public function add(){
  43. return $this->fetch();
  44. }
  45. public function addPost(){
  46. if ($this->request->isPost()) {
  47. $data = $this->request->param();
  48. $levelid=$data['levelid'];
  49. $levelname=$data['levelname'];
  50. if($levelid==""){
  51. $this->error("等级不能为空");
  52. }
  53. if(!is_numeric($levelid)){
  54. $this->error("等级必须为数字");
  55. }
  56. if($levelid<1){
  57. $this->error("等级必须大于1");
  58. }
  59. if($levelid>99999999){
  60. $this->error("等级必须在1-99999999之间");
  61. }
  62. if(floor($levelid)!=$levelid){
  63. $this->error("等级必须为整数");
  64. }
  65. $check = Db::name('level_anchor')->where(["levelid"=>$levelid])->find();
  66. if($check){
  67. $this->error('等级不能重复');
  68. }
  69. if($levelname==''){
  70. $this->error('请填写等级名称');
  71. }
  72. $level_up=$data['level_up'];
  73. if($level_up==""){
  74. $this->error("请填写等级经验上限");
  75. }
  76. if(!is_numeric($level_up)){
  77. $this->error("等级经验上限必须为数字");
  78. }
  79. if($level_up<1||$level_up>99999999){
  80. $this->error("等级经验上限必须为1-99999999数字");
  81. }
  82. if(floor($level_up)!=$level_up){
  83. $this->error("等级经验上限必须为整数");
  84. }
  85. $thumb=$data['thumb'];
  86. if($thumb==""){
  87. $this->error("请上传图标");
  88. }
  89. $data['thumb']=set_upload_path($thumb);
  90. $thumb_mark=$data['thumb_mark'];
  91. if($thumb_mark==""){
  92. $this->error("请上传头像角标");
  93. }
  94. $data['thumb_mark']=set_upload_path($thumb_mark);
  95. $bg=$data['bg'];
  96. if($bg==""){
  97. $this->error("请上传背景图片");
  98. }
  99. $data['bg']=set_upload_path($bg);
  100. $data['addtime']=time();
  101. $id = DB::name('level_anchor')->insertGetId($data);
  102. if(!$id){
  103. $this->error("添加失败!");
  104. }
  105. $this->resetcache();
  106. $this->success("添加成功!");
  107. }
  108. }
  109. public function edit(){
  110. $id = $this->request->param('id', 0, 'intval');
  111. $data=Db::name('level_anchor')
  112. ->where("id={$id}")
  113. ->find();
  114. if(!$data){
  115. $this->error("信息错误");
  116. }
  117. $this->assign('data', $data);
  118. return $this->fetch();
  119. }
  120. public function editPost(){
  121. if ($this->request->isPost()) {
  122. $data = $this->request->param();
  123. $id=$data['id'];
  124. $levelid=$data['levelid'];
  125. $levelname=$data['levelname'];
  126. if($levelid==""){
  127. $this->error("等级不能为空");
  128. }
  129. if($levelid==""){
  130. $this->error("等级不能为空");
  131. }
  132. if(!is_numeric($levelid)){
  133. $this->error("等级必须为数字");
  134. }
  135. if($levelid<1){
  136. $this->error("等级必须大于1");
  137. }
  138. if($levelid>99999999){
  139. $this->error("等级必须在1-99999999之间");
  140. }
  141. if(floor($levelid)!=$levelid){
  142. $this->error("等级必须为整数");
  143. }
  144. $check = Db::name('level_anchor')->where([['levelid','=',$levelid],['id','<>',$id]])->find();
  145. if($check){
  146. $this->error('等级不能重复');
  147. }
  148. if($levelname==''){
  149. $this->error('请填写等级名称');
  150. }
  151. $level_up=$data['level_up'];
  152. if($level_up==""){
  153. $this->error("请填写等级经验上限");
  154. }
  155. if(!is_numeric($level_up)){
  156. $this->error("等级经验上限必须为数字");
  157. }
  158. if($level_up<1||$level_up>99999999){
  159. $this->error("等级经验上限必须为1-99999999数字");
  160. }
  161. if(floor($level_up)!=$level_up){
  162. $this->error("等级经验上限必须为整数");
  163. }
  164. $thumb=$data['thumb'];
  165. if($thumb==""){
  166. $this->error("请上传图标");
  167. }
  168. $thumb_old=$data['thumb_old'];
  169. if($thumb!=$thumb_old){
  170. $data['thumb']=set_upload_path($thumb);
  171. }
  172. $thumb_mark=$data['thumb_mark'];
  173. if($thumb_mark==""){
  174. $this->error("请上传头像角标");
  175. }
  176. $thumb_mark_old=$data['thumb_mark_old'];
  177. if($thumb_mark!=$thumb_mark_old){
  178. $data['thumb_mark']=set_upload_path($thumb_mark);
  179. }
  180. $bg=$data['bg'];
  181. if($bg==""){
  182. $this->error("请上传背景图片");
  183. }
  184. $bg_old=$data['bg_old'];
  185. if($bg_old!=$bg){
  186. $data['bg']=set_upload_path($bg);
  187. }
  188. unset($data['thumb_old']);
  189. unset($data['thumb_mark_old']);
  190. unset($data['bg_old']);
  191. $rs = DB::name('level_anchor')->update($data);
  192. if($rs===false){
  193. $this->error("修改失败!");
  194. }
  195. $this->resetcache();
  196. $this->success("修改成功!");
  197. }
  198. }
  199. public function resetcache(){
  200. $key='levelanchor';
  201. $level= Db::name("level_anchor")->order("level_up asc")->select();
  202. if($level){
  203. setcaches($key,$level);
  204. }else{
  205. delcache($key);
  206. }
  207. return 1;
  208. }
  209. }