支付和加密

This commit is contained in:
2025-01-04 17:01:00 +08:00
parent f1eb9293b1
commit b086e4e5a0
4 changed files with 108 additions and 54 deletions

View File

@@ -6,7 +6,10 @@ use admin\components\BaseAdminController;
use admin\models\Admin;
use common\enums\UserRoleEnum;
use common\helpers\FuncHelper;
use common\models\newDb\AccountBalanceModel;
use common\models\newDb\AdminModel;
use common\models\newDb\CardModel;
use common\models\newDb\SupplierModel;
use common\models\oldDb\CashAccount;
use common\models\oldDb\CashApply;
use common\models\oldDb\ChargeCashPayRecord;
@@ -238,7 +241,16 @@ class DivideAccountController extends BaseAdminController
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '平台申请打款';
$log->content = '平台ID' . $user->uid . '申请打款:' . $post['apply_cash'] . '元,订单号为::' . $order_no . ',开户人姓名为:' . $post['bank_user_name'] . ',银行卡号:' . $post['bank_card'] . ',开户行名称:' . $post['bank_name'] . ',银行账户类型:' . $post['bank_account_type'] . ',账户冻结金额由原来的:' . $Account->frozen_cash . '元变为:' . $CashAccount->frozen_cash . '元';
$log->content = '平台ID'
. $user->uid
. '申请打款:' . $post['apply_cash']
. '元,订单号为::' . $order_no
. ',开户人姓名为:' . $post['bank_user_name']
. ',银行卡号:' . $post['bank_card']
. ',开户行名称:' . $post['bank_name']
. ',银行账户类型:' . $post['bank_account_type']
. ',账户冻结金额由原来的:' . $Account->frozen_cash
. '元变为:' . $CashAccount->frozen_cash . '元';
$log->mold = 3; //财务操作
$log->save();
@@ -292,22 +304,28 @@ class DivideAccountController extends BaseAdminController
'user_type' => $CashApply->user_type
])->one();
$config = Store::find()->where(['id' => $CashApply->user_id])->one();
} else { // 平台
} elseif($post['user_type'] == 2) { // 平台
$Account = CashAccount::find()->where([
'user_id' => 0,
'user_type' => $CashApply->user_type
])->one();
$config = Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
} elseif ($post['user_type'] == 3) {
$Account = AccountBalanceModel::find()->where([ 'user_id' => $CashApply->user_id, 'type' => $CashApply->user_type])->one();
$config = CardModel::find()->where(['id' => $CashApply->user_id, 'type' => $CashApply->user_type])->one();
}
// 确保诊所或平台的账号存在
if (!$Account) throw new Exception('诊所或平台的账号不存在');
// 再次确认现金账户信息
$CashAccount = CashAccount::find()->where([
'user_type' => $CashApply->user_type,
'user_id' => $CashApply->user_id
])->one();
if ($post['user_type'] == 3) {
$CashAccount = AccountBalanceModel::find()->where([ 'user_id' => $CashApply->user_id, 'type' => $CashApply->user_type])->one();
} else {
// 再次确认现金账户信息
$CashAccount = CashAccount::find()->where([
'user_type' => $CashApply->user_type,
'user_id' => $CashApply->user_id
])->one();
}
// 检查银行账户配置是否完整,如果有任一配置项为空,则解冻申请提现的金额,并记录审核失败
if (empty($config['bank_user_name']) || empty($config['bank_card']) || empty($config['bank_name']) || empty($config['bank_account_type'])) {
@@ -325,7 +343,6 @@ class DivideAccountController extends BaseAdminController
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '分账申请打款审核';
// TODO 暂时关闭手续费
// $log->content = '超级管理员:' . $user->uid . '打款操作,订单号:' . $CashApply->order_no . ',打款金额:' . bcadd($CashApply->true_cash, 2, 2) . '元,开户人姓名:' . $config->bank_user_name . ',银行卡号:' . $config->bank_card . ',银行名称:' . $config->bank_name . ',银行账户类型:' . $config->bank_account_type . ',打款失败,原因:银行卡相关配置不完善';
$log->content = '超级管理员:' . $user->uid . '打款操作,订单号:' . $CashApply->order_no . ',打款金额:' . $CashApply->true_cash . '元,开户人姓名:' . $config->bank_user_name . ',银行卡号:' . $config->bank_card . ',银行名称:' . $config->bank_name . ',银行账户类型:' . $config->bank_account_type . ',打款失败,原因:银行卡相关配置不完善';
$log->mold = 3; // 财务操作
@@ -358,8 +375,14 @@ class DivideAccountController extends BaseAdminController
// 开始事务
$transaction = \Yii::$app->db->beginTransaction();
// 更新用户账户信息,解冻申请提现的金额
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
if ($CashApply->user_type == 3) {
// 更新用户账户信息,解冻申请提现的金额
$CashAccount->withdrawn_frozen = bcsub($CashAccount->withdrawn_frozen, $CashApply->apply_cash, 6);
$CashAccount->balance = bcadd($CashAccount->balance, $CashApply->apply_cash, 6);
} else {
// 更新用户账户信息,解冻申请提现的金额
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
}
$CashAccount->saveOrFail();
// 更新提现申请状态为失败
@@ -379,8 +402,6 @@ class DivideAccountController extends BaseAdminController
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '分账申请打款审核';
// TODO 暂时关闭手续费
// $log->content = '打款失败:超级管理员:' . $user->uid . '打款操作,订单号:' . $CashApply->order_no . ',打款金额:' . bcadd($CashApply->true_cash, 2, 2) . '元,开户人姓名:' . $config->bank_user_name . ',银行卡号:' . $config->bank_card . ',银行名称:' . $config->bank_name . ',银行账户类型:' . $config->bank_account_type . ',打款失败,原因:' . $res['returnMsg'];
$log->content = '打款失败:超级管理员:' . $user->uid . '打款操作,订单号:' . $CashApply->order_no . ',打款金额:' . $CashApply->true_cash . '元,开户人姓名:' . $config->bank_user_name . ',银行卡号:' . $config->bank_card . ',银行名称:' . $config->bank_name . ',银行账户类型:' . $config->bank_account_type . ',打款失败,原因:' . $res['returnMsg'];
$log->mold = 3; // 财务操作状态码
$log->saveOrFail();
@@ -401,10 +422,12 @@ class DivideAccountController extends BaseAdminController
$t = \Yii::$app->db->beginTransaction();
try {
// 更新用户账户信息,扣除账户余额,解冻申请提现的金额,增加已提现金额和手续费
$CashAccount->able_cash = bcsub($CashAccount->able_cash, $CashApply->apply_cash, 2);
// $CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
// $CashAccount->withdrawn_cash = bcadd($CashAccount->withdrawn_cash, $CashApply->true_cash, 2);
$CashAccount->charge_cash = bcadd($CashAccount->charge_cash, $CashApply->charge_cash, 2);
if ($CashApply->user_type == 3) {
$CashAccount->charge = bcadd($CashAccount->charge, $CashApply->charge_cash, 6);
} else {
$CashAccount->able_cash = bcsub($CashAccount->able_cash, $CashApply->apply_cash, 2);
$CashAccount->charge_cash = bcadd($CashAccount->charge_cash, $CashApply->charge_cash, 2);
}
$CashAccount->saveOrFail();
// 更新提现申请状态为成功
@@ -475,10 +498,21 @@ class DivideAccountController extends BaseAdminController
if (!$CashApply) throw new Exception('申请不存在');
// 查找用户的账号信息,如果不存在抛出异常
$Account = CashAccount::find()->where([
'user_id' => $CashApply->user_id,
'user_type' => $CashApply->user_type
])->one();
$Account = false;
if ($post['user_type'] == 1) { // 诊所
$Account = CashAccount::find()->where([
'user_id' => $CashApply->user_id,
'user_type' => $CashApply->user_type
])->one();
} elseif($post['user_type'] == 2) { // 平台
$Account = CashAccount::find()->where([
'user_id' => 0,
'user_type' => $CashApply->user_type
])->one();
} elseif ($post['user_type'] == 3) {
$Account = AccountBalanceModel::find()->where([ 'user_id' => $CashApply->user_id, 'type' => $CashApply->user_type])->one();
}
if (!$Account) throw new Exception('平台或技术方的账号不存在');
// 开启数据库事务
@@ -491,18 +525,19 @@ class DivideAccountController extends BaseAdminController
$CashApply->check_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
// TODO 这里的逻辑会导致查询出来的账号信息永远是第一个用户的信息,需要修改
// $CashAccount = CashAccount::find()->where([
// 'user_type' => $CashApply->user_type
// ])->one();
// 更新用户账号的冻结金额
$CashAccount = CashAccount::find()->where([
'user_id' => $CashApply->user_id,
'user_type' => $CashApply->user_type
])->one();
if ($CashApply->user_type == 3) {
$CashAccount = AccountBalanceModel::find()->where([ 'user_id' => $CashApply->user_id, 'type' => $CashApply->user_type])->one();
$CashAccount->withdrawn_frozen = bcsub($CashAccount->withdrawn_frozen, $CashApply->apply_cash, 6);
$CashAccount->balance = bcadd($CashAccount->balance, $CashApply->apply_cash, 6);
} else {
$CashAccount = CashAccount::find()->where([
'user_id' => $CashApply->user_id,
'user_type' => $CashApply->user_type
])->one();
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
}
$CashAccount->saveOrFail();
// 记录代付的手续费
@@ -513,7 +548,11 @@ class DivideAccountController extends BaseAdminController
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
$log->type = '分账申请打款审核';
$log->content = '管理员:' . $user->uid . '拒绝了ID为' . $post['id'] . '的打款申请可提现账户ID为' . $Account->id . '的账户的冻结的金额由' . $Account->frozen_cash . '变为' . $CashAccount->frozen_cash;
if ($post['user_type'] == 3) {
$log->content = '管理员:' . $user->uid . '拒绝了ID为' . $post['id'] . '的打款申请可提现账户ID为' . $Account->id . '的账户的冻结的金额由' . $Account->withdrawn_frozen . '变为' . $CashAccount->withdrawn_frozen;
} else {
$log->content = '管理员:' . $user->uid . '拒绝了ID为' . $post['id'] . '的打款申请可提现账户ID为' . $Account->id . '的账户的冻结的金额由' . $Account->frozen_cash . '变为' . $CashAccount->frozen_cash;
}
$log->mold = 3; // 财务操作
$log->save();
@@ -833,11 +872,16 @@ class DivideAccountController extends BaseAdminController
$this->field = [
CashApply::class => [
'id', 'user_id', 'user_type', 'order_no', 'apply_cash', 'true_cash', 'charge_cash', 'check_id', 'check_status', 'check_result', 'check_time', 'apply_time', 'dakuan_status', 'dakuan_time', 'payee' => function ($m) {
'id', 'user_id', 'user_type', 'order_no', 'apply_cash', 'true_cash', 'charge_cash', 'check_id', 'check_status', 'check_result', 'check_time', 'apply_time', 'dakuan_status', 'dakuan_time',
'payee' => function ($m) {
if ($m->user_id == 0) {
return Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
} else {
return Store::find()->where(['id' => $m->user_id])->one();
if ($m->user_type === 3) {
return SupplierModel::find()->with(['card'])->where(['id' => $m->user_id])->asArray()->one();
} else {
return Store::find()->where(['id' => $m->user_id])->one();
}
}
}
]
@@ -997,9 +1041,9 @@ class DivideAccountController extends BaseAdminController
}
if ($user->role==UserRoleEnum::SUPER_ADMIN){//平台
$query->andWhere(['l.user_id'=>0,'l.user_type'=>2])->groupBy('l.order_id,l.order_type');
$query->andWhere(['l.user_id'=>0,'l.user_type'=>2])/*->groupBy('l.order_id,l.order_type')*/;
}else{
$query->andWhere(['l.user_id'=>$user->store_id,'l.user_type'=>1])->groupBy('l.order_id,l.order_type');
$query->andWhere(['l.user_id'=>$user->store_id,'l.user_type'=>1])/*->groupBy('l.order_id,l.order_type')*/;
}
$this->field = [
Ledger::class => [