123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace app\mobile\controller;
- use app\admin\BaseController;
- use app\admin\controller\field\Field;
- use app\admin\model\Admin;
- use app\admin\model\Admin as AdminList;
- use app\admin\model\Contact;
- use app\admin\model\Contact as ContactModel;
- use app\admin\model\CostProject as CostProjectModel;
- use app\admin\model\ProjectAudit as AuditModel;
- use app\admin\model\ProjectRecord;
- use think\App;
- use think\facade\Db;
- use think\facade\Request;
- use think\facade\Session;
- use think\facade\View;
- use app\admin\model\Appropriation as AppropriationModel;
- class Contract
- {
- public function __construct(App $app)
- {
- $this->AppropriationModel = new AppropriationModel();
- $this->Field = new Field($app);
- $this->model = new \app\admin\model\Contract();
- $this->Costmodel = new CostProjectModel();
- $this->Adminmodel = new Admin();
- $this->Auditmodel = new AuditModel();
- $this->ContactModel = new ContactModel();
- $this->uid = get_login_admin('id');
- $this->unit = get_login_admin('unit_name');
- $this->user_tpe = Db::name("department")->where("id", $this->unit)->value("type");
- }
- const ZERO = 0;
- const ONE = 1;
- const TWO = 2;
- const THREE = 3;
- const FORE = 4;
- const FIVE = 5;
- const SIX = 6;
- const SEVEN = 7;
- public static $Type = [
- self::ZERO => '未设置',
- self::ONE => '普通合同',
- self::TWO => '框架合同',
- self::THREE => '补充协议',
- self::FORE => '其他合同',
- ];
- public static $Status = [
- self::ZERO => '待审核',
- self::ONE => '审核中',
- self::TWO => '审核通过',
- self::THREE => '审核拒绝',
- self::FORE => '已撤销',
- self::FIVE => '已中止',
- self::SIX => '已作废',
- self::SEVEN => '修改中',
- ];
- public static $ArchiveStatus = [
- self::ZERO => '未归档',
- self::ONE => '已归档',
- ];
- public function contract(){
- $param = get_params();
- $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
- $where = [
- ["subject_id", "=", get_login_admin("unit_name")],
- ["delete_time", "=", 0],
- ["archive_status", "=", 0]
- ];
- if (!empty($param['keywords'])) {
- $where[] = ['a.id|a.name|c.title', 'like', '%' . $param['keywords'] . '%'];
- }
- if (!empty($param['cate_id'])) {
- $where[] = ['a.cate_id', '=', $param['cate_id']];
- }
- if (!empty($param['type'])) {
- $where[] = ['a.type', '=', $param['type']];
- }
- if (isset($param['check_status']) && $param['check_status'] != '') {
- $where[] = ['a.check_status', '=', $param['check_status']];
- }
- $list = $this->model
- ->alias('a')
- ->field('a.*,a.type as type_a, c.title as cate_title')
- ->where($where)
- ->join('contract_cate c', 'a.cate_id = c.id')
- ->order('a.create_time desc')
- ->paginate($rows, false, ['query' => $param])
- ->each(function ($item) {
- $item->keeper_name = Db::name('Admin')->where(['id' => $item->keeper_uid])->value('nickname');
- $item->sign_name = Db::name('Admin')->where(['id' => $item->sign_uid])->value('nickname');
- $item->cate_title = Db::name('ContractCate')->where("id", $item->cate_id)->value("title");
- $item->sign_time = date('Y-m-d', $item->sign_time);
- $item->interval_time = date('Y-m-d', $item->start_time) . ' 至 ' . date('Y-m-d', $item->end_time);
- $item->type_name = self::$Type[(int)$item->type];
- $item->status_name = self::$Status[(int)$item->check_status];
- $item->delay = countDays(date("Y-m-d"), date('Y-m-d', $item->end_time));
- if ($item->cost == 0) {
- $item->cost = '-';
- }
- });
- // return table_assign(0, '', $list);
- $cate = Db::name('ContractCate')->where("unit_id", get_login_admin("unit_name"))->order('create_time asc')->select();
- View::assign('list', $list);
- View::assign('cate', $cate);
- // halt($list);
- return view();
- }
- public function view(){
- $param = get_params();
- $id = get_params("id");
- $detail = (new \app\admin\model\Contract())->detail($id);
- //从项目页面进来的不给按钮
- $view_auth = isset($param['type']) ? $param['type'] : 0;
- $auth = 0;
- $is_check_admin = 0;
- $is_create_admin = 0;
- $check_record = [];
- $detail['create_user'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('nickname');
- $detail['copy_user'] = '-';
- if ($detail['copy_uids'] != '') {
- $copy_user = Db::name('Admin')->where('id', 'in', $detail['copy_uids'])->column('nickname');
- $detail['copy_user'] = implode(',', $copy_user);
- }
- $check_id = Db::name("check_step")->where("id", $detail["check_step_sort"])->value("check_id");
- if ($check_id == $this->uid) {
- $is_check_admin = 1;
- }
- if ($detail['admin_id'] == $this->uid) {
- $is_create_admin = 1;
- $auth = 1;
- }
- //关联项目
- $uuid = Db::name("relation")->alias("r")
- ->leftJoin("cost_project c","c.id=r.uuid")->where("uid",$id)->column("r.id,project_name,uid,uuid");
- $newArr = [];
- foreach($uuid as $item){
- $key = $item['uid'].'-'.$item['uuid'];
- if(!isset($newArr[$key])){
- $newArr[$key] = $item;
- }
- }
- $project = array_values($newArr);
- $file_array_other = Db::name('ContractFile')
- ->field('cf.id,f.filepath,f.name,f.filesize,f.fileext,f.create_time,f.admin_id')
- ->alias('cf')
- ->join('File f', 'f.id = cf.file_id', 'LEFT')
- ->order('cf.create_time asc')
- ->where(array('cf.contract_id' => $id, 'cf.delete_time' => 0))
- ->select()->toArray();
- $detail['file_array_other'] = $file_array_other;
- foreach ($check_record as $kk => &$vv) {
- $vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
- $vv['status_str'] = '提交';
- if ($vv['status'] == 1) {
- $vv['status_str'] = '审核通过';
- } else if ($vv['status'] == 2) {
- $vv['status_str'] = '审核拒绝';
- }
- if ($vv['status'] == 3) {
- $vv['status_str'] = '撤销';
- }
- }
- View::assign('is_check_admin', $is_check_admin);
- View::assign('auth', $auth);
- View::assign('view_auth', $view_auth);
- View::assign('is_create_admin', $is_create_admin);
- View::assign('check_record', $check_record);
- View::assign('project', $project);
- View::assign('detail', $detail);
- // halt($detail);
- return view();
- }
- }
|