MemberShip.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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 MemberShip
  20. * @package app\admin\controller\user
  21. */
  22. class MemberShip extends AuthController
  23. {
  24. public function index()
  25. {
  26. return $this->fetch();
  27. }
  28. /**
  29. * 会员列表
  30. */
  31. public function membership_vip_list()
  32. {
  33. $where = parent::getMore([
  34. ['page', 1],
  35. ['limit', 20],
  36. ['is_publish', ''],
  37. ['title', ''],
  38. ]);
  39. return Json::successlayui(MembershipModel::getSytemVipList($where));
  40. }
  41. public function add_vip($id = 0)
  42. {
  43. $membership = [];
  44. if ($id) {
  45. $membership = MembershipModel::get($id);
  46. if ($membership) $membership['sorts'] = $membership['sort'];
  47. if ($membership['is_free']) $membership['free_day'] = $membership['vip_day'];
  48. }
  49. $this->assign(['id' => $id, 'membership' => json_encode($membership)]);
  50. return $this->fetch();
  51. }
  52. /**编辑会员
  53. * @param int $id
  54. */
  55. public function save_sytem_vip($id = 0)
  56. {
  57. $post = parent::postMore([
  58. ['title', ''],
  59. ['img', ''],
  60. ['vip_day', 0],
  61. ['free_day', 0],
  62. ['original_price', 0],
  63. ['price', 0],
  64. ['sort', 0],
  65. ['is_permanent', 0],
  66. ['is_publish', 0],
  67. ['is_free', 0],
  68. ['is_alone', 0],
  69. ['brokerage_ratio', 0],
  70. ['brokerage_two', 0]
  71. ]);
  72. if ($post['title'] == '') return Json::fail('请输入会员标题');
  73. if ($post['is_permanent'] == 0 && $post['vip_day'] <= 0 && $post['is_free'] == 0) return Json::fail('会员有有效期时,请设置会员有效期');
  74. if ($post['is_free'] == 1 && $post['free_day'] <= 0) return Json::fail('免费会员有有效期时,请设置会员有效期');
  75. if (bcsub($post['original_price'], 0, 0) < 0) return Json::fail('请输入会员原价');
  76. if (bcsub($post['price'], 0, 0) < 0) return Json::fail('请输入会员原价');
  77. if ($post['is_free'] == 1) {
  78. $post['vip_day'] = $post['free_day'];
  79. $post['is_alone'] = 0;
  80. $post['brokerage_ratio'] = 0;
  81. $post['brokerage_two'] = 0;
  82. unset($post['free_day']);
  83. }
  84. if ($post['is_alone'] && bcadd($post['brokerage_ratio'], $post['brokerage_two'], 2) > 100) return Json::fail('两级返佣比例之和不能大于100');
  85. MembershipModel::beginTrans();
  86. try {
  87. if ($id) {
  88. MembershipModel::update($post, ['id' => $id]);
  89. MembershipModel::commitTrans();
  90. return Json::successful('修改成功');
  91. } else {
  92. $post['add_time'] = time();
  93. MembershipModel::set($post);
  94. MembershipModel::commitTrans();
  95. return Json::successful('添加成功');
  96. }
  97. } catch (\Exception $e) {
  98. MembershipModel::rollbackTrans();
  99. return Json::fail($e->getMessage());
  100. }
  101. }
  102. /**会员状态设置
  103. * @param string $is_publish
  104. * @param string $id
  105. */
  106. public function set_publish($is_publish = '', $id = '')
  107. {
  108. if ($is_publish == '' || $id == '') return Json::fail('缺少参数');
  109. $res = parent::getDataModification('ship', $id, 'is_publish', $is_publish);
  110. if ($res)
  111. return Json::successful($is_publish == 1 ? '发布成功' : '隐藏成功');
  112. else
  113. return Json::fail($is_publish == 1 ? '发布失败' : '隐藏失败');
  114. }
  115. /**会员删除
  116. * @param string $id
  117. */
  118. public function delete($id = '')
  119. {
  120. if ($id == '') return Json::fail('缺少参数');
  121. $res = parent::getDataModification('ship', $id, 'is_del', 1);
  122. if ($res)
  123. return Json::successful('删除成功');
  124. else
  125. return Json::fail('删除失败');
  126. }
  127. }