HotliverulesController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * 直播上热门投放金额规则
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. use think\db\Query;
  9. class HotliverulesController extends AdminbaseController {
  10. //列表
  11. public function index(){
  12. $lists=Db::name("hotlive_rules")
  13. ->where(function (Query $query) {
  14. })
  15. ->order("orderno asc")
  16. ->paginate(20);
  17. //分页-->筛选条件参数
  18. $data = $this->request->param();
  19. $lists->appends($data);
  20. // 获取分页显示
  21. $page = $lists->render();
  22. $configpub=getConfigPub();
  23. $this->assign('lists', $lists);
  24. $this->assign('page', $page);
  25. $this->assign('name_coin', $configpub['name_coin']);
  26. return $this->fetch();
  27. }
  28. /*添加*/
  29. public function add(){
  30. $configPub=getConfigPub();
  31. $this->assign("name_coin",$configPub['name_coin']);
  32. return $this->fetch();
  33. }
  34. /*添加提交*/
  35. public function add_post(){
  36. if($this->request->isPost()) {
  37. $data = $this->request->param();
  38. $configpub=getConfigPub();
  39. $orderno=$data['orderno'];
  40. $coin=$data['coin'];
  41. if(!is_numeric($orderno)){
  42. $this->error("排序号请填写数字");
  43. }
  44. if($orderno<0){
  45. $this->error("排序号必须大于0");
  46. }
  47. if(!$coin){
  48. $this->error("请填写".$configpub['name_coin']);
  49. }
  50. if(!is_numeric($coin)){
  51. $this->error($configpub['name_coin']."必须为数字");
  52. }
  53. if($coin<100||$coin>99999999){
  54. $this->error($configpub['name_coin']."在100-99999999之间");
  55. }
  56. if(floor($coin)!=$coin){
  57. $this->error($configpub['name_coin']."必须为整数");
  58. }
  59. if($coin % 10 >0){
  60. $this->error($configpub['name_coin']."数必须为10的倍数");
  61. }
  62. $isexit=Db::name("hotlive_rules")
  63. ->where("coin={$coin}")
  64. ->find();
  65. if($isexit){
  66. $this->error('该规则已存在');
  67. }
  68. $result=Db::name("hotlive_rules")->insert($data);
  69. if($result){
  70. $this->resetcache();
  71. $this->success('添加成功');
  72. }else{
  73. $this->error('添加失败');
  74. }
  75. }
  76. }
  77. /*删除*/
  78. public function del(){
  79. $id = $this->request->param('id');
  80. if($id){
  81. $result=Db::name("hotlive_rules")
  82. ->where("id={$id}")
  83. ->delete();
  84. if($result){
  85. $this->resetcache();
  86. $this->success('删除成功');
  87. }else{
  88. $this->error('删除失败');
  89. }
  90. }else{
  91. $this->error('数据传入失败!');
  92. }
  93. }
  94. /*分类编辑*/
  95. public function edit(){
  96. $id = $this->request->param('id');
  97. if($id){
  98. $info=Db::name("hotlive_rules")
  99. ->where("id={$id}")
  100. ->find();
  101. $configPub=getConfigPub();
  102. $this->assign("name_coin",$configPub['name_coin']);
  103. $this->assign("info",$info);
  104. }else{
  105. $this->error('数据传入失败!');
  106. }
  107. return $this->fetch();
  108. }
  109. /*分类编辑提交*/
  110. public function edit_post(){
  111. if($this->request->isPost()) {
  112. $data = $this->request->param();
  113. $configpub=getConfigPub();
  114. $id=$data["id"];
  115. $coin=$data['coin'];
  116. if(!$coin){
  117. $this->error("请填写".$configpub['name_coin']);
  118. }
  119. if(!is_numeric($coin)){
  120. $this->error($configpub['name_coin']."必须为数字");
  121. }
  122. if($coin<100||$coin>99999999){
  123. $this->error($configpub['name_coin']."在100-99999999之间");
  124. }
  125. if(floor($coin)!=$coin){
  126. $this->error($configpub['name_coin']."必须为整数");
  127. }
  128. if($coin % 10 >0){
  129. $this->error($configpub['name_coin']."数必须为10的倍数");
  130. }
  131. $isexit=Db::name("hotlive_rules")
  132. ->where("id!={$id} and coin={$coin}")
  133. ->find();
  134. if($isexit){
  135. $this->error('该规则已存在');
  136. }
  137. $result=Db::name("hotlive_rules")
  138. ->update($data);
  139. if($result!==false){
  140. $this->resetcache();
  141. $this->success('修改成功');
  142. }else{
  143. $this->error('修改失败');
  144. }
  145. }
  146. }
  147. public function listorder(){
  148. $ids=$this->request->param('listorders');
  149. foreach ($ids as $key => $r) {
  150. $data['orderno'] = $r;
  151. Db::name("hotlive_rules")->where(array('id' => $key))->update($data);
  152. }
  153. $status = true;
  154. if ($status) {
  155. $this->resetcache();
  156. $this->success("排序更新成功!");
  157. } else {
  158. $this->error("排序更新失败!");
  159. }
  160. }
  161. public function resetcache(){
  162. $key='getHotLiveRules';
  163. $rules= Db::name("hotlive_rules")
  164. ->field('id,coin')
  165. ->order('orderno asc')
  166. ->select();
  167. setcaches($key,$rules);
  168. return 1;
  169. }
  170. }