|
|
@@ -100,12 +100,13 @@ class ItemController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function actionModifyBigUnit()
|
|
|
+ public function actionModifyUnit()
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|
|
|
$id = $get['id'] ?? '';
|
|
|
$unitId = $get['unitId'] ?? 1;
|
|
|
$unit = UnitClass::getById($unitId, true);
|
|
|
+ $type = $get['type'] ?? 'big';
|
|
|
if (empty($unit)) {
|
|
|
util::fail('没有找到单位');
|
|
|
}
|
|
|
@@ -130,52 +131,17 @@ class ItemController extends BaseController
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
- $ptItem->bigUnit = $unitName;
|
|
|
- $ptItem->bigUnitId = $unitId;
|
|
|
- $ptItem->save();
|
|
|
- ItemClass::updateByCondition(['itemId' => $ptItemId], ['bigUnit' => $unitName, 'bigUnitId' => $unitId]);
|
|
|
- $transaction->commit();
|
|
|
- } catch (\Exception $e) {
|
|
|
- $transaction->rollBack();
|
|
|
- Yii::info("修改失败原因:" . $e->getMessage());
|
|
|
- util::fail('修改失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function actionModifySmallUnit()
|
|
|
- {
|
|
|
- $get = Yii::$app->request->get();
|
|
|
- $id = $get['id'] ?? '';
|
|
|
- $unitId = $get['unitId'] ?? 1;
|
|
|
- $unit = UnitClass::getById($unitId, true);
|
|
|
- if (empty($unit)) {
|
|
|
- util::fail('没有找到单位');
|
|
|
- }
|
|
|
- $unitName = $unit->name;
|
|
|
- $item = ItemClass::getById($id, true);
|
|
|
- if (empty($item)) {
|
|
|
- util::fail('没有找到花材');
|
|
|
- }
|
|
|
- if ($item->mainId != $this->mainId) {
|
|
|
- util::fail('不是你的花材');
|
|
|
- }
|
|
|
- $adminId = $this->adminId;
|
|
|
- $ptItemId = $item->itemId ?? 0;
|
|
|
- $hasRightChange = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
|
|
|
- if ($hasRightChange == 0) {
|
|
|
- util::fail('不能修改');
|
|
|
- }
|
|
|
- $ptItem = PtItemClass::getById($ptItemId, true);
|
|
|
- if (empty($ptItem)) {
|
|
|
- util::fail('花材信息缺失');
|
|
|
- }
|
|
|
- $connection = Yii::$app->db;
|
|
|
- $transaction = $connection->beginTransaction();
|
|
|
- try {
|
|
|
- $ptItem->smallUnit = $unitName;
|
|
|
- $ptItem->smallUnitId = $unitId;
|
|
|
- $ptItem->save();
|
|
|
- ItemClass::updateByCondition(['itemId' => $ptItemId], ['smallUnit' => $unitName, 'smallUnitId' => $smallUnitId]);
|
|
|
+ if ($type == 'big') {
|
|
|
+ $ptItem->bigUnit = $unitName;
|
|
|
+ $ptItem->bigUnitId = $unitId;
|
|
|
+ $ptItem->save();
|
|
|
+ ItemClass::updateByCondition(['itemId' => $ptItemId], ['bigUnit' => $unitName, 'bigUnitId' => $unitId]);
|
|
|
+ } else {
|
|
|
+ $ptItem->smallUnit = $unitName;
|
|
|
+ $ptItem->smallUnitId = $unitId;
|
|
|
+ $ptItem->save();
|
|
|
+ ItemClass::updateByCondition(['itemId' => $ptItemId], ['smallUnit' => $unitName, 'smallUnitId' => $unitId]);
|
|
|
+ }
|
|
|
$transaction->commit();
|
|
|
} catch (\Exception $e) {
|
|
|
$transaction->rollBack();
|