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.

817 lines
34 KiB

5 years ago
<?php
namespace App\Http\Controllers\Manager;
use AlicFeng\IdentityCard\InfoHelper;
use App\Customer;
5 years ago
use App\Events\OrderAssigned;
5 years ago
use App\Libs\WxMicroPay;
5 years ago
use App\Models\Area;
5 years ago
use App\Models\Balance;
5 years ago
use App\Models\Bed;
5 years ago
use App\Models\Orders;
5 years ago
use App\Models\ParamedicLevel;
5 years ago
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 Intervention\Image\Facades\Image;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
class OrdersController extends CommonController
{
/**
* @OA\Get(
* path="/manager/get-projects",
5 years ago
* summary="V2 获取医院列表",
* description="获取医院列表",
5 years ago
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
5 years ago
* description="获取医院列表"
5 years ago
* )
* )
*/
public function getProjects()
{
5 years ago
$projects = (new Project())
->join("manager_project", 'project.id', '=', 'manager_project.project_id')
->join('managers', 'managers.id', '=', 'manager_project.manager_id')
->whereRaw("managers.id = " . $this->manager->id)
->select("project.id", "project.name", "project.address", "project.latitude", "project.longitude")
->get();
5 years ago
return response()->json($projects->toArray());
}
/**
* @OA\Get(
5 years ago
* path="/manager/get-care-product/{project_id}",
* summary="V2-获取产品详情",
5 years ago
* description="获取产品详情",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
5 years ago
* @OA\Parameter(name="project_id", in="path", @OA\Schema(type="integer"), required=true, description="project_id"),
5 years ago
* @OA\Response(
* response="200",
* description="获取产品详情"
* )
* )
*/
5 years ago
public function getCareProduct($project_id)
5 years ago
{
5 years ago
DB::enableQueryLog();
$product = (new Product())->where("project_id", $project_id)->with([
"productItems" => function ($query) {
$query->select("id", "name", "product_id", "patient_quantity", "price");
},
5 years ago
"productParamedicLevels" => function ($query) {
5 years ago
$query
->select("product_paramedic_level.id", "product_paramedic_level.product_id", "product_paramedic_level.price")
->leftJoin("paramedic_level", "product_paramedic_level.paramedic_level_id", "=", "paramedic_level.id")
->addSelect("paramedic_level.name as paramedic_level_name");
5 years ago
},
"factors" => function ($query) {
5 years ago
$query->with(["factorItems" => function ($query) {
$query->select("id", "name", "factor_id", "price", "myindex")->orderBy("myindex");
}])->select("id", "name", "product_id")->orderBy("myindex");
}])
->leftJoin("project", "project.id", "=", "product.project_id")
->select("product.id", "product.name", "product.project_id", "project.name as project_name")->first();
5 years ago
return response()->json($product->toArray());
}
/**
* @OA\Get(
5 years ago
* path="/manager/get-project-orders-count/{project_id}",
* summary="V2-获取医院订单数量角标",
* description="获取医院订单数量角标",
5 years ago
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
5 years ago
* @OA\Parameter(name="project_id", in="query", @OA\Schema(type="integer"), required=true, description="医院id"),
5 years ago
* @OA\Response(
* response="200",
5 years ago
* description="获取医院订单数量角标"
5 years ago
* )
* )
*/
5 years ago
public function getProjectOrdersCount($project_id)
5 years ago
{
$orders_count = [];
5 years ago
$orders_count["all"] = (new Orders())->ofProject($project_id)->count();
$orders_count["pending"] = (new Orders())->ofProject($project_id)->whereIn("status", [Orders::STATUS_UNCONFIRMED, Orders::STATUS_UNASSIGNED])->count();
$orders_count["ongoing"] = (new Orders())->ofProject($project_id)->where("status", Orders::STATUS_ONGOING)->count();
$orders_count["finished"] = (new Orders())->ofProject($project_id)->where("status", Orders::STATUS_ONGOING)->count();
5 years ago
5 years ago
return response()->json(compact("orders_count"));
5 years ago
}
/**
* @OA\Get(
5 years ago
* path="/manager/get-projcet-orders/{project_id}",
* summary="V2-获取订单列表",
5 years ago
* description="获取订单列表",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
5 years ago
* @OA\Parameter(name="project_id", in="path", @OA\Schema(type="integer"), required=false, description="医院ID"),
5 years ago
* @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"),
5 years ago
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="integer"), required=false, description="每页数量默认为5"),
5 years ago
* @OA\Parameter(name="status", in="query", @OA\Schema(type="string"), required=false, description="订单状态:[unconfirmed=>待确认,unassigned=>待派单,ongoing=>进行中,finished=>已完成]"),
* @OA\Response(
* response="200",
* description="获取订单列表"
* )
* )
*/
public function list()
{
$data = (new Orders());
if (request()->keyword) {
$keyword = request()->keyword;
$data = $data->where(function ($query) use ($keyword) {
$query
->where("serial", "like", "%{$keyword}%")
->orWhereHas("patient", function ($query) use ($keyword) {
$query->where("name", "like", "%{$keyword}%");
})->orWhereHas("paramedic", function ($query) use ($keyword) {
$query->where("name", "like", "%{$keyword}%");
});
});
}
switch (request()->status) {
case "unconfirmed":
$data = $data
->where("status", Orders::STATUS_UNCONFIRMED)
->ofProject($this->manager->projects->pluck("id")->toArray());
break;
case "unassigned":
case "ongoing":
case "finished":
$data = $data
->where("status", constant(Orders::class . "::STATUS_" . strtoupper(request()->status)))
->ofProject($this->manager->projects->pluck("id")->toArray());
break;
default:
$data = $data
->ofProject($this->manager->projects->pluck("id")->toArray());
}
5 years ago
$page_size = request()->page_size ?? 5;
5 years ago
$data = $data
->with([
5 years ago
"patient" => function ($query) {
$query->select("id", "customer_id", "name", "sex", "age");
},
5 years ago
"productItem",
"productParamedicLevel",
"bed" => function ($query) {
5 years ago
$query->with(["room", "building"])->select("id", "room_id", "building_id");
5 years ago
},
5 years ago
"paramedic" => function ($query) {
$query->select();
5 years ago
}
])
->orderBy("id", "desc")
5 years ago
->select("id", "serial", "customer_id", "patient_id", "project_id", "product_id", "manager_id", "from_date", "to_date", "remark", "status", "contact", "mobile", "price", "patient_quantity")
5 years ago
->paginate($page_size);
5 years ago
foreach ($data as $order) {
$order = $order->refreshTotal();
}
return response()->json($data->toArray());
}
/**
* @OA\Get(
* path="/manager/get-order/{id}",
5 years ago
* summary="V2-获取订单详情",
5 years ago
* 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)
{
$order = (new Orders())->with([
"orderItems" => function ($query) {
$query->with([
5 years ago
"bed" => function ($query) {
5 years ago
$query->with(["room", "building"]);
},
"room",
"building",
"paramedic",
"productParamedicLevel",
"paramedicLevel"
]);
},
"project",
"product" => function ($query) {
$query->with(["productParamedicLevels" => function ($query) {
$query->with("paramedicLevel");
}]);
},
"customer",
"manager",
"patient",
"productItem",
"productParamedicLevel",
"bed" => function ($query) {
$query->with(["room", "building"]);
},
"room",
"building",
"paramedic",
"handlingApprovalItem" => function ($query) {
$query->with("approval");
},
"recharges" => function ($query) {
$query->with("manager");
},
"refunds" => function ($query) {
$query->with("manager");
}
])->find($id);
$order = $order->refreshTotal();
$order->balance = $order->customer->balance;
return response()->json($order->toArray());
}
5 years ago
/**
* @OA\Get(
* path="/manager/get-project-areas/{project_id}",
* summary="V2-获取医院病区",
* description="获取医院病区",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="project_id", in="path", @OA\Schema(type="integer"), required=true, description="project id"),
* @OA\Response(
* response="200",
* description="获取医院床位"
* )
* )
*/
public function getProjectAreas($project_id)
{
$areas = (new Area())
->where("area.project_id", $project_id)
->select("area.id", "area.name", "area.building_id")
->leftJoin("building", "building.id", "=", "area.building_id")
->addSelect("building.name as building_name")
->orderBy("building.myindex")
->orderBy("area.myindex")
->get();
return response()->json($areas->toArray());
}
/**
* @OA\Get(
5 years ago
* path="/manager/get-area-beds/{area_id}",
5 years ago
* summary="V2-根据病区获取病床",
* description="根据病区获取病床",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="area_id", in="path", @OA\Schema(type="integer"), required=true, description="area id"),
* @OA\Response(
* response="200",
* description="根据病区获取病床"
* )
* )
*/
public function getAreaBeds($area_id)
{
$beds = (new Bed())
->where("bed.area_id", $area_id)
->select("bed.id", "bed.name", "bed.area_id", "bed.room_id")
->leftJoin("room", "room.id", "=", "bed.room_id")
->addSelect("room.name as room_name")
->orderBy("bed.name")
->get();
return response()->json($beds->toArray());
}
5 years ago
/**
* @OA\Get(
* path="/manager/get-available-paramedics",
* summary="V2-获取可用护工列表(已基本准确,需进一步打磨)",
* description="获取可用护工列表",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="bed_id", in="query", @OA\Schema(type="integer"), required=true, description="床位ID"),
* @OA\Parameter(name="sex", in="query", @OA\Schema(type="string"), required=true, description="性别:[男/女]"),
* @OA\Parameter(name="start_date", in="query", @OA\Schema(type="string"), required=false, description="日期,默认为当天"),
* @OA\Parameter(name="factors", in="query", @OA\Schema(type="object"), required=true, description="价格因子选择,[{id:1,factor_item_id:1},{...}],如果为空数组请传[]"),
* @OA\Response(
* response="200",
* description="获取可用护工列表"
* )
* )
*/
public function getAvailableParamedics(Request $request)
{
$paramedics = (new Orders())->getAvailableParamedics();
5 years ago
return response()->json($paramedics);
5 years ago
}
5 years ago
/**
* @OA\POST(
* path="/manager/create-patient",
5 years ago
* summary="V2-创建被护理人",
5 years ago
* description="创建被护理人",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=true, description="姓名"),
* @OA\Parameter(name="sex", in="query", @OA\Schema(type="string"), required=true, description="性别:[男/女]"),
* @OA\Parameter(name="age", in="query", @OA\Schema(type="integer"), required=true, description="年龄,只需填写入院时的年龄"),
* @OA\Response(
* response="200",
* description="创建被护理人"
* )
* )
*/
public function createPatient()
{
$data = [
"name" => request()->name,
"sex" => request()->sex,
5 years ago
"age" => request()->age,
"mobile" => request()->mobile
5 years ago
];
$vo = (new Patient())->create($data);
return response()->json($vo);
}
/**
* @OA\POST(
* path="/manager/create-order",
5 years ago
* summary="V2-创建订单",
5 years ago
* description="创建订单",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="product_id", in="query", @OA\Schema(type="integer"), required=true, description="产品id"),
* @OA\Parameter(name="product_item_id", in="query", @OA\Schema(type="integer"), required=true, description="产品型号id"),
* @OA\Parameter(name="product_paramedic_level_id", in="query", @OA\Schema(type="integer"), required=true, description="产品-护工等级id"),
* @OA\Parameter(name="factors", in="query", @OA\Schema(type="object"), required=true, description="价格因子选择,[{id:1,factor_item_id:1},{...}],如果为空数组请传[]"),
* @OA\Parameter(name="bed_id", in="query", @OA\Schema(type="integer"), required=true, description="床位id"),
* @OA\Parameter(name="paramedic_id", in="query", @OA\Schema(type="integer"), required=false, description="护工id"),
5 years ago
* @OA\Parameter(name="patient_name", in="query", @OA\Schema(type="string"), required=true, description="被护理人姓名"),
* @OA\Parameter(name="patient_mobile", in="query", @OA\Schema(type="string"), required=true, description="被护理人电话"),
* @OA\Parameter(name="patient_sex", in="query", @OA\Schema(type="string"), required=true, description="被护理人性别:男,女"),
* @OA\Parameter(name="patient_age", 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="联系人电话"),
5 years ago
* @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="price", in="query", @OA\Schema(type="number"), required=true, description="协商价格"),
* @OA\Response(
* response="200",
* description="创建订单"
* )
* )
*/
public function createOrder()
{
DB::beginTransaction();
try {
$customer = (new Customer())->firstOrCreate([
"mobile" => trim(request()->mobile)
]);
$has_orders = Orders::where("customer_id", $customer->id)->whereIn("status", [Orders::STATUS_UNCONFIRMED, Orders::STATUS_UNASSIGNED, Orders::STATUS_ONGOING])->count();
if ($has_orders) {
return response()->json([
"errorcode" => "0",
"errormsg" => "客户名下有即将开始或正在进行中的订单,暂不可以再次下单"
]);
}
5 years ago
$product = (new Product())->find(request()->product_id);
5 years ago
$product_paramedic_level = (new ProductParamedicLevel())->find(request()->product_paramedic_level_id);
$product_item = (new ProductItems())->find(request()->product_item_id);
$price = $product_item->price + $product_paramedic_level->price;
$factors = (new Orders())->requestFactorsToOrderFactors();
$price += collect($factors)->sum("price");
if (request()->price < $price) {
return response()->json([
"errorcode" => "0",
"errormsg" => "协商价格不能低于系统指导价"
]);
}
5 years ago
$patient = (new Patient())->firstOrCreate([
5 years ago
"customer_id" => $customer->id,
5 years ago
"name" => request()->patient_name
5 years ago
]);
$patient->update([
"age" => request()->patient_age,
"sex" => request()->patient_sex,
5 years ago
"mobile" => request()->patient_mobile,
5 years ago
]);
5 years ago
$order = (new Orders())->create([
"customer_id" => $customer->id,
5 years ago
"project_id" => $product->id,
5 years ago
"product_id" => request()->product_id,
5 years ago
"patient_id" => $patient->id,
"contact" => request()->contact ?? request()->patient_name,
"mobile" => request()->mobile ?? request()->patient_mobile,
5 years ago
"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,
"bed_id" => request()->bed_id,
"paramedic_id" => request()->paramedic_id,
"price" => request()->price,
"factors" => json_encode($factors),
5 years ago
"status" => request()->paramedic_id ? Orders::STATUS_ONGOING : Orders::STATUS_UNASSIGNED,
5 years ago
"manager_id" => $this->manager->id
]);
$order->getSerial();
5 years ago
if (request()->paramedic_id) {
event(new OrderAssigned($order));
}
5 years ago
DB::commit();
return $this->getOrder($order->id);
} catch (\Exception $exception) {
DB::rollBack();
return response()->json([
"errorcode" => $exception->getCode(),
"errormsg" => $exception->getMessage()
]);
}
}
5 years ago
/**
5 years ago
* @OA\POST(
5 years ago
* path="/manager/scan-pay/{order_id}",
* summary="V2-扫用户支付码收款",
* description="扫用户支付码收款",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="order_id", in="path", @OA\Schema(type="integer"), required=true, description="订单id"),
* @OA\Parameter(name="money", in="query", @OA\Schema(type="number"), required=true, description="支付金额"),
* @OA\Parameter(name="auth_code", in="query", @OA\Schema(type="string"), required=true, description="扫码后获取的支付码"),
* @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=true, description="支付方式weixin,alipay"),
* @OA\Response(
* response="200",
* description="扫用户支付码收款"
* )
* )
*/
public function scanPay($order_id)
{
$order = (new Orders())->find($order_id);
$recharge = (new Recharge())->create([
"customer_id" => $order->customer->id,
"money" => request()->money,
"order_id" => $order->id,
"payment" => request()->type
]);
$recharge = $recharge->getSerial();
switch (request()->type) {
case "weixin":
5 years ago
$res = (new WxMicroPay())->pay($recharge);
if ($res !== true) {
5 years ago
return response()->json([
"errorcode" => 60003,
5 years ago
"errormsg" => $res->getMessage()
5 years ago
]);
}
5 years ago
return response()->json($res);
5 years ago
break;
5 years ago
case "alipay":
5 years ago
//todo:支付宝支付实现
return response()->json([
"errorcode" => 60003,
"errormsg" => "支付宝支付方式尚未开通,敬请期待"
]);
5 years ago
break;
default:
return response()->json([
"errorcode" => 60003,
"errormsg" => "不正确的支付方式"
]);
5 years ago
}
}
5 years ago
/**
* @OA\POST(
* path="/manager/confirm-order/{id}",
* summary="确认订单",
* 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\Parameter(name="bed_id", in="query", @OA\Schema(type="integer"), required=true, description="床位id"),
* @OA\Parameter(name="price", in="query", @OA\Schema(type="number"), required=true, description="价格"),
* @OA\Parameter(name="from_date", in="query", @OA\Schema(type="date"), required=true, description="开始日期"),
* @OA\Parameter(name="to_date", in="query", @OA\Schema(type="date"), required=true, description="预计结束日期"),
* @OA\Parameter(name="product_paramedic_level_id", in="query", @OA\Schema(type="integer"), required=true, description="产品护工等级id"),
* @OA\Parameter(name="factors", in="query", @OA\Schema(type="object"), required=true, description="价格因子选择,[{id:1,factor_item_id:1},{...}],如果为空数组请传[]"),
* @OA\Parameter(name="patient_quantity", in="query", @OA\Schema(type="integer"), required=true, description="护理人数"),
* @OA\Parameter(name="auto_checkout", in="query", @OA\Schema(type="integer"), required=false, description="是否自动结算"),
* @OA\Response(
* response="200",
* description="确认订单"
* )
* )
*/
public function confirmOrder($id)
{
$order = (new Orders())->with("firstItem")->find($id);
if ($order->status !== Orders::STATUS_UNCONFIRMED) {
return response()->json([
"errorcode" => 50001,
"errormsg" => "订单状态不适配"
]);
}
DB::beginTransaction();
try {
$dirty = [];
foreach (request()->all() as $k => $v) {
if ($k == "factors") continue;
if ($order->{$k} && $order->{$k} != $v) {
$dirty[$k] = $v;
}
}
//单独处理factors
if ($order->determineOrderFactorsIsDirty()) {
$factors = (new Orders())->requestFactorsToOrderFactors();
$dirty["factors"] = json_encode($factors);
}
$dirty["status"] = Orders::STATUS_UNASSIGNED;
$dirty["manager_id"] = $this->manager->id;
$order->update($dirty);
DB::commit();
return response()->json($order);
} catch (\Exception $exception) {
DB::rollBack();
return response()->json([
"errorcode" => $exception->getCode(),
"errormsg" => $exception->getMessage()
]);
}
}
/**
* @OA\POST(
* path="/manager/cancel-order/{id}",
5 years ago
* summary="V2-取消订单",
5 years ago
* 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 cancelOrder($id)
{
$order = (new Orders())->with("orderItems")->find($id);
if (!in_array($order->status, [Orders::STATUS_UNCONFIRMED, Orders::STATUS_UNASSIGNED])) {
return response()->json([
"errorcode" => 50001,
"errormsg" => "订单状态不适配"
]);
}
DB::beginTransaction();
try {
foreach ($order->orderItems as $orderItem) {
$orderItem->delete();
}
$order->delete();
DB::commit();
return response()->json($order);
} catch (\Exception $exception) {
DB::rollBack();
return response()->json([
"errorcode" => $exception->getCode(),
"errormsg" => $exception->getMessage()
]);
}
}
/**
* @OA\POST(
* path="/manager/get-balance/{customer_id}",
* summary="获取用户余额",
* description="获取用户余额",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="customer_id", in="path", @OA\Schema(type="integer"), required=true, description="用户id"),
* @OA\Response(
* response="200",
* description="获取用户余额"
* )
* )
*/
public function getBalance($customer_id)
{
$customer = (new Customer())->find($customer_id);
if (!$customer) {
return response()->json([
"errorcode" => 70001,
"errormsg" => "没找到用户信息"
]);
}
return response()->json([
"balance" => $customer->balance
]);
}
/**
* @OA\POST(
* path="/manager/recharge-for-order/{id}",
5 years ago
* summary="V2-现金或pos刷卡充值",
5 years ago
* description="现金或pos刷卡充值",
* @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\Parameter(name="payment", in="query", @OA\Schema(type="string"), required=true, description="枚举pos=>pos机刷卡支付, cash=>现金支付"),
* @OA\Parameter(name="money", in="query", @OA\Schema(type="number"), required=true, description="金额,非负数"),
* @OA\Parameter(name="remark", in="query", @OA\Schema(type="string"), required=false, description="备注信息:现金支付时可以忽略;刷卡支付时,填入回单号或卡号以便财务对账"),
* @OA\Response(
* response="200",
* description="现金或pos刷卡充值"
* )
* )
*/
public function rechargeForOrder($id)
{
DB::beginTransaction();
try {
$order = (new Orders())->find($id);
//创建充值记录
$recharge = [
"customer_id" => $order->customer->id,
"money" => request()->money,
"order_id" => $order->id,
"payment" => request()->payment,
"manager_id" => $this->manager->id,
"paid_at" => date("Y-m-d H:i:s")
];
switch (request()->payment) {
case "pos":
case "cash":
$recharge["remark"] = request()->remark;
break;
default:
return response()->json([
"errorcode" => "0",
"errormsg" => "不正确的支付方式"
]);
}
$recharge = (new Recharge())->create($recharge);
$recharge = $recharge->getSerial();
//更新用户余额,创建流水记录
$customer_balance = $recharge->customer->balance + $recharge->money;
$recharge->customer->update([
"balance" => $customer_balance
]);
$balance = (new Balance())->create([
"customer_id" => $recharge->customer->id,
"order_id" => $recharge->order_id,
"belongs_type" => get_class($recharge),
"belongs_id" => $recharge->id,
"money" => $recharge->money,
"balance" => $customer_balance
]);
DB::commit();
return response()->json([
"recharge" => $recharge,
"balance" => $balance
]);
} catch (\Exception $exception) {
DB::rollBack();
return response()->json([
"errorcode" => $exception->getCode(),
"errormsg" => $exception->getMessage()
]);
}
}
/**
* @OA\POST(
* path="/manager/refund-for-order/{id}",
5 years ago
* summary="V2-退款",
5 years ago
* 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\Parameter(name="money", in="query", @OA\Schema(type="number"), required=true, description="金额,非负数"),
* @OA\Parameter(name="payment", in="query", @OA\Schema(type="string"), required=true, description="退款方式枚举cashonline。注意可用的退款方式需要通过pre-chackout获取随意提交尽可能会造成问题"),
* @OA\Parameter(name="recharge_id", in="query", @OA\Schema(type="integer"), required=false, description="相关在线支付的id用于原路返回。退款方式为online时必须给出"),
* @OA\Parameter(name="remark", in="query", @OA\Schema(type="string"), required=false, description="备注信息"),
* @OA\Response(
* response="200",
* description="退款"
* )
* )
*/
public function refundForOrder($id)
{
DB::beginTransaction();
try {
$order = (new Orders())->find($id);
//创建退款记录
$refund = [
"customer_id" => $order->customer->id,
"manager_id" => $this->manager->id,
"money" => request()->money,
"order_id" => $order->id,
"remark" => request()->remark
];
switch (request()->payment) {
case "cash":
$refund["payment"] = request()->payment;
$refund["paid_at"] = date("Y-m-d H:i:s");
break;
case "online":
$recharge = Recharge::find(request()->recharge_id);
$refund["payment"] = $recharge->payment;
$refund["recharge_id"] = request()->recharge_id;
break;
default:
return response()->json([
"errorcode" => "0",
"errormsg" => "不正确的退款方式"
]);
}
$refund = (new Refund())->create($refund);
$refund = $refund->getSerial();
//更新用户余额,创建流水记录
$customer_balance = $refund->customer->balance - $refund->money;
$refund->customer->update([
"balance" => $customer_balance
]);
$balance = (new Balance())->create([
"customer_id" => $refund->customer->id,
"order_id" => $refund->order_id,
"belongs_type" => get_class($refund),
"belongs_id" => $refund->id,
"money" => -$refund->money,
"balance" => $customer_balance
]);
DB::commit();
return response()->json([
"refund" => $refund,
"balance" => $balance
]);
} catch (\Exception $exception) {
DB::rollBack();
return response()->json([
"errorcode" => $exception->getCode(),
"errormsg" => $exception->getMessage()
]);
}
}
5 years ago
/**
* @OA\Get(
* path="/manager/get-project-paramedic-levels/{project_id}",
* summary="V2-获取医院护工等级",
* description="获取医院护工等级",
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Parameter(name="project_id", in="query", @OA\Schema(type="string"), required=true, description="医院ID"),
* @OA\Response(
* response="200",
* description="获取医院护工等级"
* )
* )
*/
public function getProjectParamedicLevels($project_id)
{
$paramedic_levels = ParamedicLevel::where("project_id", $project_id)->orderBy("myindex")->get();
return response()->json($paramedic_levels->toArray());
}
5 years ago
}