|
|
@@ -18,6 +18,7 @@ use common\components\orderSn;
|
|
|
use common\components\stringUtil;
|
|
|
use common\components\util;
|
|
|
use common\services\xhItemService;
|
|
|
+use Yii;
|
|
|
|
|
|
class ItemClass extends BaseClass
|
|
|
{
|
|
|
@@ -57,11 +58,11 @@ class ItemClass extends BaseClass
|
|
|
if (!$classId) {
|
|
|
util::fail("请选择分类");
|
|
|
}
|
|
|
- if (isset($data['price']) == false || is_numeric($data['price']) == false || $data['price'] < 0) {
|
|
|
+ if (isset($data['skPrice']) == false || is_numeric($data['skPrice']) == false || $data['skPrice'] < 0) {
|
|
|
util::fail("请输入价格");
|
|
|
}
|
|
|
- if (isset($data['addPrice']) == false || is_numeric($data['addPrice']) == false) {
|
|
|
- util::fail("请输入花材的加价");
|
|
|
+ if (isset($data['skAddPrice']) == false || is_numeric($data['skAddPrice']) == false) {
|
|
|
+ util::fail("请输入加价");
|
|
|
}
|
|
|
if ($stockWarning === false) {
|
|
|
util::fail("请输入库存预警值");
|
|
|
@@ -85,66 +86,35 @@ class ItemClass extends BaseClass
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
- //新增到平台
|
|
|
- $defaultInfo = PtItemClassClass::getByCondition(['isDefault' => 1]);
|
|
|
- $defaultClassId = $defaultInfo['id'] ?? 0;
|
|
|
- if (empty($defaultClassId)) {
|
|
|
- Yii::info('添加花材时没有找到默认分类');
|
|
|
- util::fail('添加失败');
|
|
|
- }
|
|
|
-
|
|
|
- $itemData = $data;
|
|
|
- $itemData['classId'] = $defaultClassId;
|
|
|
if (isset($data['itemId']) == false || empty($data['itemId'])) {
|
|
|
- $itemData['skAddPrice'] = 3;
|
|
|
- $itemData['hjAddPrice'] = 2;
|
|
|
- $itemData['zsAddPrice'] = 1;
|
|
|
+ //添加新品种先在平台新增花材
|
|
|
+ $defaultInfo = PtItemClassClass::getByCondition(['isDefault' => 1]);
|
|
|
+ $defaultClassId = $defaultInfo['id'] ?? 0;
|
|
|
+ if (empty($defaultClassId)) {
|
|
|
+ Yii::info('添加花材时没有找到默认分类');
|
|
|
+ util::fail('添加失败');
|
|
|
+ }
|
|
|
+ $itemData = $data;
|
|
|
+ $itemData['classId'] = $defaultClassId;
|
|
|
+ $itemData['skAddPrice'] = $itemData['skAddPrice'] ?? 3;
|
|
|
+ $itemData['hjAddPrice'] = $itemData['hjAddPrice'] ?? 2;
|
|
|
+ $itemData['zsAddPrice'] = $itemData['zsAddPrice'] ?? 1;
|
|
|
$ptItemInfo = PtItemClass::addItem($itemData);
|
|
|
$data['itemId'] = $ptItemInfo['id'];
|
|
|
} else {
|
|
|
- //从平台导入花材方式添加有带itemId
|
|
|
+ //从平台导入花材
|
|
|
$has = self::getByCondition(['shopId' => $data['shopId'], 'itemId' => $data['itemId']], true);
|
|
|
if (!empty($has)) {
|
|
|
- util::fail('已经添加过了');
|
|
|
+ util::fail('已经导过了');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //小菊的结构
|
|
|
- $ptItemId = $data['itemId'] ?? 0;
|
|
|
- $ptItemInfo = PtItemClass::getById($ptItemId, true);
|
|
|
- $data['variety'] = $ptItemInfo->variety ?? 0;
|
|
|
-
|
|
|
- //加价 2021-12-07 lqh 如果前端有传取前端的,没有则取pt
|
|
|
- $skAddPrice = $data['skAddPrice'] ?? $ptItemInfo->skAddPrice;
|
|
|
- $data['skAddPrice'] = $skAddPrice;
|
|
|
- $addPrice = $data['addPrice'] ?? $ptItemInfo->addPrice;
|
|
|
- $data['addPrice'] = $addPrice;
|
|
|
- if ($addPrice > $skAddPrice) {
|
|
|
- util::fail('普店加价不能大于散客加价');
|
|
|
- }
|
|
|
- $hjAddPrice = $data['hjAddPrice'] ?? $ptItemInfo->hjAddPrice;
|
|
|
- $data['hjAddPrice'] = $hjAddPrice;
|
|
|
- if ($hjAddPrice > $addPrice) {
|
|
|
- util::fail('银店加价不能大于普店加价');
|
|
|
- }
|
|
|
- $zsAddPrice = $data['zsAddPrice'] ?? $ptItemInfo->zsAddPrice;
|
|
|
- $data['zsAddPrice'] = $zsAddPrice;
|
|
|
- if ($zsAddPrice > $hjAddPrice) {
|
|
|
- util::fail('金店加价不能大于银店加价');
|
|
|
- }
|
|
|
-
|
|
|
- //价格
|
|
|
- $price = $data['price'] ?? 0;
|
|
|
- $skPrice = bcsub($price, bcsub($addPrice, $skAddPrice, 2), 2);
|
|
|
- $hjPrice = bcsub($price, bcsub($addPrice, $hjAddPrice, 2), 2);
|
|
|
- $zsPrice = bcsub($price, bcsub($addPrice, $zsAddPrice, 2), 2);
|
|
|
- $data['skPrice'] = $skPrice;
|
|
|
- $data['hjPrice'] = $hjPrice;
|
|
|
- $data['zsPrice'] = $zsPrice;
|
|
|
-
|
|
|
- //根据sjId, 找到所有的shopId,都添加
|
|
|
+ //找到父级sj下的所有直营店,添加花材
|
|
|
$shopList = ShopClass::getAllByCondition(['sjId' => $data['sjId']], null, '*', null, true);
|
|
|
foreach ($shopList as $shop) {
|
|
|
+ if (isset($shop->join) && $shop->join == 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
$shopId = $shop->id ?? 0;
|
|
|
$currentMainId = $shop->mainId ?? 0;
|
|
|
$data['shopId'] = $shopId;
|
|
|
@@ -154,7 +124,6 @@ class ItemClass extends BaseClass
|
|
|
$data['stock'] = 0;
|
|
|
$data['status'] = 2;
|
|
|
}
|
|
|
-
|
|
|
$res = self::add($data);
|
|
|
if ($stock > 0 && $res && $currentShopId == $shopId) {
|
|
|
//有库存数量,增加盘盈记录 2021.7.9 lqh
|
|
|
@@ -215,10 +184,10 @@ class ItemClass extends BaseClass
|
|
|
}
|
|
|
}
|
|
|
$transaction->commit();
|
|
|
-
|
|
|
} catch (\Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
|
- util::fail($exception->getMessage());
|
|
|
+ Yii::info('失败原因:' . $exception->getMessage());
|
|
|
+ util::fail('添加失败');
|
|
|
}
|
|
|
}
|
|
|
|