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.
197 lines
5.6 KiB
PHP
197 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\EditProfitsharingsInput;
|
|
use App\Models\Config;
|
|
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, ['分账记录']);
|
|
if ($pl->type != 1) Yo::error_echo(200089);
|
|
$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');
|
|
$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->desc = $desc;
|
|
$p->status = $status;
|
|
$p->save();
|
|
return Yo::create_echo($p->id);
|
|
}
|
|
|
|
public function ee()
|
|
{
|
|
|
|
}
|
|
|
|
public function eval_action($php, $in_value)
|
|
{
|
|
$out_value = 0;
|
|
if ($php) {
|
|
try {
|
|
$service_config = Config::where('label', '微信手续费')->first();
|
|
$service = $service_config->value;
|
|
eval($php);
|
|
} catch (Exception $e) {
|
|
$out_value = 0;
|
|
}
|
|
}
|
|
return $out_value;
|
|
}
|
|
|
|
public function bcceilDecimal($value, $decimal)
|
|
{
|
|
$multipliedValue = bcmul($value, $decimal, 1);
|
|
$roundedValue = ceil($multipliedValue);
|
|
return bcdiv($roundedValue, $decimal, 2);
|
|
}
|
|
|
|
public function test(Request $request)
|
|
{
|
|
$php = $request->post('php');
|
|
$in_value = $request->post('in_value');
|
|
return Yo::echo([
|
|
'out_value' => self::eval_action($php, [
|
|
'price' => $in_value,
|
|
'hold' => 0
|
|
]),
|
|
]);
|
|
}
|
|
|
|
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');
|
|
$desc = $request->post('desc');
|
|
$status = $request->post('status');
|
|
$p->name = $name;
|
|
$p->type = $type;
|
|
$p->account = $account;
|
|
$p->formula = $formula;
|
|
$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);
|
|
}
|
|
}
|