Duplicate.php 6.6 KB
<?php

namespace app\school\controller\project_approval;

use app\common\controller\DoubleBase;
use app\school\model\project_common\ProjectRegister;
use think\Db;
use think\Exception;

class Duplicate extends DoubleBase
{
    protected $containerId = null;
    protected $model = null;

    protected $shopIdAutoCondition = false;

    public function _initialize()
    {
        parent::_initialize();
        $this->containerId = $_COOKIE['container_id'];
        $this->model = new ProjectRegister();
    }

    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $matchInfo = Db::name('project_container')->where(['id' => $this->containerId])->find();

            $rate = $matchInfo['checkagain'] == 1 ? $matchInfo['checkagain_scale'] : 100;

            // 默认查询项目容器下未淘汰(|未退回)的项目
            $field = [
                'a.*',
                't.name as project_type_name',
                'u.nickname',
                'u.student_no',
                'c.college_name as college_name',
                'd.specialty_name as major_name',
//            'SUM(r.result) as sum',
                'count(member_id) as memberCount'
            ];
            $total = $this->model
                ->field('a.id')
                ->alias('a')
                ->join('user u', 'a.user_id = u.id', 'left')
                ->join('project_type t', 'a.project_type = t.id', 'left')
                ->join('college c', 'u.college = c.id', 'left')
                ->join('specialty d', 'u.specialty = d.id', 'left')
                ->where(['a.container_id' => $this->containerId,'review_stage' => 0])
                ->where('a.repeat_rate','neq',$rate)
                ->count();
            $list = $this->model
                ->field($field)
                ->alias('a')
                ->join('user u', 'a.user_id = u.id', 'left')
                ->join('project_type t', 'a.project_type = t.id', 'left')
                ->join('college c', 'u.college = c.id', 'left')
                ->join('fa_members m','a.id = m.item_id and member_type = 1 and member_source = 2','left')
                ->join('specialty d', 'u.specialty = d.id', 'left')
                ->where(['a.container_id' => $this->containerId,'review_stage' => 0])
                ->where('a.repeat_rate','neq',$rate)
                ->group('a.id')
                ->limit($offset, $limit)
                ->select();
            foreach ($list as &$row) {
                $row['project_teachers'] = json_decode($row['project_teachers'], true);
                $row['repeat_rate'] = $row['repeat_rate'].'%';
                if($row['project_status'] != 0) {
                    switch ($row['project_status'])
                    {
                        case 1:
                            $row['status'] = '已淘汰';
                            break;
                        case 2:
                            $row['status'] = '已驳回';
                            break;
                        default:
                            $row['status'] = '已延期';
                    }
                }else {
                    switch ($row['project_approval_status'])
                    {
                        case 0:
                            $row['status'] = '教师未审核';
                            break;
                        case 1:
                            $row['status'] = '学院未审核';
                            break;
                        case 2:
                            $row['status'] = '学校未审核';
                            break;
                        default:
                            $row['status'] = '学校已审核';
                    }
                }


            }
            $result = [
                'total' => $total,
                'rows' => $list
            ];
            return $result;
        }
        return $this->view->fetch();
    }


    /**
     * 查重审核
     */
    public function editProject()
    {
        if ($this->request->isAjax()) {
            $list = $this->request->param('list');
            $list = json_decode($list, true);
            $user= session("school");

            $arr = [];
            foreach ($list as $val) {
                $tmp['id'] = $val['id'];
                $tmp['project_status'] = $val['project_status'];
                $arr[] = $tmp;
            }
            Db::startTrans();
            try {
                //保存审核日志
                $this->register_log($list);
                $this->model->allowField(true)->saveAll($arr);
                Db::commit();
            } catch (Exception $e) {
                Db::rollback();
                $this->error($e->getMessage());
            }
            $this->success();
        }
    }

    // 保存审核日志
    private function register_log($list){
        # 获取用户ID
        $admin_id = $this->auth->id;
        #
        if(!empty($list)) {
            $insertData = [];
            foreach ($list as $val) {
                if(isset($val['memo']) && mb_strlen($val['memo'],"UTF-8") > 200) {
                    $this->error("审核原因在200字以内");
                }
                $item = ProjectRegister::get($val['id']);
                $data['register_id']    = $item['id'];
                $data['container_id']   = $item['container_id'];
                $data['project_college'] = $item['project_college'];
                $data['project_name']   = $item['project_name'];
                $data['verify_stage']   = $val['verify_stage'];
                $data['memo']           = isset($val['memo']) ? $val['memo'] : '';
                $data['school_id']      = $this->auth->school_id;
                $data['teacher_id']     = $admin_id;
                $data['teacher_name']     = $this->auth->nickname;
                if($item['review_stage'] == 0) {
                    switch ($item['project_approval_status'])
                    {
                        case 1:
                            $data['type']  = 'collage';
                            break;
                        default:
                            $data['type']  = 'school';
                    }
                }
                $data['operation'] = '驳回';
                $data['created_time'] = date('Y-m-d H:i:s',time());
                $insertData[] = $data;
            }
            if(!empty($insertData)) {
                db('register_log')->insertAll($insertData);
            }
        }
    }

}