截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Recharge.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\basics\AdminBase;
  4. use app\admin\logic\RechargeLogic;
  5. use app\common\server\JsonServer;
  6. use app\admin\validate\RechargeTemplateValidate;
  7. use think\exception\ValidateException;
  8. class Recharge extends AdminBase
  9. {
  10. public function lists(){
  11. if($this->request->isAjax()){
  12. $get = $this->request->get();
  13. if($get['type'] == 1){ // 充值方案
  14. $list = RechargeLogic::templatelists($get['type']);
  15. }else{ // 充值配置
  16. $list = RechargeLogic::getRechargeConfig();
  17. }
  18. return JsonServer::success('', $list);
  19. }
  20. return view();
  21. }
  22. public function add(){
  23. if ($this->request->isAjax()){
  24. $post = $this->request->post();
  25. try{
  26. validate(RechargeTemplateValidate::class)->check($post);
  27. }catch(ValidateException $e) {
  28. return JsonServer::error($e->getError());
  29. }
  30. $result = RechargeLogic::add($post);
  31. if ($result === true){
  32. return JsonServer::success('新增成功');
  33. }
  34. return JsonServer::error(RechargeLogic::getError());
  35. }
  36. return view();
  37. }
  38. public function changeFields(){
  39. $table = 'recharge_template';
  40. $pk_name = 'id';
  41. $pk_value = $this->request->get('id');
  42. $field = $this->request->get('field');
  43. $field_value = $this->request->get('value');
  44. $result = RechargeLogic::changeTableValue($table,$pk_name,$pk_value,$field,$field_value);
  45. if($result){
  46. return JsonServer::success('修改成功');
  47. }
  48. return JsonServer::error('修改失败');
  49. }
  50. public function edit($id){
  51. if ($this->request->isAjax()){
  52. $post = $this->request->post();
  53. try{
  54. validate(RechargeTemplateValidate::class)->check($post);
  55. }catch(ValidateException $e) {
  56. return JsonServer::error($e->getError());
  57. }
  58. $result = RechargeLogic::edit($post);
  59. if ($result === true){
  60. return JsonServer::success('编辑成功');
  61. }
  62. return JsonServer::error('编辑失败');
  63. }
  64. $info = RechargeLogic::getRechargeTemplate($id);
  65. return view('', [
  66. 'info' => $info
  67. ]);
  68. }
  69. public function del($id)
  70. {
  71. if ($this->request->isAjax()) {
  72. $result = RechargeLogic::del($id);
  73. if ($result) {
  74. return JsonServer::success('删除成功');
  75. }
  76. return JsonServer::error('删除失败');
  77. }
  78. }
  79. public function setRecharge(){
  80. if($this->request->isAjax()){
  81. $post = $this->request->post();
  82. if($post['give_growth'] < 0) {
  83. return JsonServer::error('赠送成长值不能小于0');
  84. }
  85. if($post['min_money'] < 0) {
  86. return JsonServer::error('最低充值金额不能小于0');
  87. }
  88. RechargeLogic::setRecharge($post);
  89. return JsonServer::success('设置成功');
  90. }
  91. }
  92. }