2024-09-19 11:32:39 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace admin\controllers\base;
|
|
|
|
|
|
|
|
|
|
|
|
use admin\components\BaseAdminController;
|
|
|
|
|
|
use admin\controllers\AuthController;
|
|
|
|
|
|
use admin\models\Admin;
|
|
|
|
|
|
use common\enums\UserRoleEnum;
|
|
|
|
|
|
use common\helpers\FuncHelper;
|
|
|
|
|
|
use common\models\CashAccount;
|
|
|
|
|
|
use common\models\CashApply;
|
2024-09-28 14:00:38 +08:00
|
|
|
|
use common\models\ChargeCashPayRecord;
|
2024-09-19 11:32:39 +08:00
|
|
|
|
use common\models\Ledger;
|
|
|
|
|
|
use common\models\LedgerLog;
|
|
|
|
|
|
use common\models\Log;
|
|
|
|
|
|
use common\models\Register;
|
|
|
|
|
|
use common\models\Store;
|
|
|
|
|
|
use common\modelsgii\ProductOrder;
|
|
|
|
|
|
use common\services\EplPayService;
|
|
|
|
|
|
use yii\base\Exception;
|
|
|
|
|
|
use yii\helpers\Json;
|
|
|
|
|
|
use yii\web\Response;
|
|
|
|
|
|
use common\services\ExportService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-module 分账
|
|
|
|
|
|
*/
|
|
|
|
|
|
class DivideAccountController extends BaseAdminController
|
|
|
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 诊所申请提现操作
|
|
|
|
|
|
* @doc-param string apply_cash 申请提现金额
|
|
|
|
|
|
* @doc-param string bank_user_name 开户人姓名
|
|
|
|
|
|
* @doc-param string bank_card 银行卡号
|
|
|
|
|
|
* @doc-param string bank_name 开户行名称
|
|
|
|
|
|
* @doc-param int bank_account_type 银行账户类型 1:对公,2:对私,5:存折
|
|
|
|
|
|
* @doc-param string bank_no 银行联行号bank_account_type=1或5或非62开头的对私银行账户时必选 / optional
|
|
|
|
|
|
* @doc-param int user_type 用户类型1诊所2总部
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionStoreApply()
|
|
|
|
|
|
{
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// TODO 门店提现
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$post = \Yii::$app->request->post();
|
|
|
|
|
|
$this->requestValidate($post, [
|
|
|
|
|
|
[['apply_cash', 'bank_user_name', 'bank_card', 'bank_name', 'bank_account_type', 'user_type'], 'required']
|
|
|
|
|
|
]);
|
|
|
|
|
|
if ($post['apply_cash']<3){
|
|
|
|
|
|
throw new \yii\db\Exception('申请提现金额最少不能小于3元');
|
|
|
|
|
|
}
|
|
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
|
|
|
|
|
|
|
|
|
|
if ($user->role != UserRoleEnum::STORE_ADMIN) {
|
|
|
|
|
|
throw new Exception('您还不是诊所管理员,没有权限申请打款');
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($post['user_type'] != 1) throw new Exception('用户类型错误');
|
|
|
|
|
|
|
|
|
|
|
|
if ($post['bank_account_type'] == 1 || $post['bank_account_type'] == 5) {
|
|
|
|
|
|
if (empty($post['bank_no'])) {
|
|
|
|
|
|
throw new Exception('bank_no不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (substr($post['bank_card'], 0, 2) != '62') {
|
|
|
|
|
|
if (empty($post['bank_no'])) {
|
|
|
|
|
|
throw new Exception('bank_no不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
|
|
try {
|
|
|
|
|
|
$order_no = 'DK' . time() . rand(111111, 999999);
|
|
|
|
|
|
$Account = CashAccount::find()->where([
|
|
|
|
|
|
'user_id' => $user->store_id,
|
|
|
|
|
|
'user_type' => 1
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
if (!$Account) throw new Exception('账号不存在');
|
|
|
|
|
|
|
|
|
|
|
|
if (bcsub($Account->able_cash ,$Account->frozen_cash,2) < $post['apply_cash']) {
|
|
|
|
|
|
throw new Exception('sorry,您的账户没有那么多提现金额');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$CashAccount = CashAccount::find()->where([
|
|
|
|
|
|
'user_id' => $user->store_id,
|
|
|
|
|
|
'user_type' => 1
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
|
|
|
|
|
|
$CashAccount->frozen_cash = bcadd($post['apply_cash'], $CashAccount->frozen_cash, 2);
|
|
|
|
|
|
$CashAccount->last_apply_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
2024-09-29 16:44:06 +08:00
|
|
|
|
// TODO 暂时关闭手续费 扣除平台的手续费
|
2024-09-28 14:00:38 +08:00
|
|
|
|
$pQianliuwu=bcdiv(0.65,100,4);
|
|
|
|
|
|
$pShouxufei=bcadd(bcmul($post['apply_cash'],$pQianliuwu,2),2,3);
|
2024-09-19 11:32:39 +08:00
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
$shouxufei = 0;
|
2024-09-19 11:32:39 +08:00
|
|
|
|
// $Platform->updateAllCounters(['able_cash'=>1]);
|
|
|
|
|
|
// $Platform->updateAllCounters(['total_cash'=>1]);
|
|
|
|
|
|
|
|
|
|
|
|
$CashApply = new CashApply();
|
|
|
|
|
|
$CashApply->user_id = $user->store_id;//诊所id
|
|
|
|
|
|
$CashApply->user_type = 1;//用户类型1诊所2总部
|
|
|
|
|
|
$CashApply->order_no = $order_no;//申请提现金额
|
|
|
|
|
|
$CashApply->apply_cash = $post['apply_cash'];//申请提现金额
|
|
|
|
|
|
$CashApply->charge_cash =$shouxufei;//手续费
|
|
|
|
|
|
$CashApply->true_cash = bcsub($CashApply->apply_cash, $shouxufei, 2);//实际到账金额
|
|
|
|
|
|
$CashApply->apply_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashApply->saveOrFail();
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 记录代付的手续费
|
|
|
|
|
|
$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();
|
|
|
|
|
|
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log = new Log();
|
|
|
|
|
|
$log->admin_id = $user->uid;
|
|
|
|
|
|
$log->operate_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$log->type = '诊所申请打款';
|
|
|
|
|
|
$log->mold = 3;//财务操作
|
|
|
|
|
|
$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->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());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 平台申请提现操作
|
|
|
|
|
|
* @doc-param string apply_cash 申请提现金额
|
|
|
|
|
|
* @doc-param string bank_user_name 开户人姓名
|
|
|
|
|
|
* @doc-param string bank_card 银行卡号
|
|
|
|
|
|
* @doc-param string bank_name 开户行名称
|
|
|
|
|
|
* @doc-param int bank_account_type 银行账户类型 1:对公,2:对私,5:存折
|
|
|
|
|
|
* @doc-param string bank_no 银行联行号bank_account_type=1或5或非62开头的对私银行账户时必选 / optional
|
|
|
|
|
|
* @doc-param int user_type 用户类型1诊所2总部
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionPlatformApply()
|
|
|
|
|
|
{
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 获取前端传递的POST数据
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$post = \Yii::$app->request->post();
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 对POST数据进行验证,确保必要的字段不为空
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$this->requestValidate($post, [
|
|
|
|
|
|
[['apply_cash', 'bank_user_name', 'bank_card', 'bank_name', 'bank_account_type', 'user_type'], 'required']
|
|
|
|
|
|
]);
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 检查申请提现金额是否大于等于3元
|
|
|
|
|
|
if ($post['apply_cash'] < 3) {
|
2024-09-19 11:32:39 +08:00
|
|
|
|
throw new \yii\db\Exception('申请提现金额最少不能小于3元');
|
|
|
|
|
|
}
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取当前用户信息
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 检查用户角色是否为超级管理员
|
2024-09-19 11:32:39 +08:00
|
|
|
|
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new \yii\base\Exception('您还不是超级管理员,没有权限申请打款');
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 检查用户类型是否正确
|
2024-09-19 11:32:39 +08:00
|
|
|
|
if ($post['user_type'] != 2) throw new \yii\db\Exception('用户类型错误');
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 对公账户和私人账户的额外验证
|
2024-09-19 11:32:39 +08:00
|
|
|
|
if ($post['bank_account_type'] == 1 || $post['bank_account_type'] == 5) {
|
|
|
|
|
|
if (empty($post['bank_no'])) {
|
|
|
|
|
|
throw new \yii\base\Exception('bank_no不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (substr($post['bank_card'], 0, 2) != '62') {
|
|
|
|
|
|
if (empty($post['bank_no'])) {
|
|
|
|
|
|
throw new Exception('bank_no不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 数据库事务开始
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
|
|
try {
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 生成订单号
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$order_no = 'DK' . time() . rand(111111, 999999);
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 查询账户信息
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$Account = CashAccount::find()->where([
|
|
|
|
|
|
'user_type' => 2,
|
|
|
|
|
|
'user_id' => 0,
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
if (!$Account) throw new Exception('账号不存在');
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 检查账户是否有足够的可提现金额
|
|
|
|
|
|
if (bcsub($Account->able_cash, $Account->frozen_cash, 2) < $post['apply_cash'])
|
2024-09-19 11:32:39 +08:00
|
|
|
|
throw new Exception('sorry,您的账户没有那么多提现金额');
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新账户的冻结金额
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashAccount = CashAccount::find()->where([
|
2024-09-27 14:41:18 +08:00
|
|
|
|
'user_type' => 2, //平台
|
2024-09-19 11:32:39 +08:00
|
|
|
|
'user_id' => 0,
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
$CashAccount->frozen_cash = bcadd($post['apply_cash'], $CashAccount->frozen_cash, 2);
|
|
|
|
|
|
$CashAccount->last_apply_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 计算手续费
|
2024-09-28 16:27:52 +08:00
|
|
|
|
$pQianliuwu = bcdiv(0.65, 100, 4);
|
|
|
|
|
|
$pShouxufei = bcadd(bcmul($post['apply_cash'], $pQianliuwu, 2), 2, 3);
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// TODO 暂时不计算手续费
|
|
|
|
|
|
$shouxufei = '0';
|
2024-09-19 11:32:39 +08:00
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 创建提现申请记录
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply = new CashApply();
|
|
|
|
|
|
$CashApply->user_type = 2;
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashApply->user_id = 0; //用户ID
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->order_no = $order_no;
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashApply->apply_cash = $post['apply_cash']; //申请提现金额
|
|
|
|
|
|
$CashApply->charge_cash = $shouxufei; //手续费
|
|
|
|
|
|
$CashApply->true_cash = bcsub($CashApply->apply_cash, $shouxufei, 2); //实际到账金额
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->apply_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashApply->saveOrFail();
|
|
|
|
|
|
|
2024-09-28 16:27:52 +08:00
|
|
|
|
|
|
|
|
|
|
// 记录代付的手续费
|
|
|
|
|
|
$chargeCpr = new ChargeCashPayRecord();
|
|
|
|
|
|
$chargeCpr->order_no = $order_no;
|
|
|
|
|
|
$chargeCpr->store_id = 0;//诊所id
|
|
|
|
|
|
$chargeCpr->charge_cash = $pShouxufei;//手续费
|
|
|
|
|
|
$chargeCpr->type = 2;//用户类型1诊所2总部
|
|
|
|
|
|
$chargeCpr->status = 1;
|
|
|
|
|
|
$chargeCpr->saveOrFail();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 记录操作日志
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log = new Log();
|
|
|
|
|
|
$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 . '元';
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$log->mold = 3; //财务操作
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log->save();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新日志记录
|
2024-09-19 11:32:39 +08:00
|
|
|
|
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 提交事务
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t->commit();
|
|
|
|
|
|
return ['申请成功'];
|
|
|
|
|
|
} catch (\Exception $e) {
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 回滚事务
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t->rollBack();
|
|
|
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 分账申请打款审核(超级管理员)--通过
|
|
|
|
|
|
* @doc-param int id 申请id
|
|
|
|
|
|
* @doc-param int user_type 类型1诊所2总部
|
|
|
|
|
|
* @doc-param string check_result 审核结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionApplyAgree()
|
|
|
|
|
|
{
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 获取前端传递的POST数据
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$post = \Yii::$app->request->post();
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 对POST数据进行验证,确保必要的字段不为空
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$this->requestValidate($post, [
|
|
|
|
|
|
[['id', 'check_result', 'user_type'], 'required'],
|
|
|
|
|
|
]);
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取当前用户身份
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$user = \Yii::$app->user->identity;
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 检查用户角色,如果不是超级管理员,则抛出异常
|
2024-09-19 11:32:39 +08:00
|
|
|
|
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new Exception('你不是超级管理员,没有分账申请打款审核权限');
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 根据POST数据查找现金申请信息,确保该申请存在且待审核
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply = CashApply::find()->where([
|
|
|
|
|
|
'id' => $post['id'],
|
|
|
|
|
|
'user_type' => $post['user_type'],
|
|
|
|
|
|
'check_status' => 1
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
if (!$CashApply) throw new Exception('申请不存在');
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 根据用户类型(诊所或平台)查找对应的账户信息和配置
|
|
|
|
|
|
if ($post['user_type'] == 1) { // 诊所
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$Account = CashAccount::find()->where([
|
|
|
|
|
|
'user_id' => $CashApply->user_id,
|
|
|
|
|
|
'user_type' => $CashApply->user_type
|
|
|
|
|
|
])->one();
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$config = Store::find()->where(['id' => $CashApply->user_id])->one();
|
|
|
|
|
|
} else { // 平台
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$Account = CashAccount::find()->where([
|
|
|
|
|
|
'user_id' => 0,
|
|
|
|
|
|
'user_type' => $CashApply->user_type
|
|
|
|
|
|
])->one();
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$config = Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
|
2024-09-19 11:32:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 确保诊所或平台的账号存在
|
2024-09-19 11:32:39 +08:00
|
|
|
|
if (!$Account) throw new Exception('诊所或平台的账号不存在');
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 再次确认现金账户信息
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashAccount = CashAccount::find()->where([
|
|
|
|
|
|
'user_type' => $CashApply->user_type,
|
|
|
|
|
|
'user_id' => $CashApply->user_id
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 检查银行账户配置是否完整,如果有任一配置项为空,则解冻申请提现的金额,并记录审核失败
|
|
|
|
|
|
if (empty($config['bank_user_name']) || empty($config['bank_card']) || empty($config['bank_name']) || empty($config['bank_account_type'])) {
|
2024-09-19 11:32:39 +08:00
|
|
|
|
|
|
|
|
|
|
$CashApply->check_id = $user->uid;
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashApply->check_status = 4; // 提现失败
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->check_result = '银行卡相关配置不完善';
|
|
|
|
|
|
$CashApply->check_time = date('Y-m-d H:i:s', time());
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashApply->dakuan_status = -1; // 失败
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashApply->saveOrFail();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 创建日志记录,记录此次审核操作的详细信息
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log = new Log();
|
|
|
|
|
|
$log->admin_id = $user->uid;
|
|
|
|
|
|
$log->operate_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$log->type = '分账申请打款审核';
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 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; // 财务操作
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log->saveOrFail();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新日志内容到数据库
|
2024-09-19 11:32:39 +08:00
|
|
|
|
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
|
|
|
|
|
|
throw new \yii\db\Exception('银行卡相关配置不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 准备打款参数
|
|
|
|
|
|
$param = [
|
|
|
|
|
|
'order_no' => $CashApply->order_no, // 订单号
|
2024-09-29 17:01:05 +08:00
|
|
|
|
'apply_cash' => bcadd($CashApply->true_cash, 1, 2), // 实际打款金额 1元是银联手续费
|
2024-09-27 14:41:18 +08:00
|
|
|
|
'bank_name' => $config->bank_name, // 银行名称
|
|
|
|
|
|
'bank_account_type' => $config->bank_account_type, // 银行账户类型
|
|
|
|
|
|
'bank_no' => $config->bank_no, // 银行账号
|
|
|
|
|
|
'bank_user_name' => $config->bank_user_name, // 开户人姓名
|
|
|
|
|
|
'bank_card' => $config->bank_card, // 银行卡号
|
2024-09-19 11:32:39 +08:00
|
|
|
|
];
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 执行打款操作
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$res = EplPayService::getInstance()->withDraw($param);
|
2024-09-27 14:41:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 处理打款失败情况
|
|
|
|
|
|
if ($res['returnCode'] != '0000') {
|
2024-09-19 11:32:39 +08:00
|
|
|
|
try {
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 开始事务
|
|
|
|
|
|
$transaction = \Yii::$app->db->beginTransaction();
|
2024-09-19 11:32:39 +08:00
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新用户账户信息,解冻申请提现的金额
|
|
|
|
|
|
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新提现申请状态为失败
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->check_id = $user->uid;
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashApply->check_status = 4; // 提现失败状态码
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->check_result = $res['returnMsg'];
|
|
|
|
|
|
$CashApply->check_time = date('Y-m-d H:i:s', time());
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashApply->dakuan_status = -1; // 打款失败状态码
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashApply->saveOrFail();
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 记录代付的手续费
|
|
|
|
|
|
$this->updateChargeCashPayRecordStatusByOrderNo($CashApply->order_no, 3);
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 记录日志
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log = new Log();
|
|
|
|
|
|
$log->admin_id = $user->uid;
|
|
|
|
|
|
$log->operate_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$log->type = '分账申请打款审核';
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 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; // 财务操作状态码
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log->saveOrFail();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新日志表内容
|
2024-09-19 11:32:39 +08:00
|
|
|
|
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 提交事务
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$transaction->commit();
|
|
|
|
|
|
return $res;
|
2024-09-27 14:41:18 +08:00
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
// 回滚事务
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$transaction->rollBack();
|
|
|
|
|
|
throw new \yii\db\Exception($e->getMessage());
|
|
|
|
|
|
}
|
2024-09-27 14:41:18 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
// 处理打款成功情况
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
|
|
try {
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新用户账户信息,扣除账户余额,解冻申请提现的金额,增加已提现金额和手续费
|
|
|
|
|
|
$CashAccount->able_cash = bcsub($CashAccount->able_cash, $CashApply->apply_cash, 2);
|
2024-09-30 14:06:45 +08:00
|
|
|
|
// $CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
|
2024-09-30 15:32:35 +08:00
|
|
|
|
// $CashAccount->withdrawn_cash = bcadd($CashAccount->withdrawn_cash, $CashApply->true_cash, 2);
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashAccount->charge_cash = bcadd($CashAccount->charge_cash, $CashApply->charge_cash, 2);
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新提现申请状态为成功
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->check_id = $user->uid;
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashApply->check_status = 2; // 提现成功状态码
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->check_result = $post['check_result'];
|
|
|
|
|
|
$CashApply->check_time = date('Y-m-d H:i:s', time());
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$CashApply->dakuan_status = 1; // 打款成功状态码
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashApply->saveOrFail();
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 记录代付的手续费
|
2024-09-28 16:27:52 +08:00
|
|
|
|
$this->updateChargeCashPayRecordStatusByOrderNo($CashApply->order_no, 2, $param['apply_cash']);
|
2024-09-28 14:00:38 +08:00
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 记录日志
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$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'] . '的打款申请,打款结果:成功';
|
2024-09-27 14:41:18 +08:00
|
|
|
|
$log->mold = 3; // 财务操作状态码
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log->save();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 更新日志表内容
|
2024-09-19 11:32:39 +08:00
|
|
|
|
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
|
|
|
|
|
|
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 提交事务
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t->commit();
|
|
|
|
|
|
return ['审核成功'];
|
|
|
|
|
|
} catch (\Exception $e) {
|
2024-09-27 14:41:18 +08:00
|
|
|
|
// 回滚事务
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t->rollBack();
|
|
|
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 分账申请打款审核(超级管理员)--拒绝
|
|
|
|
|
|
* @doc-param int id 申请id
|
|
|
|
|
|
* @doc-param int user_type 类型1诊所2总部
|
|
|
|
|
|
* @doc-param string check_result 审核结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionApplyRefuse()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 获取前端传递的POST数据
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$post = \Yii::$app->request->post();
|
2024-09-28 14:00:38 +08:00
|
|
|
|
|
|
|
|
|
|
// 对POST数据进行验证
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$this->requestValidate($post, [
|
|
|
|
|
|
[['id', 'check_result', 'user_type'], 'required'],
|
|
|
|
|
|
]);
|
2024-09-28 14:00:38 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取当前用户身份
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$user = \Yii::$app->user->identity;
|
2024-09-28 14:00:38 +08:00
|
|
|
|
|
|
|
|
|
|
// 检查用户角色,如果不是超级管理员则抛出异常
|
2024-09-19 11:32:39 +08:00
|
|
|
|
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new Exception('你不是超级管理员,没有分账申请打款审核权限');
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 根据ID和用户类型查找现金申请信息,如果状态为1(可能代表待审核),则获取该申请,否则抛出异常
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply = CashApply::find()->where([
|
|
|
|
|
|
'id' => $post['id'],
|
|
|
|
|
|
'user_type' => $post['user_type'],
|
|
|
|
|
|
'check_status' => 1,
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
if (!$CashApply) throw new Exception('申请不存在');
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 查找用户的账号信息,如果不存在抛出异常
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$Account = CashAccount::find()->where([
|
|
|
|
|
|
'user_id' => $CashApply->user_id,
|
|
|
|
|
|
'user_type' => $CashApply->user_type
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
if (!$Account) throw new Exception('平台或技术方的账号不存在');
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 开启数据库事务
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
|
|
try {
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 设置申请的审核人为当前用户,并将审核状态设置为拒绝,保存审核结果和时间
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->check_id = $user->uid;
|
2024-09-28 14:00:38 +08:00
|
|
|
|
$CashApply->check_status = 3; // 拒绝状态
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashApply->check_result = $post['check_result'];
|
|
|
|
|
|
$CashApply->check_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashApply->saveOrFail();
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// TODO 这里的逻辑会导致查询出来的账号信息永远是第一个用户的信息,需要修改
|
|
|
|
|
|
|
|
|
|
|
|
// $CashAccount = CashAccount::find()->where([
|
|
|
|
|
|
// 'user_type' => $CashApply->user_type
|
|
|
|
|
|
// ])->one();
|
|
|
|
|
|
// 更新用户账号的冻结金额
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashAccount = CashAccount::find()->where([
|
2024-09-28 14:00:38 +08:00
|
|
|
|
'user_id' => $CashApply->user_id,
|
2024-09-19 11:32:39 +08:00
|
|
|
|
'user_type' => $CashApply->user_type
|
|
|
|
|
|
])->one();
|
2024-09-28 14:00:38 +08:00
|
|
|
|
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);
|
|
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 记录代付的手续费
|
|
|
|
|
|
$this->updateChargeCashPayRecordStatusByOrderNo($CashApply->order_no, 3);
|
|
|
|
|
|
|
|
|
|
|
|
// 记录操作日志
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$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;
|
2024-09-28 14:00:38 +08:00
|
|
|
|
$log->mold = 3; // 财务操作
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$log->save();
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 更新日志内容到数据库
|
2024-09-19 11:32:39 +08:00
|
|
|
|
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 提交事务
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t->commit();
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 返回操作结果
|
2024-09-19 11:32:39 +08:00
|
|
|
|
return ['成功拒绝'];
|
|
|
|
|
|
} catch (\Exception $e) {
|
2024-09-28 14:00:38 +08:00
|
|
|
|
// 如果有异常则回滚事务,并抛出异常
|
2024-09-19 11:32:39 +08:00
|
|
|
|
$t->rollBack();
|
|
|
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-28 14:00:38 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 更新代付记录状态
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $orderNo
|
|
|
|
|
|
* @param $status
|
2024-09-29 16:44:06 +08:00
|
|
|
|
* @param string $chargeCash // 在status = 2的时候是冻结金额
|
2024-09-28 14:00:38 +08:00
|
|
|
|
* @return void
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
2024-09-29 16:44:06 +08:00
|
|
|
|
private function updateChargeCashPayRecordStatusByOrderNo($orderNo, $status, $chargeCash = '')
|
2024-09-28 14:00:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (empty($orderNo) || empty($status)) throw new Exception('参数错误');
|
|
|
|
|
|
// 记录代付的手续费
|
2024-09-28 16:27:52 +08:00
|
|
|
|
$chargeCpr = $this->getChargeCashPayRecordStatusByOrderNo($orderNo);
|
|
|
|
|
|
$chargeCpr->status = $status;
|
|
|
|
|
|
$chargeCpr->saveOrFail();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据订单号获取代付记录
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $orderNo
|
|
|
|
|
|
* @return array|\yii\db\ActiveRecord|null
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function getChargeCashPayRecordStatusByOrderNo($orderNo)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ChargeCashPayRecord::find()->where([
|
2024-09-28 14:00:38 +08:00
|
|
|
|
'status' => 1,
|
|
|
|
|
|
'order_no' => $orderNo
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-19 11:32:39 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 分账打款
|
|
|
|
|
|
* @doc-param int apply_id 提现申请ID
|
|
|
|
|
|
* @doc-param string order_no 订单号
|
|
|
|
|
|
* @doc-param string order_no 订单号
|
|
|
|
|
|
* @doc-param string bank_user_name 开户人姓名
|
|
|
|
|
|
* @doc-param string bank_card 银行卡号
|
|
|
|
|
|
* @doc-param string bank_name 银行名称
|
|
|
|
|
|
* @doc-param string bank_account_type 1对公2对私5存
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionPayment()
|
|
|
|
|
|
{
|
|
|
|
|
|
$post = \Yii::$app->request->post();
|
|
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
|
|
|
|
|
|
|
|
|
|
if ($user->role != UserRoleEnum::SUPER_ADMIN) throw new \yii\db\Exception('您不是超级管理员,没权限打款');
|
|
|
|
|
|
|
|
|
|
|
|
$this->requestValidate($post, [
|
|
|
|
|
|
[['apply_id', 'order_no', 'bank_user_name', 'bank_card', 'bank_name', 'bank_account_type'], 'required']
|
|
|
|
|
|
]);
|
|
|
|
|
|
$CashApply = CashApply::find()->where(['id' => $post['apply_id']])->one();
|
|
|
|
|
|
if (!$CashApply) throw new Exception('提现申请不存在');
|
|
|
|
|
|
|
|
|
|
|
|
if ($CashApply->check_status != 2) {//不是已通过状态
|
|
|
|
|
|
throw new Exception('提现申请不是已通过状态,您还不能打款');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$CashAccount = CashAccount::find()->where([
|
|
|
|
|
|
'user_type' => $CashApply->user_type,
|
|
|
|
|
|
'user_id' => $CashApply->user_id
|
|
|
|
|
|
])->one();
|
|
|
|
|
|
if (!$CashAccount) throw new Exception('账户不存在');
|
|
|
|
|
|
|
|
|
|
|
|
$post['apply_cash'] = $CashApply->apply_cash;
|
|
|
|
|
|
|
|
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
|
|
try {
|
|
|
|
|
|
//打款
|
|
|
|
|
|
$res = EplPayService::getInstance()->withDraw($post);
|
|
|
|
|
|
//打款失败
|
|
|
|
|
|
if ($res['returnCode'] != 0000) {
|
|
|
|
|
|
$CashAccount->frozen_cash = bcsub($CashAccount->frozen_cash, $CashApply->apply_cash, 2);//申请提现冻结的金额
|
|
|
|
|
|
// $CashAccount->able_cash=bcadd($CashAccount->able_cash,$CashApply->apply_cash,2);//可提现金额
|
|
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$CashApply->dakuan_status = -1;
|
|
|
|
|
|
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
$CashApply->saveOrFail();
|
|
|
|
|
|
|
|
|
|
|
|
$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 . '打款操作,订单号:' . $post['order_no'] . ',打款金额:' . $post['apply_cash'] . '元,开户人姓名:' . $post['bank_user_name'] . ',银行卡号:' . $post['bank_card'] . ',银行名称:' . $post['bank_name'] . ',银行账户类型:' . $post['bank_account_type'] . '打款失败:失败原因' . $res;
|
|
|
|
|
|
$log->mold = 3;//财务操作
|
|
|
|
|
|
$log->saveOrFail();
|
|
|
|
|
|
|
|
|
|
|
|
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
|
|
|
|
|
|
return $res;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//打款成功
|
|
|
|
|
|
$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->apply_cash, 2);//已提现金额
|
|
|
|
|
|
$CashAccount->charge_cash = bcadd($CashAccount->charge_cash, $CashApply->charge_cash, 2);//手续费
|
|
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
|
|
|
|
|
$CashApply->dakuan_status = 1;
|
|
|
|
|
|
$CashApply->dakuan_time = date('Y-m-d H:i:s', time());
|
|
|
|
|
|
|
|
|
|
|
|
$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 . '打款操作:订单号:' . $post['order_no'] . ',打款金额:' . $post['apply_cash'] . '元,开户人姓名:' . $post['bank_user_name'] . ',银行卡号:' . $post['bank_card'] . ',银行名称:' . $post['bank_name'] . ',银行账户类型:' . $post['bank_account_type'];
|
|
|
|
|
|
$log->mold = 3;//财务操作
|
|
|
|
|
|
$log->saveOrFail();
|
|
|
|
|
|
|
|
|
|
|
|
\Yii::$app->db->createCommand()->update('yii_log', ['content' => Json::encode($log->attributes)], ['id' => $log->attributes['id']])->execute();
|
|
|
|
|
|
|
|
|
|
|
|
$t->commit();
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
$t->rollBack();
|
|
|
|
|
|
throw new Exception($e->getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 分账资金流水
|
|
|
|
|
|
* @doc-param string type 1增2减 / optional
|
|
|
|
|
|
* @doc-param string content 内容 / optional
|
|
|
|
|
|
* @doc-return mixed @List{id,order_id-int-订单id,user_id-int-业务员id或仓库id其他为0,user_type-int-用户类型 1诊所 2平台,type-int-1增2减,amount-float-金额,content-string-内容,created_at-string-流水时间} 快递公司
|
|
|
|
|
|
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionDivideFundWater()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$get = \Yii::$app->request->get();
|
|
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
|
|
|
|
$query = LedgerLog::find()->orderBy(['id' => SORT_DESC]);
|
|
|
|
|
|
|
|
|
|
|
|
if ($user->role == UserRoleEnum::STORE_ADMIN) {
|
|
|
|
|
|
$query->andWhere(['user_type' => 1]);
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($user->role == UserRoleEnum::SUPER_ADMIN) {
|
|
|
|
|
|
$query->andWhere(['user_type' => [1, 2]]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($get['type'])) {
|
|
|
|
|
|
$query->andWhere(['type' => $get['type']]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($get['content'])) {
|
|
|
|
|
|
$query->andWhere(['like', 'content', $get['content']]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->field = [
|
|
|
|
|
|
LedgerLog::class => [
|
|
|
|
|
|
'id', 'order_id', 'user_id', 'username' => function ($m) {
|
|
|
|
|
|
return Admin::find()->select(['username'])->where(['uid' => $m->user_id])->column();
|
|
|
|
|
|
}, 'user_type', 'type', 'amount', 'content',
|
|
|
|
|
|
'created_at' => function ($m) {
|
|
|
|
|
|
return date('Y-m-d H:i:s', $m->created_at);
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
];
|
|
|
|
|
|
return $this->create($query, $get);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 首页数据
|
|
|
|
|
|
* @doc-return mixed @List{id,user_id-int-用户ID,total_cash-float-累计收益,able_cash-int-账户余额,frozen_cash-int-申请提现冻结的金额,withdrawn_cash-int-已提现金额,wait_cash-float-待结算收益,charge_cash-float-手续费,user_type-int-用户类型 1诊所 2平台,last_apply_time-string-最近提现申请时间,account-string-账户} 首页数据
|
|
|
|
|
|
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionHomeData()
|
|
|
|
|
|
{
|
|
|
|
|
|
$get = \Yii::$app->request->get();
|
|
|
|
|
|
$QUERY = CashAccount::find();
|
|
|
|
|
|
$this->field = [
|
|
|
|
|
|
CashAccount::class => [
|
|
|
|
|
|
'id', 'user_id', 'total_cash', 'able_cash', 'frozen_cash', 'withdrawn_cash', 'wait_cash', 'charge_cash',
|
|
|
|
|
|
'account' => 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();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'user_type',
|
|
|
|
|
|
'last_apply_time'
|
|
|
|
|
|
]
|
|
|
|
|
|
];
|
|
|
|
|
|
return $this->create($QUERY, $get);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 平台的提现账户
|
|
|
|
|
|
* @doc-return string user_id 用户
|
|
|
|
|
|
* @doc-return string total_cash 累计收益
|
|
|
|
|
|
* @doc-return string able_cash 账户余额
|
|
|
|
|
|
* @doc-return string frozen_cash 申请提现冻结的金额
|
|
|
|
|
|
* @doc-return string withdrawn_cash 待结算收益
|
|
|
|
|
|
* @doc-return string wait_cash 已提现金额
|
|
|
|
|
|
* @doc-return string charge_cash 手续费
|
|
|
|
|
|
* @doc-return string user_type 用户类型 1诊所 2平台
|
|
|
|
|
|
* @doc-return string last_apply_time 最近提现申请时间
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionPlatformAccount()
|
|
|
|
|
|
{
|
|
|
|
|
|
$get = \Yii::$app->request->get();
|
|
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
|
|
|
|
|
|
|
|
|
|
$CashAccount = CashAccount::find()->where(['user_id' => 0, 'user_type' => 2])->one();
|
|
|
|
|
|
if (!$CashAccount) throw new \yii\db\Exception('账户不存在');
|
|
|
|
|
|
$price=Ledger::find()->where(['status'=>0,'user_type'=>2,'user_id'=>0])->sum('money');
|
|
|
|
|
|
$CashAccount->total_cash=bcadd(bcadd($CashAccount->able_cash,$CashAccount->withdrawn_cash,2),$CashAccount->charge_cash,2);
|
|
|
|
|
|
|
|
|
|
|
|
$CashAccount->wait_cash=$price;
|
|
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
|
|
|
|
|
return $CashAccount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 诊所提现账户
|
|
|
|
|
|
* @doc-param int store_id 诊所ID
|
|
|
|
|
|
* @doc-return string user_id 用户
|
|
|
|
|
|
* @doc-return string total_cash 累计收益
|
|
|
|
|
|
* @doc-return string able_cash 账户余额
|
|
|
|
|
|
* @doc-return string frozen_cash 申请提现冻结的金额
|
|
|
|
|
|
* @doc-return string withdrawn_cash 待结算收益
|
|
|
|
|
|
* @doc-return string wait_cash 已提现金额
|
|
|
|
|
|
* @doc-return string charge_cash 手续费
|
|
|
|
|
|
* @doc-return string user_type 用户类型 1诊所2平台
|
|
|
|
|
|
* @doc-return string last_apply_time 最近提现申请时间
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionStoreAccount()
|
|
|
|
|
|
{
|
|
|
|
|
|
$get = \Yii::$app->request->get();
|
|
|
|
|
|
$this->requestValidate($get, [
|
|
|
|
|
|
['store_id', 'required'],
|
|
|
|
|
|
]);
|
|
|
|
|
|
$store = Store::find()->where(['id' => $get['store_id']])->one();
|
|
|
|
|
|
if (!$store) throw new \yii\db\Exception('诊所不存在');
|
|
|
|
|
|
|
|
|
|
|
|
$CashAccount = CashAccount::find()->where(['user_id' => $get['store_id'], 'user_type' => 1])->one();
|
|
|
|
|
|
if (!$CashAccount) throw new \yii\db\Exception('账户不存在');
|
|
|
|
|
|
|
|
|
|
|
|
$price=Ledger::find()->where(['status'=>0,'user_type'=>1,'user_id'=>$CashAccount->user_id])->sum('money');
|
|
|
|
|
|
$CashAccount->total_cash=bcadd(bcadd($CashAccount->able_cash,$CashAccount->withdrawn_cash,2),$CashAccount->charge_cash,2);
|
|
|
|
|
|
|
|
|
|
|
|
$CashAccount->wait_cash=$price??0;
|
|
|
|
|
|
$CashAccount->saveOrFail();
|
|
|
|
|
|
|
|
|
|
|
|
return $CashAccount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 分账--审核管理列表
|
|
|
|
|
|
* @doc-param int status 1待审核2审核通过3审核拒绝
|
|
|
|
|
|
* @doc-return mixed @List{id,user_id-int-用户ID,user_type-int-用户类型1诊所2总部,order_no-int-订单,apply_cash-float-申请提现金额,true_cash-float-实际到账金额,charge_cash-string-手续费,check_id-string-关联admin表 审核人ID,check_status-string-审核状态0待审核1审核中2已通过3已拒绝,check_result-string-审核结果/拒绝原因,check_time-string-审核时间,apply_time-string-申请时间,dakuan_status-string-打款状态-1失败0未知1成功,dakuan_time-string-打款时间,payee-string-收款人} 审核管理列表
|
|
|
|
|
|
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionCheckManage()
|
|
|
|
|
|
{
|
|
|
|
|
|
$get = \Yii::$app->request->get();
|
|
|
|
|
|
$this->requestValidate($get, [
|
|
|
|
|
|
['status', 'required']
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$query = CashApply::find()->orderBy(['id' => SORT_DESC]);
|
|
|
|
|
|
switch ($get['status']) {
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
$query->andWhere(['check_status' => [0, 1]]);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
$query->andWhere(['check_status' => 2]);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
$query->andWhere(['check_status' => 3]);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new \yii\db\Exception('参数错误');
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!empty($get['start_time']) && !empty($get['end_time'])){
|
|
|
|
|
|
$start_time=strtotime($get['start_time'].' '.'00:00:00');
|
|
|
|
|
|
$end_time=strtotime($get['end_time'].' '.'23:59:59');
|
|
|
|
|
|
$query->andWhere(['between','created_at',$start_time,$end_time]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!empty($get['name'])){
|
|
|
|
|
|
if($get['name'] == '平台'){
|
|
|
|
|
|
$query->andWhere(['user_id' => 0]);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$store = Store::find()->where(['name'=>$get['name']])->asArray()->one();
|
|
|
|
|
|
if($store){
|
|
|
|
|
|
$query->andWhere(['user_id' => intval($store['id'])]);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$query->andWhere(['user_id' => -1]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$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) {
|
|
|
|
|
|
if ($m->user_id == 0) {
|
|
|
|
|
|
return Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return Store::find()->where(['id' => $m->user_id])->one();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
];
|
|
|
|
|
|
return $this->create($query, $get);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 导出提现审核
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionExportWithDraw()
|
|
|
|
|
|
{
|
|
|
|
|
|
\Yii::$app->response->format = Response::FORMAT_RAW;
|
|
|
|
|
|
$params = \Yii::$app->request->get();
|
|
|
|
|
|
$parameter['header'] = ['订单号', '平台/诊所', '收款人', '申请提现金额', '审核状态', '时间'];
|
|
|
|
|
|
$parameter['data'] = CashApply::inventory($params,\Yii::$app->user->identity->store_id);
|
|
|
|
|
|
ExportService::ExportByCors($parameter);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 分账--财务数据
|
|
|
|
|
|
* @doc-param float total_cash 累计收益
|
|
|
|
|
|
* @doc-param float able_cash 账户余额
|
|
|
|
|
|
* @doc-param float withdrawn_cash 已体现
|
|
|
|
|
|
* @doc-param float charge_cash 手续费
|
|
|
|
|
|
* @doc-param float wait_cash 待结算
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionFenzhangFinance()
|
|
|
|
|
|
{
|
|
|
|
|
|
//总收入
|
|
|
|
|
|
$total_price=CashAccount::find()->sum('total_cash');
|
|
|
|
|
|
//账户余额
|
|
|
|
|
|
$account_price=CashAccount::find()->sum('able_cash');
|
|
|
|
|
|
$withdrawn_cash=CashAccount::find()->sum('withdrawn_cash');
|
|
|
|
|
|
$charge_cash=CashAccount::find()->sum('charge_cash');
|
|
|
|
|
|
// $wait_cash=CashAccount::find()->sum('wait_cash');
|
|
|
|
|
|
|
|
|
|
|
|
$wait_cash=Ledger::find()->where(['status'=>0])->sum('money');
|
|
|
|
|
|
return [
|
|
|
|
|
|
'total_cash'=>$total_price,
|
|
|
|
|
|
'able_cash'=>$account_price,
|
|
|
|
|
|
'withdrawn_cash'=>$withdrawn_cash,
|
|
|
|
|
|
'charge_cash'=>$charge_cash,
|
|
|
|
|
|
'wait_cash'=>$wait_cash??0,
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 分账--财务数据的明细
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionFenzhangFinanceDetail()
|
|
|
|
|
|
{
|
|
|
|
|
|
$CashApply=CashApply::find()->orderBy(['id'=>SORT_DESC])->all();
|
|
|
|
|
|
$Ledger=Ledger::find()->orderBy(['id'=>SORT_DESC])->with(['productOrder'])->asArray()->all();
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
'CashApply'=>$CashApply,
|
|
|
|
|
|
'Ledger'=>$Ledger,
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 平台/诊所提现管理
|
|
|
|
|
|
* @doc-return mixed @List{id,user_id-int-用户ID,user_type-int-用户类型1诊所2总部,order_no-int-订单,apply_cash-float-申请提现金额,true_cash-float-实际到账金额,charge_cash-string-手续费,check_id-string-关联admin表 审核人ID,check_status-string-审核状态0待审核1审核中2已通过3已拒绝,check_result-string-审核结果/拒绝原因,check_time-string-审核时间,apply_time-string-申请时间,dakuan_status-string-打款状态-1失败0未知1成功,dakuan_time-string-打款时间,payee-string-收款人} 平台/诊所提现管理
|
|
|
|
|
|
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionWithdrawnManage()
|
|
|
|
|
|
{
|
|
|
|
|
|
$get = \Yii::$app->request->get();
|
|
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
|
|
|
|
$order_no=$get['order_no'];
|
|
|
|
|
|
$query = CashApply::find()->alias('c')->orderBy(['id' => SORT_DESC]);
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($order_no)){
|
|
|
|
|
|
$query->andWhere(['c.order_no'=>$order_no]);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!empty($get['start_time']) && !empty($get['end_time'])){
|
|
|
|
|
|
$query->andWhere(['between','c.apply_time',$get['start_time'],$get['end_time']]);
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($user->role==UserRoleEnum::SUPER_ADMIN){//平台
|
|
|
|
|
|
$query->andWhere(['c.user_id'=>0,'c.user_type'=>2]);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$query->andWhere(['c.user_id'=>$user->store_id,'c.user_type'=>1]);
|
|
|
|
|
|
}
|
|
|
|
|
|
$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) {
|
|
|
|
|
|
if ($m->user_id == 0) {
|
|
|
|
|
|
return Admin::find()->where(['role' => UserRoleEnum::SUPER_ADMIN])->one();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return Store::find()->where(['id' => $m->user_id])->one();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'type' => function ($c) {//结算类别
|
|
|
|
|
|
return '提现记录';
|
|
|
|
|
|
},
|
|
|
|
|
|
'status' => function ($ca) {
|
|
|
|
|
|
if ($ca->check_status == 1 ) {
|
|
|
|
|
|
return '审核中';
|
|
|
|
|
|
} elseif($ca->check_status == 2) {
|
|
|
|
|
|
return '审核通过,提现成功';
|
|
|
|
|
|
}elseif($ca->check_status == 3) {
|
|
|
|
|
|
return '申请已拒绝,手续费未扣';
|
|
|
|
|
|
}elseif($ca->check_status == 4 ) {
|
|
|
|
|
|
return '审核通过,提现失败';
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return '未知';
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'tixian_person'=>function($m){
|
|
|
|
|
|
if ($m->user_type==1)return '诊所';
|
|
|
|
|
|
if ($m->user_type==2)return '平台';
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
];
|
|
|
|
|
|
return $this->create($query, $get);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 平台/诊所结算列表
|
|
|
|
|
|
* @doc-param string order_no 产品订单号
|
|
|
|
|
|
* @doc-param string register_no 挂号订单号
|
|
|
|
|
|
* @doc-param string start_time 开始时间
|
|
|
|
|
|
* @doc-param string end_time 结束时间
|
|
|
|
|
|
* @doc-return mixed @List{id,user_id-int-用户ID,user_type-int-用户类型1诊所2总部,order_no-int-订单,order_id-int-订单id,su_id-int-医生id,drugstore_id-int-仓库id,drug_id-string-药品id,status-string-结算状态 0待结算 1已结算 2已取消,money-string-分佣金额,time-string-时间} 平台/诊所是否结算管理
|
|
|
|
|
|
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionJiesuanList()
|
|
|
|
|
|
{
|
|
|
|
|
|
$get = \Yii::$app->request->get();
|
|
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
|
|
|
|
$order_no=$get['order_no'];
|
|
|
|
|
|
$register_no=$get['register_no'];
|
|
|
|
|
|
$start_time=strtotime($get['start_time']);
|
|
|
|
|
|
$end_time=strtotime($get['end_time']);
|
|
|
|
|
|
|
|
|
|
|
|
$query = Ledger::find()->alias('l')->where(['l.status'=>[0,1]])->orderBy(['l.id' => SORT_DESC]);
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($order_no)){
|
|
|
|
|
|
$query->joinWith(['productOrder'=>function($p)use($order_no){
|
|
|
|
|
|
$p->where(['order_no'=>$order_no]);
|
|
|
|
|
|
}]);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!empty($register_no)){
|
|
|
|
|
|
$query->joinWith(['register'=>function($p)use($register_no){
|
|
|
|
|
|
$p->where(['order_no'=>$register_no]);
|
|
|
|
|
|
}]);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!empty($start_time) && !empty($end_time)){
|
|
|
|
|
|
if ($start_time==$end_time){//筛选某一天
|
|
|
|
|
|
$time=FuncHelper::getDayBE($get['start_time']);
|
|
|
|
|
|
|
|
|
|
|
|
$end_time=$time[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
$query->andWhere(['between','l.created_at',$start_time,$end_time]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($user->role==UserRoleEnum::SUPER_ADMIN){//平台
|
|
|
|
|
|
$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');
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->field = [
|
|
|
|
|
|
Ledger::class => [
|
|
|
|
|
|
'id', 'user_id','order_id', 'user_type','su_id', 'drugstore_id', 'drug_id', 'status', 'money'=> function ($m) {
|
|
|
|
|
|
return $this->actionTotal($m->order_id,$m->user_type,$m->order_type);
|
|
|
|
|
|
},
|
|
|
|
|
|
'order_no'=> function ($order) {
|
|
|
|
|
|
if ($order->order_type == 1) {
|
|
|
|
|
|
return ProductOrder::find()->select(['order_no'])->where(['id' => $order->order_id])->column();
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($order->order_type == 2) {
|
|
|
|
|
|
return Register::find()->select(['order_no'])->where(['id' => $order->order_id])->column();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'type'=>function($l){
|
|
|
|
|
|
if ($l->order_type==1){
|
|
|
|
|
|
return '产品订单';
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return '挂号订单';
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'fee_type'=>function($f){
|
|
|
|
|
|
if ($f->fee_type==1){
|
|
|
|
|
|
return '药品费用';
|
|
|
|
|
|
}elseif($f->fee_type==2){
|
|
|
|
|
|
return '挂号费用';
|
|
|
|
|
|
}elseif($f->fee_type==3){
|
|
|
|
|
|
return '快递费用';
|
|
|
|
|
|
}elseif($f->fee_type==4){
|
|
|
|
|
|
return '代煎费用';
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return '其他';
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'price_from'=>'productOrder.user.nickname',
|
|
|
|
|
|
'time'=>function($le){
|
|
|
|
|
|
return date('Y-m-d H:i:s',$le->created_at);
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
];
|
|
|
|
|
|
return $this->create($query, $get);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function actionTotal($order_id='',$user_type=1,$order_type='')
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$money = Ledger::find()->alias('l')->where(['l.order_id' => $order_id, 'l.status' => [0, 1]])->andWhere(['l.user_type'=>$user_type,'l.order_type'=>$order_type])->sum('money');
|
|
|
|
|
|
return $money ?? 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|