소스 검색

购买须知

shizhongqi 1 년 전
부모
커밋
6cf36b5a68

+ 135 - 0
app-ghs/controllers/PicTextController.php

@@ -0,0 +1,135 @@
+<?php
+namespace ghs\controllers;
+
+use biz\shop\models\ShopExt;
+use Yii;
+use bizHd\goods\classes\CategoryClass;
+use bizHd\pictext\classes\PicTextClass;
+use common\components\util;
+
+class PicTextController extends BaseController
+{
+    /**
+     * 购买须知、售前与售后说明等列表
+     */
+    public function actionList()
+    {
+        $where = [];
+        $where['mainId'] = $this->mainId;
+        $where['delStatus'] = 0;
+        // 当要兼容不同类型时,请从前端传过来
+        $where['type'] = PicTextClass::TYPE_BEFORE_AFTER_SAIL;
+        
+        $list = PicTextClass::getList('id, title, addTime', $where, 'addTime desc');
+        util::success($list);
+    }
+
+    /**
+     * 创建购买须知、售前与售后说明
+     */
+    public function actionAdd()
+    {
+        $post = Yii::$app->request->post();
+        $content = $post['content'];
+        
+        $post['content'] = $content;
+        $post['mainId'] = $this->mainId;
+        // $post['staffId'] = intval($this->shopAdmin->id);
+
+        // 类别 1. 花束分类说明(运用于分类的商品) 2. 商品特有说明(非商品简介,优先级可高于分类说明) 3. 购买须知、售前与售后说明
+        $post['type'] = PicTextClass::TYPE_BEFORE_AFTER_SAIL; // type 默认为 3
+        $id = PicTextClass::add($post);
+        util::success($id);
+    }
+
+    public function actionUpdate()
+    {
+        $post = Yii::$app->request->post();
+        $id = $post['id'];
+
+        $picText = PicTextClass::getById($id, true);
+        if (empty($picText)) {
+            util::fail('没有找到图文');
+        }
+        if ($picText->mainId != $this->mainId) {
+            util::fail('没有权限修改');
+        }
+
+        $post['staffId'] = intval($this->shopAdmin->id);
+        $id = PicTextClass::updateById($id, $post);
+        util::success('修改成功');
+    }
+
+    public function actionUpdatePurchaseGuide()
+    {
+        $post = Yii::$app->request->post();
+        $id = $post['id'];
+        $shopId = intval($this->shopId);
+        if ($shopId <= 0) {
+            util::fail('门店出错');
+        }
+       // 检测门店状态 TODO
+        
+        $updateCount = ShopExt::updateByCondition(['shopId' => $shopId], ['purchaseGuide' => $id]);
+        if ($updateCount <= 0) {
+            util::fail('变更失败');
+        }
+        util::success('变更成功');
+    }
+
+    public function actionDel()
+    {
+        $id = intval(Yii::$app->request->post('id'));
+        $picText = PicTextClass::getById($id, true, 'id,mainId,content');
+        if (empty($picText)) {
+            util::fail('图文id不对');
+        }
+        if ($picText->mainId != $this->mainId) {
+            util::fail('没有权限');
+        }
+        $re = PicTextClass::deleteById($id);
+        if ($re) {
+            // 删除 oss 图片
+            $content = $picText->content;
+            if (!empty($content)) {
+                $contentArr = json_decode($content, true);
+                $filePaths = [];
+                if (is_array($contentArr)) {
+                    foreach ($contentArr as $item) {
+                        if (isset($item['type']) && in_array($item['type'], [1, 2]) && !empty($item['content'])) {
+                            if ($item['type'] == 1) {
+                                $filePaths[] = $item['content'];
+                            } elseif ($item['type'] == 2 && is_array($item['content'])) {
+                                $filePaths = array_merge($filePaths, $item['content']);
+                            }
+                        }
+                    }
+                }
+
+                if (!empty($filePaths)) {
+                    try {
+                        \common\components\oss::deleteObjects($filePaths);
+                    } catch (\Exception $e) {
+                        util::fail('删除OSS文件失败:' . $e->getMessage());
+                    }
+                }
+            }
+            util::complete('成功删除');
+        }
+        util::fail('删除失败');
+    }
+
+    public function actionDetail()
+    {
+        $id = intval(Yii::$app->request->get('id'));
+        $picText = PicTextClass::getById($id, true);
+        if (empty($picText)) {
+            util::fail('没有找到图片');
+        }
+        if ($picText->mainId != $this->mainId) {
+            util::fail('没有权限');
+        }
+
+        util::success($picText);
+    }
+}

