update:其他任务提交时创建审批

This commit is contained in:
chenbo 2023-09-15 13:37:15 +08:00
parent f60346260c
commit 7e54616332
3 changed files with 55 additions and 9 deletions

View File

@ -3,13 +3,17 @@
namespace app\api\controller;
use app\common\logic\task\TaskLogic;
use app\common\model\Approve;
use app\common\model\Company;
use app\common\model\company\CompanyProperty;
use app\common\model\flow\Flow;
use app\common\model\informationg\UserInformationg;
use app\common\model\task\Task;
use app\common\model\task_template\TaskTemplate;
use app\common\model\user\User;
use think\facade\Log;
use think\Exception;
use think\facade\Db;
class TaskController extends BaseApiController
{
@ -217,14 +221,45 @@ class TaskController extends BaseApiController
*/
public function cimmit_other_task()
{
$parmas = $this->request->param(); //id note annex
$task = TaskLogic::detail($parmas);
if (empty($task)) {
$this->fail('任务不存在');
try {
$parmas = $this->request->param(); //id note annex
$task = TaskLogic::detail($parmas);
if (empty($task)) {
$this->fail('任务不存在');
}
$extend = ['other' => ['is_commit' => 1, 'note' => $parmas['note'], 'annex'=>$parmas['annex']]];
Db::startTrans();
Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend)]);
// 片区经理
$areaManagerId = User::where(['id' => $this->userId])->with('company')->value('area_manager');
// 创建审批任务
$approveModel = new Approve();
$approveModel->type = 1;
$approveModel->flow_id = 1;
$approveModel->name = $task['title'];
$approveModel->type = 1;
$approveModel->admin_id = 0; // 后台发起人id 暂时为0
$approveModel->user_id = $this->userId; // 前台发起人用户id
$approveModel->task_id = $task['id']; // 前台发起人用户id
$approveModel->check_admin_id = $areaManagerId; // 前审批人ID 片区经理的admin_id
$approveModel->check_status = 1; // 状态 0待审核,1审核中,2审核通过,3审核不通过,4撤销审核
$approveModel->last_admin_id = $areaManagerId;
$approveModel->other_type = 6;
$approveModel->create_time = time();
$approveModel->update_time = time();
$approveModel->save();
if ($approveModel->id) {
Db::commit();
}
return $this->success('ok', []);
} catch (Exception $e) {
Db::rollback();
return $this->fail($e->getMessage());
}
$extend = ['other' => ['is_commit' => 1, 'note' => $parmas['note'], 'annex'=>$parmas['annex']]];
Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend)]);
return $this->success('ok', []);
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace app\common\model;
use think\model\concern\SoftDelete;
class Approve extends BaseModel
{
use SoftDelete;
protected $name = 'approve';
}

View File

@ -182,7 +182,7 @@ class User extends BaseModel
public function company()
{
return $this->hasOne(Company::class, 'id', 'company_id')->field(['id','company_name','admin_id','company_type','responsible_area']);
return $this->hasOne(Company::class, 'id', 'company_id')->field(['id','company_name','admin_id','company_type','responsible_area', 'area_manager']);
}
public function getProvinceNameAttr($value)
{