Browse Source

Merge branch 'zhongqi-addGoods'
图文

shish 1 year ago
parent
commit
30ae77aade
43 changed files with 1265 additions and 256 deletions
  1. 4 3
      app-ghs/controllers/CategoryController.php
  2. 62 0
      app-ghs/controllers/ItemController.php
  3. 146 0
      app-ghs/controllers/PicTextController.php
  4. 19 1
      app-ghs/controllers/ShopController.php
  5. 69 5
      app-ghs/controllers/UploadController.php
  6. 27 0
      app-ghs/models/BaseForm.php
  7. 52 0
      app-ghs/models/item/CreateDescForm.php
  8. 19 0
      app-hd/controllers/BaseController.php
  9. 32 10
      app-hd/controllers/CategoryController.php
  10. 7 1
      app-hd/controllers/GhsController.php
  11. 67 4
      app-hd/controllers/GoodsController.php
  12. 1 1
      app-hd/controllers/KindController.php
  13. 157 0
      app-hd/controllers/PicTextController.php
  14. 1 1
      app-hd/controllers/ShopController.php
  15. 70 5
      app-hd/controllers/UploadController.php
  16. 52 0
      app-hd/models/goods/CreateDescForm.php
  17. 16 4
      app-mall/controllers/GoodsController.php
  18. 22 0
      biz-ghs/pictext/classes/PicTextClass.php
  19. 10 0
      biz-ghs/pictext/classes/PicTextGhsItemClass.php
  20. 10 0
      biz-ghs/pictext/classes/PicTextGoodsClass.php
  21. 12 0
      biz-ghs/pictext/models/PicText.php
  22. 12 0
      biz-ghs/pictext/models/PicTextGhsItem.php
  23. 12 0
      biz-ghs/pictext/models/PicTextGoods.php
  24. 1 3
      biz-hd/goods/classes/CategoryClass.php
  25. 3 3
      biz-hd/goods/classes/GoodsCategoryClass.php
  26. 131 110
      biz-hd/goods/classes/GoodsClass.php
  27. 0 5
      biz-hd/goods/classes/GoodsSettingClass.php
  28. 5 13
      biz-hd/goods/services/CategoryService.php
  29. 1 1
      biz-hd/goods/services/GoodsCategoryService.php
  30. 21 7
      biz-hd/goods/services/GoodsService.php
  31. 22 0
      biz-hd/pictext/classes/PicTextClass.php
  32. 10 0
      biz-hd/pictext/classes/PicTextGoodsClass.php
  33. 12 0
      biz-hd/pictext/models/PicText.php
  34. 12 0
      biz-hd/pictext/models/PicTextGoods.php
  35. 14 0
      biz-mall/pictext/classes/PicTextClass.php
  36. 10 0
      biz-mall/pictext/classes/PicTextGoodsClass.php
  37. 12 0
      biz-mall/pictext/models/PicText.php
  38. 12 0
      biz-mall/pictext/models/PicTextGoods.php
  39. 49 55
      common/base/classes/BaseClass.php
  40. 37 17
      common/base/models/Base.php
  41. 29 6
      common/components/oss.php
  42. 4 0
      common/config/main.php
  43. 1 1
      composer.json

+ 4 - 3
app-ghs/controllers/CategoryController.php

@@ -12,6 +12,7 @@ use bizHd\goods\services\CategoryService;
 use bizHd\goods\services\GoodsCategoryService;
 use Yii;
 use common\components\util;
+use bizHd\goods\classes\CategoryClass;
 
 class CategoryController extends BaseController
 {
@@ -20,8 +21,8 @@ class CategoryController extends BaseController
     public function actionList()
     {
         $get = Yii::$app->request->get();
-        $property = $get['property'] ?? '';
-        $list = CategoryService::getCategoryList($this->mainId, $property);
+        //$property = $get['property'] ?? '';
+        $list = CategoryService::getCategoryList($this->mainId);
         util::success($list);
     }
 
@@ -74,7 +75,7 @@ class CategoryController extends BaseController
         $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
         $category = CategoryService::getById($categoryId);
         CategoryService::valid($category, $this->mainId);
-        CategoryService::deleteCategory($categoryId);
+        CategoryClass::deleteCategory($categoryId);
         util::complete('删除成功');
     }
 

+ 62 - 0
app-ghs/controllers/ItemController.php

@@ -9,6 +9,7 @@ use bizGhs\book\classes\BookItemClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\item\classes\ItemClass;
 use bizGhs\shop\classes\ShopAdminClass;
+use bizGhs\pictext\classes\PicTextGhsItemClass;
 use common\components\arrayUtil;
 use common\components\dict;
 use common\components\imgUtil;
@@ -1215,4 +1216,65 @@ class ItemController extends BaseController
         util::complete('修改成功');
     }
 
+    //获取花材描述
+    public function actionDesc()
+    {
+        $itemId = Yii::$app->request->get('itemId', 0);
+        $picText = PicTextGhsItemClass::getByCondition(['mainId'=> $this->mainId, 'ghsItemId' => $itemId, 'delStatus' => 0], true);
+        if (empty($picText)) {
+            // 适配前端的返回处理 -- 本来要使用 util::fail()
+            util::success('not_exist');
+        }
+        if ($picText->mainId != $this->mainId) {
+            util::fail('没有找到描述');
+        }
+        util::success($picText);
+    }
+
+    //创建花材描述(花材介绍)
+    public function actionCreateDesc()
+    {
+        $form = new \ghs\models\item\CreateDescForm();
+        $form->load(Yii::$app->request->post(), '');
+        if (!$form->validateForm()) {
+            return;
+        }
+
+        $data = $form->attributes;
+        $exists = PicTextGhsItemClass::exists(['mainId'=>$this->mainId, 'ghsItemId' => $data['itemId'], 'delStatus' => 0]);
+        if ($exists) {
+            util::fail('该商品已存在图文内容,请勿重复添加');
+        }
+
+        $data['mainId'] = $this->mainId;
+        $data['ghsItemId'] = $data['itemId'];
+        $result = PicTextGhsItemClass::add($data);
+        if ($result) {
+            util::success($result);
+        }
+
+        util::fail('创建失败');
+    }
+
+    //更新花材描述(花材介绍)
+    public function actionUpdateDesc()
+    {
+        $form = new \ghs\models\item\CreateDescForm();
+        $form->load(Yii::$app->request->post(), '');
+        if (!$form->validateForm()) {
+            return;
+        }
+        $data = $form->attributes;
+        $id = $data['id'];
+        $info = PicTextGhsItemClass::getById($id, false, 'id');
+        if (empty($info)) {
+            util::fail('描述不存在');
+        }
+        $data['mainId'] = $this->mainId;
+        $result = PicTextGhsItemClass::updateById($id, $data);
+        if ($result) {
+            util::success($result);
+        }
+        util::fail('更新失败');
+    }
 }

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

@@ -0,0 +1,146 @@
+<?php
+namespace ghs\controllers;
+
+use Yii;
+use biz\shop\classes\ShopExtClass;
+use bizGhs\pictext\classes\PicTextClass;
+use common\components\util;
+
+class PicTextController extends BaseController
+{
+    /**
+     * 购买须知、售前与售后说明等列表
+     */
+    public function actionList()
+    {
+        // 当要兼容不同类型时,请从前端传过来
+        $typeArr = [PicTextClass::TYPE_CATEGORY, PicTextClass::TYPE_BEFORE_AFTER_SAIL];
+        $type = intval(Yii::$app->request->get('type'));
+        if (!in_array($type, $typeArr)) {
+            util::fail('类型不对');
+        }
+        $where = [];
+        $where['mainId'] = $this->mainId;
+        $where['delStatus'] = 0;
+        // $where['type'] = $type; // 需求需要所有都展示,不分类别
+        
+        $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'] = intval($post['type']);
+        if (!in_array($post['type'], [1, 2, 3])) {
+            util::fail('类型不对');
+        }
+        $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 actionSwitch()
+    {
+        $post = Yii::$app->request->post();
+        $switch = intval($post['switch']);
+        $shopId = intval($this->shopId);
+        if ($shopId <= 0) {
+            util::fail('门店出错');
+        }
+        if($switch == 1) {
+            $picTextId = intval($post['picTextId']);
+            $updateCount = ShopExtClass::updateByCondition(['shopId' => $shopId], ['purchaseGuide' => $picTextId]);
+        }else{
+            $updateCount = ShopExtClass::updateByCondition(['shopId' => $shopId], ['purchaseGuide' => 0]);
+        }
+        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);
+    }
+}

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

@@ -4,19 +4,20 @@ 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;
 use bizGhs\ghs\classes\GhsClass;
 use bizGhs\merchant\classes\ShopClass;
 use bizGhs\merchant\services\ShopService;
+use bizGhs\pictext\classes\PicTextClass;
 use bizHd\saas\services\RegionService;
 use common\components\arrayUtil;
 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 +577,21 @@ 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['purchaseGuide'] > 0){
+            $picText = PicTextClass::getById($shopExt['purchaseGuide'], false, 'id, title');
+        }
+        if ($shopExt) {
+            $shopExt['title'] = isset($picText['title']) ? $picText['title'] : '';
+            util::success(['shopExt'=>$shopExt]);
+        }
+        util::fail('获取数据失败');
+    }
 }