+ 14 - 1
app-ghs/controllers/ShopController.php

@@ -4,6 +4,7 @@ namespace ghs\controllers;
 
 use biz\shop\classes\MainClass;
 use biz\shop\classes\ShopAdminClass;
+use biz\shop\classes\ShopExtClass;
 use biz\sj\services\MerchantExtendService;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
@@ -16,7 +17,6 @@ use common\components\dict;
 use common\components\dirUtil;
 use common\components\httpUtil;
 use common\components\imgUtil;
-use common\components\noticeUtil;
 use common\components\stringUtil;
 use common\components\util;
 use common\components\wxUtil;
@@ -576,4 +576,17 @@ class ShopController extends BaseController
         util::success(['region' => $regionTree]);
     }
 
+    //获取购买须知信息
+    public function actionPurchaseGuide()
+    {
+        $shopId = intval($this->shopId);
+        if ($shopId <= 0) {
+            util::fail('门店数据错误');
+        }
+        $shopExt = ShopExtClass::getByCondition(['shopId'=>$shopId], false, false, 'id, shopId, purchaseGuide');
+        if ($shopExt) {
+            util::success(['shopExt'=>$shopExt]);
+        }
+        util::fail('获取数据失败');
+    }
 }

+ 2 - 1
app-hd/controllers/PicTextController.php

@@ -2,6 +2,7 @@
 namespace hd\controllers;
 
 use bizHd\goods\classes\CategoryClass;
+use bizHd\goods\models\Pic;
 use Yii;
 use bizHd\pictext\classes\PicTextClass;
 use common\components\util;
@@ -13,7 +14,7 @@ class PicTextController extends BaseController
         $where = [];
         $where['mainId'] = $this->mainId;
         $where['delStatus'] = 0;
-        $where['type'] = 1;
+        $where['type'] = PicTextClass::TYPE_CATEGORY;
         
         $list = PicTextClass::getList('id, title, addTime', $where, 'addTime desc');
         util::success($list);

+ 1 - 1
app-hd/controllers/ShopController.php

@@ -3,6 +3,7 @@
 namespace hd\controllers;
 
 use biz\shop\classes\ShopClass;
+use biz\shop\classes\ShopExtClass;
 use biz\sj\services\MerchantExtendService;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
@@ -398,5 +399,4 @@ class ShopController extends BaseController
         $shop->save();
         util::complete('修改成功');
     }
-
 }

+ 4 - 1
biz-hd/pictext/classes/PicTextClass.php

@@ -7,9 +7,12 @@ class PicTextClass extends BaseClass
 {
     public static $baseFile = '\bizHd\pictext\models\PicText';
 
-    // 类别 1.花束分类说明(运用于分类的商品) 2.商品特有说明(非商品简介,优先级可高于分类说明) 3.售前与售后说明
+    // 类别
+    // 1.花束分类说明(运用于分类的商品)
     const TYPE_CATEGORY = 1;
+    // 2.商品特有说明(非商品简介,优先级可高于分类说明)
     const TYPE_GOODS_SPEC = 2;
+    // 3.购买须知、售前与售后说明
     const TYPE_BEFORE_AFTER_SAIL = 3;
 
     public static function addBase($data, $bool = false)