weizong song 5 years ago
parent b09b110520
commit 9ec3cfd986

@ -332,56 +332,57 @@ class OrdersController extends CommonController
{
DB::beginTransaction();
$request = request();
$has_orders = Orders::where("customer_id", $this->customer->id)->whereIn("status", [Orders::STATUS_UNCONFIRMED, Orders::STATUS_UNASSIGNED, Orders::STATUS_ONGOING])->count();
if ($has_orders) {
return response()->json([
"errorcode" => "0",
"errormsg" => "您有即将开始或正在进行中的订单,暂不可以再次下单"
]);
}
$product = Product::find($request->product_id);
if ($request->paramedic_id) {
$paramedic = Paramedic::withCount("orders",function($query) use ($request) {
$query->where("status", Orders::STATUS_ONGOING);
//todo:计算自动结单对当前所选日期的订单数的影响
})->find($request->paramedic_id);
$product_paramedic_level = (new ProductParamedicLevel())->find($paramedic->paramedic_level_id);
$product_item = (new ProductItems())->where("patient_quantity", "<=", $paramedic->orders_count + 1)->orderBy("patient_quantity", "desc")->first();
} else {
$product_paramedic_level = (new ProductParamedicLevel())->where("product_id", $request->product_id)->where("price", 0)->first();
$product_item = (new ProductItems())->where("product_id", $request->product_id)->where("patient_quantity",1)->first();
}
$price = $product_item->price + $product_paramedic_level->price;
$factors = (new Orders())->requestFactorsToOrderFactors();
$price += collect($factors)->sum("price");
$patient = Patient::firstOrCreate([
"customer_id" => $this->customer->id,
"name" => $request->patient_name,
"sex" => $request->patient_sex
]);
$order = (new Orders())->create([
"customer_id" => $this->customer->id,
"project_id" => $product->project_id,
"product_id" => $request->product_id,
"patient_id" => $patient->id,
"contact" => $request->contact,
"mobile" => $request->mobile,
"from_date" => $request->from_date,
"to_date" => $request->to_date,
"product_item_id" => $product_item->id,
"product_paramedic_level_id" => $product_paramedic_level->id,
"bed_id" => $request->bed_id,
"paramedic_id" => $request->paramedic_id,
"price" => $price,
"factors" => json_encode($factors)
]);
$order->getSerial();
try {
$has_orders = Orders::where("customer_id", $this->customer->id)->whereIn("status", [Orders::STATUS_UNCONFIRMED, Orders::STATUS_UNASSIGNED, Orders::STATUS_ONGOING])->count();
if ($has_orders) {
return response()->json([
"errorcode" => "0",
"errormsg" => "您有即将开始或正在进行中的订单,暂不可以再次下单"
]);
}
$product = Product::find($request->product_id);
if ($request->paramedic_id) {
$paramedic = Paramedic::withCount("orders",function($query) use ($request) {
$query->where("status", Orders::STATUS_ONGOING);
//todo:计算自动结单对当前所选日期的订单数的影响
})->find($request->paramedic_id);
$product_paramedic_level = (new ProductParamedicLevel())->find($paramedic->paramedic_level_id);
$product_item = (new ProductItems())->where("patient_quantity", "<=", $paramedic->orders_count + 1)->orderBy("patient_quantity", "desc")->first();
} else {
$product_paramedic_level = (new ProductParamedicLevel())->where("product_id", $request->product_id)->where("price", 0)->first();
$product_item = (new ProductItems())->where("product_id", $request->product_id)->where("patient_quantity",1)->first();
}
$price = $product_item->price + $product_paramedic_level->price;
$factors = (new Orders())->requestFactorsToOrderFactors();
$price += collect($factors)->sum("price");
$patient = Patient::firstOrCreate([
"customer_id" => $this->customer->id,
"name" => $request->patient_name,
"sex" => $request->patient_sex
]);
dd($patient);
$order = (new Orders())->create([
"customer_id" => $this->customer->id,
"project_id" => $product->project_id,
"product_id" => $request->product_id,
"patient_id" => $patient->id,
"contact" => $request->contact,
"mobile" => $request->mobile,
"from_date" => $request->from_date,
"to_date" => $request->to_date,
"product_item_id" => $product_item->id,
"product_paramedic_level_id" => $product_paramedic_level->id,
"bed_id" => $request->bed_id,
"paramedic_id" => $request->paramedic_id,
"price" => $price,
"factors" => json_encode($factors)
]);
$order->getSerial();
DB::commit();
return $this->getOrder($order->id);
} catch (\Exception $exception) {

Loading…
Cancel
Save