+ 69 - 5
app-ghs/controllers/UploadController.php

@@ -3,15 +3,12 @@
 namespace ghs\controllers;
 
 use bizHd\goods\services\CategoryService;
-use bizHd\goods\services\PicCategoryService;
-use bizHd\goods\services\PicService;
 use common\components\business;
 use common\components\dirUtil;
 use common\components\noticeUtil;
 use common\components\stringUtil;
 use Yii;
 use common\components\util;
-use yii\imagine\Image;
 use common\components\oss;
 
 class UploadController extends BaseController
@@ -22,11 +19,21 @@ class UploadController extends BaseController
     //保存图片上传
     public function actionSaveFile()
     {
+        $uploadPath = 'uploads';
+        // 对上传的文件进行多文件夹管理
+        $rootPath = Yii::$app->request->post('rootPath');
+        if (!empty($rootPath) && in_array($rootPath, oss::ROOT_PATHS)) {
+            $uploadPath = $rootPath;
+        }
         $file = $_FILES['file'];
         if (!is_uploaded_file($file['tmp_name'])) {
             util::fail('please upload img');
         }
-        $mainId = $this->sjId;
+        $mainId = $this->mainId; // 变动:$this->sjId 改为 $this->mainId
+        if (intval($mainId) == 0) {
+            Yii::error('------- lose token -------');
+            noticeUtil::push('save-file 无token进行上传文件');
+        }
         $shopId = $this->shopId;
         $month = date("Ym");
         $date = date("d");
@@ -39,7 +46,7 @@ class UploadController extends BaseController
         $newFile = $preFileName . ".jpg";
         $fullPathFile = $path . $newFile;
         if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
-            $img = "uploads/{$mainId}/{$shopId}/{$month}/{$date}/" . $newFile;
+            $img = "{$uploadPath}/{$mainId}/{$shopId}/{$month}/{$date}/" . $newFile;
             oss::uploadImage($img, $fullPathFile);
             $data = business::formatUploadImg($img);
             $data['shortUrl'] = $img;
@@ -199,4 +206,61 @@ class UploadController extends BaseController
         }
     }
 
+    //删除oss上的图片
+    public function actionDeleteFile()
+    {
+        $filePath = Yii::$app->request->post('filePath');
+        if(empty($filePath)){
+            util::fail('参数错误');
+        }
+        // 删除前判断文件是否存在
+        if(!oss::fileExist($filePath)){
+            Yii::error('file not exist: ' . $filePath);
+            util::fail('file not exist');
+        } else {
+            Yii::info('file exist: ' . $filePath);
+        }
+        // 删除OSS文件
+        try {
+            // 设置超时时间为15秒
+            set_time_limit(15);
+            $startTime = time();
+            $timeout = 15; // 15秒超时
+
+            oss::deleteObject($filePath);
+
+            // 检查是否超时
+            if (time() - $startTime > $timeout) {
+                throw new \Exception('删除文件操作超时');
+            }
+        } catch (\Exception $e) {
+            util::fail('删除文件失败:' . $e->getMessage());
+        }
+        util::success('success');
+    }
+
+    //批量删除oss上的图片
+    public function actionDeleteFiles()
+    {
+        $filePaths = Yii::$app->request->post('filePaths');
+        if(empty($filePaths) || !is_array($filePaths)){
+            util::fail('参数错误');
+        }
+        foreach($filePaths as $filePath){
+            if(!oss::fileExist($filePath)){
+                Yii::error('file not exist: ' . $filePath);
+                util::fail('file not exist');
+            } else {
+                Yii::info('file exist: ' . $filePath);
+            }
+        }
+        // 删除OSS文件
+        try {
+            oss::deleteObjects($filePaths);
+        } catch (\Exception $e) {
+            util::fail('删除文件失败:' . $e->getMessage());
+        }
+        util::success('success');
+    }
+
 }

+ 27 - 0
app-ghs/models/BaseForm.php

@@ -0,0 +1,27 @@
+<?php
+namespace ghs\models;
+
+use yii\base\Model;
+use common\components\util;
+
+/**
+ * 管理员表单基类
+ */
+class BaseForm extends Model
+{
+    /**
+     * 验证表单数据并返回结果
+     *
+     * @return bool 验证是否通过
+     */
+    public function validateForm()
+    {
+        if (!$this->validate()) {
+            $errors = $this->getFirstErrors();
+            $message = reset($errors);
+            util::fail($message);
+            return false;
+        }
+        return true;
+    }
+}

+ 52 - 0
app-ghs/models/item/CreateDescForm.php

@@ -0,0 +1,52 @@
+<?php
+namespace ghs\models\item;
+
+use bizGhs\item\classes\ItemClass;
+use ghs\models\BaseForm;
+use Yii;
+
+/**
+ * 创建花材描述表单模型
+ */
+class CreateDescForm extends BaseForm
+{
+    public $id;
+    public $mainId;
+    public $title;
+    public $itemId;
+    public $content;
+
+    public function rules()
+    {
+        return [
+            [['itemId'], 'required'],
+            ['title', 'string', 'max' => 60],
+            [['id', 'itemId', 'mainId'], 'integer'],
+            ['itemId', 'validateItemId'],
+            ['content', 'safe'],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'title' => '标题',
+            'itemId' => '商品ID',
+            'content' => '图文内容',
+        ];
+    }
+
+    /**
+     * 验证商品ID
+     * @param $attribute
+     */
+    public function validateItemId($attribute)
+    {
+        if (!$this->hasErrors()) {
+            $item = ItemClass::getById($this->itemId, true, 'mainId');
+            if (empty($item) || $item->mainId != Yii::$app->controller->mainId) {
+                $this->addError($attribute, '花材不存在或不属于当前商户');
+            }
+        }
+    }
+}

+ 19 - 0
app-hd/controllers/BaseController.php

@@ -102,4 +102,23 @@ class BaseController extends PublicController
         return parent::beforeAction($action);
     }
 
+    /**
+     * 把必要参数放 $_POST 或 $_GET 中
+     */
+    private function formParams()
+    {
+        // 将参数放入 $_POST 中(如果是 POST 请求)
+        if (Yii::$app->request->isPost) {
+            $_POST['adminId'] = intval($this->adminId);
+            $_POST['mainId'] = intval($this->mainId);
+            $_POST['shopId'] = intval($this->shopId);
+        }
+        
+        // 将参数放入 $_GET 中(如果是 GET 请求)
+        if (Yii::$app->request->isGet) {
+            $_GET['adminId'] = intval($this->adminId);
+            $_GET['mainId'] = intval($this->mainId);
+            $_GET['shopId'] = intval($this->shopId);
+        }
+    }
 }

+ 32 - 10
app-hd/controllers/CategoryController.php

@@ -3,6 +3,7 @@
 namespace hd\controllers;
 
 use bizHd\goods\classes\CategoryClass;
+use bizHd\goods\classes\GoodsCategoryClass;
 use bizHd\goods\services\CategoryService;
 use bizHd\goods\services\GoodsCategoryService;
 use Yii;
@@ -22,8 +23,8 @@ class CategoryController extends BaseController
     public function actionList()
     {
         $get = Yii::$app->request->get();
-        $flower = $get['flower'] ?? '';
-        $list = CategoryService::getCategoryList($this->mainId, $flower);
+        //$flower = $get['flower'] ?? '';
+        $list = CategoryService::getCategoryList($this->mainId);
         util::success($list);
     }
 
