123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\adminapi\controller\v1\setting;
- use crmeb\exceptions\AdminException;
- use app\services\other\CacheServices;
- use think\facade\App;
- use app\adminapi\controller\AuthController;
- use app\services\system\config\SystemGroupDataServices;
- use app\services\system\config\SystemGroupServices;
- /**
- * 数据管理
- * Class SystemGroupData
- * @package app\adminapi\controller\v1\setting
- */
- class SystemGroupData extends AuthController
- {
- /**
- * 构造方法
- * SystemGroupData constructor.
- * @param App $app
- * @param SystemGroupDataServices $services
- */
- public function __construct(App $app, SystemGroupDataServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
- /**
- * 获取数据列表头
- * @return mixed
- */
- public function header(SystemGroupServices $services)
- {
- [$gid, $config_name] = $this->request->getMore([
- ['gid', 0],
- ['config_name', '']
- ], true);
- if (!$gid && !$config_name) return app('json')->fail(100100);
- if (!$gid) {
- $gid = $services->value(['config_name' => $config_name], 'id');
- }
- return app('json')->success($services->getGroupDataTabHeader($gid));
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index(SystemGroupServices $group)
- {
- $where = $this->request->getMore([
- ['gid', 0],
- ['status', ''],
- ['config_name', '']
- ]);
- if (!$where['gid'] && !$where['config_name']) return app('json')->fail(100100);
- if (!$where['gid']) {
- $where['gid'] = $group->value(['config_name' => $where['config_name']], 'id');
- }
- unset($where['config_name']);
- return app('json')->success($this->services->getGroupDataList($where));
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- $gid = $this->request->param('gid/d');
- if ($this->services->isGroupGidSave($gid, 4, 'index_categy_images')) {
- return app('json')->fail(400298);
- }
- if ($this->services->isGroupGidSave($gid, 7, 'sign_day_num')) {
- return app('json')->fail(400299);
- }
- return app('json')->success($this->services->createForm($gid));
- }
- /**
- * 保存新建的资源
- *
- * @return \think\Response
- */
- public function save(SystemGroupServices $services)
- {
- $params = request()->post();
- $gid = (int)$params['gid'];
- $group = $services->getOne(['id' => $gid], 'id,config_name,fields');
- if ($group && $group['config_name'] == 'order_details_images') {
- $groupDatas = $this->services->getColumn(['gid' => $gid], 'value', 'id');
- foreach ($groupDatas as $groupData) {
- $groupData = json_decode($groupData, true);
- if (isset($groupData['order_status']['value']) && $groupData['order_status']['value'] == $params['order_status']) {
- return app('json')->fail(400188);
- }
- }
- }
- if ($group && $group['config_name'] == 'user_recharge_quota') {
- if ($params['price'] <= 0) return app('json')->fail('售价必须大于0');
- if ($params['give_money'] < 0) return app('json')->fail('赠送不能小于0');
- }
- $this->services->checkSeckillTime($services, $gid, $params);
- $this->checkSign($services, $gid, $params);
- $fields = json_decode($group['fields'], true) ?? [];
- $value = [];
- foreach ($params as $key => $param) {
- foreach ($fields as $index => $field) {
- if ($key == $field["title"]) {
- if ($param == "")
- return app('json')->fail(400297);
- else {
- $value[$key]["type"] = $field["type"];
- $value[$key]["value"] = $param;
- }
- }
- }
- }
- $data = [
- "gid" => $params['gid'],
- "add_time" => time(),
- "value" => json_encode($value),
- "sort" => $params["sort"] ?: 0,
- "status" => $params["status"]
- ];
- $this->services->save($data);
- \crmeb\services\CacheService::clear();
- return app('json')->success(400189);
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- //
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function edit($id)
- {
- $gid = $this->request->param('gid/d');
- if (!$gid) {
- return app('json')->fail(100100);
- }
- return app('json')->success($this->services->updateForm((int)$gid, (int)$id));
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function update(SystemGroupServices $services, $id)
- {
- $groupData = $this->services->get($id);
- $fields = $services->getValueFields((int)$groupData["gid"]);
- $params = request()->post();
- $group = $services->getOne(['id' => $params['gid']], 'id,config_name,fields');
- if ($group && $group['config_name'] == 'user_recharge_quota') {
- if ($params['price'] <= 0) return app('json')->fail('售价必须大于0');
- if ($params['give_money'] < 0) return app('json')->fail('赠送不能小于0');
- }
- $this->services->checkSeckillTime($services, $groupData["gid"], $params, $id);
- $this->checkSign($services, $groupData["gid"], $params);
- $value = [];
- foreach ($params as $key => $param) {
- foreach ($fields as $index => $field) {
- if ($key == $field["title"]) {
- if ($param == '')
- return app('json')->fail(400297);
- else {
- $value[$key]["type"] = $field["type"];
- $value[$key]["value"] = $param;
- }
- }
- }
- }
- $data = [
- "value" => json_encode($value),
- "sort" => $params["sort"],
- "status" => $params["status"]
- ];
- $this->services->update($id, $data);
- \crmeb\services\CacheService::clear();
- return app('json')->success(100001);
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- if (!$this->services->delete($id))
- return app('json')->fail(100008);
- else {
- \crmeb\services\CacheService::clear();
- return app('json')->success(100002);
- }
- }
- /**
- * 修改状态
- * @param $id
- * @param $status
- * @return mixed
- */
- public function set_status($id, $status)
- {
- if ($status == '' || $id == 0) return app('json')->fail(100100);
- $this->services->update($id, ['status' => $status]);
- \crmeb\services\CacheService::clear();
- return app('json')->success(100014);
- }
- /**
- * 检查签到配置
- * @param SystemGroupServices $services
- * @param $gid
- * @param $params
- * @param int $id
- * @return mixed
- */
- public function checkSign(SystemGroupServices $services, $gid, $params, $id = 0)
- {
- $name = $services->value(['id' => $gid], 'config_name');
- if ($name == 'sign_day_num') {
- if (!$params['sign_num']) {
- throw new AdminException(400196);
- }
- if (!preg_match('/^\+?[1-9]\d*$/', $params['sign_num'])) {
- throw new AdminException(400197);
- }
- }
- }
- /**
- * 获取客服页面广告内容
- * @return mixed
- */
- public function getKfAdv()
- {
- /** @var CacheServices $cache */
- $cache = app()->make(CacheServices::class);
- $content = $cache->getDbCache('kf_adv', '');
- return app('json')->success(compact('content'));
- }
- /**
- * 设置客服页面广告内容
- * @return mixed
- */
- public function setKfAdv()
- {
- $content = $this->request->post('content');
- /** @var CacheServices $cache */
- $cache = app()->make(CacheServices::class);
- $cache->setDbCache('kf_adv', $content);
- return app('json')->success(100014);
- }
- public function saveAll()
- {
- $params = request()->post();
- if (!isset($params['config_name']) || !isset($params['data'])) {
- return app('json')->fail(100100);
- }
- $this->services->saveAllData($params['data'], $params['config_name']);
- return app('json')->success(400295);
- }
- /**
- * 获取用户协议内容
- * @return mixed
- */
- public function getUserAgreement()
- {
- /** @var CacheServices $cache */
- $cache = app()->make(CacheServices::class);
- $content = $cache->getDbCache('user_agreement', '');
- return app('json')->success(compact('content'));
- }
- /**
- * 设置用户协议内容
- * @return mixed
- */
- public function setUserAgreement()
- {
- $content = $this->request->post('content');
- /** @var CacheServices $cache */
- $cache = app()->make(CacheServices::class);
- $cache->setDbCache('user_agreement', $content);
- return app('json')->success(100014);
- }
- }
|