TurntableconController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * 大转盘 价格配置
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. class TurntableconController extends AdminbaseController {
  9. function index(){
  10. $lists = Db::name("turntable_con")
  11. ->order("list_order asc,id asc")
  12. ->paginate(20);
  13. $page = $lists->render();
  14. $this->assign('lists', $lists);
  15. $this->assign("page", $page);
  16. return $this->fetch();
  17. }
  18. //排序
  19. public function listOrder() {
  20. $model = DB::name('turntable_con');
  21. parent::listOrders($model);
  22. $this->resetcache();
  23. $this->success("排序更新成功!");
  24. }
  25. function edit(){
  26. $id = $this->request->param('id', 0, 'intval');
  27. $data=Db::name('turntable_con')
  28. ->where("id={$id}")
  29. ->find();
  30. if(!$data){
  31. $this->error("信息错误");
  32. }
  33. $this->assign('data', $data);
  34. return $this->fetch();
  35. }
  36. function editPost(){
  37. if ($this->request->isPost()) {
  38. $data = $this->request->param();
  39. $times=$data['times'];
  40. if($times<1){
  41. $this->error("请输入正确的次数");
  42. }
  43. $coin=$data['coin'];
  44. if($coin<1){
  45. $this->error("请输入正确的价格");
  46. }
  47. $rs = DB::name('turntable_con')->update($data);
  48. if($rs===false){
  49. $this->error("修改失败!");
  50. }
  51. $this->resetcache();
  52. $this->success("修改成功!");
  53. }
  54. }
  55. function resetcache(){
  56. $key='turntable_con';
  57. $list=DB::name('turntable_con')
  58. ->field("id,times,coin")
  59. ->order('list_order asc,id asc')
  60. ->select();
  61. if($list){
  62. setcaches($key,$list);
  63. }else{
  64. delcache($key);
  65. }
  66. return 1;
  67. }
  68. }