123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\main\constants\AdminConstants;
- use app\main\constants\PayConstants;
- use app\main\service\AdminService;
- use app\main\service\GoodsService;
- use think\Exception;
- /**
- * 渠道VIP充值配置
- *
- * @icon fa fa-circle-o
- */
- class Viprecharge extends Backend
- {
- public function index()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- switch ($params['fun']) {
- case 'vip_recharge':
- $this->saveVipRecharge($params);
- break;
- case 'custom_goods':
- $this->saveCustomGoods($params);
- break;
- case 'get_custom_goods_list':
- //获取充值商品列表
- $this->getCustomGoodsList();
- break;
- default:
- $this->error('未知类型的保存');
- break;
- }
- }
- $adminId = $this->auth->id;
- $adminConfig = model('AdminConfig')->getAdminInfoAll($adminId);
- //检查是否是测试号
- if ($this->group == AdminConstants::ADMIN_GROUP_ID_AGENT) {
- $is_test = AdminService::instance()->checkIsTestChannel($this->auth->id, null);
- } else {
- $is_test = AdminService::instance()->checkIsTestChannel(null, $this->auth->id);
- }
- $goods_list = model('Goods')->getGoodsList(PayConstants::BUSINESS_WECHAT, PayConstants::GOODS_CATEGORY_RECHARGE, PayConstants::GOODS_TYPE_VIP, $is_test);
- $vip_custom_goods_list = [];
- foreach ($goods_list as $item) {
- if ($item['show_type'] == PayConstants::GOODS_SHOW_TYPE_ALL) {
- $vip_custom_goods_list[] = $item;
- }
- }
- $customGoodsList = GoodsService::instance()->getCustomGoodsList($adminId);
- $this->assignconfig('customGoodsList', json_encode($customGoodsList));
- $this->assign('custom_goods', $adminConfig['custom_goods']);
- $this->assign('goods_list', $goods_list);
- $this->assign('vip_custom_goods_list', $vip_custom_goods_list);
- $this->assign('vip_pay_tpl', $adminConfig['vip_pay_tpl'] ?? 'default.html');
- $this->assign('vip_goods_id', $adminConfig['vip_goods_id'] ?? null);
- $this->assign('vip_goods_id_custom', $adminConfig['vip_goods_id_custom'] ?? '');
- $this->assign('vip_state', $adminConfig['vip_state'] ?? 0);
- $this->assign('vip_custom_money', $adminConfig['vip_custom_money'] ?? 0);
- return $this->fetch();
- }
- private function saveVipRecharge($params)
- {
- unset($params['fun']);
- //检查是否有商品
- if (!$params['vip_goods_id'] && $params['vip_state']) {
- $this->error('请选择VIP充值商品');
- }
- //更新
- $vipStateUp = model('AdminConfig')->where('admin_id', $this->auth->id)->update($params);
- if ($vipStateUp === false) {
- $this->error('操作失败');
- }
- //删除缓存
- model('AdminConfig')->delAdminInfoAllCache($this->auth->id);
- $this->success('操作成功');
- }
- private function saveCustomGoods($params)
- {
- $adminId = $this->auth->id;
- if (empty($params['goods_id'])) {
- $this->error('请添加一个商品');
- }
- $goodsIds = $params['goods_id'];
- try {
- GoodsService::instance()->saveChannelGoodsList($goodsIds, $adminId, 0, $params['default'] ?? 0);
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('操作成功');
- }
- public function reset()
- {
- if ($this->request->isPost()) {
- $adminId = $this->auth->id;
- try {
- GoodsService::instance()->delChannelGoodsList($adminId);
- $defaultGoodsList = GoodsService::instance()->getDefaultGoodsList();
- $this->success('操作成功', '', $defaultGoodsList);
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('操作成功');
- }
- }
- /**
- * 获取商品列表
- *
- * return String 商品列表json
- */
- private function getCustomGoodsList()
- {
- $adminId = $this->auth->id;
- $customGoodsList = GoodsService::instance()->getCustomGoodsList($adminId);
- $this->success('', null, $customGoodsList);
- }
- }
|