TaskSystem/app/adminapi/controller/approve/ApproveController.php

149 lines
5.5 KiB
PHP
Raw Normal View History

<?php
namespace app\adminapi\controller\approve;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\approve\ApproveLists;
2023-10-18 15:49:14 +08:00
use app\common\logic\task\TaskLogic;
2023-09-15 19:04:45 +08:00
use app\common\model\Approve;
use app\common\model\task\Task;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
2023-10-26 13:45:27 +08:00
use app\common\model\task_template\TaskTemplate;
2023-09-15 19:04:45 +08:00
use think\facade\Db;
class ApproveController extends BaseAdminController
{
public function lists()
{
return $this->dataLists(new ApproveLists());
}
2023-09-15 19:04:45 +08:00
2023-10-26 13:45:27 +08:00
public function lists2()
{
return $this->success('成功',(new ApproveLists())->lists2());
}
2023-09-15 19:04:45 +08:00
public function audit()
{
try {
$params = $this->request->param(); // id check_status remark
$approve = Approve::find($params['id']);
if (!$approve) {
$this->fail('数据不存在');
}
2023-10-26 13:45:27 +08:00
2023-09-15 19:04:45 +08:00
Db::startTrans();
// 拒绝通过 要让用户今天可以继续做任务
2023-09-15 19:04:45 +08:00
if ($params['check_status'] == 3) {
$this->refuse($params, $approve);
2023-09-15 19:04:45 +08:00
}
// 修改任务完成状态
if ($params['check_status'] == 2) {
2023-10-26 13:45:27 +08:00
if ($approve->type == Approve::APPROVE_TYPE_7) {
$taskTemplate = TaskTemplate::where(['id'=>$approve->business_id])->find();
// 提前完成
if ($taskTemplate['day_count'] < $taskTemplate['stage_day_one']) {
if (bccomp($params['amount'], 300000, 2) == -1) {
$this->fail('该任务提前完成条件销售总额必须达到30万元及以上');
} else {
// 提前完成标识
$extend = json_decode($taskTemplate['extend'], true);
$extend['early_finish'] = 1;
$taskTemplate->extend = json_encode($extend);
$taskTemplate->save();
$this->pass($approve, $params);
}
} else {
$this->pass($approve, $params);
}
} else {
$this->pass($approve);
}
2023-09-15 19:04:45 +08:00
}
Db::commit();
return $this->success('审核成功');
} catch (\Exception $e) {
Db::rollback();
return $this->fail($e->getFile().$e->getLine().$e->getMessage());
2023-09-15 19:04:45 +08:00
}
}
// 通过
2023-10-26 13:45:27 +08:00
private function pass($approve, $params=[])
{
2023-10-18 15:49:14 +08:00
Db::startTrans();
$approve->check_status = 2;
$approve->update_time = time();
$approve->save();
// 任务
$task = Task::find($approve['task_id']);
if ($task['status'] == 2) {
$task->status = 3;
$task->save();
}
2023-10-18 15:49:14 +08:00
Db::commit();
// 镇农科公司任务-数字农贸宣传业务、加工业务的建设和招商工作任务 结算
2023-10-18 15:49:14 +08:00
if ($approve->type == Approve::APPROVE_TYPE_4) {
$taskSchedulePlan = TaskSchedulingPlan::where('la_task_scheduling_plan.id', $task['scheduling_plan_id'])
2023-10-18 15:49:14 +08:00
->where('is_pay',0)
->with(['template_info'])
->withJoin(['scheduling'], 'left')
->where('scheduling.company_type', 41)
->find()
->toArray();
2023-10-18 15:49:14 +08:00
TaskLogic::dealTaskMarketingDirector10($taskSchedulePlan, $approve);
}
if ($approve->type == Approve::APPROVE_TYPE_5) {
$taskSchedulePlan = TaskSchedulingPlan::where('la_task_scheduling_plan.id', $task['scheduling_plan_id'])
->where('is_pay',0)
->with(['template_info'])
->withJoin(['scheduling'], 'left')
->where('scheduling.company_type', 17)
->find()
->toArray();
2023-10-26 13:45:27 +08:00
TaskLogic::dealVillageTask6($taskSchedulePlan);
}
if ($approve->type == Approve::APPROVE_TYPE_6) {
$taskSchedulePlan = TaskSchedulingPlan::where('la_task_scheduling_plan.id', $task['scheduling_plan_id'])
->where('is_pay',0)
->with(['template_info'])
->withJoin(['scheduling'], 'left')
->where('scheduling.company_type', 17)
->find()
->toArray();
TaskLogic::dealVillageTask8($taskSchedulePlan);
}
2023-10-26 13:45:27 +08:00
if ($approve->type == Approve::APPROVE_TYPE_7) {
// 需要手动输入销售总额
$approve->amount = $params['amount'];
$approve->save();
}
}
2023-09-15 19:04:45 +08:00
// 拒绝
private function refuse($params, $approve)
{
$approve->check_status = $params['check_status'];
$approve->remark = $params['remark'];
$approve->update_time = time();
$approve->save();
2023-09-15 19:04:45 +08:00
// 更新schedule_plan时间和task的时间为今天依旧可提交
$schedulePlan = TaskSchedulingPlan::find(['tast_id' => $approve['task_id']]);
if (empty($schedule_plan)) {
return $this->fail('数据异常,任务计划不存在');
}
$time = strtotime(date('Y-m-d'));
TaskSchedulingPlan::where(['id' => $schedulePlan['id']])->update([
'start_time'=>$time,
'end_time'=>$time + 86399
]);
Task::where('id', $approve['task_id'])->update([
'start_time'=>$time,
'end_time'=>$time + 86399
]);
2023-09-15 19:04:45 +08:00
}
}