取消提现手续费

This commit is contained in:
2024-09-28 14:00:38 +08:00
parent db5732c8c5
commit a256ae0a78

View File

@@ -9,6 +9,7 @@ use common\enums\UserRoleEnum;
use common\helpers\FuncHelper;
use common\models\CashAccount;
use common\models\CashApply;
use common\models\ChargeCashPayRecord;
use common\models\Ledger;
use common\models\LedgerLog;
use common\models\Log;
@@ -38,6 +39,7 @@ class DivideAccountController extends BaseAdminController
*/
public function actionStoreApply()
{
// TODO 门店提现
$post = \Yii::$app->request->post();
$this->requestValidate($post, [
[['apply_cash', 'bank_user_name', 'bank_card', 'bank_name', 'bank_account_type', 'user_type'], 'required']
@@ -91,9 +93,13 @@ class DivideAccountController extends BaseAdminController
$CashAccount->last_apply_time = date('Y-m-d H:i:s', time());
$CashAccount->saveOrFail();
$qianliuwu=bcdiv(0.65,100,4);
$shouxufei=bcadd(bcmul($post['apply_cash'],$qianliuwu,2),2,3);
// TODO 暂时关闭手续费
$pQianliuwu=bcdiv(0.65,100,4);
$pShouxufei=bcadd(bcmul($post['apply_cash'],$pQianliuwu,2),2,3);
$Platform->charge_cash = bcadd($Platform->charge_cash, $pShouxufei, 2);
$Platform->saveOrFail();
$shouxufei = 0;
// $Platform->updateAllCounters(['able_cash'=>1]);
// $Platform->updateAllCounters(['total_cash'=>1]);
@@ -107,6 +113,15 @@ class DivideAccountController extends BaseAdminController
$CashApply->apply_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
// 记录代付的手续费
$chargeCpr = new ChargeCashPayRecord();
$chargeCpr->order_no = $order_no;
$chargeCpr->store_id = $user->store_id;//诊所id
$chargeCpr->charge_cash = $pShouxufei;//手续费
$chargeCpr->type = 1;//用户类型1诊所2总部
$chargeCpr->status = 1;
$chargeCpr->saveOrFail();
$log = new Log();
$log->admin_id = $user->uid;
$log->operate_time = date('Y-m-d H:i:s', time());
@@ -354,6 +369,9 @@ class DivideAccountController extends BaseAdminController
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
// 记录代付的手续费
$this->updateChargeCashPayRecordStatusByOrderNo($CashApply->order_no, 3);
// 记录日志
$log = new Log();
$log->admin_id = $user->uid;
@@ -396,6 +414,9 @@ class DivideAccountController extends BaseAdminController
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
$CashApply->saveOrFail();
// 记录代付的手续费
$this->updateChargeCashPayRecordStatusByOrderNo($CashApply->order_no, 2);
// 记录日志
$log = new Log();
$log->admin_id = $user->uid;
@@ -429,13 +450,21 @@ class DivideAccountController extends BaseAdminController
public function actionApplyRefuse()
{
// 获取前端传递的POST数据
$post = \Yii::$app->request->post();
// 对POST数据进行验证
$this->requestValidate($post, [
[['id', 'check_result', 'user_type'], 'required'],
]);
// 获取当前用户身份
$user = \Yii::$app->user->identity;
// 检查用户角色,如果不是超级管理员则抛出异常
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new Exception('你不是超级管理员,没有分账申请打款审核权限');
// 根据ID和用户类型查找现金申请信息如果状态为1可能代表待审核则获取该申请否则抛出异常
$CashApply = CashApply::find()->where([
'id' => $post['id'],
'user_type' => $post['user_type'],
@@ -443,45 +472,83 @@ class DivideAccountController extends BaseAdminController
])->one();
if (!$CashApply) throw new Exception('申请不存在');
// 查找用户的账号信息,如果不存在抛出异常
$Account = CashAccount::find()->where([
'user_id' => $CashApply->user_id,
'user_type' => $CashApply->user_type
])->one();
if (!$Account) throw new Exception('平台或技术方的账号不存在');
// 开启数据库事务
$t = \Yii::$app->db->beginTransaction();
try {
// 设置申请的审核人为当前用户,并将审核状态设置为拒绝,保存审核结果和时间
$CashApply->check_id = $user->uid;
$CashApply->check_status = 3;//拒绝
$CashApply->check_status = 3; // 拒绝状态
$CashApply->check_result = $post['check_result'];
$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();
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
$CashAccount->saveOrFail();
// 记录代付的手续费
$this->updateChargeCashPayRecordStatusByOrderNo($CashApply->order_no, 3);
// 记录操作日志
$log = new Log();
$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;
$log->mold = 3;//财务操作
$log->mold = 3; // 财务操作
$log->save();
// 更新日志内容到数据库
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
// 提交事务
$t->commit();
// 返回操作结果
return ['成功拒绝'];
} catch (\Exception $e) {
// 如果有异常则回滚事务,并抛出异常
$t->rollBack();
throw new Exception($e->getMessage());
}
}
/**
* 更新代付记录状态
*
* @param $orderNo
* @param $status
* @return void
* @throws Exception
*/
private function updateChargeCashPayRecordStatusByOrderNo($orderNo, $status)
{
if (empty($orderNo) || empty($status)) throw new Exception('参数错误');
// 记录代付的手续费
$chargeCpr = ChargeCashPayRecord::find()->where([
'status' => 1,
'order_no' => $orderNo
])->one();
$chargeCpr->status = $status;
$chargeCpr->saveOrFail();
}
/**
* @doc-name 分账打款
* @doc-param int apply_id 提现申请ID