Contract.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\admin\BaseController;
  4. use app\admin\controller\field\Field;
  5. use app\admin\model\Admin;
  6. use app\admin\model\Admin as AdminList;
  7. use app\admin\model\Contact;
  8. use app\admin\model\Contact as ContactModel;
  9. use app\admin\model\CostProject as CostProjectModel;
  10. use app\admin\model\ProjectAudit as AuditModel;
  11. use app\admin\model\ProjectRecord;
  12. use think\App;
  13. use think\facade\Db;
  14. use think\facade\Request;
  15. use think\facade\Session;
  16. use think\facade\View;
  17. use app\admin\model\Appropriation as AppropriationModel;
  18. class Contract
  19. {
  20. public function __construct(App $app)
  21. {
  22. $this->AppropriationModel = new AppropriationModel();
  23. $this->Field = new Field($app);
  24. $this->model = new \app\admin\model\Contract();
  25. $this->Costmodel = new CostProjectModel();
  26. $this->Adminmodel = new Admin();
  27. $this->Auditmodel = new AuditModel();
  28. $this->ContactModel = new ContactModel();
  29. $this->uid = get_login_admin('id');
  30. $this->unit = get_login_admin('unit_name');
  31. $this->user_tpe = Db::name("department")->where("id", $this->unit)->value("type");
  32. }
  33. const ZERO = 0;
  34. const ONE = 1;
  35. const TWO = 2;
  36. const THREE = 3;
  37. const FORE = 4;
  38. const FIVE = 5;
  39. const SIX = 6;
  40. const SEVEN = 7;
  41. public static $Type = [
  42. self::ZERO => '未设置',
  43. self::ONE => '普通合同',
  44. self::TWO => '框架合同',
  45. self::THREE => '补充协议',
  46. self::FORE => '其他合同',
  47. ];
  48. public static $Status = [
  49. self::ZERO => '待审核',
  50. self::ONE => '审核中',
  51. self::TWO => '审核通过',
  52. self::THREE => '审核拒绝',
  53. self::FORE => '已撤销',
  54. self::FIVE => '已中止',
  55. self::SIX => '已作废',
  56. self::SEVEN => '修改中',
  57. ];
  58. public static $ArchiveStatus = [
  59. self::ZERO => '未归档',
  60. self::ONE => '已归档',
  61. ];
  62. public function contract(){
  63. $param = get_params();
  64. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  65. $where = [
  66. ["subject_id", "=", get_login_admin("unit_name")],
  67. ["delete_time", "=", 0],
  68. ["archive_status", "=", 0]
  69. ];
  70. if (!empty($param['keywords'])) {
  71. $where[] = ['a.id|a.name|c.title', 'like', '%' . $param['keywords'] . '%'];
  72. }
  73. if (!empty($param['cate_id'])) {
  74. $where[] = ['a.cate_id', '=', $param['cate_id']];
  75. }
  76. if (!empty($param['type'])) {
  77. $where[] = ['a.type', '=', $param['type']];
  78. }
  79. if (isset($param['check_status']) && $param['check_status'] != '') {
  80. $where[] = ['a.check_status', '=', $param['check_status']];
  81. }
  82. $list = $this->model
  83. ->alias('a')
  84. ->field('a.*,a.type as type_a, c.title as cate_title')
  85. ->where($where)
  86. ->join('contract_cate c', 'a.cate_id = c.id')
  87. ->order('a.create_time desc')
  88. ->paginate($rows, false, ['query' => $param])
  89. ->each(function ($item) {
  90. $item->keeper_name = Db::name('Admin')->where(['id' => $item->keeper_uid])->value('nickname');
  91. $item->sign_name = Db::name('Admin')->where(['id' => $item->sign_uid])->value('nickname');
  92. $item->cate_title = Db::name('ContractCate')->where("id", $item->cate_id)->value("title");
  93. $item->sign_time = date('Y-m-d', $item->sign_time);
  94. $item->interval_time = date('Y-m-d', $item->start_time) . ' 至 ' . date('Y-m-d', $item->end_time);
  95. $item->type_name = self::$Type[(int)$item->type];
  96. $item->status_name = self::$Status[(int)$item->check_status];
  97. $item->delay = countDays(date("Y-m-d"), date('Y-m-d', $item->end_time));
  98. if ($item->cost == 0) {
  99. $item->cost = '-';
  100. }
  101. });
  102. // return table_assign(0, '', $list);
  103. $cate = Db::name('ContractCate')->where("unit_id", get_login_admin("unit_name"))->order('create_time asc')->select();
  104. View::assign('list', $list);
  105. View::assign('cate', $cate);
  106. // halt($list);
  107. return view();
  108. }
  109. public function view(){
  110. $param = get_params();
  111. $id = get_params("id");
  112. $detail = (new \app\admin\model\Contract())->detail($id);
  113. //从项目页面进来的不给按钮
  114. $view_auth = isset($param['type']) ? $param['type'] : 0;
  115. $auth = 0;
  116. $is_check_admin = 0;
  117. $is_create_admin = 0;
  118. $check_record = [];
  119. $detail['create_user'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('nickname');
  120. $detail['copy_user'] = '-';
  121. if ($detail['copy_uids'] != '') {
  122. $copy_user = Db::name('Admin')->where('id', 'in', $detail['copy_uids'])->column('nickname');
  123. $detail['copy_user'] = implode(',', $copy_user);
  124. }
  125. $check_id = Db::name("check_step")->where("id", $detail["check_step_sort"])->value("check_id");
  126. if ($check_id == $this->uid) {
  127. $is_check_admin = 1;
  128. }
  129. if ($detail['admin_id'] == $this->uid) {
  130. $is_create_admin = 1;
  131. $auth = 1;
  132. }
  133. //关联项目
  134. $uuid = Db::name("relation")->alias("r")
  135. ->leftJoin("cost_project c","c.id=r.uuid")->where("uid",$id)->column("r.id,project_name,uid,uuid");
  136. $newArr = [];
  137. foreach($uuid as $item){
  138. $key = $item['uid'].'-'.$item['uuid'];
  139. if(!isset($newArr[$key])){
  140. $newArr[$key] = $item;
  141. }
  142. }
  143. $project = array_values($newArr);
  144. $file_array_other = Db::name('ContractFile')
  145. ->field('cf.id,f.filepath,f.name,f.filesize,f.fileext,f.create_time,f.admin_id')
  146. ->alias('cf')
  147. ->join('File f', 'f.id = cf.file_id', 'LEFT')
  148. ->order('cf.create_time asc')
  149. ->where(array('cf.contract_id' => $id, 'cf.delete_time' => 0))
  150. ->select()->toArray();
  151. $detail['file_array_other'] = $file_array_other;
  152. foreach ($check_record as $kk => &$vv) {
  153. $vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
  154. $vv['status_str'] = '提交';
  155. if ($vv['status'] == 1) {
  156. $vv['status_str'] = '审核通过';
  157. } else if ($vv['status'] == 2) {
  158. $vv['status_str'] = '审核拒绝';
  159. }
  160. if ($vv['status'] == 3) {
  161. $vv['status_str'] = '撤销';
  162. }
  163. }
  164. View::assign('is_check_admin', $is_check_admin);
  165. View::assign('auth', $auth);
  166. View::assign('view_auth', $view_auth);
  167. View::assign('is_create_admin', $is_create_admin);
  168. View::assign('check_record', $check_record);
  169. View::assign('project', $project);
  170. View::assign('detail', $detail);
  171. // halt($detail);
  172. return view();
  173. }
  174. }