ChargerulesController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 ChargerulesController extends AdminbaseController {
  18. public function index(){
  19. $lists = Db::name("charge_rules")
  20. ->order("list_order asc")
  21. ->paginate(20);
  22. $page = $lists->render();
  23. $this->assign('lists', $lists);
  24. $this->assign("page", $page);
  25. return $this->fetch();
  26. }
  27. public function del(){
  28. $id = $this->request->param('id', 0, 'intval');
  29. $rs = DB::name('charge_rules')->where("id={$id}")->delete();
  30. if(!$rs){
  31. $this->error("删除失败!");
  32. }
  33. $this->resetcache();
  34. $this->success("删除成功!",url("Chargerules/index"));
  35. }
  36. //排序
  37. public function listOrder() {
  38. $model = DB::name('charge_rules');
  39. parent::listOrders($model);
  40. $this->resetcache();
  41. $this->success("排序更新成功!");
  42. }
  43. public function add(){
  44. $configpub=getConfigPub();
  45. $this->assign('name_coin',$configpub['name_coin']);
  46. return $this->fetch();
  47. }
  48. public function addPost(){
  49. if ($this->request->isPost()) {
  50. $data = $this->request->param();
  51. $configpub=getConfigPub();
  52. $name=$data['name'];
  53. $money=$data['money'];
  54. $coin=$data['coin'];
  55. $give=$data['give'];
  56. if(!$name){
  57. $this->error("请填写名称");
  58. }
  59. if(!$money){
  60. $this->error("请填写价格");
  61. }
  62. if(!is_numeric($money)){
  63. $this->error("价格必须为数字");
  64. }
  65. if($money<=0||$money>99999999){
  66. $this->error("价格在0.01-99999999之间");
  67. }
  68. $data['money']=round($money,2);
  69. if(!$coin){
  70. $this->error("请填写".$configpub['name_coin']);
  71. }
  72. if(!is_numeric($coin)){
  73. $this->error($configpub['name_coin']."必须为数字");
  74. }
  75. if($coin<1||$coin>99999999){
  76. $this->error($configpub['name_coin']."在1-99999999之间");
  77. }
  78. if(floor($coin)!=$coin){
  79. $this->error($configpub['name_coin']."必须为整数");
  80. }
  81. if($give==''){
  82. $this->error("赠送".$configpub['name_coin']."不能为空");
  83. }
  84. if(!is_numeric($give)){
  85. $this->error("赠送".$configpub['name_coin']."必须为数字");
  86. }
  87. if($give<0||$give>99999999){
  88. $this->error("赠送".$configpub['name_coin']."在0-99999999之间");
  89. }
  90. if(floor($give)!=$give){
  91. $this->error("赠送".$configpub['name_coin']."必须为整数");
  92. }
  93. $data['addtime']=time();
  94. $id = DB::name('charge_rules')->insertGetId($data);
  95. if(!$id){
  96. $this->error("添加失败!");
  97. }
  98. $this->resetcache();
  99. $this->success("添加成功!");
  100. }
  101. }
  102. public function edit(){
  103. $id = $this->request->param('id', 0, 'intval');
  104. $data=Db::name('charge_rules')
  105. ->where("id={$id}")
  106. ->find();
  107. if(!$data){
  108. $this->error("信息错误");
  109. }
  110. $configpub=getConfigPub();
  111. $this->assign('name_coin',$configpub['name_coin']);
  112. $this->assign('data', $data);
  113. return $this->fetch();
  114. }
  115. public function editPost(){
  116. if ($this->request->isPost()) {
  117. $data = $this->request->param();
  118. $configpub=getConfigPub();
  119. $name=$data['name'];
  120. $money=$data['money'];
  121. $coin=$data['coin'];
  122. if(!$name){
  123. $this->error("请填写名称");
  124. }
  125. if(!$money){
  126. $this->error("请填写价格");
  127. }
  128. if(!is_numeric($money)){
  129. $this->error("价格必须为数字");
  130. }
  131. if($money<=0||$money>99999999){
  132. $this->error("价格在0.01-99999999之间");
  133. }
  134. $data['money']=round($money,2);
  135. if(!$coin){
  136. $this->error("请填写".$configpub['name_coin']);
  137. }
  138. if(!is_numeric($coin)){
  139. $this->error($configpub['name_coin']."必须为数字");
  140. }
  141. if($coin<1||$coin>99999999){
  142. $this->error($configpub['name_coin']."在1-99999999之间");
  143. }
  144. if(floor($coin)!=$coin){
  145. $this->error($configpub['name_coin']."必须为整数");
  146. }
  147. $give=$data['give'];
  148. //-----------------
  149. if($give==''){
  150. $this->error("赠送".$configpub['name_coin']."不能为空");
  151. }
  152. if(!is_numeric($give)){
  153. $this->error("赠送".$configpub['name_coin']."必须为数字");
  154. }
  155. if($give<0||$give>99999999){
  156. $this->error("赠送".$configpub['name_coin']."在0-99999999之间");
  157. }
  158. if(floor($give)!=$give){
  159. $this->error("赠送".$configpub['name_coin']."必须为整数");
  160. }
  161. $data['uptime']=time();
  162. $rs = DB::name('charge_rules')->update($data);
  163. if($rs===false){
  164. $this->error("修改失败!");
  165. }
  166. $this->resetcache();
  167. $this->success("修改成功!");
  168. }
  169. }
  170. public function resetcache(){
  171. $key='getChargeRules';
  172. $rules= DB::name("charge_rules")
  173. ->field('id,coin,money,give')
  174. ->order('list_order asc')
  175. ->select();
  176. if($rules){
  177. setcaches($key,$rules);
  178. }else{
  179. delcache($key);
  180. }
  181. return 1;
  182. }
  183. }