From b086e4e5a0fafd865114698c57758556ae2eb191 Mon Sep 17 00:00:00 2001 From: liqi Date: Sat, 4 Jan 2025 17:01:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=92=8C=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/DivideAccountController.php | 116 ++++++++++++------ common/config/params-local.php | 7 -- composer.json | 3 +- .../controllers/EplpayCallbackController.php | 36 ++++-- 4 files changed, 108 insertions(+), 54 deletions(-) diff --git a/admin/controllers/base/DivideAccountController.php b/admin/controllers/base/DivideAccountController.php index bba1490..fe501ce 100644 --- a/admin/controllers/base/DivideAccountController.php +++ b/admin/controllers/base/DivideAccountController.php @@ -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 => [ diff --git a/common/config/params-local.php b/common/config/params-local.php index b7df6af..453b111 100644 --- a/common/config/params-local.php +++ b/common/config/params-local.php @@ -137,16 +137,9 @@ JJvBfLfudYNUjUCyW3gAcOIJ 'aseList' => [ 'contact', 'mobile', - 'express_address', - 'clinical_diagnose', - 'drug_alias', - 'function', - 'usage', 'express_mobile', - 'express_region', 'doctor', 'accept_tel', - 'patient', 'patient_mobile', # 身份证 'id_card', diff --git a/composer.json b/composer.json index 4dd1347..604fb61 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "ext-bcmath": "*", "ext-openssl": "*", "ext-redis": "*", - "ext-zend-opcache": "*" + "ext-zend-opcache": "*", + "ext-curl": "*" }, "require-dev": { "yiisoft/yii2-debug": "~2.1.0", diff --git a/member/modules/v1/controllers/EplpayCallbackController.php b/member/modules/v1/controllers/EplpayCallbackController.php index fed4021..33c1b65 100644 --- a/member/modules/v1/controllers/EplpayCallbackController.php +++ b/member/modules/v1/controllers/EplpayCallbackController.php @@ -7,6 +7,7 @@ use common\forms\DrugRollBackForm; use common\forms\LedgerForm; use common\jobs\ProductOrderRefundJob; use common\jobs\ProductOrderSyncPlatformJob; +use common\models\newDb\AccountBalanceModel; use common\models\oldDb\Callback; use common\models\oldDb\CashAccount; use common\models\oldDb\CashApply; @@ -288,10 +289,15 @@ class EplpayCallbackController extends \yii\web\Controller if(!$applyOrder){ throw new Exception('提现申请不存在'); } - $CashAccount = CashAccount::findOne([ - 'user_type' => $applyOrder->user_type, - 'user_id' => $applyOrder->user_id - ]); + if ($applyOrder->user_type === 3) { + $CashAccount = AccountBalanceModel::find()->where([ 'user_id' => $applyOrder->user_id, 'type' => $applyOrder->user_type])->one(); + } else { + $CashAccount = CashAccount::findOne([ + 'user_type' => $applyOrder->user_type, + 'user_id' => $applyOrder->user_id + ]); + } + if(!$CashAccount){ throw new Exception('分账账号不存在'); } @@ -302,8 +308,13 @@ class EplpayCallbackController extends \yii\web\Controller $applyOrder->dakuan_status = -1; $applyOrder->saveOrFail(); - $CashAccount->able_cash = $CashAccount->able_cash + $applyOrder->apply_cash; - $CashAccount->frozen_cash -= $applyOrder->apply_cash; + if ($applyOrder->user_type === 3) { + $CashAccount->balance = bcadd($CashAccount->balance, $applyOrder->apply_cash, 6); + $CashAccount->withdrawn_frozen = bcsub($CashAccount->withdrawn_frozen, $applyOrder->apply_cash, 6); + } else { + $CashAccount->able_cash = $CashAccount->able_cash + $applyOrder->apply_cash; + $CashAccount->frozen_cash -= $applyOrder->apply_cash; + } $CashAccount->saveOrFail(); } else { // 获取代扣订单 @@ -314,12 +325,17 @@ class EplpayCallbackController extends \yii\web\Controller $applyOrder->dakuan_time = date('Y-m-d H:i:s'); $applyOrder->saveOrFail(); - $CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $applyOrder->apply_cash, 2); - $CashAccount->withdrawn_cash = bcadd($CashAccount->withdrawn_cash, $applyOrder->apply_cash, 2); - $CashAccount->charge_cash = bcadd($CashAccount->charge_cash, $applyOrder->charge_cash, 2); + if ($applyOrder->user_type === 3) { + $CashAccount->withdrawn_frozen = bcsub($CashAccount->withdrawn_frozen, $applyOrder->apply_cash, 6); + $CashAccount->withdrawn = bcadd($CashAccount->withdrawn, $applyOrder->apply_cash, 6); + $CashAccount->charge = bcadd($CashAccount->charge, $applyOrder->charge_cash, 6); + } else { + $CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $applyOrder->apply_cash, 2); + $CashAccount->withdrawn_cash = bcadd($CashAccount->withdrawn_cash, $applyOrder->apply_cash, 2); + $CashAccount->charge_cash = bcadd($CashAccount->charge_cash, $applyOrder->charge_cash, 2); + } $CashAccount->saveOrFail(); - // 扣除平台账户的金额 $platformAccount = CashAccount::find()->where([ 'user_id' => 0,