Browse Source

update: add coupon and notice switch

tokumeikoi 3 years ago
parent
commit
1790de63f6

+ 19 - 0
app/Http/Controllers/Admin/CouponController.php

@@ -30,6 +30,25 @@ class CouponController extends Controller
         ]);
     }
 
+    public function show(Request $request)
+    {
+        if (empty($request->input('id'))) {
+            abort(500, '参数有误');
+        }
+        $coupon = Coupon::find($request->input('id'));
+        if (!$coupon) {
+            abort(500, '优惠券不存在');
+        }
+        $coupon->show = $coupon->show ? 0 : 1;
+        if (!$coupon->save()) {
+            abort(500, '保存失败');
+        }
+
+        return response([
+            'data' => true
+        ]);
+    }
+
     public function generate(CouponGenerate $request)
     {
         if ($request->input('generate_count')) {

+ 21 - 0
app/Http/Controllers/Admin/NoticeController.php

@@ -40,6 +40,27 @@ class NoticeController extends Controller
         ]);
     }
 
+
+
+    public function show(Request $request)
+    {
+        if (empty($request->input('id'))) {
+            abort(500, '参数有误');
+        }
+        $notice = Notice::find($request->input('id'));
+        if (!$notice) {
+            abort(500, '公告不存在');
+        }
+        $notice->show = $notice->show ? 0 : 1;
+        if (!$notice->save()) {
+            abort(500, '保存失败');
+        }
+
+        return response([
+            'data' => true
+        ]);
+    }
+
     public function drop(Request $request)
     {
         if (empty($request->input('id'))) {

+ 2 - 1
app/Http/Controllers/User/NoticeController.php

@@ -13,7 +13,8 @@ class NoticeController extends Controller
     {
         $current = $request->input('current') ? $request->input('current') : 1;
         $pageSize = 5;
-        $model = Notice::orderBy('created_at', 'DESC');
+        $model = Notice::orderBy('created_at', 'DESC')
+            ->where('show', 1);
         $total = $model->count();
         $res = $model->forPage($current, $pageSize)
             ->get();

+ 2 - 0
app/Http/Routes/AdminRoute.php

@@ -87,6 +87,7 @@ class AdminRoute
             $router->post('/notice/save', 'Admin\\NoticeController@save');
             $router->post('/notice/update', 'Admin\\NoticeController@update');
             $router->post('/notice/drop', 'Admin\\NoticeController@drop');
+            $router->post('/notice/show', 'Admin\\NoticeController@show');
             // Ticket
             $router->get ('/ticket/fetch', 'Admin\\TicketController@fetch');
             $router->post('/ticket/reply', 'Admin\\TicketController@reply');
@@ -95,6 +96,7 @@ class AdminRoute
             $router->get ('/coupon/fetch', 'Admin\\CouponController@fetch');
             $router->post('/coupon/generate', 'Admin\\CouponController@generate');
             $router->post('/coupon/drop', 'Admin\\CouponController@drop');
+            $router->post('/coupon/show', 'Admin\\CouponController@show');
             // Knowledge
             $router->get ('/knowledge/fetch', 'Admin\\KnowledgeController@fetch');
             $router->get ('/knowledge/getCategory', 'Admin\\KnowledgeController@getCategory');

+ 1 - 1
app/Services/CouponService.php

@@ -81,7 +81,7 @@ class CouponService
 
     public function check()
     {
-        if (!$this->coupon) {
+        if (!$this->coupon || !$this->coupon->show) {
             abort(500, __('Invalid coupon'));
         }
         if ($this->coupon->limit_use <= 0 && $this->coupon->limit_use !== NULL) {

+ 3 - 1
database/install.sql

@@ -40,6 +40,7 @@ CREATE TABLE `v2_coupon` (
                              `name` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
                              `type` tinyint(1) NOT NULL,
                              `value` int(11) NOT NULL,
+                             `show` tinyint(1) NOT NULL DEFAULT '0',
                              `limit_use` int(11) DEFAULT NULL,
                              `limit_use_with_user` int(11) DEFAULT NULL,
                              `limit_plan_ids` varchar(255) DEFAULT NULL,
@@ -98,6 +99,7 @@ CREATE TABLE `v2_notice` (
                              `id` int(11) NOT NULL AUTO_INCREMENT,
                              `title` varchar(255) NOT NULL,
                              `content` text NOT NULL,
+                             `show` tinyint(1) NOT NULL DEFAULT '0',
                              `img_url` varchar(255) DEFAULT NULL,
                              `created_at` int(11) NOT NULL,
                              `updated_at` int(11) NOT NULL,
@@ -369,4 +371,4 @@ CREATE TABLE `v2_user` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
--- 2022-01-04 16:20:42
+-- 2022-01-21 18:20:29

+ 6 - 0
database/update.sql

@@ -477,3 +477,9 @@ DROP `alter_id`;
 
 ALTER TABLE `v2_user`
     CHANGE `commission_type` `commission_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0: system 1: period 2: onetime' AFTER `discount`;
+
+ALTER TABLE `v2_coupon`
+    ADD `show` tinyint(1) NOT NULL DEFAULT '0' AFTER `value`;
+
+ALTER TABLE `v2_notice`
+    ADD `show` tinyint(1) NOT NULL DEFAULT '0' AFTER `content`;

File diff suppressed because it is too large
+ 0 - 0
public/assets/admin/umi.js


Some files were not shown because too many files changed in this diff