VipchargerulesController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * vip充值规则
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. use think\db\Query;
  9. class VipchargerulesController extends AdminbaseController {
  10. //列表
  11. public function index(){
  12. $lists=Db::name("vip_charge_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. $this->assign('lists', $lists);
  23. $this->assign('page', $page);
  24. return $this->fetch();
  25. }
  26. /*添加*/
  27. public function add(){
  28. $configPub=getConfigPub();
  29. $this->assign("name_coin",$configPub['name_coin']);
  30. return $this->fetch();
  31. }
  32. /*添加提交*/
  33. public function add_post(){
  34. if($this->request->isPost()) {
  35. $data = $this->request->param();
  36. $name=trim($data['name']);
  37. $days=$data['days'];
  38. $orderno=$data['orderno'];
  39. if($name==""){
  40. $this->error("请填写充值规则名称");
  41. }
  42. if(!is_numeric($days)){
  43. $this->error("vip天数请填写数字");
  44. }
  45. if($days<0){
  46. $this->error("vip天数必须大于0");
  47. }
  48. if(!is_numeric($orderno)){
  49. $this->error("排序规则请填写数字");
  50. }
  51. if($orderno<0){
  52. $this->error("排序规则必须大于0");
  53. }
  54. $isexit=Db::name("vip_charge_rules")
  55. ->where("name='{$name}' or days='{$days}'")
  56. ->find();
  57. if($isexit){
  58. $this->error('vip充值规则已经存在');
  59. }
  60. $data['name']=$name;
  61. $data['addtime']=time();
  62. $result=Db::name("vip_charge_rules")->insert($data);
  63. if($result){
  64. $this->resetcache();
  65. $this->success('添加成功');
  66. }else{
  67. $this->error('添加失败');
  68. }
  69. }
  70. }
  71. /*删除*/
  72. public function del(){
  73. $id = $this->request->param('id');
  74. if($id){
  75. $result=Db::name("vip_charge_rules")
  76. ->where("id={$id}")
  77. ->delete();
  78. if($result){
  79. $this->resetcache();
  80. $this->success('删除成功');
  81. }else{
  82. $this->error('删除失败');
  83. }
  84. }else{
  85. $this->error('数据传入失败!');
  86. }
  87. }
  88. /*分类编辑*/
  89. public function edit(){
  90. $id = $this->request->param('id');
  91. if($id){
  92. $info=Db::name("vip_charge_rules")
  93. ->where("id={$id}")
  94. ->find();
  95. $configPub=getConfigPub();
  96. $this->assign("name_coin",$configPub['name_coin']);
  97. $this->assign("info",$info);
  98. }else{
  99. $this->error('数据传入失败!');
  100. }
  101. return $this->fetch();
  102. }
  103. /*分类编辑提交*/
  104. public function edit_post(){
  105. if($this->request->isPost()) {
  106. $data = $this->request->param();
  107. $id=$data["id"];
  108. $name=$data["name"];
  109. $orderno=$data["orderno"];
  110. $days=$data["days"];
  111. if(!trim($name)){
  112. $this->error('分类标题不能为空');
  113. }
  114. if(!is_numeric($orderno)){
  115. $this->error("排序号请填写数字");
  116. }
  117. if($orderno<0){
  118. $this->error("排序号必须大于0");
  119. }
  120. if(!is_numeric($days)){
  121. $this->error("充值天数请填写数字");
  122. }
  123. if($days<0){
  124. $this->error("充值天数必须大于0");
  125. }
  126. $isexit=Db::name("vip_charge_rules")
  127. ->where("id!={$id} and (name='{$name}' or days='{$days}')")
  128. ->find();
  129. if($isexit){
  130. $this->error('vip充值规则已经存在');
  131. }
  132. $result=Db::name("vip_charge_rules")
  133. ->update($data);
  134. if($result!==false){
  135. $this->resetcache();
  136. $this->success('修改成功');
  137. }else{
  138. $this->error('修改失败');
  139. }
  140. }
  141. }
  142. public function listorder(){
  143. $ids=$this->request->param('listorders');
  144. foreach ($ids as $key => $r) {
  145. $data['orderno'] = $r;
  146. Db::name("vip_charge_rules")->where(array('id' => $key))->update($data);
  147. }
  148. $status = true;
  149. if ($status) {
  150. $this->resetcache();
  151. $this->success("排序更新成功!");
  152. } else {
  153. $this->error("排序更新失败!");
  154. }
  155. }
  156. public function resetcache(){
  157. $key='getVipChargeRules';
  158. $rules= Db::name("vip_charge_rules")
  159. ->field('id,name,name_en,money,days,coin')
  160. ->order('orderno asc')
  161. ->select();
  162. setcaches($key,$rules);
  163. return 1;
  164. }
  165. }