Svip.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\user;
  12. use app\common\repositories\system\groupData\GroupDataRepository;
  13. use app\common\repositories\system\groupData\GroupRepository;
  14. use app\common\repositories\system\serve\ServeOrderRepository;
  15. use app\common\repositories\user\MemberinterestsRepository;
  16. use app\common\repositories\user\UserBrokerageRepository;
  17. use app\common\repositories\user\UserOrderRepository;
  18. use app\validate\admin\UserBrokerageValidate;
  19. use crmeb\basic\BaseController;
  20. use think\App;
  21. /**
  22. * 付费会员
  23. * app\controller\admin\user
  24. * Svip
  25. */
  26. class Svip extends BaseController
  27. {
  28. protected $repository;
  29. public function __construct(App $app, UserBrokerageRepository $repository)
  30. {
  31. parent::__construct($app);
  32. $this->repository = $repository;
  33. }
  34. /**
  35. * 购买会员套餐的列表
  36. * @param GroupRepository $groupRepository
  37. * @param GroupDataRepository $groupDataRepository
  38. * @return \think\response\Json
  39. * @author Qinii
  40. * @day 2022/11/4
  41. */
  42. public function getTypeLst(GroupRepository $groupRepository, GroupDataRepository $groupDataRepository)
  43. {
  44. [$page, $limit] = $this->getPage();
  45. $group_id = $groupRepository->getSearch(['group_key' => 'svip_pay'])->value('group_id');
  46. $lst = $groupDataRepository->getGroupDataLst(0, intval($group_id), $page, $limit);
  47. return app('json')->success($lst);
  48. }
  49. /**
  50. * 添加够没类型
  51. * @param GroupRepository $groupRepository
  52. * @param GroupDataRepository $groupDataRepository
  53. * @return \think\response\Json
  54. * @author Qinii
  55. * @day 2022/11/4
  56. */
  57. public function createTypeCreateForm(GroupRepository $groupRepository, GroupDataRepository $groupDataRepository)
  58. {
  59. $group_id = $groupRepository->getSearch(['group_key' => 'svip_pay'])->value('group_id');
  60. $data = $groupDataRepository->reSetDataForm($group_id, null, null);
  61. return app('json')->success(formToData($data));
  62. }
  63. /**
  64. * 编辑会员购买类型
  65. * @param $id
  66. * @param GroupRepository $groupRepository
  67. * @param GroupDataRepository $groupDataRepository
  68. * @return \think\response\Json
  69. * @author Qinii
  70. * @day 2022/11/8
  71. */
  72. public function updateTypeCreateForm($id, GroupRepository $groupRepository, GroupDataRepository $groupDataRepository)
  73. {
  74. $group_id = $groupRepository->getSearch(['group_key' => 'svip_pay'])->value('group_id');
  75. $data = $groupDataRepository->reSetDataForm($group_id, $id, null);
  76. return app('json')->success(formToData($data));
  77. }
  78. /**
  79. * 付费会员权益列表
  80. * @return \think\response\Json
  81. * @author Qinii
  82. * @day 2022/11/8
  83. */
  84. public function getInterestsLst(MemberinterestsRepository $memberinterestsRepository)
  85. {
  86. $data = $memberinterestsRepository->getInterestsByLevel($memberinterestsRepository::TYPE_SVIP);
  87. return app('json')->success($data);
  88. }
  89. /**
  90. * 添加类型创建列表
  91. * @return \think\response\Json
  92. * @author Qinii
  93. */
  94. public function createForm()
  95. {
  96. return app('json')->success(formToData($this->repository->form()));
  97. }
  98. /**
  99. * 添加类型创建
  100. * @return \think\response\Json
  101. * @author Qinii
  102. */
  103. public function create()
  104. {
  105. $data = $this->checkParams();
  106. if ($this->repository->fieldExists('brokerage_level', $data['brokerage_level'], null, $data['type'])) {
  107. return app('json')->fail('会员等级已存在');
  108. }
  109. if ($data['type']) {
  110. $data['brokerage_rule'] = [
  111. 'image' => $data['image'],
  112. 'value' => $data['value'],
  113. ];
  114. }
  115. unset($data['image'], $data['value']);
  116. $this->repository->create($data);
  117. return app('json')->success('添加成功');
  118. }
  119. /**
  120. * 修改类型创建
  121. * @param $id
  122. * @return \think\response\Json
  123. * @author Qinii
  124. */
  125. public function updateForm($id)
  126. {
  127. return app('json')->success(formToData($this->repository->form($id)));
  128. }
  129. /**
  130. * 修改类型创建
  131. * @param $id
  132. * @return \think\response\Json
  133. * @author Qinii
  134. */
  135. public function update($id)
  136. {
  137. $id = (int)$id;
  138. $data = $this->checkParams();
  139. if (!$id || !$this->repository->get($id)) {
  140. return app('json')->fail('数据不存在');
  141. }
  142. if ($this->repository->fieldExists('brokerage_level', $data['brokerage_level'], $id, $data['type'])) {
  143. return app('json')->fail('会员等级已存在');
  144. }
  145. if ($data['type']) {
  146. $data['brokerage_rule'] = [
  147. 'image' => $data['image'],
  148. 'value' => $data['value'],
  149. ];
  150. }
  151. unset($data['image'], $data['value']);
  152. $data['brokerage_rule'] = json_encode($data['brokerage_rule'], JSON_UNESCAPED_UNICODE);
  153. $this->repository->update($id, $data);
  154. return app('json')->success('修改成功');
  155. }
  156. /**
  157. * 详情
  158. * @param $id
  159. * @return \think\response\Json
  160. * @author Qinii
  161. */
  162. public function detail($id)
  163. {
  164. $id = (int)$id;
  165. if (!$id || !$brokerage = $this->repository->get($id)) {
  166. return app('json')->fail('数据不存在');
  167. }
  168. return app('json')->success($brokerage->toArray());
  169. }
  170. /**
  171. * 删除
  172. * @param $id
  173. * @return \think\response\Json
  174. * @author Qinii
  175. */
  176. public function delete($id)
  177. {
  178. $id = (int)$id;
  179. if (!$id || !$brokerage = $this->repository->get($id)) {
  180. return app('json')->fail('数据不存在');
  181. }
  182. if ($brokerage->user_num > 0) {
  183. return app('json')->fail('该等级下有数据,不能进行删除操作!');
  184. }
  185. $brokerage->delete();
  186. return app('json')->success('删除成功');
  187. }
  188. /**
  189. * 验证数据
  190. * @return array
  191. * @author Qinii
  192. * @day 2022/11/8
  193. */
  194. public function checkParams()
  195. {
  196. $data = $this->request->params(['brokerage_level', 'brokerage_name', 'brokerage_icon', 'brokerage_rule', 'extension_one', 'extension_two', 'image', 'value', ['type', 0]]);
  197. app()->make(UserBrokerageValidate::class)->check($data);
  198. return $data;
  199. }
  200. /**
  201. * 会员购买记录
  202. * @param UserOrderRepository $userOrderRepository
  203. * @return \think\response\Json
  204. * @author Qinii
  205. * @day 2022/11/12
  206. */
  207. public function payList(UserOrderRepository $userOrderRepository)
  208. {
  209. [$page, $limit] = $this->getPage();
  210. $type = $this->request->param('svip_type', '');
  211. $where = $this->request->params(['pay_type', 'title', 'date', 'nickname', 'keyword']);
  212. if ($type) $where['type'] = $userOrderRepository::TYPE_SVIP . $type;
  213. $data = $userOrderRepository->getList($where, $page, $limit);
  214. return app('json')->success($data);
  215. }
  216. /**
  217. * 会员购买记录
  218. * @param UserOrderRepository $userOrderRepository
  219. * @return \think\response\Json
  220. * @author Qinii
  221. * @day 2022/11/12
  222. */
  223. public function countInfo()
  224. {
  225. $where = $this->request->params(['pay_type', 'title', 'date', 'nickname', 'keyword']);
  226. return app('json')->success(app()->make(UserOrderRepository::class)->countMemberInfo($where));
  227. }
  228. }