ChargerulesController.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 ChargerulesController extends AdminbaseController {
  10. //列表
  11. public function index(){
  12. $lists=Db::name("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. $configpub=getConfigPub();
  37. $name=trim($data['name']);
  38. $money=$data['money'];
  39. $orderno=$data['orderno'];
  40. $coin=$data['coin'];
  41. $coin_ios=$data['coin_ios'];
  42. $product_id=$data['product_id'];
  43. $give=$data['give'];
  44. $coin_paypal=$data['coin_paypal'];
  45. if($name==""){
  46. $this->error("请填写充值规则名称");
  47. }
  48. if(!$money){
  49. $this->error("请填写价格");
  50. }
  51. if(!is_numeric($money)){
  52. $this->error("价格必须为数字");
  53. }
  54. if($money<=0||$money>99999999){
  55. $this->error("价格在0.01-99999999之间");
  56. }
  57. $data['money']=round($money,2);
  58. if(!is_numeric($orderno)){
  59. $this->error("排序号请填写数字");
  60. }
  61. if($orderno<0){
  62. $this->error("排序号必须大于0");
  63. }
  64. if(!$coin){
  65. $this->error("请填写".$configpub['name_coin']);
  66. }
  67. if(!is_numeric($coin)){
  68. $this->error($configpub['name_coin']."必须为数字");
  69. }
  70. if($coin<1||$coin>99999999){
  71. $this->error($configpub['name_coin']."在1-99999999之间");
  72. }
  73. if(floor($coin)!=$coin){
  74. $this->error($configpub['name_coin']."必须为整数");
  75. }
  76. if(!$coin_ios){
  77. $this->error("请填写苹果支付".$configpub['name_coin']);
  78. }
  79. if(!is_numeric($coin_ios)){
  80. $this->error("苹果支付".$configpub['name_coin']."必须为数字");
  81. }
  82. if($coin_ios<1||$coin_ios>99999999){
  83. $this->error("苹果支付".$configpub['name_coin']."在1-99999999之间");
  84. }
  85. if(floor($coin_ios)!=$coin_ios){
  86. $this->error("苹果支付".$configpub['name_coin']."必须为整数");
  87. }
  88. if($product_id==''){
  89. $this->error("苹果项目ID不能为空");
  90. }
  91. if($give==''){
  92. $this->error("赠送".$configpub['name_coin']."不能为空");
  93. }
  94. if(!is_numeric($give)){
  95. $this->error("赠送".$configpub['name_coin']."必须为数字");
  96. }
  97. if($give<0||$give>99999999){
  98. $this->error("赠送".$configpub['name_coin']."在0-99999999之间");
  99. }
  100. if(floor($give)!=$give){
  101. $this->error("赠送".$configpub['name_coin']."必须为整数");
  102. }
  103. if($coin_paypal==''){
  104. $this->error("paypal支付".$configpub['name_coin']."不能为空");
  105. }
  106. if(!is_numeric($coin_paypal)){
  107. $this->error("paypal支付".$configpub['name_coin']."必须为数字");
  108. }
  109. if($coin_paypal<1||$coin_paypal>99999999){
  110. $this->error("paypal支付".$configpub['name_coin']."在1-99999999之间");
  111. }
  112. if(floor($coin_paypal)!=$coin_paypal){
  113. $this->error("paypal支付".$configpub['name_coin']."必须为整数");
  114. }
  115. $isexit=Db::name("charge_rules")
  116. ->where("name='{$name}'")
  117. ->find();
  118. if($isexit){
  119. $this->error('该规则名称已存在');
  120. }
  121. $data['name']=$name;
  122. $data['addtime']=time();
  123. $result=Db::name("charge_rules")->insert($data);
  124. if($result){
  125. $this->resetcache();
  126. $this->success('添加成功');
  127. }else{
  128. $this->error('添加失败');
  129. }
  130. }
  131. }
  132. /*删除*/
  133. public function del(){
  134. $id = $this->request->param('id');
  135. if($id){
  136. $result=Db::name("charge_rules")
  137. ->where("id={$id}")
  138. ->delete();
  139. if($result){
  140. $this->resetcache();
  141. $this->success('删除成功');
  142. }else{
  143. $this->error('删除失败');
  144. }
  145. }else{
  146. $this->error('数据传入失败!');
  147. }
  148. }
  149. /*分类编辑*/
  150. public function edit(){
  151. $id = $this->request->param('id');
  152. if($id){
  153. $info=Db::name("charge_rules")
  154. ->where("id={$id}")
  155. ->find();
  156. $configPub=getConfigPub();
  157. $this->assign("name_coin",$configPub['name_coin']);
  158. $this->assign("info",$info);
  159. }else{
  160. $this->error('数据传入失败!');
  161. }
  162. return $this->fetch();
  163. }
  164. /*分类编辑提交*/
  165. public function edit_post(){
  166. if($this->request->isPost()) {
  167. $data = $this->request->param();
  168. $configpub=getConfigPub();
  169. $id=$data["id"];
  170. $name=$data["name"];
  171. $money=$data['money'];
  172. $orderno=$data["orderno"];
  173. $coin=$data['coin'];
  174. $product_id=$data['product_id'];
  175. $give=$data['give'];
  176. $coin_paypal=$data['coin_paypal'];
  177. $coin_ios=$data['coin_ios'];
  178. if(!trim($name)){
  179. $this->error('分类标题不能为空');
  180. }
  181. $isexit=Db::name("charge_rules")
  182. ->where("id!={$id} and name='{$name}'")
  183. ->find();
  184. if($isexit){
  185. $this->error('该名称已存在');
  186. }
  187. if(!$money){
  188. $this->error("请填写价格");
  189. }
  190. if(!is_numeric($money)){
  191. $this->error("价格必须为数字");
  192. }
  193. if($money<=0||$money>99999999){
  194. $this->error("价格在0.01-99999999之间");
  195. }
  196. $data['money']=round($money,2);
  197. if(!is_numeric($orderno)){
  198. $this->error("排序号请填写数字");
  199. }
  200. if($orderno<0){
  201. $this->error("排序号必须大于0");
  202. }
  203. if(!$coin){
  204. $this->error("请填写".$configpub['name_coin']);
  205. }
  206. if(!is_numeric($coin)){
  207. $this->error($configpub['name_coin']."必须为数字");
  208. }
  209. if($coin<1||$coin>99999999){
  210. $this->error($configpub['name_coin']."在1-99999999之间");
  211. }
  212. if(floor($coin)!=$coin){
  213. $this->error($configpub['name_coin']."必须为整数");
  214. }
  215. if($product_id==''){
  216. $this->error("苹果项目ID不能为空");
  217. }
  218. if($give==''){
  219. $this->error("赠送".$configpub['name_coin']."不能为空");
  220. }
  221. if(!is_numeric($give)){
  222. $this->error("赠送".$configpub['name_coin']."必须为数字");
  223. }
  224. if($give<0||$give>99999999){
  225. $this->error("赠送".$configpub['name_coin']."在0-99999999之间");
  226. }
  227. if(floor($give)!=$give){
  228. $this->error("赠送".$configpub['name_coin']."必须为整数");
  229. }
  230. if(!$coin_ios){
  231. $this->error("请填写苹果支付".$configpub['name_coin']);
  232. }
  233. if(!is_numeric($coin_ios)){
  234. $this->error("苹果支付".$configpub['name_coin']."必须为数字");
  235. }
  236. if($coin_ios<1||$coin_ios>99999999){
  237. $this->error("苹果支付".$configpub['name_coin']."在1-99999999之间");
  238. }
  239. if(floor($coin_ios)!=$coin_ios){
  240. $this->error("苹果支付".$configpub['name_coin']."必须为整数");
  241. }
  242. if($coin_paypal==''){
  243. $this->error("paypal支付".$configpub['name_coin']."不能为空");
  244. }
  245. if(!is_numeric($coin_paypal)){
  246. $this->error("paypal支付".$configpub['name_coin']."必须为数字");
  247. }
  248. if($coin_paypal<1||$coin_paypal>99999999){
  249. $this->error("paypal支付".$configpub['name_coin']."在1-99999999之间");
  250. }
  251. if(floor($coin_paypal)!=$coin_paypal){
  252. $this->error("paypal支付".$configpub['name_coin']."必须为整数");
  253. }
  254. $result=Db::name("charge_rules")
  255. ->update($data);
  256. if($result!==false){
  257. $this->resetcache();
  258. $this->success('修改成功');
  259. }else{
  260. $this->error('修改失败');
  261. }
  262. }
  263. }
  264. public function listorder(){
  265. $ids=$this->request->param('listorders');
  266. foreach ($ids as $key => $r) {
  267. $data['orderno'] = $r;
  268. Db::name("charge_rules")->where(array('id' => $key))->update($data);
  269. }
  270. $status = true;
  271. if ($status) {
  272. $this->resetcache();
  273. $this->success("排序更新成功!");
  274. } else {
  275. $this->error("排序更新失败!");
  276. }
  277. }
  278. public function resetcache(){
  279. $key='getChargeRules';
  280. $rules= Db::name("charge_rules")
  281. ->field('id,coin,coin_ios,money,product_id,give,coin_paypal')
  282. ->order('orderno asc')
  283. ->select();
  284. setcaches($key,$rules);
  285. return 1;
  286. }
  287. }