|
|
@@ -19,6 +19,40 @@ class OrderItemController extends BaseController
|
|
|
//更换花材 ssh 20240430
|
|
|
public function actionChangeItem()
|
|
|
{
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $delId = $post['delId'] ?? 0;
|
|
|
+ $orderSn = $post['orderSn'] ?? '';
|
|
|
+ $num = $post['num'] ?? 0;
|
|
|
+ $price = $post['price'] ?? 0;
|
|
|
+ $productId = $post['productId'] ?? 0;
|
|
|
+ $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('订单没有找到哦');
|
|
|
+ }
|
|
|
+ if ($order->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的订单');
|
|
|
+ }
|
|
|
+ $delInfo = OrderItemClass::getById($delId, true);
|
|
|
+ if (empty($delInfo)) {
|
|
|
+ util::fail('没有找到要删除的花材');
|
|
|
+ }
|
|
|
+ if ($delInfo->orderSn != $orderSn) {
|
|
|
+ util::fail('这个花材你不能删除');
|
|
|
+ }
|
|
|
+ $connection = Yii::$app->db;//事务处理
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ $delInfo->delete();
|
|
|
+ $delInfo->save();
|
|
|
+ $new = [];
|
|
|
+ $new[$productId] = ['num' => $num, 'productId' => $productId];
|
|
|
+ OrderItemClass::bookAddItem($order, $new);
|
|
|
+ $transaction->commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ Yii::info("出错了:" . $e->getMessage());
|
|
|
+ util::fail('出错了');
|
|
|
+ }
|
|
|
util::complete('更换成功');
|
|
|
}
|
|
|
|