@@ -75,12 +76,38 @@ class CategoryController extends BaseController
     {
         $get = Yii::$app->request->get();
         $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
-        $category = CategoryService::getById($categoryId);
+        $category = CategoryClass::getById($categoryId);
         CategoryService::valid($category, $this->mainId);
+
         if ($category['goodsNum'] > 0) {
-            util::fail('分类下还有商品');
+            $goodsCateObjs = GoodsCategoryClass::getAllByCondition(['mainId'=>$this->mainId, 'cId'=>$categoryId]);
+
+            //检查是否有默认分类,没有默认分类创建一个
+            $defaultCategory = CategoryClass::getByCondition(['mainId'=>$this->mainId, 'default'=>1]);
+            if ($defaultCategory == null){
+                $data = [
+                    'mainId' => $this->mainId,
+                    'sjId' => $this->sjId,
+                    'categoryName' => '默认分类',
+                    'default' => 1
+                ];
+                $defaultCategory = CategoryClass::addCategory($data);
+            }
+            $defaultCategoryId = $defaultCategory['id'];
+            foreach ($goodsCateObjs as $gcObj) {
+                // 先判断商品是否也在其它分类下
+                $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId'=>$this->mainId, 'gId'=>$gcObj['gId'], 'delStatus'=>0]);
+                if ($goodsOtherCateCount == 1) {
+                    // 如果商品仅在此分类下,则归到默认分类
+                    GoodsCategoryClass::updateById($gcObj['id'], ['cId' => $defaultCategoryId, 'delStatus' => 0]);
+                } else {
+                    // 如果商品还在其它分类下,则直接删除此商品的当前分类
+                    GoodsCategoryClass::delGoodsCategory($this->mainId, $categoryId, $gcObj['gId']);
+                }
+            }
         }
-        $count = CategoryService::deleteCategory($categoryId);
+
+        $count = CategoryClass::deleteCategory($categoryId);
         if (!$count) {
             util::fail('删除失败');
         }
@@ -101,11 +128,6 @@ class CategoryController extends BaseController
         if (is_numeric($flower)) {
             $where['flower'] = $flower;
         }
-        $where['delStatus'] = $get['delStatus'] ?? 0;
-        $status = $get['status'] ?? '';
-        if (is_numeric($status)) {
-            $where['status'] = $status;
-        }
         $flowerNum = $get['flowerNum'] ?? 0;
         if (!empty($flowerNum)) {
             $where['flowerNum'] = $flowerNum;

+ 7 - 1
app-hd/controllers/GhsController.php

@@ -9,6 +9,8 @@ use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\classes\CustomLevelClass;
 use bizGhs\merchant\classes\WlClass;
 use bizHd\purchase\classes\PurchaseClass;
+use bizHd\shop\classes\ShopExtClass;
+use bizHd\shop\models\ShopExt;
 use bizHd\stat\classes\StatVisitClass;
 use common\components\dict;
 use common\components\imgUtil;
@@ -253,7 +255,6 @@ class GhsController extends BaseController
         $info['needAddPackFreight'] = $needAddPackFreight;
         $info['lackExpend'] = $lackExpend;
         $info['showSold'] = $ghsShop->showSold ?? 0;
-        $info['buyNotice'] = $ghsShop->buyNotice ?? 0;
         $info['lsShopId'] = $ghsShop->lsShopId ?? 0;
         //预订单的最低公斤数和每公斤服务费
         $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
@@ -288,6 +289,11 @@ class GhsController extends BaseController
             }
         }
 
+        // 弃用 buyNotice, 使用 xhShopExt 表里的 purchaseGuide
+        // $info['buyNotice'] = $ghsShop->buyNotice ?? 0;
+        $shopExt = ShopExtClass::getByCondition(['shopId'=>$ghsShopId], false, false, 'purchaseGuide');
+        $info['buyNotice'] = $shopExt['purchaseGuide'] > 0 ? 1 : 0; //兼容原有设定:购买须知 0.没有 1.有
+
         util::success($info);
     }
 

+ 67 - 4
app-hd/controllers/GoodsController.php

@@ -9,6 +9,7 @@ use bizHd\goods\classes\GoodsClass;
 use bizHd\goods\services\CategoryService;
 use bizHd\goods\services\GoodsCategoryService;
 use bizHd\goods\services\GoodsSettingService;
+use bizHd\pictext\classes\PicTextGoodsClass;
 use common\components\printUtil;
 use Yii;
 use common\components\util;
@@ -116,7 +117,7 @@ class GoodsController extends BaseController
         $cId = isset($get['cId']) ? intval($get['cId']) : 0;
         $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
         $flowerNum = isset($get['flowerNum']) && $get['flowerNum'] > 0 ? $get['flowerNum'] : 0;
-        $flower = isset($get['flower']) ? $get['flower'] : '';
+        //$flower = isset($get['flower']) ? $get['flower'] : '';
         $hasStock = isset($get['hasStock']) ? $get['hasStock'] : 0;
 
         $where = [];
@@ -134,9 +135,10 @@ class GoodsController extends BaseController
         if ($flowerNum > 0) {
             $where['flowerNum'] = $flowerNum;
         }
-        if (is_numeric($flower)) {
-            $where['flower'] = $flower;
-        }
+        // 需求变动:不再用 flower 做区分
+        //if (is_numeric($flower)) {
+            //$where['flower'] = $flower;
+        //}
         if ($hasStock == 1) {
             $where['stock>'] = 0;
         }
@@ -278,6 +280,67 @@ class GoodsController extends BaseController
         util::complete('提交成功');
     }
 
+    //获取商品描述
+    public function actionDesc()
+    {
+        $goodsId = Yii::$app->request->get('id', 0);
+        $picText = PicTextGoodsClass::getByCondition(['mainId'=> $this->mainId, 'goodsId' => $goodsId, 'delStatus' => 0], true);
+        if (empty($picText)) {
+            // 适配前端的返回处理 -- 本来要使用 util::fail()
+            util::success('not_exist');
+        }
+        if ($picText->mainId != $this->mainId) {
+            util::fail('没有找到描述');
+        }
+        util::success($picText);
+    }
+
+    //创建商品描述(商品介绍)
+    public function actionCreateDesc()
+    {
+        $form = new \hd\models\goods\CreateDescForm();
+        $form->load(Yii::$app->request->post(), '');
+        if (!$form->validateForm()) {
+            return;
+        }
+
+        $data = $form->attributes;
+        $exists = PicTextGoodsClass::exists(['goodsId' => $data['goodsId'], 'delStatus' => 0]);
+        if ($exists) {
+            util::fail('该商品已存在图文内容,请勿重复添加');
+        }
+
+        $data['mainId'] = $this->mainId;
+        $result = PicTextGoodsClass::add($data);
+        if ($result) {
+            util::success($result);
+        }
+
+        util::fail('创建失败');
+    }
+
+    //更新商品描述(商品介绍)
+    public function actionUpdateDesc()
+    {
+        $form = new \hd\models\goods\CreateDescForm();
+        $form->load(Yii::$app->request->post(), '');
+        if (!$form->validateForm()) {
+            return;
+        }
+        $data = $form->attributes;
+        $id = $data['id'];
+        $info = PicTextGoodsClass::getById($id, false, 'id');
+        if (empty($info)) {
+            util::fail('描述不存在');
+        }
+        $data['mainId'] = $this->mainId;
+        $result = PicTextGoodsClass::updateById($id, $data);
+        if ($result) {
+            util::success($result);
+        }
+        util::fail('更新失败');
+    }
+
     //设置 ssh 2019.12.8
     public function actionSetting()
     {

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

@@ -114,7 +114,7 @@ class KindController extends BaseController
         if ($category['goodsNum'] > 0) {
             util::fail('品类下还有商品');
         }
-        $count = CategoryService::deleteCategory($categoryId);
+        $count = \bizHd\goods\classes\CategoryClass::deleteCategory($categoryId);
         if (!$count) {
             util::fail('删除失败');
         }

+ 157 - 0
app-hd/controllers/PicTextController.php

@@ -0,0 +1,157 @@
+<?php
+namespace hd\controllers;
+
+use bizHd\goods\classes\CategoryClass;
+use bizHd\goods\models\Pic;
+use bizHd\shop\classes\ShopExtClass;
+use Yii;
+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_CATEGORY;
+        
+        $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_CATEGORY; // type 默认为 1
+        $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 actionUpdateCategoryId()
+    {
+        $post = Yii::$app->request->post();
+        $id = $post['id'];
+        $categoryId = intval($post['categoryId']);
+        if ($categoryId <= 0) {
+            util::fail('分类id出错');
+        }
+        $picText = PicTextClass::getById($id, true, 'id, mainId, type');
+        if (empty($picText)) {
+            util::fail('没有找到图文');
+        }
+        if ($picText->type != PicTextClass::TYPE_CATEGORY) {
+            util::fail('图文类型不支持设置分类');
+        }
+        if ($picText->mainId != $this->mainId) {
+            util::fail('没有权限修改');
+        }
+        
+        $updateCount = CategoryClass::updateByCondition(['id' => $categoryId, 'mainId' => $this->mainId], ['picTextId' => $id]);
+        //CategoryClass::updateById($id, ['picTextId' => $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);
+    }
+
+    public function actionGetPurchaseGuide()
+    {
+        $ghsShopId = intval(Yii::$app->request->get('shopId'));
+        $shopExt = ShopExtClass::getByCondition(['shopId'=>$ghsShopId], false, false, 'purchaseGuide');
+        if (empty($shopExt)) {
+            util::fail('数据出错');
+        }
+        if ($shopExt['purchaseGuide'] == 0) {
+            util::success(['picText' => []]);
+        }
+
+        $pt = PicTextClass::getById($shopExt['purchaseGuide'], true);
+        if (empty($pt)) {
+            util::fail('数据出错');
+        }
+        util::success(['picText'=>$pt]);
+    }
+}

+ 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('修改成功');
     }
-
 }

+ 70 - 5
app-hd/controllers/UploadController.php

@@ -3,29 +3,37 @@
 namespace hd\controllers;
 
 use bizHd\goods\services\CategoryService;
-use bizHd\goods\services\PicCategoryService;
-use bizHd\goods\services\PicService;
 use common\components\business;
 use common\components\dirUtil;
 use common\components\oss;
 use common\components\stringUtil;
