|
|
@@ -4,11 +4,11 @@ namespace hd\controllers;
|
|
|
|
|
|
use biz\shop\classes\ShopExtClass;
|
|
|
use bizGhs\order\classes\OrderItemClass;
|
|
|
+use bizHd\goods\classes\GoodsCategoryClass;
|
|
|
use bizHd\goods\classes\GoodsClass;
|
|
|
use bizHd\goods\services\CategoryService;
|
|
|
use bizHd\goods\services\GoodsCategoryService;
|
|
|
use bizHd\goods\services\GoodsSettingService;
|
|
|
-use bizHd\saas\services\FestRiseService;
|
|
|
use common\components\printUtil;
|
|
|
use Yii;
|
|
|
use common\components\util;
|
|
|
@@ -57,7 +57,14 @@ class GoodsController extends BaseController
|
|
|
//添加商品 ssh 2019.12.7
|
|
|
public function actionAdd()
|
|
|
{
|
|
|
- $data = Yii::$app->request->post();
|
|
|
+ $form = new \hd\models\goods\AddForm();
|
|
|
+ $form->load(Yii::$app->request->post(), '');
|
|
|
+ if (!$form->validateForm()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //$data = Yii::$app->request->post();
|
|
|
+ $data = $form->attributes;
|
|
|
$data['sjId'] = $this->sjId;
|
|
|
$data['mainId'] = $this->mainId;
|
|
|
$data['shopId'] = $this->shopId ?? 0;
|
|
|
@@ -106,11 +113,12 @@ class GoodsController extends BaseController
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|
|
|
$status = isset($get['status']) && is_numeric($get['status']) ? $get['status'] : -1;
|
|
|
- $cId = isset($get['cId']) && !empty($get['cId']) ? $get['cId'] : 0;
|
|
|
+ $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'] : '';
|
|
|
$hasStock = isset($get['hasStock']) ? $get['hasStock'] : 0;
|
|
|
+
|
|
|
$where = [];
|
|
|
if ($status != -1) {
|
|
|
$where['status'] = $status;
|
|
|
@@ -156,7 +164,7 @@ class GoodsController extends BaseController
|
|
|
//获取商品详情 ssh 2019.12.7
|
|
|
public function actionDetail()
|
|
|
{
|
|
|
- $id = Yii::$app->request->get('id');
|
|
|
+ $id = intval(Yii::$app->request->get('id'));
|
|
|
$goods = GoodsClass::getGoodsInfo($id);
|
|
|
GoodsClass::valid($goods, $this->mainId);
|
|
|
util::success($goods);
|
|
|
@@ -165,9 +173,15 @@ class GoodsController extends BaseController
|
|
|
//更新商品 ssh 2019.12.7
|
|
|
public function actionUpdate()
|
|
|
{
|
|
|
- $data = Yii::$app->request->post();
|
|
|
- $id = isset($data['id']) ? $data['id'] : 0;
|
|
|
- $info = GoodsService::getById($id);
|
|
|
+ $form = new \hd\models\goods\UpdateForm();
|
|
|
+ $form->load(Yii::$app->request->post(), '');
|
|
|
+ if (!$form->validateForm()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $form->attributes;
|
|
|
+ $id = $data['id'];
|
|
|
+ $info = GoodsClass::getById($id);
|
|
|
GoodsService::valid($info, $this->mainId);
|
|
|
$data['sjId'] = $this->sjId;
|
|
|
$data['mainId'] = $this->mainId;
|
|
|
@@ -187,30 +201,43 @@ class GoodsController extends BaseController
|
|
|
$transaction->commit();
|
|
|
util::complete();
|
|
|
} catch (\Exception $e) {
|
|
|
+ // 记录错误日志
|
|
|
+ Yii::error('商品更新失败:' . $e->getMessage(), 'goods.update'); //. "\n" . $e->getTraceAsString()
|
|
|
$transaction->rollBack();
|
|
|
util::fail();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //商品排序 ssh 2020.3.11
|
|
|
+ //商品排序
|
|
|
public function actionSort()
|
|
|
{
|
|
|
- $id = Yii::$app->request->get('id', 0);
|
|
|
- $cId = Yii::$app->request->get('cId', 0);
|
|
|
- $inTurn = Yii::$app->request->get('inTurn', 0);
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $items = $post['items'];
|
|
|
+ $cId = intval($post['cId']);
|
|
|
+
|
|
|
//验证商品
|
|
|
- $info = GoodsService::getById($id);
|
|
|
- GoodsService::valid($info, $this->mainId);
|
|
|
- if ($cId != 0) {
|
|
|
- //验证分类
|
|
|
- $category = CategoryService::getById($cId);
|
|
|
- CategoryService::valid($category, $this->mainId);
|
|
|
- GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
|
|
|
- } else {
|
|
|
- GoodsService::updateById($id, ['inTurn' => $inTurn]);
|
|
|
- GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
|
|
|
+ // 提取所有商品ID
|
|
|
+ $categoryIds = array_map(function($item) {
|
|
|
+ return intval($item['id']);
|
|
|
+ }, $items);
|
|
|
+
|
|
|
+ // 批量获取商品信息
|
|
|
+ $goodsInfos = GoodsClass::getByIds($categoryIds);
|
|
|
+ // 批量验证商品
|
|
|
+ foreach($goodsInfos as $info) {
|
|
|
+ GoodsService::valid($info, $this->mainId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $category = CategoryService::getById($cId);
|
|
|
+ CategoryService::valid($category, $this->mainId);
|
|
|
+ // 更新商品排序
|
|
|
+ foreach($items as $item) {
|
|
|
+ $id = intval($item['id']);
|
|
|
+ $inTurn = intval($item['inTurn']);
|
|
|
+ GoodsCategoryClass::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
|
|
|
}
|
|
|
- util::complete('操作成功');
|
|
|
+
|
|
|
+ util::complete('排序完成');
|
|
|
}
|
|
|
|
|
|
//删除商品 ssh 2019.12.7
|
|
|
@@ -261,21 +288,27 @@ class GoodsController extends BaseController
|
|
|
//更新涨价 ssh 2019.12.9
|
|
|
public function actionUpdateRise()
|
|
|
{
|
|
|
- $post = Yii::$app->request->post();
|
|
|
+ $form = new \hd\models\goods\UpdateRiseForm();
|
|
|
+ $form->load(Yii::$app->request->post(), '');
|
|
|
+ if (!$form->validateForm()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $post = $form->attributes;
|
|
|
$festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
|
|
|
unset($post['festIdList']);
|
|
|
- $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
|
|
|
- if ($riseSwitch == 1) {
|
|
|
- if (empty($festIdList)) {
|
|
|
- util::fail('请选择节日');
|
|
|
- }
|
|
|
- FestRiseService::deleteByCondition(['mainId' => $this->mainId]);
|
|
|
- $add = [];
|
|
|
- foreach ($festIdList as $festId) {
|
|
|
- $add[] = ['mainId' => $this->mainId, 'festId' => $festId];
|
|
|
- }
|
|
|
- FestRiseService::batchAdd($add);
|
|
|
- }
|
|
|
+ // $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
|
|
|
+ // if ($riseSwitch == 1) {
|
|
|
+ // if (empty($festIdList)) {
|
|
|
+ // util::fail('请选择节日');
|
|
|
+ // }
|
|
|
+ // FestRiseService::deleteByCondition(['mainId' => $this->mainId]);
|
|
|
+ // $add = [];
|
|
|
+ // foreach ($festIdList as $festId) {
|
|
|
+ // $add[] = ['mainId' => $this->mainId, 'festId' => $festId];
|
|
|
+ // }
|
|
|
+ // FestRiseService::batchAdd($add);
|
|
|
+ // }
|
|
|
GoodsSettingService::updateByCondition(['mainId' => $this->mainId], $post);
|
|
|
util::complete('提交成功');
|
|
|
}
|