weizong song 5 years ago
parent b2388d52a0
commit 4d079f61f6

@ -45,7 +45,7 @@ class OrdersController extends CommonController
"factors" => function ($query) {
$query->select("id", "name", "product_id")->orderBy("myindex")
->with(["factorItems" => function ($query) {
$query->select("id","name","factor_id")->orderBy("myindex");
$query->select("id", "name", "factor_id")->orderBy("myindex");
}]);
}])
->where("project_id", $id)
@ -318,12 +318,10 @@ class OrdersController extends CommonController
* @OA\Parameter(name="paramedic_id", in="query", @OA\Schema(type="integer"), required=false, description="护工id"),
* @OA\Parameter(name="patient_name", in="query", @OA\Schema(type="integer"), required=true, description="被看护人姓名"),
* @OA\Parameter(name="patient_sex", in="query", @OA\Schema(type="integer"), required=true, description="被看护人性别"),
* @OA\Parameter(name="patient_mobile", in="query", @OA\Schema(type="integer"), required=true, description="被看护人联系电话"),
* @OA\Parameter(name="from_date", in="query", @OA\Schema(type="string"), required=true, description="开始日期"),
* @OA\Parameter(name="to_date", in="query", @OA\Schema(type="string"), required=true, description="结束日期"),
* @OA\Parameter(name="contact", in="query", @OA\Schema(type="string"), required=false, description="家属姓名"),
* @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), required=false, description="家属电话"),
* @OA\Response(
* response="200",
* description="创建订单"
@ -333,6 +331,8 @@ class OrdersController extends CommonController
public function createOrder()
{
DB::beginTransaction();
$request = request();
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) {
@ -342,24 +342,39 @@ class OrdersController extends CommonController
]);
}
$product_paramedic_level = (new ProductParamedicLevel())->find(request()->product_paramedic_level_id);
$product_item = (new ProductItems())->find(request()->product_item_id);
$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" => request()->project_id,
"product_id" => request()->product_id,
"patient_id" => request()->patient_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" => request()->product_item_id,
"product_paramedic_level_id" => request()->product_paramedic_level_id,
"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,

Loading…
Cancel
Save