+use common\components\noticeUtil;
 use Yii;
 use common\components\util;
 use yii\imagine\Image;
 
 class UploadController extends BaseController
 {
-
     public $guestAccess = ['save-img', 'save-file'];
 
     //保存图片上传
     public function actionSaveFile()
     {
+        $uploadPath = 'uploads';
+        // 对上传的文件进行多文件夹管理
+        $rootPath = Yii::$app->request->post('rootPath');
+        if (!empty($rootPath) && in_array($rootPath, oss::ROOT_PATHS)) {
+            $uploadPath = $rootPath;
+        }
         $file = $_FILES['file'];
         if (!is_uploaded_file($file['tmp_name'])) {
             util::fail('please upload img');
         }
-        $mainId = $this->sjId;
+        $mainId = $this->mainId; // 变动:$this->sjId 改为 $this->mainId
+        if (intval($mainId) == 0) {
+            Yii::error('------- lose token -------');
+            noticeUtil::push('save-file 无token进行上传文件');
+        }
         $shopId = $this->shopId;
         $month = date("Ym");
         $date = date("d");
@@ -38,7 +46,7 @@ class UploadController extends BaseController
         $newFile = $preFileName . ".jpg";
         $fullPathFile = $path . $newFile;
         if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
-            $img = "uploads/{$mainId}/{$shopId}/{$month}/{$date}/" . $newFile;
+            $img = "{$uploadPath}/{$mainId}/{$shopId}/{$month}/{$date}/" . $newFile;
             oss::uploadImage($img, $fullPathFile);
             $data = business::formatUploadImg($img);
             $data['shortUrl'] = $img;
@@ -163,4 +171,61 @@ class UploadController extends BaseController
         }
     }
 
+    //删除oss上的图片
+    public function actionDeleteFile()
+    {
+        $filePath = Yii::$app->request->post('filePath');
+        if(empty($filePath)){
+            util::fail('参数错误');
+        }
+        // 删除前判断文件是否存在
+        if(!oss::fileExist($filePath)){
+            Yii::error('file not exist: ' . $filePath);
+            util::fail('file not exist');
+        } else {
+            Yii::info('file exist: ' . $filePath);
+        }
+        // 删除OSS文件
+        try {
+            // 设置超时时间为15秒
+            set_time_limit(15);
+            $startTime = time();
+            $timeout = 15; // 15秒超时
+            
+            oss::deleteObject($filePath);
+            
+            // 检查是否超时
+            if (time() - $startTime > $timeout) {
+                throw new \Exception('删除文件操作超时');
+            }
+        } catch (\Exception $e) {
+            util::fail('删除文件失败:' . $e->getMessage());
+        }
+        util::success('success');
+    }
+
+    //批量删除oss上的图片
+    public function actionDeleteFiles()
+    {
+        $filePaths = Yii::$app->request->post('filePaths');
+        if(empty($filePaths) || !is_array($filePaths)){
+            util::fail('参数错误');
+        }
+        foreach($filePaths as $filePath){
+            if(!oss::fileExist($filePath)){
+                Yii::error('file not exist: ' . $filePath);
+                util::fail('file not exist');
+            } else {
+                Yii::info('file exist: ' . $filePath);
+            }
+        }
+        // 删除OSS文件
+        try {
+            oss::deleteObjects($filePaths);
+        } catch (\Exception $e) {
+            util::fail('删除文件失败:' . $e->getMessage());
+        }
+        util::success('success');
+    }
 }
+

+ 52 - 0
app-hd/models/goods/CreateDescForm.php

@@ -0,0 +1,52 @@
+<?php
+namespace hd\models\goods;
+
+use bizHd\goods\classes\GoodsClass;
+use hd\models\BaseForm;
+use Yii;
+
+/**
+ * 创建商品描述表单模型
+ */
+class CreateDescForm extends BaseForm
+{
+    public $id;
+    public $mainId;
+    public $title;
+    public $goodsId;
+    public $content;
+
+    public function rules()
+    {
+        return [
+            [['goodsId'], 'required'],
+            ['title', 'string', 'max' => 60],
+            [['id', 'goodsId', 'mainId'], 'integer'],
+            ['goodsId', 'validateGoodsId'],
+            ['content', 'safe'],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'title' => '标题',
+            'goodsId' => '商品ID',
+            'content' => '图文内容',
+        ];
+    }
+
+    /**
+     * 验证商品ID
+     * @param $attribute
+     */
+    public function validateGoodsId($attribute)
+    {
+        if (!$this->hasErrors()) {
+            $goods = GoodsClass::getById($this->goodsId, true, 'mainId');
+            if (empty($goods) || $goods->mainId != Yii::$app->controller->mainId) {
+                $this->addError($attribute, '商品不存在或不属于当前商户');
+            }
+        }
+    }
+}

+ 16 - 4
app-mall/controllers/GoodsController.php

@@ -4,12 +4,11 @@ namespace mall\controllers;
 
 use bizMall\goods\classes\GoodsClass;
 use bizMall\goods\classes\GoodsSettingClass;
-use bizMall\goods\services\CategoryService;
-use bizMall\goods\services\GoodsCategoryService;
+use bizMall\pictext\classes\PicTextGoodsClass;
+use bizMall\goods\classes\CategoryClass;
+use bizMall\pictext\classes\PicTextClass;
 use bizMall\goods\services\GoodsService;
-use bizMall\goods\services\GoodsSettingService;
 use Yii;
-use yii\web\Controller;
 use common\components\util;
 
 class GoodsController extends BaseController
@@ -19,11 +18,24 @@ class GoodsController extends BaseController
     public function actionDetail()
     {
         $id = Yii::$app->request->get('id', 0);
+        $categoryId = intval(Yii::$app->request->get('categoryId'));
         $info = GoodsClass::getGoodsInfo($id);
         GoodsService::valid($info, $this->mainId);
         $setting = GoodsSettingClass::getByCondition(['mainId' => $this->mainId]);
         $intro = isset($setting['goodsIntroduce']) ? $setting['goodsIntroduce'] : '';
         $info['commonIntro'] = $intro;
+
+        $pixTextGoods = PicTextGoodsClass::getByCondition(['mainId'=>$this->mainId, 'goodsId'=>$id], true);
+        $info['picTextGoods'] = $pixTextGoods;
+
+        $info['picText'] = [];
+        $category = CategoryClass::getById($categoryId);
+        if (!empty($category)) {
+            $picTextId = $category['picTextId'];
+            $picText  = PicTextClass::getById($picTextId, true);
+            $info['picText'] = $picText;
+        }
+
         util::success($info);
     }
 

+ 22 - 0
biz-ghs/pictext/classes/PicTextClass.php

@@ -0,0 +1,22 @@
+<?php
+namespace bizGhs\pictext\classes;
+
+use bizGhs\base\classes\BaseClass;
+
+class PicTextClass extends BaseClass
+{
+    public static $baseFile = '\bizGhs\pictext\models\PicText';
+
+    // 类别
+    // 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)
+    {
+        return self::add($data, $bool);
+    }
+}

+ 10 - 0
biz-ghs/pictext/classes/PicTextGhsItemClass.php

@@ -0,0 +1,10 @@
+<?php
+namespace bizGhs\pictext\classes;
+
+use bizGhs\base\classes\BaseClass;
+
+class PicTextGhsItemClass extends BaseClass
+{
+    public static $baseFile = '\bizGhs\pictext\models\PicTextGhsItem';
+
+}

+ 10 - 0
biz-ghs/pictext/classes/PicTextGoodsClass.php

@@ -0,0 +1,10 @@
+<?php
+namespace bizGhs\pictext\classes;
+
+use bizGhs\base\classes\BaseClass;
+
+class PicTextGoodsClass extends BaseClass
+{
+    public static $baseFile = '\bizGhs\pictext\models\PicTextGoods';
+
+}

+ 12 - 0
biz-ghs/pictext/models/PicText.php

@@ -0,0 +1,12 @@
+<?php
+namespace bizGhs\pictext\models;
+use bizGhs\base\models\Base;
+
+class PicText extends Base
+{
+    public static function tableName()
+    {
+        return 'xhPicText';
+    }
+    
+}

+ 12 - 0
biz-ghs/pictext/models/PicTextGhsItem.php

@@ -0,0 +1,12 @@
+<?php
+namespace bizGhs\pictext\models;
+use bizGhs\base\models\Base;
+
+class PicTextGhsItem extends Base
+{
+    public static function tableName()
+    {
+        return 'xhPicTextGhsItem';
+    }
+    
+}

+ 12 - 0
biz-ghs/pictext/models/PicTextGoods.php

@@ -0,0 +1,12 @@
+<?php
+namespace bizGhs\pictext\models;
+use bizGhs\base\models\Base;
+
+class PicTextGoods extends Base
+{
+    public static function tableName()
+    {
+        return 'xhPicTextGoods';
+    }
+    
+}

+ 1 - 3
biz-hd/goods/classes/CategoryClass.php

@@ -79,8 +79,6 @@ class CategoryClass extends BaseClass
     //删除分类 ssh 2020.3.3
     public static function deleteCategory($id)
     {
-        return self::updateByCondition(['id' => $id, 'goodsNum' => 0], ['delStatus' => 1]);
-        return true;
+        return self::updateByCondition(['id' => $id], ['goodsNum'=>0, 'delStatus'=>1]);
     }
