WokerTask/app/middleapi/controller/ApproveController.php

200 lines
7.8 KiB
PHP
Raw Normal View History

2023-12-27 14:06:33 +08:00
<?php
namespace app\middleapi\controller;
use app\adminapi\lists\approve\ApproveLists;
use app\common\logic\task\TaskLogic;
use app\common\model\Approve;
use app\common\model\task\Task;
use app\common\model\auth\Admin;
use app\common\model\Company;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate;
use think\facade\Db;
use app\common\controller\BaseLikeAdminController;
class ApproveController extends BaseLikeAdminController
{
public function lists()
{
if(!$this->request->isPost()){
return $this->fail('请求方式错误');
}
$params=$this->request->post(['page_no','page_size','type','check_status']);
$where = [];
if (isset($params['check_status']) && $params['check_status'] != '') {
$where[] = ['check_status', '=', $params['check_status']];
}
if (isset($params['type']) && $params['type'] != '') {
$where[] = ['type', 'in', $params['type']];
}
$pageNo = !empty($params['page_no']) ? $params['page_no'] : 1;
$pageSize = !empty($params['page_size']) ? $params['page_size'] : 20;
$data = Approve::where($where)
->with('task')
->field('*')
->append(['area_manager', 'company_name'], true)
->page($pageNo, $pageSize)
->order(['id' => 'desc'])
->select()
->withAttr('area_manager',function($value,$data){
return Admin::where(['id' => $data['check_admin_ids']])->value('name');
})
->withAttr('company_name',function($value,$data){
$task = Task::where('id', $data['task_id'])->find();
return Company::where(['id' => $task['company_id'] ?? 0])->value('company_name');
})
->toArray();
$count = Approve::where($where)->count();
$result = [
'lists' => $data,
'count' => $count,
'page_no' => $pageNo,
'page_size' => $pageSize
];
return $this->success('请求成功',$result);
}
public function audit()
{
try {
$params = $this->request->param();
if(empty($params['id'])){
return $this->fail('缺少必要参数id');
}
if(empty($params['check_status'])){
return $this->fail('缺少必要参数审核状态');
}
$approve = Approve::find($params['id']);
if (!$approve) {
$this->fail('数据不存在');
}
Db::startTrans();
// 拒绝通过 要让用户今天可以继续做任务
if ($params['check_status'] == 3) {
$this->refuse($params, $approve);
}
// 修改任务完成状态
if ($params['check_status'] == 2) {
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);
}
}
Db::commit();
return $this->success('审核成功');
} catch (\Exception $e) {
Db::rollback();
return $this->fail($e->getFile().$e->getLine().$e->getMessage());
}
}
// 通过
private function pass($approve, $params=[])
{
$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();
}
// 镇农科公司任务-数字农贸宣传业务、加工业务的建设和招商工作任务 结算
if ($approve->type == Approve::APPROVE_TYPE_4) {
$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', 41)
->find()
->toArray();
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();
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);
}
if ($approve->type == Approve::APPROVE_TYPE_7) {
// 需要手动输入销售总额
$approve->amount = $params['amount'];
$approve->save();
}
if ($approve->type == Approve::APPROVE_TYPE_8) {
// 需要手动输入申请的政策补贴金额
$approve->amount = $params['amount'];
$approve->save();
}
if ($approve->type == Approve::APPROVE_TYPE_9) {
$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::masterTask8Settlement($taskSchedulePlan);
}
}
// 拒绝
private function refuse($params, $approve)
{
$approve->check_status = $params['check_status'];
$approve->remark = $params['remark'];
$approve->update_time = time();
$approve->save();
// 更新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
]);
}
}