You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
6.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Http\Controllers\Worker;
use AlicFeng\IdentityCard\InfoHelper;
use App\Actions\AttachAffectedOrders;
use App\Actions\ChangeOrderStatus;
use App\Customer;
use App\Events\OrderAssigned;
use App\Libs\AlipayF2F;
use App\Libs\WxMicroPay;
use App\Models\Area;
use App\Models\Balance;
use App\Models\Bed;
use App\Models\OrderItems;
use App\Models\Orders;
use App\Models\Paramedic;
use App\Models\ParamedicLevel;
use App\Models\Patient;
use App\Models\Product;
use App\Models\ProductItems;
use App\Models\ProductParamedicLevel;
use App\Models\Project;
use App\Models\Recharge;
use App\Models\Refund;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Intervention\Image\Facades\Image;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use function GuzzleHttp\Psr7\str;
class OrdersController extends CommonController
{
/**
* @OA\Get(
* path="/worker/get-orders",
* tags={"护工端订单处理"},
* summary="V2-获取订单列表",
* description="获取订单列表",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=false, description="查询关键词"),
* @OA\Parameter(name="page", in="query", @OA\Schema(type="integer"), required=false, description="当前页码默认为1"),
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="integer"), required=false, description="每页数量默认为5"),
* @OA\Parameter(name="status", in="query", @OA\Schema(type="string"), required=false, description="订单状态:[pending=>待处理,ongoing=>进行中,finished=>已完成]"),
* @OA\Response(
* response="200",
* description="获取订单列表"
* )
* )
*/
public function list()
{
$worker = $this->guard()->user();
$model = $this->_getOrderModel();
$ids = OrderItems::where("paramedic_id", $worker->id)->where("total", ">", 0)->pluck("order_id")->toArray();
$model = $model->whereIn("id", $ids);
if (request()->keyword) {
$keyword = request()->keyword;
$model = $model->where(function ($query) use ($keyword) {
$query
->where("serial", "like", "%{$keyword}%")
->orWhereHas("patient", function ($query) use ($keyword) {
$query->where("name", "like", "%{$keyword}%");
})->orWhereHas("customer", function ($query) use ($keyword) {
$query->where("mobile", "like", "%{$keyword}%");
})->orWhereHas("paramedic", function ($query) use ($keyword) {
$query->where("name", "like", "%{$keyword}%");
});
});
}
if (request()->start_date_from && request()->start_date_to) {
$model = $model->whereRaw(DB::raw("UNIX_TIMESTAMP(`from_date`) between " . strtotime(request()->start_date_from) . " and " . strtotime(request()->start_date_to)));
}
switch (request()->status) {
case "pending":
$model = $model->whereIn("status", [Orders::STATUS_UNCONFIRMED, Orders::STATUS_UNASSIGNED]);
break;
case "ongoing":
case "finished":
$model = $model->where("status", constant(Orders::class . "::STATUS_" . strtoupper(request()->status)));
break;
default:
//do nothing
}
$page_size = request()->page_size ?? 5;
$data = $model->orderBy("id", "desc")->paginate($page_size);
return response()->json($data->toArray());
}
/**
* @OA\Get(
* path="/worker/get-order/{id}",
* tags={"护工端订单处理"},
* summary="V2-获取订单详情",
* description="获取订单详情",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="id"),
* @OA\Response(
* response="200",
* description="获取订单详情"
* )
* )
*/
public function getOrder($id)
{
$worker = $this->guard()->user();
$model = $this->_getOrderModel();
$ids = OrderItems::where("order_id", $id)->where("paramedic_id", $worker->id)->where("total", ">", 0)->pluck("order_id")->toArray();
if (!$ids) {
return response()->json([
"errorcode" => "40004",
"errormsg" => "没找到订单"
]);
}
$order = $model->with([
"orderItems" => function ($query) use ($worker) {
$query->where("paramedic_id", $worker->id)->where("total", ">", 0)->orderBy("service_date", "desc");
}
])->find($id);
return response()->json($order->toArray());
}
public function _getOrderModel()
{
$model = $order = (new Orders())
->select(
"orders.id",
"orders.serial",
"orders.customer_id",
"orders.manager_id",
"orders.bed_id",
"orders.patient_id",
"orders.project_id",
"orders.product_id",
"orders.product_item_id",
"orders.product_paramedic_level_id",
"orders.from_date",
"orders.to_date",
"orders.status",
"orders.total",
"orders.paid_total",
"orders.contact",
"orders.mobile",
"orders.paramedic_id",
"orders.price",
"orders.factors",
"orders.patient_quantity",
"orders.created_at"
)
->with([
"project" => function ($query) {
$query->select("id", "name");
},
"bed" => function ($query) {
$query->select("bed.id", "bed.name", "bed.building_id", "bed.area_id")
->leftJoin("building", "building.id", "=", "bed.building_id")
->leftJoin("area", "area.id", "=", "bed.area_id")
->leftJoin("room", "room.id", "=", "bed.room_id")
->addSelect("room.name as room_name", "area.name as area_name", "building.name as building_name");
},
"customer" => function ($query) {
$query->select("id", "name", "balance");
},
"patient" => function ($query) {
$query->select("id", "name", "sex", "age", "mobile");
}
]);
return $model;
}
}