-
 }

+ 3 - 3
biz-hd/goods/classes/GoodsCategoryClass.php

@@ -11,10 +11,10 @@ class GoodsCategoryClass extends BaseClass
 
 	public static $baseFile = '\bizHd\goods\models\GoodsCategory';
 
-	//删除商品的分类 ssh 2019.12.7
-	public static function delGoodsCategory($goodsId)
+	//删除商品的分类
+	public static function delGoodsCategory($mainId, $categoryId, $goodsId)
 	{
-		self::deleteByCondition(['gId'=>$goodsId]);
+		self::updateByCondition(['mainId'=>$mainId, 'cId'=>$categoryId, 'gId'=>$goodsId], ['delStatus' => 1]);
 	}
 
 	//批量获取多个商品的分类ID ssh 2023

+ 131 - 110
biz-hd/goods/classes/GoodsClass.php

@@ -293,33 +293,32 @@ class GoodsClass extends BaseClass
         return $info;
     }
 
-    public static function getGoodsData($where, $params)
-    {
+    public static function getGoodsData($where,$params){
         // 获取分页参数
         $page = Yii::$app->request->get('page', 1);
         $pageSize = Yii::$app->request->get('pageSize', 20);
-
+        
         $flowerNum = $params['flowerNum'] ?? 0;
         // 查询某分类下有库存的商品
         $query = GoodsCategory::find()
             ->where($where)
-            ->joinWith(['goods' => function ($query) use ($flowerNum) {
+            ->joinWith(['goods' => function($query) use ($flowerNum) {
                 $query->andWhere(['delStatus' => 0]);
                 $query->andWhere(['>', 'stock', 0]);
-                if (isset($flowerNum) && $flowerNum > 0) {
-                    $query->andWhere(['flowerNum' => $flowerNum]);
+                if(isset($flowerNum) && $flowerNum > 0){
+                    $query->andWhere(['flowerNum' => $flowerNum]); 
                 }
             }])
             ->orderBy(['inTurn' => SORT_DESC]);
-
+            
         // 获取总数
         $total = $query->count();
-
+        
         // 分页查询
         $goodsList = $query->offset(($page - 1) * $pageSize)
             ->limit($pageSize)
             ->all();
-
+        
         // 整理结果,只要有库存的商品
         $list = [];
         foreach ($goodsList as $goodsCategory) {
@@ -327,7 +326,7 @@ class GoodsClass extends BaseClass
                 $list[] = $goodsCategory->goods->attributes;
             }
         }
-        if (!empty($list)) {
+        if(!empty($list)){
             $list = self::groupGoodsBaseInfo($list);
         }
 
@@ -343,24 +342,44 @@ class GoodsClass extends BaseClass
         ];
     }
 
-    //组装商品基本信息 ssh 2019.12.2
-    public static function groupGoodsBaseInfo($list, $getItem = false, $sortIds = [])
+    /**
+     * 组装商品基本信息
+     * @param $list goods商品数组
+     * @param bool $getItem 是否获取"成品的花材"
+     * @param array $sortIds 按商品分类的inTurn 进行排序的商品id数组
+     * @return mixed
+     */
+    public static function groupGoodsBaseInfo($list, $getItem = false, $sortIds= [])
     {
-        $newList = [];
+        if (empty($list)) {
+            return [];
+        }
         $arrNotEmpty = is_array($sortIds) && !empty($sortIds);
-
+        
         //注意这里涉及商家节日涨价的问题,不要去取不同商家的商品,确有必要另外起方法!!!!!!!!!!
         $currentData = current($list);
-        $mainId = $currentData['mainId'] ?? 0;
+        $mainId = intval($currentData['mainId']);
+        if ($mainId <= 0) {
+            util::fail('mainId 出错');
+        }
         $rise = GoodsSettingClass::getRise($mainId);
         $sjHasCategory = CategoryClass::getCategory($mainId);
-
+        
         // 收集所有商品ID
         $goodsIds = array_column($list, 'id');
         // 一次性获取所有商品的分类关系
         $allGoodsCategories = GoodsCategoryClass::getGoodsHasCategoryIdsBatch($goodsIds);
 
-        foreach ($list as $key => $val) {
+        $groupedItems = [];
+        if ($getItem && !empty($goodsIds)) {
+            $itemList = GoodsItemClass::getAllByCondition(['goodsId' => ['in', $goodsIds]]);
+            // 手动按 goodsId 分组
+            foreach ($itemList as $item) {
+                $groupedItems[$item['goodsId']][] = $item;
+            }
+        }
+        
+        foreach ($list as $key => &$val) {
             $id = $val['id'];
             //大中小图片转化
             $val = business::formatGoodsImg($val);
@@ -388,6 +407,7 @@ class GoodsClass extends BaseClass
                 }
             }
             $val['belongCategory'] = $belongCategory;
+
             $shortCover = $val['cover'] ?? '';
             // 兼容 cover 保存的是数字(表示第几张图片)
             if (intval($shortCover) > 0) {
@@ -401,17 +421,16 @@ class GoodsClass extends BaseClass
             $val['cover'] = imgUtil::groupImg($shortCover);
             $val['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
             $val['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+
             if ($getItem) {
-                $itemList = GoodsItemClass::getAllByCondition(['goodsId' => $id], null, '*');
-                foreach ($itemList as $itemKey => $itemVal) {
+                $currentItems = isset($groupedItems[$id]) ? $groupedItems[$id] : [];
+                foreach ($currentItems as &$itemVal) {
                     $shortCover = $itemVal['cover'] ?? '';
-                    $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
-                    $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
-                    $itemList[$itemKey]['shortCover'] = $shortCover;
-                    $itemList[$itemKey]['smallCover'] = $smallCover;
-                    $itemList[$itemKey]['bigCover'] = $bigCover;
+                    $itemVal['shortCover'] = $shortCover;
+                    $itemVal['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+                    $itemVal['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
                 }
-                $val['goodsItem'] = $itemList;
+                $val['goodsItem'] = $currentItems;
             }
             //前端使用字段
             $val['bigCount'] = 0;
@@ -420,12 +439,11 @@ class GoodsClass extends BaseClass
                 // $newList[$sortIndex] = $val;
                 $val['sortWeight'] = $sortIndex !== false ? $sortIndex : count($sortIds);
             }
-
-            $list[$key] = $val;
         }
+        unset($val); // 销毁引用
 
         if ($arrNotEmpty) {
-            usort($list, function ($a, $b) {
+            usort($list, function($a, $b) {
                 return $a['sortWeight'] - $b['sortWeight'];
             });
             //return $newList;
@@ -435,6 +453,7 @@ class GoodsClass extends BaseClass
         return $list;
     }
 
+
     //新建商品 ssh 20220404
     public static function addGoods($data, $work = null)
     {
@@ -599,14 +618,16 @@ class GoodsClass extends BaseClass
         }
         //精确处理分类变更:分别处理删除、新增、修改三种情况
         $goodsHasCategoryIds = GoodsCategoryService::getGoodsHasCategoryIds($id);
-
+        
         // 1. 找出需要删除的分类:原有分类中不在新分类列表中的
         $toDeleteCategoryIds = array_diff($goodsHasCategoryIds, $categoryIdList);
         if (!empty($toDeleteCategoryIds)) {
-            GoodsCategoryClass::deleteByCondition(['gId' => $id, 'cId' => ['in', $toDeleteCategoryIds]]);
+            //GoodsCategoryClass::deleteByCondition(['gId' => $id, 'cId' => ['in', $toDeleteCategoryIds]]); //不支持,改用 ActiveRecord 的 deleteAll 方法
+            GoodsCategoryClass::getModel()::deleteAll(['and', ['gId' => $id], ['in', 'cId', $toDeleteCategoryIds]]); //先通过 getModel 获取 AR 实例,再调用 deleteAll 方法
+            //\bizHd\goods\models\GoodsCategory::deleteAll(['and', ['gId' => $id], ['in', 'cId', $toDeleteCategoryIds]]); //直接调用 deleteAll 方法
             CategoryClass::counters(['goodsNum' => -1], ['id' => $toDeleteCategoryIds]);
         }
-
+        
         // 2. 找出需要新增的分类:新分类列表中不在原有分类中的
         $toAddCategoryIds = array_diff($categoryIdList, $goodsHasCategoryIds);
         if (!empty($toAddCategoryIds)) {
@@ -629,7 +650,7 @@ class GoodsClass extends BaseClass
             GoodsCategoryClass::batchAdd($addCategory);
             CategoryClass::counters(['goodsNum' => 1], ['id' => $toAddCategoryIds]);
         }
-
+        
         // 3. 处理需要修改的分类:既在原有分类中也在新分类列表中的
         $toUpdateCategoryIds = array_intersect($goodsHasCategoryIds, $categoryIdList);
         if (!empty($toUpdateCategoryIds)) {
@@ -645,10 +666,10 @@ class GoodsClass extends BaseClass
                 GoodsCategoryClass::updateByCondition(['gId' => $id, 'cId' => $categoryId], $updateData);
             }
         }
+        
+        // 字符串的,即认为是 图片URL
+        if (isset($data['cover']) && is_string($data['cover'])) {
 
-        // 兼容 cover 参数是数字
-        if (intval($data['cover']) > 0) {
-            // 如果是大于0的整数,说明是图片序号
         } else {
             $data['cover'] = $data['shopImg'][0] ?? '';
         }
@@ -805,84 +826,84 @@ class GoodsClass extends BaseClass
         //改库存
         $newStock = $goodsData['stock'] - $num;
 
-        //不管有没库存,都生成任务
-
-        $goodsName = $goodsData['name'] ?? '';
-        if ($checkStock) {
-            util::fail($goodsName . '库存不足,剩余:' . $goodsData['stock']);
-        }
-
-        $flower = $goodsData['flower'] ?? 0;
-        if ($flower == 0) {
-            util::complete('绿植盆栽资材类无法生成制作单');
-        }
-
-        //缺的库存生成制作单
-        $sjId = $goodsData['sjId'] ?? 0;
-        $orderSn = $params['orderSn'] ?? '';
-        $orderId = $params['orderId'] ?? 0;
-        $shopId = $params['shopId'] ?? 0;
-        $orderPrice = $params['orderPrice'] ?? 0;
-        $fromType = $params['fromType'] ?? 1;
-        $remark = $params['remark'] ?? '';
-        $orderDebtPrice = $params['orderDebtPrice'] ?? 0;
-        $sendType = $params['sendType'] ?? 0;
-        $thirdSn = $params['thirdSn'] ?? '';
-        $cardInfo = $params['cardInfo'] ?? '';
-        $anonymity = $params['anonymity'] ?? 0;
-        $manyType = $params['manyType'] ?? 0;
-        $sendNum = $params['sendNum'] ?? '';
-        $hasReachTime = 0;
-        $reachPeriod = 0;
-        $reachDate = '0000-00-00';
-        $staffName = '';
-        $staffId = 0;
-        $bookName = '';
-        if (!empty($orderId)) {
-            $order = OrderClass::getById($orderId, true);
-            if (!empty($order)) {
-                $reachDate = $order->reachDate ?? '';
-                if (!empty($reachDate) && $reachDate != '0000-00-00') {
-                    $hasReachTime = 1;
+        if ($newStock < 0) {
+
+            $goodsName = $goodsData['name'] ?? '';
+            if ($checkStock) {
+                util::fail($goodsName . '库存不足,剩余:' . $goodsData['stock']);
+            }
+
+            $flower = $goodsData['flower'] ?? 0;
+            if ($flower == 0) {
+                util::complete('绿植盆栽资材类无法生成制作单');
+            }
+
+            //缺的库存生成制作单
+            $sjId = $goodsData['sjId'] ?? 0;
+            $orderSn = $params['orderSn'] ?? '';
+            $orderId = $params['orderId'] ?? 0;
+            $shopId = $params['shopId'] ?? 0;
+            $orderPrice = $params['orderPrice'] ?? 0;
+            $fromType = $params['fromType'] ?? 1;
+            $remark = $params['remark'] ?? '';
+            $orderDebtPrice = $params['orderDebtPrice'] ?? 0;
+            $sendType = $params['sendType'] ?? 0;
+            $thirdSn = $params['thirdSn'] ?? '';
+            $cardInfo = $params['cardInfo'] ?? '';
+            $anonymity = $params['anonymity'] ?? 0;
+            $manyType = $params['manyType'] ?? 0;
+            $sendNum = $params['sendNum'] ?? '';
+            $hasReachTime = 0;
+            $reachPeriod = 0;
+            $reachDate = '0000-00-00';
+            $staffName = '';
+            $staffId = 0;
+            $bookName = '';
+            if (!empty($orderId)) {
+                $order = OrderClass::getById($orderId, true);
+                if (!empty($order)) {
+                    $reachDate = $order->reachDate ?? '';
+                    if (!empty($reachDate) && $reachDate != '0000-00-00') {
+                        $hasReachTime = 1;
+                    }
+                    $reachPeriod = $order->reachPeriod ?? 0;
+                    $staffName = $order->shopAdminName ?? '';
+                    $staffId = $order->shopAdminId ?? '';
+                    $bookName = $order->bookName ?? '';
                 }
-                $reachPeriod = $order->reachPeriod ?? 0;
-                $staffName = $order->shopAdminName ?? '';
-                $staffId = $order->shopAdminId ?? '';
-                $bookName = $order->bookName ?? '';
             }
+            $sh = $goodsData['sh'] ?? 0;
+            $params = [
+                'goods' => [['productId' => $goodsId, 'num' => abs($num)]],
+                'sjId' => $sjId,
+                'mainId' => $mainId,
+                'orderSn' => $orderSn,
+                'orderId' => $orderId,
+                'hasReachTime' => $hasReachTime,
+                'reachPeriod' => $reachPeriod,
+                'reachDate' => $reachDate,
+                'shopId' => $shopId,
+                'staffName' => $staffName,
+                'staffId' => $staffId,
+                'bookName' => $bookName,
+                'orderPrice' => $orderPrice,
+                'orderDebtPrice' => $orderDebtPrice,
+                'fromType' => $fromType,
+                'sendType' => $sendType,
+                'remark' => $remark,
+                'thirdSn' => $thirdSn,
+                'cardInfo' => $cardInfo,
+                'anonymity' => $anonymity,
+                'sh' => $sh,
+                'manyType' => $manyType,
+                'sendNum' => $sendNum,
+            ];
+            $main = MainClass::getById($mainId, true);
+            if (empty($main)) {
+                util::fail('没有main信息37');
+            }
+            WorkClass::goodsCreateFinish($params, $main);
         }
-        $sh = $goodsData['sh'] ?? 0;
-        $params = [
-            'goods' => [['productId' => $goodsId, 'num' => abs($num)]],
-            'sjId' => $sjId,
-            'mainId' => $mainId,
-            'orderSn' => $orderSn,
-            'orderId' => $orderId,
-            'hasReachTime' => $hasReachTime,
-            'reachPeriod' => $reachPeriod,
-            'reachDate' => $reachDate,
-            'shopId' => $shopId,
-            'staffName' => $staffName,
-            'staffId' => $staffId,
-            'bookName' => $bookName,
-            'orderPrice' => $orderPrice,
-            'orderDebtPrice' => $orderDebtPrice,
-            'fromType' => $fromType,
-            'sendType' => $sendType,
-            'remark' => $remark,
-            'thirdSn' => $thirdSn,
-            'cardInfo' => $cardInfo,
-            'anonymity' => $anonymity,
-            'sh' => $sh,
-            'manyType' => $manyType,
-            'sendNum' => $sendNum,
-        ];
-        $main = MainClass::getById($mainId, true);
-        if (empty($main)) {
-            util::fail('没有main信息37');
-        }
-        WorkClass::goodsCreateFinish($params, $main);
-
 
         $data['stock'] = $newStock;
         self::updateById($goodsId, $data);

+ 0 - 5
biz-hd/goods/classes/GoodsSettingClass.php

@@ -2,14 +2,9 @@
 
 namespace bizHd\goods\classes;
 
-use bizHd\goods\services\GoodsCategoryService;
-use bizHd\goods\services\GoodsStyleService;
 use bizHd\saas\classes\FestClass;
 use bizHd\saas\classes\FestRiseClass;
-use common\components\business;
-use common\components\stringUtil;
 use common\components\util;
-use Yii;
 use bizHd\base\classes\BaseClass;
 
 class GoodsSettingClass extends BaseClass

+ 5 - 13
biz-hd/goods/services/CategoryService.php

@@ -7,22 +7,19 @@ use bizHd\goods\classes\CategoryClass;
 use bizHd\goods\classes\GoodsCategoryClass;
 use common\components\imgUtil;
 use common\components\util;
-use Yii;
-use linslin\yii2\curl;
 
 class CategoryService extends BaseService
 {
-
-
     public static $baseFile = '\bizHd\goods\classes\CategoryClass';
 
     //取所有的分类 ssh 2019.12.7
-    public static function getCategoryList($mainId, $flower = '')
+    public static function getCategoryList($mainId)
     {
         $where = ['mainId' => $mainId, 'delStatus' => 0];
-        if (is_numeric($flower)) {
-            $where['flower'] = $flower;
-        }
+        // 需求变动:不再用 flower 做区分
+        //if (is_numeric($flower)) {
+            //$where['flower'] = $flower;
+        //}
         $cat = CategoryClass::getAllByCondition($where, 'inTurn DESC', '*');
         if (empty($cat)) {
             return $cat;
@@ -119,11 +116,6 @@ class CategoryService extends BaseService
         GoodsCategoryClass::updateByCondition(['cId' => $categoryId], ['cName' => $post['categoryName']]);
     }
 
-    public static function deleteCategory($id)
-    {
-        return CategoryClass::deleteCategory($id);
-    }
-
     //获取开单页所有的分类
     public static function getCategoryClassAll($where)
     {

+ 1 - 1
biz-hd/goods/services/GoodsCategoryService.php

@@ -14,7 +14,7 @@ class GoodsCategoryService extends BaseService
     //查询一个分类下的商品,有分页 ssh 2019.12.2
     public static function getGoodsList($where)
     {
-        unset($where['delStatus']);//这个后面改进
+        $where['delStatus'] = 0; // 排除已删除
         $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
         $list = isset($data['list']) ? $data['list'] : [];
         if (empty($list)) {

+ 21 - 7
biz-hd/goods/services/GoodsService.php

@@ -164,19 +164,33 @@ class GoodsService extends BaseService
         // 获取数据
         $list = $query->all();
 
+        // 整理数据 -- 旧的实现
+        // $goodsList = [];
+        // foreach ($list as $goodsCategory) {
+        //     if ($goodsCategory->goods) {
+        //         $goodsData = $goodsCategory->goods->toArray();
+        //         // 使用现有的方法处理商品信息
+        //         $processedGoods = GoodsClass::groupGoodsBaseInfo([$goodsData]);
+        //         if (!empty($processedGoods)) {
+        //             $goodsList[] = current($processedGoods);
+        //         }
+        //     }
+        // }
+
+
         // 整理数据
-        $goodsList = [];
+        $goodsToProcess = [];
         foreach ($list as $goodsCategory) {
             if ($goodsCategory->goods) {
-                $goodsData = $goodsCategory->goods->toArray();
-                // 使用现有的方法处理商品信息
-                $processedGoods = GoodsClass::groupGoodsBaseInfo([$goodsData]);
-                if (!empty($processedGoods)) {
-                    $goodsList[] = current($processedGoods);
-                }
+                $goodsToProcess[] = $goodsCategory->goods->toArray();
             }
         }
 
+        $goodsList = [];
+        if (!empty($goodsToProcess)) {
+            $goodsList = GoodsClass::groupGoodsBaseInfo($goodsToProcess);
+        }
+
         $totalPage = ceil($total / $pageSize);
         $moreData = $totalPage > $page ? 1 : 0;//是否还有更多数据
         return [

+ 22 - 0
biz-hd/pictext/classes/PicTextClass.php

@@ -0,0 +1,22 @@
+<?php
+namespace bizHd\pictext\classes;
+
+use bizHd\base\classes\BaseClass;
+
+class PicTextClass extends BaseClass
+{
+    public static $baseFile = '\bizHd\pictext\models\PicText';
+
+    // 类别
+    // 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)
+    {
+        return self::add($data, $bool);
+    }
+}

+ 10 - 0
biz-hd/pictext/classes/PicTextGoodsClass.php

@@ -0,0 +1,10 @@
+<?php
+namespace bizHd\pictext\classes;
+
+use bizHd\base\classes\BaseClass;
+
+class PicTextGoodsClass extends BaseClass
+{
+    public static $baseFile = '\bizHd\pictext\models\PicTextGoods';
+
+}

+ 12 - 0
biz-hd/pictext/models/PicText.php

@@ -0,0 +1,12 @@
+<?php
+namespace bizHd\pictext\models;
+use bizHd\base\models\Base;
+
+class PicText extends Base
+{
+    public static function tableName()
+    {
+        return 'xhPicText';
+    }
+    
+}

+ 12 - 0
biz-hd/pictext/models/PicTextGoods.php

@@ -0,0 +1,12 @@
+<?php
+namespace bizHd\pictext\models;
+use bizHd\base\models\Base;
+
+class PicTextGoods extends Base
+{
+    public static function tableName()
+    {
+        return 'xhPicTextGoods';
+    }
+    
+}

+ 14 - 0
biz-mall/pictext/classes/PicTextClass.php

@@ -0,0 +1,14 @@
+<?php
+namespace bizMall\pictext\classes;
+
+use bizMall\base\classes\BaseClass;
+
+class PicTextClass extends BaseClass
+{
+    public static $baseFile = '\bizMall\pictext\models\PicText';
+
+    // 类别 1.花束分类说明(运用于分类的商品) 2.商品特有说明(非商品简介,优先级可高于分类说明) 3.售前与售后说明
+    const TYPE_CATEGORY = 1;
+    const TYPE_GOODS_SPEC = 2;
+    const TYPE_BEFORE_AFTER_SAIL = 3;
+}

+ 10 - 0
biz-mall/pictext/classes/PicTextGoodsClass.php

@@ -0,0 +1,10 @@
+<?php
+namespace bizMall\pictext\classes;
+
+use bizMall\base\classes\BaseClass;
+
+class PicTextGoodsClass extends BaseClass
+{
+    public static $baseFile = '\bizMall\pictext\models\PicTextGoods';
+
+}

+ 12 - 0
biz-mall/pictext/models/PicText.php

@@ -0,0 +1,12 @@
+<?php
+namespace bizMall\pictext\models;
+use bizMall\base\models\Base;
+
+class PicText extends Base
+{
+    public static function tableName()
+    {
+        return 'xhPicText';
+    }
+    
+}

+ 12 - 0
biz-mall/pictext/models/PicTextGoods.php

@@ -0,0 +1,12 @@
+<?php
+namespace bizMall\pictext\models;
+use bizMall\base\models\Base;
+
+class PicTextGoods extends Base
+{
+    public static function tableName()
+    {
+        return 'xhPicTextGoods';
+    }
+    
+}

+ 49 - 55
common/base/classes/BaseClass.php

@@ -7,14 +7,20 @@ use \common\base\models\Base;
 
 class BaseClass
 {
-
     public static $baseFile;
 
+    /**
+     * @return Base
+     */
+    protected static function getModel()
+    {
+        return Yii::createObject(['class' => static::$baseFile]);
+    }
+
     //查询全部 ssh 2019.11.27
     public static function getAllList($select, $where, $order = '', $with = '')
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         $return = $model->getAllList($select, $where, $order, $with);
         return $return;
     }
@@ -22,12 +28,11 @@ class BaseClass
     //分页查询 ssh 2019.9.21
     public static function getList($select, $where, $order = '', $with = '')
     {
-        /** @var Base $model */
         $get = Yii::$app->request->get();
         $page = isset($get['page']) ? $get['page'] : 1;
         Yii::$app->params['page'] = $page;
         $pageSize = isset($get['pageSize']) && !empty($get['pageSize']) ? $get['pageSize'] : Yii::$app->params['pageSize'];
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         $return = $model->getList($select, $where, $page, $pageSize, $order, $with);
         return $return;
     }
@@ -35,16 +40,14 @@ class BaseClass
     //查询指定条数 ssh 2019.11.30
     public static function getLimitList($select, $where, $limit = 10, $order = '', $with = '')
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         $return = $model->getLimitList($select, $where, $limit, $order, $with);
         return $return;
     }
 
     public static function add($data, $returnObject = false)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->add($data, $returnObject);
     }
 
@@ -53,18 +56,20 @@ class BaseClass
      */
     public static function batchAdd($data)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         $model->batchAdd($data);
     }
 
     /**
      * 根据主键ID删除一条记录
+     * @param $id
+     * @return false|int the number of rows deleted, or `false` if the deletion is unsuccessful for some reason.
+     * @throws \Throwable
+     * @throws \yii\db\StaleObjectException
      */
     public static function deleteById($id)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->deleteById($id);
     }
 
@@ -73,8 +78,7 @@ class BaseClass
      */
     public static function deleteByCondition($condition)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         $count = $model->deleteByCondition($condition);
         return $count;
     }
@@ -82,8 +86,7 @@ class BaseClass
     //根据id批量删 ssh 2019.12.7
     public static function deleteByIds($ids)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->deleteByIds($ids);
     }
 
@@ -92,16 +95,14 @@ class BaseClass
      */
     public static function updateById($id, $data)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->updateById($id, $data);
     }
 
     //根据多个主键id更新 ssh 2019.9.3
     public static function updateByIds($ids, $data)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->updateByIds($ids, $data);
     }
 
@@ -110,66 +111,63 @@ class BaseClass
      */
     public static function updateByCondition($condition, $data)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         $count = $model->updateByCondition($condition, $data);
         return $count;
     }
 
     /**
      * 根据主键ID查出一条记录
+     * @param $id
+     * @param bool $returnObject
+     * @param string $field
+     * @return array|\yii\db\ActiveRecord|null
      */
-    public static function getById($id, $returnObject = false)
+    public static function getById($id, $returnObject = false, $field = '*')
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
-        return $model->getById($id, $returnObject);
+        $model = self::getModel();
+        return $model->getById($id, $returnObject, $field);
     }
 
     //随机取一个 ssh 2020.2.10
-    public static function getOne($returnObject = false, $order = false)
+    public static function getOne($returnObject = false, $order = false, $field = '*')
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
-        return $model->getOne($returnObject, $order);
+        $model = self::getModel();
+        return $model->getOne($returnObject, $order, $field);
     }
 
     /**
      *根据条件查出一条记录
      */
-    public static function getByCondition($condition, $returnObject = false, $order = false)
+    public static function getByCondition($condition, $returnObject = false, $order = false, $field = '*')
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
-        return $model->getByCondition($condition, $returnObject, $order);
+        $model = self::getModel();
+        return $model->getByCondition($condition, $returnObject, $order, $field);
     }
 
     //是否存在  ssh 2019.8.30
     public static function exists($condition)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->exists($condition);
     }
 
     /**
      *根据条件查出多条记录
      */
-    public static function getAllByCondition($condition, $order = null, $field, $indexBy = null, $returnObject = false)
+    public static function getAllByCondition($condition, $order = null, $field = '*', $indexBy = null, $returnObject = false)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->getAllByCondition($condition, $order, $field, $indexBy, $returnObject);
     }
 
     /**
      * 根据多个主键ID查询多条记录
      */
-    public static function getByIds($ids, $order = null, $indexBy = null)
+    public static function getByIds($ids, $order = null, $indexBy = null, $field = '*')
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
-        return $model->getByIds($ids, $order, $indexBy);
+        $model = self::getModel();
+        return $model->getByIds($ids, $order, $indexBy, $field);
     }
 
     /**
@@ -177,33 +175,29 @@ class BaseClass
      */
     public static function getCount($condition)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->getCount($condition);
     }
 
     //计数器+1-1 shizq 2019-12-05
     public static function counters($counters, $condition, $params = [])
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->counters($counters, $condition, $params);
     }
 
     //根据主键获取被销的信息 ssh 2021.5.18
-    public static function getLockById($id)
+    public static function getLockById($id, $field = '*')
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
-        return $model->getLockById($id);
+        $model = self::getModel();
+        return $model->getLockById($id, $field);
     }
 
     //求和
     public static function sum($condition, $field)
     {
-        /** @var Base $model */
-        $model = Yii::createObject(['class' => static::$baseFile]);
+        $model = self::getModel();
         return $model->sum($condition, $field);
     }
 
-}
+}

