LevelController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 LevelController extends AdminbaseController {
  18. public function index(){
  19. $lists = Db::name("level")
  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')->where("id={$id}")->delete();
  36. if(!$rs){
  37. $this->error("删除失败!");
  38. }
  39. $this->resetcache();
  40. $this->success("删除成功!",url("level/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')->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. $colour=$data['colour'];
  86. if($colour==""){
  87. $this->error("请填写昵称颜色");
  88. }
  89. $thumb=$data['thumb'];
  90. if($thumb==""){
  91. $this->error("请上传图标");
  92. }
  93. $data['thumb']=set_upload_path($thumb);
  94. $thumb_mark=$data['thumb_mark'];
  95. if($thumb_mark==""){
  96. $this->error("请上传头像角标");
  97. }
  98. $data['thumb_mark']=set_upload_path($thumb_mark);
  99. $bg=$data['bg'];
  100. if($bg==""){
  101. $this->error("请上传背景图片");
  102. }
  103. $data['bg']=set_upload_path($bg);
  104. $data['addtime']=time();
  105. $id = DB::name('level')->insertGetId($data);
  106. if(!$id){
  107. $this->error("添加失败!");
  108. }
  109. $this->resetcache();
  110. $this->success("添加成功!");
  111. }
  112. }
  113. public function edit(){
  114. $id = $this->request->param('id', 0, 'intval');
  115. $data=Db::name('level')
  116. ->where("id={$id}")
  117. ->find();
  118. if(!$data){
  119. $this->error("信息错误");
  120. }
  121. $this->assign('data', $data);
  122. return $this->fetch();
  123. }
  124. public function editPost(){
  125. if ($this->request->isPost()) {
  126. $data = $this->request->param();
  127. $id=$data['id'];
  128. $levelid=$data['levelid'];
  129. $levelname=$data['levelname'];
  130. if($levelid==""){
  131. $this->error("等级不能为空");
  132. }
  133. if($levelid==""){
  134. $this->error("等级不能为空");
  135. }
  136. if(!is_numeric($levelid)){
  137. $this->error("等级必须为数字");
  138. }
  139. if($levelid<1){
  140. $this->error("等级必须大于1");
  141. }
  142. if($levelid>99999999){
  143. $this->error("等级必须在1-99999999之间");
  144. }
  145. if(floor($levelid)!=$levelid){
  146. $this->error("等级必须为整数");
  147. }
  148. $check = Db::name('level')->where([['levelid','=',$levelid],['id','<>',$id]])->find();
  149. if($check){
  150. $this->error('等级不能重复');
  151. }
  152. if($levelname==''){
  153. $this->error('请填写等级名称');
  154. }
  155. $level_up=$data['level_up'];
  156. if($level_up==""){
  157. $this->error("请填写等级经验上限");
  158. }
  159. if(!is_numeric($level_up)){
  160. $this->error("等级经验上限必须为数字");
  161. }
  162. if($level_up<1||$level_up>99999999){
  163. $this->error("等级经验上限必须为1-99999999数字");
  164. }
  165. if(floor($level_up)!=$level_up){
  166. $this->error("等级经验上限必须为整数");
  167. }
  168. $colour=$data['colour'];
  169. if($colour==""){
  170. $this->error("请填写昵称颜色");
  171. }
  172. $thumb=$data['thumb'];
  173. if($thumb==""){
  174. $this->error("请上传图标");
  175. }
  176. $thumb_old=$data['thumb_old'];
  177. if($thumb!=$thumb_old){
  178. $data['thumb']=set_upload_path($thumb);
  179. }
  180. $thumb_mark=$data['thumb_mark'];
  181. if($thumb_mark==""){
  182. $this->error("请上传头像角标");
  183. }
  184. $thumb_mark_old=$data['thumb_mark_old'];
  185. if($thumb_mark!=$thumb_mark_old){
  186. $data['thumb_mark']=set_upload_path($thumb_mark);
  187. }
  188. $bg=$data['bg'];
  189. if($bg==""){
  190. $this->error("请上传背景图片");
  191. }
  192. $bg_old=$data['bg_old'];
  193. if($bg_old!=$bg){
  194. $data['bg']=set_upload_path($bg);
  195. }
  196. unset($data['thumb_old']);
  197. unset($data['thumb_mark_old']);
  198. unset($data['bg_old']);
  199. $rs = DB::name('level')->update($data);
  200. if($rs===false){
  201. $this->error("修改失败!");
  202. }
  203. $this->resetcache();
  204. $this->success("修改成功!");
  205. }
  206. }
  207. public function resetcache(){
  208. $key='level';
  209. $level= Db::name("level")->order("level_up asc")->select();
  210. if($level){
  211. setcaches($key,$level);
  212. }else{
  213. delcache($key);
  214. }
  215. return 1;
  216. }
  217. }