|
|
|
|
@ -77,25 +77,29 @@ class OrdersController extends CommonController
|
|
|
|
|
|
|
|
|
|
public function changeItem(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$order_item = OrderItems::with(["order", "siblings"])->find($request->item_id);
|
|
|
|
|
$item = OrderItems::with(["order", "siblings"])->find($request->item_id);
|
|
|
|
|
if (request()->is_batch) {
|
|
|
|
|
$order_items = $order_item->siblings;
|
|
|
|
|
$order_items = $item->siblings;
|
|
|
|
|
$total = $item->siblings->count();
|
|
|
|
|
} else {
|
|
|
|
|
$order_items = collect($order_item);
|
|
|
|
|
$order_items = [$item];
|
|
|
|
|
$total = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
try {
|
|
|
|
|
foreach($order_items as $order_item) {
|
|
|
|
|
if ($order_item->paid_at && $request->total != $order_item->total) {
|
|
|
|
|
foreach ($order_items as $order_item) {
|
|
|
|
|
if ($request->has("total") && $order_item->paid_at && $request->total != $order_item->total) {
|
|
|
|
|
return $this->error("子订单已扣款,不支持后台更改价格,请通过其他方法进行更改");
|
|
|
|
|
}
|
|
|
|
|
if ($order_item->total == 0 && $request->total != $order_item->total) {
|
|
|
|
|
if ($request->has("total") && $order_item->total == 0 && $request->total != $order_item->total) {
|
|
|
|
|
return $this->error("未服务子订单不支持后台更改价格,请通过其他方法进行更改");
|
|
|
|
|
}
|
|
|
|
|
$order_item->update([
|
|
|
|
|
"total" => $request->total
|
|
|
|
|
]);
|
|
|
|
|
if ($request->has("total")) {
|
|
|
|
|
$order_item->update([
|
|
|
|
|
"total" => $request->total
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
if ($request->factor_item) {
|
|
|
|
|
$factors = json_decode($order_item->factors, true);
|
|
|
|
|
foreach ($factors as &$factor) {
|
|
|
|
|
@ -112,10 +116,10 @@ class OrdersController extends CommonController
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DB::commit();
|
|
|
|
|
return $this->success("处理成功!");
|
|
|
|
|
return $this->success("处理成功" . $total . "条数据!");
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return $this->error($exception->getMessage());
|
|
|
|
|
return $this->error($exception->getMessage() . $exception->getLine());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|