+ 37 - 17
common/base/models/Base.php

@@ -8,6 +8,9 @@ use yii\db\ActiveRecord;
 class Base extends ActiveRecord
 {
 
+    /**
+     * @return static
+     */
     public function getModel()
     {
         $self = get_called_class();
@@ -67,19 +70,26 @@ class Base extends ActiveRecord
 
     /**
      * 根据主键ID删除一条记录
+     * @param $id
+     * @return int|false the number of rows deleted, or `false` if the deletion is unsuccessful for some reason.
+     * @throws \Throwable
+     * @throws \yii\db\StaleObjectException
      */
     public function deleteById($id)
     {
-        //shizhongqi 2019-12-07
         $model = $this->getModel();
         return $model::findOne($id)->delete();
     }
 
-    //根据id批量删 ssh 2019.12.7
+    /**
+     * 根据id批量删 ssh 2019.12.7
+     * @param $ids
+     * @return int the number of rows deleted
+     */
     public function deleteByIds($ids)
     {
         $model = $this->getModel();
-        $model::deleteAll(['id' => $ids]);
+        return $model::deleteAll(['id' => $ids]);
     }
 
     /**
@@ -126,7 +136,7 @@ class Base extends ActiveRecord
     //多个主键更新 ssh 2019.9.3
     public function updateByIds($ids, $data)
     {
-        self::updateAll($data, ['id' => $ids]);
+        return self::updateAll($data, ['id' => $ids]);
     }
 
     /**
@@ -147,22 +157,32 @@ class Base extends ActiveRecord
 
     /**
      * 根据主键ID查出一条记录
+     * @param $id
+     * @param bool $returnObject
+     * @param string $field
+     * @return array|ActiveRecord|null
      */
-    public function getById($id, $returnObject = false)
+    public function getById($id, $returnObject = false, $field = '*')
     {
+        $query = $this->conditionQuery(['id' => $id])->select($field);
         if ($returnObject == false) {
-            return $this->conditionQuery(['id' => $id])->asArray()->one();
+            return $query->asArray()->one();
         } else {
-            return $this->conditionQuery(['id' => $id])->one();
+            return $query->one();
         }
     }
 
     /**
-     *根据条件查出一条记录
+     * 根据条件查出一条记录
+     * @param $condition
+     * @param bool $returnObject
+     * @param bool $order
+     * @param string $field
+     * @return array|ActiveRecord|null
      */
-    public function getByCondition($condition, $returnObject = false, $order = false)
+    public function getByCondition($condition, $returnObject = false, $order = false, $field = '*')
     {
-        $query = $this->conditionQuery($condition);
+        $query = $this->conditionQuery($condition)->select($field);
         if (isset($order)) {
             $query->orderBy($order);
         }
@@ -170,9 +190,9 @@ class Base extends ActiveRecord
     }
 
     //随机取一个 ssh 2020.2.10
-    public function getOne($returnObject = false, $order = false)
+    public function getOne($returnObject = false, $order = false, $field = '*')
     {
-        $query = $this->conditionQuery([]);
+        $query = $this->conditionQuery([])->select($field);
         if (isset($order)) {
             $query->orderBy($order);
         }
@@ -256,13 +276,13 @@ class Base extends ActiveRecord
     /**
      * 根据多个主键ID查询多条记录
      */
-    public function getByIds($ids, $order = null, $indexBy = null)
+    public function getByIds($ids, $order = null, $indexBy = null, $field = '*')
     {
         $data = [];
         if (empty($ids)) {
             return $data;
         }
-        $query = $this->conditionQuery(['id' => ['in', $ids]]);
+        $query = $this->conditionQuery(['id' => ['in', $ids]])->select($field);
         if (isset($indexBy)) {
             $query->indexBy($indexBy);
         }
@@ -352,9 +372,9 @@ class Base extends ActiveRecord
     }
 
     //根据主键获取被销的信息 ssh 2021.5.18
-    public function getLockById($id)
+    public function getLockById($id, $field = '*')
     {
-        return self::findBySql('select * from ' . static::tableName() . ' where id = :id for update', ['id' => $id])->one();
+        return self::findBySql('select ' . $field . ' from ' . static::tableName() . ' where id = :id for update', ['id' => $id])->one();
     }
 
     //求和
@@ -363,4 +383,4 @@ class Base extends ActiveRecord
         return $this->conditionQuery($condition)->sum($field);
     }
 
-}
+}

