完善提现功能:1.公司新增提现截止日期字段,公司第一次发布任务时根据数据字典设置的提现周期,计算和初始化公司的提现截止日期。2.申请提现新增上传发票3.提现审核通过后,重置公司下一次的提现截止日期

This commit is contained in:
chenbo 2023-09-16 17:45:46 +08:00
parent 34a6a60b97
commit 62fbc3b995
6 changed files with 91 additions and 26 deletions

View File

@ -47,30 +47,34 @@ class WithdrawLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array
{
$lists = Withdraw::where($this->searchWhere)
->append(['s_date', 'e_date', 'company_name'], true)
->with('user')
->where($this->queryWhere())
->withAttr('company_name', function ($value, $data) {
$company = Company::where(['admin_id'=>$data['admin_id']])->find();
return $company['company_name'];
})
->withAttr('s_date', function ($value, $data) {
$withdrawedCount = Withdraw::where(['user_id'=>$data['user_id'], 'status'=>3])->count();
$company = Company::where(['admin_id'=>$data['admin_id']])->find();
// 开始时间 如果用户第一次提现申请,则以该公司内用户 周期内第一条数据的生成时间为开始时间
if ($withdrawedCount == 0) {
$firstUserLog = UserAccountLog::where(['company_id'=>$company['id']])->order('id', 'asc')->find();
return $firstUserLog['create_time'];
} else {
// 如果用户已成功申请过提现,则以上次提现的截止日期为开始时间
$withdrawedCount = Withdraw::where(['user_id'=>$data['user_id'], 'status'=>3])->order('id', 'desc')->find();
return $withdrawedCount['transfer_end_cycel'];
}
})
->withAttr('e_date', function ($value, $data) {
// 结束时间
return date('Y-m-d H:i:s', $data['transfer_end_cycel']);
})
->order('id', 'desc')
->limit($this->limitOffset, $this->limitLength)
->select()
->toArray();
// 组装审核时直接跳转到余额明细列表的 开始和结束时间
foreach ($lists as &$item) {
$withdrawedCount = Withdraw::where(['user_id'=>$item['user_id'], 'status'=>3])->count();
$company = Company::where(['admin_id'=>$item['admin_id']])->find();
$item['company_name'] = $company['company_name'];
// 开始时间 如果用户第一次提现申请,则以该公司内用户 周期内第一条数据的生成时间为开始时间
if ($withdrawedCount == 0) {
$firstUserLog = UserAccountLog::where(['company_id'=>$company['id']])->order('id', 'asc')->find();
$item['s_date'] = $firstUserLog['create_time'];
} else {
// 如果用户已成功申请过提现,则以上次提现的截止日期为开始时间
$withdrawedCount = Withdraw::where(['user_id'=>$item['user_id'], 'status'=>3])->order('id', 'desc')->find();
$item['s_date'] = $withdrawedCount['transfer_end_cycel'];
}
// 结束时间
$item['e_date'] = date('Y-m-d H:i:s', $item['transfer_end_cycel']);
}
unset($item);
return $lists;
}

View File

@ -99,6 +99,36 @@ class ConfigLogic
return $result;
}
/**
* @notes 根据类型获取字典类型
* @param $type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/27 19:09
*/
public static function getDictTypeValueByType($type)
{
if (!is_string($type)) {
return [];
}
$type = explode(',', $type);
$lists = DictData::whereIn('type_value', $type)->select()->toArray();
if (empty($lists)) {
return [];
}
$result = [];
foreach ($lists as $dict) {
$result[$dict['name']] = $dict;
}
return $result;
}
}

View File

