Viprecharge.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\main\constants\AdminConstants;
  5. use app\main\constants\PayConstants;
  6. use app\main\service\AdminService;
  7. use app\main\service\GoodsService;
  8. use think\Exception;
  9. /**
  10. * 渠道VIP充值配置
  11. *
  12. * @icon fa fa-circle-o
  13. */
  14. class Viprecharge extends Backend
  15. {
  16. public function index()
  17. {
  18. if ($this->request->isPost()) {
  19. $params = $this->request->post("row/a");
  20. switch ($params['fun']) {
  21. case 'vip_recharge':
  22. $this->saveVipRecharge($params);
  23. break;
  24. case 'custom_goods':
  25. $this->saveCustomGoods($params);
  26. break;
  27. case 'get_custom_goods_list':
  28. //获取充值商品列表
  29. $this->getCustomGoodsList();
  30. break;
  31. default:
  32. $this->error('未知类型的保存');
  33. break;
  34. }
  35. }
  36. $adminId = $this->auth->id;
  37. $adminConfig = model('AdminConfig')->getAdminInfoAll($adminId);
  38. //检查是否是测试号
  39. if ($this->group == AdminConstants::ADMIN_GROUP_ID_AGENT) {
  40. $is_test = AdminService::instance()->checkIsTestChannel($this->auth->id, null);
  41. } else {
  42. $is_test = AdminService::instance()->checkIsTestChannel(null, $this->auth->id);
  43. }
  44. $goods_list = model('Goods')->getGoodsList(PayConstants::BUSINESS_WECHAT, PayConstants::GOODS_CATEGORY_RECHARGE, PayConstants::GOODS_TYPE_VIP, $is_test);
  45. $vip_custom_goods_list = [];
  46. foreach ($goods_list as $item) {
  47. if ($item['show_type'] == PayConstants::GOODS_SHOW_TYPE_ALL) {
  48. $vip_custom_goods_list[] = $item;
  49. }
  50. }
  51. $customGoodsList = GoodsService::instance()->getCustomGoodsList($adminId);
  52. $this->assignconfig('customGoodsList', json_encode($customGoodsList));
  53. $this->assign('custom_goods', $adminConfig['custom_goods']);
  54. $this->assign('goods_list', $goods_list);
  55. $this->assign('vip_custom_goods_list', $vip_custom_goods_list);
  56. $this->assign('vip_pay_tpl', $adminConfig['vip_pay_tpl'] ?? 'default.html');
  57. $this->assign('vip_goods_id', $adminConfig['vip_goods_id'] ?? null);
  58. $this->assign('vip_goods_id_custom', $adminConfig['vip_goods_id_custom'] ?? '');
  59. $this->assign('vip_state', $adminConfig['vip_state'] ?? 0);
  60. $this->assign('vip_custom_money', $adminConfig['vip_custom_money'] ?? 0);
  61. return $this->fetch();
  62. }
  63. private function saveVipRecharge($params)
  64. {
  65. unset($params['fun']);
  66. //检查是否有商品
  67. if (!$params['vip_goods_id'] && $params['vip_state']) {
  68. $this->error('请选择VIP充值商品');
  69. }
  70. //更新
  71. $vipStateUp = model('AdminConfig')->where('admin_id', $this->auth->id)->update($params);
  72. if ($vipStateUp === false) {
  73. $this->error('操作失败');
  74. }
  75. //删除缓存
  76. model('AdminConfig')->delAdminInfoAllCache($this->auth->id);
  77. $this->success('操作成功');
  78. }
  79. private function saveCustomGoods($params)
  80. {
  81. $adminId = $this->auth->id;
  82. if (empty($params['goods_id'])) {
  83. $this->error('请添加一个商品');
  84. }
  85. $goodsIds = $params['goods_id'];
  86. try {
  87. GoodsService::instance()->saveChannelGoodsList($goodsIds, $adminId, 0, $params['default'] ?? 0);
  88. } catch (Exception $e) {
  89. $this->error($e->getMessage());
  90. }
  91. $this->success('操作成功');
  92. }
  93. public function reset()
  94. {
  95. if ($this->request->isPost()) {
  96. $adminId = $this->auth->id;
  97. try {
  98. GoodsService::instance()->delChannelGoodsList($adminId);
  99. $defaultGoodsList = GoodsService::instance()->getDefaultGoodsList();
  100. $this->success('操作成功', '', $defaultGoodsList);
  101. } catch (Exception $e) {
  102. $this->error($e->getMessage());
  103. }
  104. $this->success('操作成功');
  105. }
  106. }
  107. /**
  108. * 获取商品列表
  109. *
  110. * return String 商品列表json
  111. */
  112. private function getCustomGoodsList()
  113. {
  114. $adminId = $this->auth->id;
  115. $customGoodsList = GoodsService::instance()->getCustomGoodsList($adminId);
  116. $this->success('', null, $customGoodsList);
  117. }
  118. }