+ 29 - 6
common/components/oss.php

@@ -1,9 +1,4 @@
 <?php
-/**
- * User: admin
- * Date Time: 2021/3/18 20:15
- */
-
 namespace common\components;
 
 use OSS\Core\OssException;
@@ -12,6 +7,8 @@ use Yii;
 
 class oss
 {
+    // 文件夹常量数组: 1. uploads_pic_text -- 图文专用文件夹  2.
+    const ROOT_PATHS = ['uploads_pic_text'];
 
     //上传文件
     public static function uploadImage($object, $filePath)
@@ -70,7 +67,7 @@ class oss
         $bucket = Yii::$app->params['ossBucket'];
         $ossClient->doesObjectExist($bucket, $object);
         try {
-            $ossClient->doesObjectExist($bucket, $object);
+            return $ossClient->doesObjectExist($bucket, $object);
         } catch (OssException $e) {
             util::fail($e->getMessage());
         }
@@ -98,4 +95,30 @@ class oss
         }
         return true;
     }
+
+    //删除文件
+    public static function deleteObject($object)
+    {
+        $ossClient = self::getOssClient();
+        $bucket = Yii::$app->params['ossBucket'];
+        try {
+            $ossClient->deleteObject($bucket, $object);
+        } catch (OssException $e) {
+            util::fail($e->getMessage());
+        }
+        return true;
+    }
+
+    //批量删除文件
+    public static function deleteObjects($objects)
+    {
+        $ossClient = self::getOssClient();
+        $bucket = Yii::$app->params['ossBucket'];
+        try {
+            $ossClient->deleteObjects($bucket, $objects);
+        } catch (OssException $e) {
+            util::fail($e->getMessage());
+        }
+        return true;
+    }
 }

+ 4 - 0
common/config/main.php

@@ -5,6 +5,10 @@ return [
 		'request' => [
 			'cookieValidationKey' => '3i18DOM7ZDqqQfr2S0hj0c60wFxxTb3J',
 			'enableCsrfValidation' => false,
+			// 'parsers' => [
+			// 	'application/json' => 'yii\web\JsonParser',
+			// ] // 启用 JSON 输入
+			// 信息: 上述配置是可选的。若未按上述配置,API 将仅可以分辨 application/x-www-form-urlencoded 和 multipart/form-data 输入格式
 		],
 		'cache' => [
 			'class' => 'yii\caching\FileCache',

+ 1 - 1
composer.json

@@ -14,7 +14,7 @@
     },
     "minimum-stability": "dev",
     "require": {
-        "php": ">=5.4.0",
+        "php": ">=7.0",
         "yiisoft/yii2": "2.0.29",
         "yiisoft/yii2-bootstrap": "~2.0.6",
         "yiisoft/yii2-swiftmailer": "~2.0.6",