|
|
@@ -281,8 +281,8 @@ class ProductClass extends BaseClass
|
|
|
self::updateStockById($productId, $newStock);
|
|
|
//减库存,加销量 2021.6.21 linqh
|
|
|
$actualSold = $productData->actualSold;
|
|
|
- $newActualSold = bcadd($actualSold,$itemNum,2);
|
|
|
- self::updateActualSoldById($productId,$newActualSold);
|
|
|
+ $newActualSold = bcadd($actualSold, $itemNum, 2);
|
|
|
+ self::updateActualSoldById($productId, $newActualSold);
|
|
|
|
|
|
util::unlock($key);
|
|
|
return ['oldStock' => $productData['stock'], 'newStock' => $newStock];
|
|
|
@@ -290,6 +290,7 @@ class ProductClass extends BaseClass
|
|
|
|
|
|
|
|
|
//根据数量减库存
|
|
|
+
|
|
|
/**
|
|
|
* @param $productId
|
|
|
* @param $itemNum
|
|
|
@@ -317,8 +318,8 @@ class ProductClass extends BaseClass
|
|
|
|
|
|
//减库存,加销量 2021.6.21 linqh
|
|
|
$actualSold = $productData['actualSold'];
|
|
|
- $newActualSold = bcadd($actualSold,$itemNum,2);
|
|
|
- self::updateActualSoldById($productId,$newActualSold);
|
|
|
+ $newActualSold = bcadd($actualSold, $itemNum, 2);
|
|
|
+ self::updateActualSoldById($productId, $newActualSold);
|
|
|
|
|
|
util::unlock($key);
|
|
|
return ['oldStock' => $productData['stock'], 'newStock' => $newStock];
|
|
|
@@ -603,12 +604,6 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
$upData['cover'] = $data['cover'];
|
|
|
}
|
|
|
-// if (isset($data['alias'])) {
|
|
|
-// if (empty($data['alias'])) {
|
|
|
-// util::fail("请输入花材别名");
|
|
|
-// }
|
|
|
-// $upData['alias'] = $data['alias'];
|
|
|
-// }
|
|
|
if (isset($data['cost'])) {
|
|
|
if (empty($data['cost'])) {
|
|
|
util::fail("请输入花材成本价");
|
|
|
@@ -619,6 +614,9 @@ class ProductClass extends BaseClass
|
|
|
if (empty($data['ratio'])) {
|
|
|
util::fail("请输入花材比例");
|
|
|
}
|
|
|
+ if (preg_match("/^[1-9][0-9]*$/", $data['ratio']) == false || $data['ratio'] <= 0) {
|
|
|
+ util::fail('比例请填写整数,并且大于0');
|
|
|
+ }
|
|
|
$upData['ratio'] = $data['ratio'];
|
|
|
}
|
|
|
if (isset($data['weight'])) {
|
|
|
@@ -627,8 +625,6 @@ class ProductClass extends BaseClass
|
|
|
if (isset($data['addPrice'])) {
|
|
|
$upData['addPrice'] = $data['addPrice'];
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
if (isset($data['stockWarning'])) {
|
|
|
$upData['stockWarning'] = $data['stockWarning'];
|
|
|
}
|
|
|
@@ -649,7 +645,7 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
if (isset($data['delStatus'])) {
|
|
|
- if(!in_array($data['delStatus'],[0,1])){
|
|
|
+ if (!in_array($data['delStatus'], [0, 1])) {
|
|
|
util::fail("上下架参数错误");
|
|
|
}
|
|
|
$upData['delStatus'] = $data['delStatus'];
|
|
|
@@ -819,8 +815,8 @@ class ProductClass extends BaseClass
|
|
|
$weight = $data['weight'] ?? false;
|
|
|
$data['bigUnit'] = $data['bigUnit'] ?? '';
|
|
|
$data['smallUnit'] = $data['smallUnit'] ?? '';
|
|
|
- $data['shopId'] = $data['shopId']??0;
|
|
|
- $data['sjId'] = $data['sjId']??0;
|
|
|
+ $data['shopId'] = $data['shopId'] ?? 0;
|
|
|
+ $data['sjId'] = $data['sjId'] ?? 0;
|
|
|
if (!$data['sjId']) {
|
|
|
util::fail("参数错误");
|
|
|
}
|
|
|
@@ -848,34 +844,34 @@ class ProductClass extends BaseClass
|
|
|
util::fail("请输入花材重量");
|
|
|
}
|
|
|
|
|
|
- $existItemClass = ItemClassClass::exists(['id' => $classId,'sjId'=>$data['sjId']]);
|
|
|
+ $existItemClass = ItemClassClass::exists(['id' => $classId, 'sjId' => $data['sjId']]);
|
|
|
if (!$existItemClass) {
|
|
|
util::fail("花材分类不存在");
|
|
|
}
|
|
|
//
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
//新增到平台,分类为18
|
|
|
$itemData = $data;
|
|
|
$itemData['classId'] = 18;
|
|
|
$itemRes = PtItemClass::addItem($itemData);
|
|
|
$data['price'] = $data['cost'] + $data['addPrice'];
|
|
|
//获取到itemId
|
|
|
- if($itemRes && $itemRes['id']){
|
|
|
+ if ($itemRes && $itemRes['id']) {
|
|
|
$data['itemId'] = $itemRes['id'];
|
|
|
//根据sjId, 找到所有的shopId,都添加
|
|
|
$shopIds = ShopService::getShopIds($data['sjId']);
|
|
|
- foreach ($shopIds as $shopId){
|
|
|
+ foreach ($shopIds as $shopId) {
|
|
|
$data['shopId'] = $shopId;
|
|
|
self::add($data);
|
|
|
}
|
|
|
$transaction->commit();
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$transaction->rollBack();
|
|
|
util::fail("花材添加失败");
|
|
|
}
|
|
|
- }catch (\Exception $exception){
|
|
|
+ } catch (\Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
|
util::fail($exception->getMessage());
|
|
|
}
|