| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\admin\user;
- use app\common\repositories\system\groupData\GroupDataRepository;
- use app\common\repositories\system\groupData\GroupRepository;
- use app\common\repositories\system\serve\ServeOrderRepository;
- use app\common\repositories\user\MemberinterestsRepository;
- use app\common\repositories\user\UserBrokerageRepository;
- use app\common\repositories\user\UserOrderRepository;
- use app\validate\admin\UserBrokerageValidate;
- use crmeb\basic\BaseController;
- use think\App;
- /**
- * 付费会员
- * app\controller\admin\user
- * Svip
- */
- class Svip extends BaseController
- {
- protected $repository;
- public function __construct(App $app, UserBrokerageRepository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- }
- /**
- * 购买会员套餐的列表
- * @param GroupRepository $groupRepository
- * @param GroupDataRepository $groupDataRepository
- * @return \think\response\Json
- * @author Qinii
- * @day 2022/11/4
- */
- public function getTypeLst(GroupRepository $groupRepository, GroupDataRepository $groupDataRepository)
- {
- [$page, $limit] = $this->getPage();
- $group_id = $groupRepository->getSearch(['group_key' => 'svip_pay'])->value('group_id');
- $lst = $groupDataRepository->getGroupDataLst(0, intval($group_id), $page, $limit);
- return app('json')->success($lst);
- }
- /**
- * 添加够没类型
- * @param GroupRepository $groupRepository
- * @param GroupDataRepository $groupDataRepository
- * @return \think\response\Json
- * @author Qinii
- * @day 2022/11/4
- */
- public function createTypeCreateForm(GroupRepository $groupRepository, GroupDataRepository $groupDataRepository)
- {
- $group_id = $groupRepository->getSearch(['group_key' => 'svip_pay'])->value('group_id');
- $data = $groupDataRepository->reSetDataForm($group_id, null, null);
- return app('json')->success(formToData($data));
- }
- /**
- * 编辑会员购买类型
- * @param $id
- * @param GroupRepository $groupRepository
- * @param GroupDataRepository $groupDataRepository
- * @return \think\response\Json
- * @author Qinii
- * @day 2022/11/8
- */
- public function updateTypeCreateForm($id, GroupRepository $groupRepository, GroupDataRepository $groupDataRepository)
- {
- $group_id = $groupRepository->getSearch(['group_key' => 'svip_pay'])->value('group_id');
- $data = $groupDataRepository->reSetDataForm($group_id, $id, null);
- return app('json')->success(formToData($data));
- }
- /**
- * 付费会员权益列表
- * @return \think\response\Json
- * @author Qinii
- * @day 2022/11/8
- */
- public function getInterestsLst(MemberinterestsRepository $memberinterestsRepository)
- {
- $data = $memberinterestsRepository->getInterestsByLevel($memberinterestsRepository::TYPE_SVIP);
- return app('json')->success($data);
- }
- /**
- * 添加类型创建列表
- * @return \think\response\Json
- * @author Qinii
- */
- public function createForm()
- {
- return app('json')->success(formToData($this->repository->form()));
- }
- /**
- * 添加类型创建
- * @return \think\response\Json
- * @author Qinii
- */
- public function create()
- {
- $data = $this->checkParams();
- if ($this->repository->fieldExists('brokerage_level', $data['brokerage_level'], null, $data['type'])) {
- return app('json')->fail('会员等级已存在');
- }
- if ($data['type']) {
- $data['brokerage_rule'] = [
- 'image' => $data['image'],
- 'value' => $data['value'],
- ];
- }
- unset($data['image'], $data['value']);
- $this->repository->create($data);
- return app('json')->success('添加成功');
- }
- /**
- * 修改类型创建
- * @param $id
- * @return \think\response\Json
- * @author Qinii
- */
- public function updateForm($id)
- {
- return app('json')->success(formToData($this->repository->form($id)));
- }
- /**
- * 修改类型创建
- * @param $id
- * @return \think\response\Json
- * @author Qinii
- */
- public function update($id)
- {
- $id = (int)$id;
- $data = $this->checkParams();
- if (!$id || !$this->repository->get($id)) {
- return app('json')->fail('数据不存在');
- }
- if ($this->repository->fieldExists('brokerage_level', $data['brokerage_level'], $id, $data['type'])) {
- return app('json')->fail('会员等级已存在');
- }
- if ($data['type']) {
- $data['brokerage_rule'] = [
- 'image' => $data['image'],
- 'value' => $data['value'],
- ];
- }
- unset($data['image'], $data['value']);
- $data['brokerage_rule'] = json_encode($data['brokerage_rule'], JSON_UNESCAPED_UNICODE);
- $this->repository->update($id, $data);
- return app('json')->success('修改成功');
- }
- /**
- * 详情
- * @param $id
- * @return \think\response\Json
- * @author Qinii
- */
- public function detail($id)
- {
- $id = (int)$id;
- if (!$id || !$brokerage = $this->repository->get($id)) {
- return app('json')->fail('数据不存在');
- }
- return app('json')->success($brokerage->toArray());
- }
- /**
- * 删除
- * @param $id
- * @return \think\response\Json
- * @author Qinii
- */
- public function delete($id)
- {
- $id = (int)$id;
- if (!$id || !$brokerage = $this->repository->get($id)) {
- return app('json')->fail('数据不存在');
- }
- if ($brokerage->user_num > 0) {
- return app('json')->fail('该等级下有数据,不能进行删除操作!');
- }
- $brokerage->delete();
- return app('json')->success('删除成功');
- }
- /**
- * 验证数据
- * @return array
- * @author Qinii
- * @day 2022/11/8
- */
- public function checkParams()
- {
- $data = $this->request->params(['brokerage_level', 'brokerage_name', 'brokerage_icon', 'brokerage_rule', 'extension_one', 'extension_two', 'image', 'value', ['type', 0]]);
- app()->make(UserBrokerageValidate::class)->check($data);
- return $data;
- }
- /**
- * 会员购买记录
- * @param UserOrderRepository $userOrderRepository
- * @return \think\response\Json
- * @author Qinii
- * @day 2022/11/12
- */
- public function payList(UserOrderRepository $userOrderRepository)
- {
- [$page, $limit] = $this->getPage();
- $type = $this->request->param('svip_type', '');
- $where = $this->request->params(['pay_type', 'title', 'date', 'nickname', 'keyword']);
- if ($type) $where['type'] = $userOrderRepository::TYPE_SVIP . $type;
- $data = $userOrderRepository->getList($where, $page, $limit);
- return app('json')->success($data);
- }
- /**
- * 会员购买记录
- * @param UserOrderRepository $userOrderRepository
- * @return \think\response\Json
- * @author Qinii
- * @day 2022/11/12
- */
- public function countInfo()
- {
- $where = $this->request->params(['pay_type', 'title', 'date', 'nickname', 'keyword']);
- return app('json')->success(app()->make(UserOrderRepository::class)->countMemberInfo($where));
- }
- }
|