@ -21,10 +21,12 @@ use app\api\validate\PasswordValidate;
use app\api\validate\SetUserInfoValidate;
use app\api\validate\UserValidate;
use app\common\logic\contract\ContractLogic;
use app\common\model\Company;
use app\common\model\contract\Contract;
use app\common\model\dict\DictData;
use app\common\model\user\User;
use app\common\model\user\UserAccountLog;
use app\common\model\user\Withdraw;
use Common;
use think\facade\Db;
@ -160,17 +162,18 @@ class UserController extends BaseApiController
}
/**
* 获取用户当前可提现的周期以及可提现的金额
* 获取用户当前可提现的截止时间以及可提现的金额
*/
public function getCurrCycleWithdraw()
{
$userInfo = User::find(['id' => $this->userId]);
// 数据字典 提现周期 单位:天数
$dictData = ConfigLogic::getDictByType('withdraw_cycle');
$endCycle = strtotime(date('Y-m-d', strtotime("-{$dictData['withdraw_cycle'][0]['value']} day")));
$company = Company::find(['id' => $userInfo['company_id']]);
// 用户提现周期截止日期
$endCycle = $company['withdraw_deadline'];
$isDraw = time() >= $endCycle? 1: 0; // 当前时间大于截止时间,可提现
// 计算公司周期内所有用户已完成的 变动类型为任务收益金额增加 动作为增加的 未提现状态 的变动金额之和
$currTotalWithdrawMoney = UserAccountLog::where(['company_id'=>$userInfo['company_id'], 'action'=>1, 'status'=>1, 'is_withdraw'=>0, 'change_type'=>202])->where('create_time','<', $endCycle)->sum('change_amount');
return $this->success('成功', ['end_cycle'=>$endCycle, 'user_currrent_total_withdraw_money'=>$currTotalWithdrawMoney], 1, 1);
$currTotalWithdrawMoney = UserAccountLog::where(['company_id'=>$userInfo['company_id'], 'action'=>1, 'status'=>1, 'is_withdraw'=>0, 'change_type'=>202])->where('create_time', '<', $endCycle)->sum('change_amount');
return $this->success('成功', ['is_draw' => $isDraw,'end_cycle'=>$endCycle, 'user_currrent_total_withdraw_money'=>$currTotalWithdrawMoney], 1, 1);
}
public function withdraw()
{

View File

@ -328,6 +328,11 @@ class UserLogic extends BaseLogic
throw new ValidateException('余额不足');
}
// 发票校验
if (empty($params['invoice'])) {
throw new ValidateException('没有上传电子发票');
}
// 保存提现记录
$withdraw = new Withdraw();
$withdraw->user_id = $user['id'];
@ -335,6 +340,7 @@ class UserLogic extends BaseLogic
$withdraw->order_sn = $withdraw->buildOrderSn();
$withdraw->amount = $params['amount'];
$withdraw->transfer_end_cycel = $params['transfer_end_cycel'];
$withdraw->invoice = $params['invoice'];
$withdraw->create_time = time();
$withdraw->update_time = time();
$withdraw->save();

View File

@ -2,6 +2,7 @@
namespace app\common\logic\finance;
use app\adminapi\logic\ConfigLogic;
use app\common\enum\user\AccountLogEnum;
use app\common\logic\BaseLogic;
use app\common\model\Company;
@ -115,8 +116,17 @@ class WithdrawLogic extends BaseLogic
// 将用户周期内的账户变动记录变更为已提现状态
UserAccountLog::where(['user_id'=>$user->id, 'status'=>1, 'action'=>1, 'change_type'=>202, 'is_withdraw'=>0])->where('create_time','<', $endCycle)->update(['is_withdraw'=>1]);
}
// 重置公司可提现截止日期 上一次截止日期 + 长期周期天数
$dictData = ConfigLogic::getDictTypeValueByType('withdraw_cycle');
$cycle = $dictData['withdraw_cycle_long']['value']; // 数据字典-提现周期 单位:天数
$withdrawDeadline = $endCycle + $cycle * 24 * 60 * 60;
$companyInfo->save(['withdraw_deadline' => $withdrawDeadline]);
// 更新状态,保存转账凭证
Withdraw::where(['id'=>$withDrawInfo['id']])->update(['status'=>3, 'transfer_voucher'=>$params['transfer_voucher']]);
Db::commit();
return true;
} catch (Exception $exception) {

View File

@ -15,6 +15,8 @@
namespace app\common\logic\task_template;
use app\adminapi\logic\ConfigLogic;
use app\common\model\Company;
use app\common\model\task_template\TaskTemplate;
use app\common\logic\BaseLogic;
use app\common\model\company\CompanyProperty;
@ -41,8 +43,19 @@ class TaskTemplateLogic extends BaseLogic
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Db::startTrans();
// 如果是公司第一次创建安排任务,初始化公司的可提现周期
$templateCount = TaskTemplate::where(['company_id'=>$params['company_id']])->count();
if ($templateCount == 0) {
$dictData = ConfigLogic::getDictTypeValueByType('withdraw_cycle');
$cycle = $dictData['withdraw_cycle_1']['value']; // 数据字典-提现周期 单位:天数
$today = strtotime(date('Y-m-d'));
$withdrawDeadline = $today + $cycle * 24 * 60 * 60 + 86400;
$company = Company::find([$params['company_id']]);
$company->withdraw_deadline = $withdrawDeadline;
$company->save();
}
$find=TaskTemplate::where('task_scheduling', $params['task_scheduling'])->where('company_id',$params['company_id'])->where('type',$params['type'])->field('id,types,type')->find();
if($find&&$params['type']==$find['type']){
self::setError('已经有同一种任务类型了');
@ -103,7 +116,6 @@ class TaskTemplateLogic extends BaseLogic
'proportion_two' => $params['proportion_two']??0,
'recharge' => $params['recharge']??0,
]);
Db::commit();
return true;
} catch (\Exception $e) {