第一次成功创建任务模板,初始化公司的提现截止时间
This commit is contained in:
parent
e6abc74302
commit
055152f6c9
@ -20,6 +20,7 @@ use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\task_template\TaskTemplateLists;
|
||||
use app\common\logic\task_template\TaskTemplateLogic;
|
||||
use app\adminapi\validate\task_template\TaskTemplateValidate;
|
||||
use app\common\model\Company;
|
||||
|
||||
|
||||
/**
|
||||
@ -55,6 +56,10 @@ class TaskTemplateController extends BaseAdminController
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = TaskTemplateLogic::add($params);
|
||||
if (true === $result) {
|
||||
/**
|
||||
* 如果是公司第一次创建安排任务,则初始化公司的提现周期截止时间
|
||||
*/
|
||||
TaskTemplateLogic::initCompanyWithdrawDeadline($params['company_id']);
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(TaskTemplateLogic::getError());
|
||||
|
@ -88,18 +88,6 @@ class TaskTemplateLogic extends BaseLogic
|
||||
$params['extend']=['shareholder'=>['user_id'=>$params['task_admin']]];
|
||||
}
|
||||
|
||||
// 如果是公司第一次创建安排任务,初始化公司的可提现周期
|
||||
$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();
|
||||
}
|
||||
|
||||
TaskTemplate::create([
|
||||
'title' => $params['title'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
@ -232,4 +220,86 @@ class TaskTemplateLogic extends BaseLogic
|
||||
{
|
||||
return TaskTemplate::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
public static function initCompanyWithdrawDeadline($params)
|
||||
{
|
||||
// 如果是公司第一次创建安排任务,初始化公司的可提现周期截止时间
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加任务模板
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2023/08/06 17:30
|
||||
*/
|
||||
public static function addTownTaskTemplate(array $params): bool
|
||||
{
|
||||
try {
|
||||
Db::startTrans();
|
||||
|
||||
$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('已经有同一种任务类型了');
|
||||
return false;
|
||||
}
|
||||
|
||||
$moeny = TaskTemplate::where('company_id', $params['company_id'])->sum('money');
|
||||
if($moeny + $params['money'] > 200){
|
||||
self::setError('任务模板一阶段合计金额不能大于任务调度金额');
|
||||
return false;
|
||||
}
|
||||
$moneyTwo = TaskTemplate::where('company_id', $params['company_id'])->sum('money_two');
|
||||
if($moneyTwo + $params['money_two'] > 200){
|
||||
self::setError('任务模板二阶段合计金额不能大于任务调度金额');
|
||||
return false;
|
||||
}
|
||||
$newMoneyThree = TaskTemplate::where('company_id', $params['company_id'])->sum('new_money_three');
|
||||
if($newMoneyThree + $params['new_money_three'] > 200){
|
||||
self::setError('任务模板三阶段合计金额不能大于任务调度金额');
|
||||
return false;
|
||||
}
|
||||
$moneyThree = TaskTemplate::where('company_id', $params['company_id'])->sum('money_three');
|
||||
if($moneyThree + $params['money_three']>200){
|
||||
self::setError('任务模板长期合计金额不能大于任务调度金额');
|
||||
return false;
|
||||
}
|
||||
|
||||
TaskTemplate::create([
|
||||
'title' => $params['title'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'company_id' => $params['company_id'],
|
||||
'task_scheduling' => $params['task_scheduling']??0,
|
||||
'money' => $params['money'],
|
||||
'money_two' => $params['money_two'],
|
||||
'money_three' => $params['money_three'],
|
||||
'type' => $params['type'],
|
||||
'types' => $params['types'],
|
||||
'status' => $params['status'],
|
||||
'content' => $params['content'],
|
||||
'extend'=>json_encode($params['extend']),
|
||||
'stage_day_one' => $params['stage_day_one']??0,
|
||||
'proportion_one' => $params['proportion_one']??0,
|
||||
'stage_day_two' => $params['stage_day_two']??0,
|
||||
'proportion_two' => $params['proportion_two']??0,
|
||||
'recharge' => $params['recharge']??0,
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user