256 lines
9.2 KiB
PHP
Executable File
256 lines
9.2 KiB
PHP
Executable File
<?php
|
|
namespace app\adminapi\logic\finance;
|
|
use app\common\enum\accountLog\CoachAccountLogEnum;
|
|
use app\common\enum\accountLog\ShopAccountLogEnum;
|
|
use app\common\logic\CoachAccountLogLogic;
|
|
use app\common\logic\ShopAccountLogLogic;
|
|
use app\common\model\coach\Coach;
|
|
use app\common\model\shop\Shop;
|
|
use app\common\model\withdraw\WithdrawApply;
|
|
use Exception;
|
|
use think\facade\Db;
|
|
|
|
class WithdrawLogic
|
|
{
|
|
|
|
/**
|
|
* @notes 详情
|
|
* @param $id
|
|
* @return WithdrawApply|array|\think\Model
|
|
* @author cjhao
|
|
* @date 2024/10/31 16:22
|
|
*/
|
|
public function detail($id)
|
|
{
|
|
$detail = WithdrawApply::where(['id'=>$id])->append(['apply_type_desc'])->findOrEmpty();
|
|
if(1 == $detail['source']){
|
|
$detail['relation_info'] = Coach::where(['id'=>$detail['relation_id']])->field('id,name,sn,work_photo as image,mobile')->findOrEmpty()->toArray();
|
|
}else {
|
|
$detail['relation_info'] = Shop::where(['id' => $detail['relation_id']])->field('id,name,sn,logo as image,mobile')->findOrEmpty()->toArray();
|
|
}
|
|
return $detail->toArray();
|
|
}
|
|
|
|
/**
|
|
* @notes 审核
|
|
* @param $params
|
|
* @return string|true
|
|
* @author cjhao
|
|
* @date 2024/10/31 17:44
|
|
*/
|
|
public function audit($params)
|
|
{
|
|
try {
|
|
Db::startTrans();
|
|
$id = $params['id'] ?? '';
|
|
$status = $params['status'] ?? '';
|
|
$remark = $params['remark'] ?? '';
|
|
if(empty($id)){
|
|
throw new Exception('请选择提现记录');
|
|
}
|
|
if('' == $status){
|
|
throw new Exception('请选择审核操作');
|
|
}
|
|
if(empty($remark) && 0 == $status){
|
|
throw new Exception('请输入备注');
|
|
}
|
|
$apply = WithdrawApply::where(['id'=>$id])->findOrEmpty();
|
|
if(1 != $apply->status){
|
|
throw new Exception('记录状态已改变');
|
|
}
|
|
$auditStatus = 2;
|
|
if(0 == $status){
|
|
$auditStatus = 3;
|
|
}
|
|
|
|
$apply->status = $auditStatus;
|
|
$apply->verify_remark = $remark;
|
|
$apply->save();
|
|
//拒绝,退回余额
|
|
if(0 == $status){
|
|
|
|
//申请类型
|
|
if(1 == $apply['apply_type']){
|
|
//类型
|
|
if( 1 == $apply['source']){
|
|
$relation = Coach::where(['id'=>$apply['relation_id']])->findOrEmpty();
|
|
//余额
|
|
$relation->money = round($relation->money+$apply['money']);
|
|
$relation->save();
|
|
CoachAccountLogLogic::add(
|
|
$relation->id,
|
|
CoachAccountLogEnum::MONEY,
|
|
CoachAccountLogEnum::WITHDRAW_INC_MONEY,
|
|
1,
|
|
$apply['money'],
|
|
$apply['sn']
|
|
);
|
|
|
|
}else{
|
|
$relation = shop::where(['id'=> $apply['relation_id']])->findOrEmpty();
|
|
//余额
|
|
$relation->money = round($relation->money+$apply['money']);
|
|
$relation->save();
|
|
ShopAccountLogLogic::add(
|
|
$relation->id,
|
|
ShopAccountLogEnum::MONEY,
|
|
ShopAccountLogEnum::WITHDRAW_INC_MONEY,
|
|
1,
|
|
$apply['money'],
|
|
$apply['sn']
|
|
|
|
);
|
|
}
|
|
|
|
}else{
|
|
if( 1 == $apply['source']){
|
|
$relation = coach::where(['id'=> $apply['relation_id']])->findOrEmpty();
|
|
//余额
|
|
$relation->deposit = round($relation->deposit+$apply['money']);
|
|
$relation->save();
|
|
CoachAccountLogLogic::add(
|
|
$relation->id,
|
|
CoachAccountLogEnum::DEPOSIT,
|
|
CoachAccountLogEnum::WITHDRAW_INC_DEPOSIT,
|
|
1,
|
|
$apply['money'],
|
|
$apply['sn']
|
|
|
|
);
|
|
}else{
|
|
$relation = shop::where(['id'=> $apply['relation_id']])->findOrEmpty();
|
|
//余额
|
|
$relation->deposit = round($relation->deposit+$apply['money']);
|
|
$relation->save();
|
|
ShopAccountLogLogic::add(
|
|
$relation->id,
|
|
ShopAccountLogEnum::DEPOSIT,
|
|
ShopAccountLogEnum::WITHDRAW_INC_DEPOSIT,
|
|
1,
|
|
$apply['money'],
|
|
$apply['sn']
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|
|
Db::commit();
|
|
return true;
|
|
}catch (Exception $e){
|
|
Db::rollback();
|
|
return $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @notes 转账
|
|
* @param $params
|
|
* @return string|true
|
|
* @author cjhao
|
|
* @date 2024/10/31 18:13
|
|
*/
|
|
public function transfer($params)
|
|
{
|
|
|
|
try {
|
|
Db::startTrans();
|
|
$id = $params['id'] ?? '';
|
|
$status = $params['status'] ?? '';
|
|
$remark = $params['remark'] ?? '';
|
|
$transferProof = $params['transfer_proof'] ?? '';
|
|
if(empty($id)){
|
|
throw new Exception('请选择提现记录');
|
|
}
|
|
if('' == $status){
|
|
throw new Exception('请选择审核操作');
|
|
}
|
|
if(empty($remark) && 0 == $status){
|
|
throw new Exception('请输入备注');
|
|
}
|
|
$auditStatus = 5;
|
|
if(1 == $status){
|
|
if(empty($transferProof)){
|
|
throw new Exception('请上传转账凭证');
|
|
}
|
|
}else{
|
|
$auditStatus = 6;
|
|
}
|
|
$apply = WithdrawApply::where(['id'=>$id])->findOrEmpty();
|
|
$apply->status = $auditStatus;
|
|
$apply->verify_remark = $remark;
|
|
$apply->transfer_proof = $transferProof;
|
|
$apply->save();
|
|
//拒绝,退回余额
|
|
if(0 == $status){
|
|
|
|
//申请类型
|
|
if(1 == $apply['apply_type']){
|
|
//类型
|
|
if( 1 == $apply['source']){
|
|
$relation = Coach::where(['id'=>$apply['relation_id']])->findOrEmpty();
|
|
//余额
|
|
$relation->money = round($relation->money+$apply['money']);
|
|
$relation->save();
|
|
CoachAccountLogLogic::add(
|
|
$relation->id,
|
|
CoachAccountLogEnum::MONEY,
|
|
CoachAccountLogEnum::WITHDRAW_INC_MONEY,
|
|
1,
|
|
$apply['money'],
|
|
);
|
|
|
|
}else{
|
|
$relation = shop::where(['id'=> $apply['relation_id']])->findOrEmpty();
|
|
//余额
|
|
$relation->money = round($relation->money+$apply['money']);
|
|
$relation->save();
|
|
ShopAccountLogLogic::add(
|
|
$relation->id,
|
|
ShopAccountLogEnum::MONEY,
|
|
ShopAccountLogEnum::WITHDRAW_INC_MONEY,
|
|
1,
|
|
$apply['money'],
|
|
);
|
|
}
|
|
|
|
}else{
|
|
if( 1 == $apply['source']){
|
|
$relation = coach::where(['id'=>$apply['relation_id']])->findOrEmpty();
|
|
//余额
|
|
$relation->deposit = round($relation->deposit+$apply['money']);
|
|
$relation->save();
|
|
CoachAccountLogLogic::add(
|
|
$relation->id,
|
|
CoachAccountLogEnum::DEPOSIT,
|
|
CoachAccountLogEnum::WITHDRAW_INC_DEPOSIT,
|
|
1,
|
|
$apply['money'],
|
|
);
|
|
}else{
|
|
$relation = shop::where(['id'=> $apply['relation_id']])->findOrEmpty();
|
|
//余额
|
|
$relation->deposit = round($relation->deposit+$apply['money']);
|
|
$relation->save();
|
|
ShopAccountLogLogic::add(
|
|
$relation->id,
|
|
ShopAccountLogEnum::DEPOSIT,
|
|
ShopAccountLogEnum::WITHDRAW_INC_DEPOSIT,
|
|
1,
|
|
$apply['money'],
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|
|
Db::commit();
|
|
return true;
|
|
}catch (Exception $e){
|
|
Db::rollback();
|
|
return $e->getMessage();
|
|
|
|
}
|
|
}
|
|
|
|
} |