|
|
@@ -305,36 +305,62 @@ class ItemController extends BaseController
|
|
|
util::fail('超管才能操作');
|
|
|
}
|
|
|
$post = Yii::$app->request->post();
|
|
|
- //[{itemId:1000,classId:2,price:1,stockWarning:1}]
|
|
|
+ //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
|
|
|
$data = $post['data'];
|
|
|
if (empty($data)) {
|
|
|
util::fail("请选花材");
|
|
|
}
|
|
|
$data = json_decode($data, true);
|
|
|
- if (!is_array($data) || empty($data)) {
|
|
|
+ if (is_array($data) == false || empty($data)) {
|
|
|
util::fail("请选花材");
|
|
|
}
|
|
|
-
|
|
|
+ $shop = $this->shop;
|
|
|
+ $shopId = $this->shopId;
|
|
|
+ $mainId = $this->mainId;
|
|
|
$sjId = $this->sjId;
|
|
|
+ $adminId = $this->adminId;
|
|
|
$ids = array_column($data, 'itemId');
|
|
|
$ids = array_unique(array_filter($ids));
|
|
|
-
|
|
|
- $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId' => ['in', $ids]]);
|
|
|
+ $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
|
|
|
if (!empty($has)) {
|
|
|
- util::fail("有花材已经添加过了");
|
|
|
+ $hasName = $has->name ?? '';
|
|
|
+ util::fail($hasName . " 已经添加过了");
|
|
|
}
|
|
|
- $shopId = $this->shopId;
|
|
|
- $mainId = $this->mainId;
|
|
|
+ $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
foreach ($data as $v) {
|
|
|
- $v['adminId'] = $this->adminId;
|
|
|
+ $ptItemId = $v['itemId'] ?? 0;
|
|
|
+ $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
|
|
|
+ $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
|
|
|
+ $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
|
|
|
+ $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
|
|
|
+ $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
|
|
|
+ $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
|
|
|
+ $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
|
|
|
+ $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
|
|
|
+ $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
|
|
|
+ $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
|
|
|
+
|
|
|
+ $v['ratio'] = $ratio;
|
|
|
+ $v['shelfLife'] = $shelfLife;
|
|
|
+ $v['ratioType'] = $ratioType;
|
|
|
+ $v['variety'] = $variety;
|
|
|
+ $v['stockWarning'] = $stockWarning;
|
|
|
+ $v['weight'] = $weight;
|
|
|
+ $v['bigUnit'] = $bigUnit;
|
|
|
+ $v['smallUnit'] = $smallUnit;
|
|
|
+ $v['bigUnitId'] = $bigUnitId;
|
|
|
+ $v['smallUnitId'] = $smallUnitId;
|
|
|
+
|
|
|
+ $v['adminId'] = $adminId;
|
|
|
$v['sjId'] = $sjId;
|
|
|
$v['shopId'] = $shopId;
|
|
|
$v['mainId'] = $mainId;
|
|
|
$v['staffName'] = $shopAdmin->name ?? '';
|
|
|
- ProductClass::addProduct($v, $this->shop);
|
|
|
+ print_r($v);die;
|
|
|
+ ProductClass::addProduct($v, $shop);
|
|
|
}
|
|
|
$transaction->commit();
|
|
|
util::complete('添加成功');
|