From 62fbc3b995d6cc62ec8598ca8fd497b054eb6d23 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Sat, 16 Sep 2023 17:45:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=8F=90=E7=8E=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=9A1.=E5=85=AC=E5=8F=B8=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8F=90=E7=8E=B0=E6=88=AA=E6=AD=A2=E6=97=A5=E6=9C=9F=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=8C=E5=85=AC=E5=8F=B8=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E4=BB=BB=E5=8A=A1=E6=97=B6=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8=E8=AE=BE=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=8E=B0=E5=91=A8=E6=9C=9F=EF=BC=8C=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=92=8C=E5=88=9D=E5=A7=8B=E5=8C=96=E5=85=AC=E5=8F=B8=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=8E=B0=E6=88=AA=E6=AD=A2=E6=97=A5=E6=9C=9F=E3=80=82?= =?UTF-8?q?2.=E7=94=B3=E8=AF=B7=E6=8F=90=E7=8E=B0=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8F=91=E7=A5=A83.=E6=8F=90=E7=8E=B0?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E9=80=9A=E8=BF=87=E5=90=8E=EF=BC=8C=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=E5=85=AC=E5=8F=B8=E4=B8=8B=E4=B8=80=E6=AC=A1=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=8E=B0=E6=88=AA=E6=AD=A2=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/adminapi/lists/finance/WithdrawLists.php | 40 ++++++++++--------- app/adminapi/logic/ConfigLogic.php | 30 ++++++++++++++ app/api/controller/UserController.php | 15 ++++--- app/api/logic/UserLogic.php | 6 +++ app/common/logic/finance/WithdrawLogic.php | 10 +++++ .../logic/task_template/TaskTemplateLogic.php | 16 +++++++- 6 files changed, 91 insertions(+), 26 deletions(-) diff --git a/app/adminapi/lists/finance/WithdrawLists.php b/app/adminapi/lists/finance/WithdrawLists.php index 99eb6822b..cf46b1706 100644 --- a/app/adminapi/lists/finance/WithdrawLists.php +++ b/app/adminapi/lists/finance/WithdrawLists.php @@ -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; } diff --git a/app/adminapi/logic/ConfigLogic.php b/app/adminapi/logic/ConfigLogic.php index 73330fe54..e507c8e96 100755 --- a/app/adminapi/logic/ConfigLogic.php +++ b/app/adminapi/logic/ConfigLogic.php @@ -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; + } + } \ No newline at end of file diff --git a/app/api/controller/UserController.php b/app/api/controller/UserController.php index 6ff4ceeec..9e35902a3 100755 --- a/app/api/controller/UserController.php +++ b/app/api/controller/UserController.php @@ -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() { diff --git a/app/api/logic/UserLogic.php b/app/api/logic/UserLogic.php index 729e3e143..87b827a91 100755 --- a/app/api/logic/UserLogic.php +++ b/app/api/logic/UserLogic.php @@ -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(); diff --git a/app/common/logic/finance/WithdrawLogic.php b/app/common/logic/finance/WithdrawLogic.php index 8694bd508..b94dbc4a8 100644 --- a/app/common/logic/finance/WithdrawLogic.php +++ b/app/common/logic/finance/WithdrawLogic.php @@ -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) { diff --git a/app/common/logic/task_template/TaskTemplateLogic.php b/app/common/logic/task_template/TaskTemplateLogic.php index d38013983..601f92854 100644 --- a/app/common/logic/task_template/TaskTemplateLogic.php +++ b/app/common/logic/task_template/TaskTemplateLogic.php @@ -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) {