From 96f0adb79e45b0f2d3a5287bbcdb124eef95b59c Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Thu, 28 Nov 2024 16:03:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=AF=8F=E6=97=A5=E7=89=B9?= =?UTF-8?q?=E4=BB=B7=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/groupbuy/GroupBuy.php | 9 +- app/admin/logic/groupbuy/GroupbuyLogic.php | 37 +++- app/admin/view/groupbuy/group_buy/lists.html | 170 +++++++++++------- app/api/logic/IndexLogic.php | 5 +- app/common/model/groupbuy/GroupbuyConfig.php | 9 + ...128074040_create_groupbuy_config_table.php | 41 +++++ 6 files changed, 194 insertions(+), 77 deletions(-) create mode 100644 app/common/model/groupbuy/GroupbuyConfig.php create mode 100644 database/migrations/20241128074040_create_groupbuy_config_table.php diff --git a/app/admin/controller/groupbuy/GroupBuy.php b/app/admin/controller/groupbuy/GroupBuy.php index c8765bff..1cada966 100644 --- a/app/admin/controller/groupbuy/GroupBuy.php +++ b/app/admin/controller/groupbuy/GroupBuy.php @@ -4,6 +4,7 @@ namespace app\admin\controller\groupbuy; use app\common\basics\AdminBase; +use app\common\model\groupbuy\GroupbuyConfig; use app\common\server\JsonServer; use app\admin\logic\groupbuy\GroupbuyLogic; use app\admin\validate\groupbuy\GroupbuyValidate; @@ -108,8 +109,12 @@ class GroupBuy extends AdminBase { if ($this->request->isAjax()){ $post = $this->request->post(); - GroupbuyLogic::setConfig($post); - return JsonServer::success('操作成功'); + $result = GroupbuyLogic::setConfig($post); + if ($result) { + return JsonServer::success('操作成功'); + } + + return JsonServer::error(GroupbuyLogic::getError()); } } } \ No newline at end of file diff --git a/app/admin/logic/groupbuy/GroupbuyLogic.php b/app/admin/logic/groupbuy/GroupbuyLogic.php index 719caebb..e4f41435 100644 --- a/app/admin/logic/groupbuy/GroupbuyLogic.php +++ b/app/admin/logic/groupbuy/GroupbuyLogic.php @@ -8,8 +8,8 @@ use app\common\model\goods\Goods; use app\common\model\goods\GoodsItem; use app\common\model\groupbuy\GroupbuyGoods; use app\common\model\goods\GoodsCategory as GoodsCategory; -use app\common\server\ConfigServer; use app\common\server\UrlServer; +use app\common\model\groupbuy\GroupbuyConfig; use think\facade\Db; class GroupbuyLogic extends Logic @@ -216,17 +216,42 @@ class GroupbuyLogic extends Logic return empty($lists) ? [] : $lists->toArray(); } - // 获取配置项 public static function getConfig() { - return [ - 'group_buy_status' => ConfigServer::get('group_buy', 'group_buy_status'), - ]; + $data = GroupbuyConfig::select(); + $config = array(); + if (!empty($data)) { + $result = $data->toArray(); + foreach ($result as &$v) { + $config[$v['name']] = $v['value']; + } + } + + return $config; } // 设置配置 public static function setConfig($post) { - return ConfigServer::set('group_buy', 'group_buy_status', !empty($post)); + try { + Db::startTrans(); + + $time = time(); + $data = [ + ['name' => 'status', 'value' => (isset($post['status']) && $post['status'] == 'on') ? 1 : 0, 'update_time' => $time], + ['name' => 'end_time', 'value' => $post['end_time'], 'update_time' => $time], + ['name' => 'rule', 'value' => $post['rule'], 'update_time' => $time], + ['name' => 'service', 'value' => str_replace(',', ',', $post['service']), 'update_time' => $time], + ]; + foreach ($data as $item) { + Db::name('groupbuy_config')->replace()->save($item); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::$error = $e->getMessage(); + return false; + } } } \ No newline at end of file diff --git a/app/admin/view/groupbuy/group_buy/lists.html b/app/admin/view/groupbuy/group_buy/lists.html index 71898413..35db7a45 100644 --- a/app/admin/view/groupbuy/group_buy/lists.html +++ b/app/admin/view/groupbuy/group_buy/lists.html @@ -14,85 +14,119 @@ -
- 好物直降 -
-
-
- 活动开启 -
- -
-
-
- -
-
-
-
+
+
+
    +
  • 商品设置
  • +
  • 配置
  • +
-
- -
-
-
- -
- +
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+
+
+
+ +
+ +
+ +
+ + +
+ + + + + +
-
- -
- -
-
-
- -
-
- +
+
+
+
+ 活动开启 +
+ +
+
+ +
+ 活动倒计时(结束)时间 +
+ +
+
+ +
+ 规则说明: +
+ +
+
+ +
+ 服务: +
+ +
+
+ +
+ +
+
+
- - - -
- -
- -
- - -
- - - - - - -