Index.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 会员设置
  7. */
  8. namespace app\ais\controller\vip;
  9. use app\ais\controller\Common;
  10. use app\ais\model\AisVip;
  11. use app\ais\model\AisVipUser;
  12. class Index extends Common{
  13. public $mini_program = [];
  14. public function initialize() {
  15. parent::initialize();
  16. $this->assign('pathMaps',[['name'=>'会员组','url'=>url("vip.index/index")]]);
  17. }
  18. /**
  19. * 列表
  20. */
  21. public function index(){
  22. $view['lists'] = AisVip::where($this->mini_program)->order('sort desc,id desc')->paginate(20);
  23. return view()->assign($view);
  24. }
  25. //编辑
  26. public function edit(){
  27. if(request()->isAjax()){
  28. $param = [
  29. 'name' => $this->request->param('name/s'),
  30. 'price' => $this->request->param('price/f'),
  31. 'rule' => $this->request->param('rule'),
  32. 'fund' => $this->request->param('fund/d',0),
  33. 'open_queue_reward' => $this->request->param('open_queue_reward/f',0),
  34. 'open_share_reward' => $this->request->param('open_share_reward/f',0),
  35. 'pay_queue_reward' => $this->request->param('pay_queue_reward/d',0),
  36. 'pay_share_reward' => $this->request->param('pay_share_reward/d',0),
  37. 'open_store_num' => $this->request->param('open_store_num/d',0),
  38. 'open_vip_num' => $this->request->param('open_vip_num/d',0),
  39. 'is_auto_up' => $this->request->param('is_auto_up/d',0),
  40. 'member_miniapp_id' => $this->member_miniapp_id
  41. ];
  42. $validate = $this->validate($param,'Vip.edit');
  43. if(true !== $validate){
  44. return enjson(0,$validate);
  45. }
  46. $id = $this->request->param('id/d',0);
  47. if($id){
  48. $result = AisVip::where(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id])->update($param);
  49. }else{
  50. $param['update_time'] = time();
  51. $param['member_miniapp_id'] = $this->member_miniapp_id;
  52. $result = AisVip::create($param);
  53. }
  54. if($result){
  55. return enjson(200,['url' => url("vip.index/index")]);
  56. }
  57. return enjson(0);
  58. }else{
  59. $view['info'] = AisVip::where(['id' => $this->request->param('id/d',0)])->find();
  60. return view()->assign($view);
  61. }
  62. }
  63. /**
  64. * 排序
  65. */
  66. public function sort(){
  67. if(request()->isAjax()){
  68. $data = [
  69. 'sort' => $this->request->param('sort/d'),
  70. 'id' => $this->request->param('id/d'),
  71. ];
  72. $validate = $this->validate($data,'Category.sort');
  73. if(true !== $validate){
  74. return json(['code'=>0,'msg'=>$validate]);
  75. }
  76. $result = AisVip::where(['id' => $data['id'],'member_miniapp_id' => $this->member_miniapp_id])->update(['sort'=>$data['sort']]);
  77. if($result){
  78. return enjson(200);
  79. }
  80. return enjson(0);
  81. }
  82. }
  83. /**
  84. * 是否自读升级
  85. * @param integer $id 用户ID
  86. */
  87. public function isAutoUp(int $id){
  88. AisVip::where(['member_miniapp_id' => $this->member_miniapp_id])->update(['is_auto_up' => 1]);
  89. if(AisVip::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->update(['is_auto_up' => 0])){
  90. return enjson(200);
  91. }
  92. return enjson(0);
  93. }
  94. /**
  95. * 是否自读升级
  96. * @param integer $id 用户ID
  97. */
  98. public function isLock(int $id){
  99. $rel = AisVip::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->find();
  100. $rel->is_lock = !$rel->is_lock;
  101. $rel->save();
  102. return enjson(200);
  103. }
  104. //删除
  105. public function delete(int $id){
  106. $rel = AisVipUser::where($this->mini_program)->where(['vip_id' => $id])->find();
  107. if($rel){
  108. return enjson(0,'会员组已有会员开通,建议禁止');
  109. }
  110. $result = AisVip::where($this->mini_program)->where(['id' => $id])->delete();
  111. if($result){
  112. return enjson(200);
  113. }
  114. return enjson(0);
  115. }
  116. }