MemberShip.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\user;
  12. use app\admin\controller\AuthController;
  13. use service\JsonService as Json;
  14. use service\FormBuilder as Form;
  15. use think\Url;
  16. use app\admin\model\user\MemberShip as MembershipModel;
  17. /**
  18. * 会员设置控制器
  19. * Class User
  20. * @package app\admin\controller\user
  21. */
  22. class MemberShip extends AuthController
  23. {
  24. public function index()
  25. {
  26. return $this->fetch();
  27. }
  28. public function membership_vip_list()
  29. {
  30. $where = parent::getMore([
  31. ['page', 1],
  32. ['limit', 20],
  33. ['is_publish', ''],
  34. ['title', ''],
  35. ]);
  36. return Json::successlayui(MembershipModel::getSytemVipList($where));
  37. }
  38. public function add_vip($id = 0)
  39. {
  40. $membership =[];
  41. if ($id) {
  42. $membership = MembershipModel::get($id);
  43. if ($membership) $membership['sorts'] = $membership['sort'];
  44. if ($membership['is_free']) $membership['free_day'] = $membership['vip_day'];
  45. }
  46. $this->assign('id',$id);
  47. $this->assign('membership',json_encode($membership));
  48. return $this->fetch();
  49. }
  50. public function save_sytem_vip($id = 0)
  51. {
  52. $post = parent::postMore([
  53. ['title', ''],
  54. ['vip_day', 0],
  55. ['free_day', 0],
  56. ['original_price', 0],
  57. ['price', 0],
  58. ['sort', 0],
  59. ['is_permanent', 0],
  60. ['is_publish', 0],
  61. ['is_free', 0],
  62. ['add_time', time()],
  63. ]);
  64. if ($post['title'] == '') $this->failed('请输入会员标题');
  65. if ($post['is_permanent'] == 0 && $post['vip_day'] <= 0 && $post['is_free'] ==0) $this->failed('会员有有效期时,请设置会员有效期');
  66. if ($post['is_free'] == 1 && $post['free_day'] <= 0) $this->failed('免费会员有有效期时,请设置会员有效期');
  67. if (bcsub($post['original_price'],0,0) < 0) $this->failed('请输入会员原价');
  68. if (bcsub($post['price'],0,0) < 0) $this->failed('请输入会员原价');
  69. if($post['is_free'] == 1){
  70. $post['vip_day']=$post['free_day'];
  71. unset($post['free_day']);
  72. }
  73. MembershipModel::beginTrans();
  74. try {
  75. if ($id) {
  76. $vipinfo = MembershipModel::get($id);
  77. unset($post['add_time']);
  78. MembershipModel::update($post, ['id' => $id]);
  79. MembershipModel::commitTrans();
  80. return Json::successful('修改成功');
  81. } else {
  82. MembershipModel::set($post);
  83. MembershipModel::commitTrans();
  84. return Json::successful('添加成功');
  85. }
  86. } catch (\Exception $e) {
  87. MembershipModel::rollbackTrans();
  88. return Json::fail($e->getMessage());
  89. }
  90. }
  91. public function set_publish($is_publish = '', $id = '')
  92. {
  93. if ($is_publish == '' || $id == '') return Json::fail('缺少参数');
  94. if (MembershipModel::update(['is_publish' => $is_publish], ['id' => $id]))
  95. return Json::successful($is_publish == 1 ? '发布成功' : '隐藏成功');
  96. else
  97. return Json::fail($is_publish == 1 ? '发布失败' : '隐藏失败');
  98. }
  99. public function delete($id = '')
  100. {
  101. if ($id == '') return Json::fail('缺少参数');
  102. if (MembershipModel::update(['is_del' => 1], ['id' => $id]))
  103. return Json::successful('删除成功');
  104. else
  105. return Json::fail('删除失败');
  106. }
  107. }