113 lines
4.2 KiB
PHP
Executable File
113 lines
4.2 KiB
PHP
Executable File
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\common\logic;
|
||
|
||
use app\common\enum\PayEnum;
|
||
use app\common\enum\user\AccountLogEnum;
|
||
use app\common\model\recharge\RechargeOrder;
|
||
use app\common\model\task\Task;
|
||
use app\common\model\task_template\TaskTemplate;
|
||
use app\common\model\user\User;
|
||
use think\facade\Db;
|
||
use think\facade\Log;
|
||
|
||
/**
|
||
* 支付成功后处理订单状态
|
||
* Class PayNotifyLogic
|
||
* @package app\api\logic
|
||
*/
|
||
class PayNotifyLogic extends BaseLogic
|
||
{
|
||
|
||
public static function handle($action, $orderSn, $extra = [])
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
self::$action($orderSn, $extra);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
Log::write(implode('-', [
|
||
__CLASS__,
|
||
__FUNCTION__,
|
||
$e->getFile(),
|
||
$e->getLine(),
|
||
$e->getMessage()
|
||
]));
|
||
self::setError($e->getMessage());
|
||
return $e->getMessage();
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 充值回调
|
||
* @param $orderSn
|
||
* @param array $extra
|
||
* @author 段誉
|
||
* @date 2023/2/27 15:28
|
||
*/
|
||
public static function recharge($orderSn, $extra = [])
|
||
{
|
||
$order = RechargeOrder::where('sn', $orderSn)->findOrEmpty();
|
||
// 增加用户累计充值金额及用户余额
|
||
$user = User::findOrEmpty($order->user_id);
|
||
$user->total_recharge_amount += $order->order_amount;
|
||
$user->user_money += $order->order_amount;
|
||
$user->save();
|
||
|
||
// 记录账户流水
|
||
AccountLogLogic::add(
|
||
$order->user_id,
|
||
AccountLogEnum::UM_INC_RECHARGE,
|
||
AccountLogEnum::INC,
|
||
$order->order_amount,
|
||
$order->sn,
|
||
'用户充值'
|
||
);
|
||
|
||
// 更新充值订单状态
|
||
$order->transaction_id = $extra['transaction_id'];
|
||
$order->pay_status = PayEnum::ISPAID;
|
||
$order->pay_time = time();
|
||
$order->save();
|
||
if ($order && isset($order['extend']['type']) && $order['extend']['type'] == 1) {
|
||
$find = Task::where('id', $order['extend']['task_id'])->find();
|
||
Task::where('id', $order['extend']['task_id'])->update(['status' => 3]);
|
||
TaskTemplate::where('id', $find['template_id'])->update(['over_decimal' => $order->order_amount]);
|
||
|
||
|
||
|
||
$user_ids = User::where('company_id', $find['company_id'])->where('is_captain', 1)->field('id,nickname,brigade')->select();
|
||
$shareholder_user = User::where('id', $find['director_uid'])->field('id,nickname,brigade')->find();
|
||
foreach ($user_ids as $kkk => $vvv) {
|
||
$company_log = [
|
||
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
|
||
'company_id'=>$find['company_id'],
|
||
'change_object' => $change_object,//变动对象
|
||
'change_type' => $change_type,//变动类型
|
||
'action' => $action,//1-增加 2-减少
|
||
'left_amount' => $left_amount,//变动后数量
|
||
'change_amount' => $changeAmount,//变动数量
|
||
'status'=>1,
|
||
];
|
||
CompanyAccountLog::create($company_log);
|
||
$v['extend']['shareholder']['user_list'][$kkk] = ['info'=>$shareholder_user['nickname'].'完成了'.$vvv['brigade'].'队的股金:'.bcdiv($v['recharge'],count($user_ids),2), 'time' => $v['create_time']];
|
||
}
|
||
}
|
||
}
|
||
}
|