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

160 lines
4.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\EditProfitsharingsInput;
use App\Models\Profitsharing;
use App\Models\ProfitsharingLog;
use App\Models\UserOrder;
use Illuminate\Http\Request;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Login;
use Yo;
class ProfitsharingController extends Controller
{
public function recover(Request $request)
{
Login::admin([], [31, 32]);
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$id = $request->post('id');
$pl = ProfitsharingLog::where('id', $id)->where('status', 1)->first();
if (!$pl) Yo::error_echo(100000, ['分账记录']);
$wcp = new WeChatPayController();
$builder_config = json_decode($pl->builder, JSON_UNESCAPED_UNICODE);
$receivers = json_decode($pl->receivers, JSON_UNESCAPED_UNICODE);
$response = json_decode($pl->response, JSON_UNESCAPED_UNICODE);
$wcp->builder($builder_config);
$order_id = $response['order_id'];
$recover = [];
foreach ($receivers as $key => $receiver) {
if ($receiver['type'] == 'MERCHANT_ID') {
$return_data = [
'out_order_no' => 'P' . $order_id,
'out_return_no' => 'R' . $order_id . 'P' . $key,
'return_mchid' => $receiver['account'],
'amount' => $receiver['amount'],
'description' => $receiver['description'] . '退回',
];
$res = $wcp->profitsharing_return($return_data);
$recover[] = $res;
}
}
$pl->recover = json_encode($recover, JSON_UNESCAPED_UNICODE);
$pl->status = 2;
$pl->save();
return Yo::echo();
}
public function create(EditProfitsharingsInput $request)
{
Login::admin([], [17, 25]);
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$name = $request->post('name');
$type = $request->post('type');
$account = $request->post('account');
$formula = $request->post('formula');
$max = $request->post('max');
$desc = $request->post('desc');
$status = $request->post('status');
$p = new Profitsharing();
$p->hospital = $hospital;
$p->name = $name;
$p->type = $type;
$p->account = $account;
$p->formula = $formula;
$p->max = $max;
$p->desc = $desc;
$p->status = $status;
$p->save();
return Yo::create_echo($p->id);
}
public function update(EditProfitsharingsInput $request)
{
Login::admin([], [17, 25]);
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$id = $request->post('id');
$p = Profitsharing::where('id', $id)->where('hospital', $hospital)->where('del', 2)->first();
if (!$p) Yo::error_echo(100000, ['分账']);
$name = $request->post('name');
$type = $request->post('type');
$account = $request->post('account');
$formula = $request->post('formula');
$max = $request->post('max');
$desc = $request->post('desc');
$status = $request->post('status');
$p->name = $name;
$p->type = $type;
$p->account = $account;
$p->formula = $formula;
$p->max = $max;
$p->desc = $desc;
$p->status = $status;
$p->save();
return Yo::update_echo($p->id);
}
public function delete(Request $request)
{
Login::admin([], [17, 25]);
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$id = $request->post('id');
$p = Profitsharing::where('id', $id)->where('hospital', $hospital)->where('del', 2)->first();
if (!$p) Yo::error_echo(100000, ['分账']);
$p->del = 1;
$p->save();
return Yo::delete_echo($p->id);
}
public function list(Request $request)
{
Login::admin([], [17, 25]);
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$p = Profitsharing::where('hospital', $hospital)->where('del', 2)->get();
return Yo::echo([
'list' => $p
]);
}
public function sharing($order_id, $hospital)
{
$user_order = UserOrder::where('id', $order_id)->first();
if (!!$user_order) {
return Profitsharing::where('hospital', $hospital)->where('status', 1)->where('del', 2)->get();
}
return [];
}
public function calculateExpression($expression)
{
$language = new ExpressionLanguage();
return $language->evaluate($expression);
}
}