weizong song 4 years ago
parent 1759b6f0bc
commit a86ecfbf31

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

@ -31,6 +31,10 @@ class OrderItems extends SoftDeletesModel
return $this->belongsTo(Orders::class); return $this->belongsTo(Orders::class);
} }
public function siblings() {
return $this->hasManyThrough(OrderItems::class,Orders::class,"id","order_id","order_id","id");
}
public function customer() public function customer()
{ {
return $this->hasOneThrough(Customer::class, Orders::class, "id", "id", "order_id", "customer_id"); return $this->hasOneThrough(Customer::class, Orders::class, "id", "id", "order_id", "customer_id");

@ -198,6 +198,10 @@
' <label for="salary">护工工资</label>' + ' <label for="salary">护工工资</label>' +
' <input class="form-control" type="number" name="salary" disabled>' + ' <input class="form-control" type="number" name="salary" disabled>' +
' </div>'; ' </div>';
html += '<div class="custom-control custom-checkbox">' +
'<input type="checkbox" class="custom-control-input" id="is_batch" name="is_batch" value="1">' +
'<label class="custom-control-label" for="is_batch">是否批量修改同级子订单</label>' +
'</div>';
$("#factor-box").html(html); $("#factor-box").html(html);
calculateSalary(); calculateSalary();

Loading…
Cancel
Save