取消提现手续费-附加一些功能测试

This commit is contained in:
2024-09-29 16:44:06 +08:00
parent 3cca920102
commit 8ffba61ea7
4 changed files with 174 additions and 10 deletions

View File

@@ -0,0 +1,70 @@
<?php
namespace admin\controllers\base;
use admin\components\BaseAdminController;
use common\models\ChargeCashPayRecord;
use common\models\Ledger;
/**
* @doc-module 分账
*/
class ChargeCashController extends BaseAdminController
{
public function actionList()
{
// TODO 待完善
$params = \Yii::$app->request->get();
$query = ChargeCashPayRecord::find();
if (!empty($params['status'])) {
$query->where(['status' => $params['status']]);
}
if (!empty($params['store_id'])) {
$query->andWhere(['store_id' => $params['store_id']]);
}
// if (!empty($params['start_time']) && !empty($params['end_time'])) {
// // 确保 start_time 不大于 end_time
// if ($params['start_time'] <= $params['end_time']) {
// $query->andWhere(['between', 'created_at', $params['start_time'], $params['end_time']]);
// } else {
// // 如果 start_time 大于 end_time可以抛出异常或者记录错误
// throw new \InvalidArgumentException("Start time must be before end time.");
// }
// } elseif (!empty($params['start_time'])) {
// // 只有开始时间的情况下,查询 created_at 大于等于 start_time 的数据
// $query->andWhere(['>=', 'created_at', $params['start_time']]);
// } elseif (!empty($params['end_time'])) {
// // 只有结束时间的情况下,查询 created_at 小于等于 end_time 的数据
// $query->andWhere(['<=', 'created_at', $params['end_time']]);
// }
$query->with(['store'])->orderBy(['id' => SORT_DESC]);
$this->field = [
ChargeCashPayRecord::class => [
'id',
'store_id',
'order_no',
'charge_cash',
'type',
'status',
'store',
'created_at' => function ($le) {
return date('Y-m-d H:i:s', $le->created_at);
}
],
];
return $this->create($query, $params);
}
public function actionCount()
{
}
}

View File

@@ -93,12 +93,10 @@ class DivideAccountController extends BaseAdminController
$CashAccount->last_apply_time = date('Y-m-d H:i:s', time());
$CashAccount->saveOrFail();
// TODO 暂时关闭手续费
// 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]);
@@ -548,10 +546,11 @@ class DivideAccountController extends BaseAdminController
*
* @param $orderNo
* @param $status
* @param string $chargeCash // 在status = 2的时候是冻结金额
* @return void
* @throws Exception
*/
private function updateChargeCashPayRecordStatusByOrderNo($orderNo, $status, $chargeCash)
private function updateChargeCashPayRecordStatusByOrderNo($orderNo, $status, $chargeCash = '')
{
if (empty($orderNo) || empty($status)) throw new Exception('参数错误');
// 记录代付的手续费
@@ -560,21 +559,29 @@ class DivideAccountController extends BaseAdminController
$chargeCpr->saveOrFail();
if ($status == 2) {
if (empty($chargeCash)) {
throw new Exception('充值金额不能为空');
throw new Exception('金额不能为空');
}
$account = CashAccount::find()->where([
'user_id' => $chargeCpr->user_id,
'user_type' => $chargeCpr->user_type
'user_id' => $chargeCpr->store_id,
'user_type' => $chargeCpr->type
])->one();
// 将冻结金额和充值金额进行合并计算,并将结果赋值给可用金额
$account->charge_cash = bcadd($account->frozen_cash, $chargeCpr->charge_cash, 2);
$account->charge_cash = bcadd($account->charge_cash, $chargeCpr->charge_cash, 2);
// 从冻结金额中减去充值金额,并将结果赋值回冻结金额
$account->frozen_cash = bcsub($account->frozen_cash, $chargeCash, 2);
// 减少账户可用余额
$account->able_cash = bcsub($account->able_cash, $chargeCpr->charge_cash, 2);
$account->saveOrFail();
return $account->saveOrFail();
}
// if ($status == 3) {
// $account = CashAccount::find()->where([
// 'user_id' => 0,
// 'user_type' => 2
// ])->one();
// // 将冻结金额和充值金额进行合并计算,并将结果赋值给可用金额
// $account->charge_cash = bcadd($account->charge_cash, $chargeCpr->charge_cash, 2);
// return $account->saveOrFail();
// }
}
/**

View File

@@ -0,0 +1,30 @@
<?php
namespace common\models;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
class ChargeCashPayRecord extends \common\modelsgii\ChargeCashPayRecord
{
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
],
];
}
//门店
public function getStore()
{
return $this->hasOne(Store::class, ['id'=>'store_id']);
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace common\modelsgii;
use Yii;
/**
* This is the model class for table "yii_charge_cash_pay_record".
*
* @property int $id // ID
* @property int $store_id // 诊所id
* @property string $charge_cash // 手续费
* @property string $order_no // 订单号
* @property int $type // 类型 0平台 1诊所
* @property int $status // 状态 1已记录 2已代付 3已取消
* @property $store // 诊所
* @property int $created_at
* @property int $updated_at
*/
class ChargeCashPayRecord extends \common\core\BaseActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'yii_charge_cash_pay_record';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['store_id', 'charge_cash', 'type', 'status'], 'required'],
[['created_at', 'updated_at'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'order_no' => '订单号',
'store_id' => '诊所ID',
'charge_cash' => '手续费',
'type' => 'type',
'status' => 'status',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
}