|
|
@@ -6,7 +6,7 @@ use biz\item\classes\PtItemClass;
|
|
|
use bizGhs\item\classes\ItemClass;
|
|
|
use bizGhs\item\services\ItemService;
|
|
|
use common\components\util;
|
|
|
-use common\services\xhItemService;
|
|
|
+use bizGhs\product\classes\ProductClass;
|
|
|
use Yii;
|
|
|
|
|
|
class ItemController extends BaseController
|
|
|
@@ -28,8 +28,18 @@ class ItemController extends BaseController
|
|
|
$post = Yii::$app->request->post();
|
|
|
$post['adminId'] = $this->adminId;
|
|
|
$post['sjId'] = $this->sjId;
|
|
|
- ItemService::addGhsItem($post);
|
|
|
- util::complete('添加成功');
|
|
|
+
|
|
|
+ $connection = Yii::$app->db;//事务处理
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ ItemService::addGhsItem($post);
|
|
|
+ $transaction->commit();
|
|
|
+ util::complete('添加成功');
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ util::fail('添加失败');
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//批量添加花材
|
|
|
@@ -51,12 +61,31 @@ class ItemController extends BaseController
|
|
|
if (!is_array($data) || empty($data)) {
|
|
|
util::fail("请选花材");
|
|
|
}
|
|
|
- foreach ($data as $v) {
|
|
|
- $v['adminId'] = $this->adminId;
|
|
|
- $v['sjId'] = $this->sjId;
|
|
|
- ItemService::addGhsItem($v);
|
|
|
+
|
|
|
+ $sjId = $this->sjId;
|
|
|
+ $ids = array_column($data,'itemId');
|
|
|
+ $ids = array_unique(array_filter($ids));
|
|
|
+
|
|
|
+ $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId'=>['in',$ids]]);
|
|
|
+ if(!empty($has)){
|
|
|
+ util::fail("有花材已经添加过了");
|
|
|
+ }
|
|
|
+
|
|
|
+ $connection = Yii::$app->db;//事务处理
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ foreach ($data as $v) {
|
|
|
+ $v['adminId'] = $this->adminId;
|
|
|
+ $v['sjId'] = $sjId;
|
|
|
+ ItemService::addGhsItem($v);
|
|
|
+ }
|
|
|
+ $transaction->commit();
|
|
|
+ util::complete('添加成功');
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ util::fail();
|
|
|
}
|
|
|
- util::complete('添加成功');
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public function actionUpdate()
|