|
|
@@ -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);
|
|
|
+ }
|
|
|
+}
|