|
|
|
|
@ -77,32 +77,39 @@ class OrdersController extends CommonController
|
|
|
|
|
|
|
|
|
|
public function changeItem(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$order_item = OrderItems::with("order")->find($request->item_id);
|
|
|
|
|
if ($order_item->paid_at && $request->total != $order_item->total) {
|
|
|
|
|
return $this->error("子订单已扣款,不支持后台更改价格,请通过其他方法进行更改");
|
|
|
|
|
}
|
|
|
|
|
if ($order_item->total == 0 && $request->total != $order_item->total) {
|
|
|
|
|
return $this->error("未服务子订单不支持后台更改价格,请通过其他方法进行更改");
|
|
|
|
|
$order_item = OrderItems::with(["order", "siblings"])->find($request->item_id);
|
|
|
|
|
if (request()->is_batch) {
|
|
|
|
|
$order_items = $order_item->siblings;
|
|
|
|
|
} else {
|
|
|
|
|
$order_items = collect($order_item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
try {
|
|
|
|
|
$order_item->update([
|
|
|
|
|
"total" => $request->total
|
|
|
|
|
]);
|
|
|
|
|
if ($request->factor_item) {
|
|
|
|
|
$factors = json_decode($order_item->factors, true);
|
|
|
|
|
foreach ($factors as &$factor) {
|
|
|
|
|
if (!$factor["used_for_fee"]) continue;
|
|
|
|
|
foreach ($request->factor_item as $k => $v) {
|
|
|
|
|
if ($k != $factor["factor_item_id"]) continue;
|
|
|
|
|
$factor["fee_percent"] = $v["fee_percent"];
|
|
|
|
|
$factor["fee"] = $v["fee"];
|
|
|
|
|
}
|
|
|
|
|
foreach($order_items as $order_item) {
|
|
|
|
|
if ($order_item->paid_at && $request->total != $order_item->total) {
|
|
|
|
|
return $this->error("子订单已扣款,不支持后台更改价格,请通过其他方法进行更改");
|
|
|
|
|
}
|
|
|
|
|
if ($order_item->total == 0 && $request->total != $order_item->total) {
|
|
|
|
|
return $this->error("未服务子订单不支持后台更改价格,请通过其他方法进行更改");
|
|
|
|
|
}
|
|
|
|
|
$order_item->update([
|
|
|
|
|
"factors" => json_encode($factors)
|
|
|
|
|
"total" => $request->total
|
|
|
|
|
]);
|
|
|
|
|
if ($request->factor_item) {
|
|
|
|
|
$factors = json_decode($order_item->factors, true);
|
|
|
|
|
foreach ($factors as &$factor) {
|
|
|
|
|
if (!$factor["used_for_fee"]) continue;
|
|
|
|
|
foreach ($request->factor_item as $k => $v) {
|
|
|
|
|
if ($k != $factor["factor_item_id"]) continue;
|
|
|
|
|
$factor["fee_percent"] = $v["fee_percent"];
|
|
|
|
|
$factor["fee"] = $v["fee"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$order_item->update([
|
|
|
|
|
"factors" => json_encode($factors)
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DB::commit();
|
|
|
|
|
return $this->success("处理成功!");
|
|
|
|
|
|