Index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/GPL-3.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types = 1);
  8. namespace app\contract\controller;
  9. use app\base\BaseController;
  10. use app\contract\model\Contract as ContractList;
  11. use app\contract\validate\ContractCheck;
  12. use think\exception\ValidateException;
  13. use think\facade\Db;
  14. use think\facade\View;
  15. class Index extends BaseController
  16. {
  17. public function index()
  18. {
  19. // if (request()->isAjax()) {
  20. $param = get_params();
  21. // dump($param);
  22. $where = array();
  23. $whereOr = array();
  24. if (!empty($param['keywords'])) {
  25. $where[] = ['a.id|a.name|c.title', 'like', '%' . $param['keywords'] . '%'];
  26. }
  27. if (!empty($param['cate_id'])) {
  28. $where[] = ['a.cate_id', '=', $param['cate_id']];
  29. }
  30. if (!empty($param['type'])) {
  31. $where[] = ['a.type', '=', $param['type']];
  32. }
  33. if (isset($param['check_status']) && $param['check_status']!='') {
  34. $where[] = ['a.check_status', '=', $param['check_status']];
  35. }
  36. $where[] = ['a.delete_time', '=', 0];
  37. $where[] = ['a.archive_status', '=', 0];
  38. // $uid = $this->uid;
  39. // $auth = isAuth($uid,'contract_admin');
  40. // if($auth==0){
  41. // $whereOr[] = ['a.admin_id|a.prepared_uid|a.sign_uid|a.keeper_uid', '=', $uid];
  42. // $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',a.share_ids)")];
  43. // $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',a.check_admin_ids)")];
  44. // $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',a.flow_admin_ids)")];
  45. // $dids = get_department_role($this->uid);
  46. // if(!empty($dids)){
  47. // $whereOr[] =['a.sign_did', 'in', $dids];
  48. // }
  49. // }
  50. $model = new ContractList();
  51. $list = $model->get_list($param, $where, $whereOr);
  52. // $list = Db::name('Contract')->select();
  53. halt($list);
  54. // return table_assign(0, '', $list);
  55. // } else {
  56. // // $uid = $this->uid;
  57. // // $auth = isAuth($uid,'contract_admin');
  58. // //
  59. // // View::assign('auth', $auth);
  60. // return view();
  61. // }
  62. }
  63. public function archive()
  64. {
  65. if (request()->isAjax()) {
  66. $param = get_params();
  67. $where = array();
  68. $whereOr = array();
  69. if (!empty($param['keywords'])) {
  70. $where[] = ['a.id|a.name|c.title', 'like', '%' . $param['keywords'] . '%'];
  71. }
  72. if (!empty($param['cate_id'])) {
  73. $where[] = ['a.cate_id', '=', $param['cate_id']];
  74. }
  75. if (!empty($param['cate_id'])) {
  76. $where[] = ['a.cate_id', '=', $param['cate_id']];
  77. }
  78. if (!empty($param['type'])) {
  79. $where[] = ['a.type', '=', $param['type']];
  80. }
  81. $where[] = ['a.delete_time', '=', 0];
  82. $where[] = ['a.archive_status', '=', 1];
  83. // $uid = $this->uid;
  84. // $auth = isAuth($uid,'contract_admin');
  85. // if($auth==0){
  86. // $whereOr[] =['a.admin_id|a.prepared_uid|a.sign_uid|a.keeper_uid', '=', $uid];
  87. // $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',a.share_ids)")];
  88. // $dids = get_department_role($this->uid);
  89. // if(!empty($dids)){
  90. // $whereOr[] =['a.sign_did', 'in', $dids];
  91. // }
  92. // }
  93. $model = new ContractList();
  94. $list = $model->get_list($param, $where, $whereOr);
  95. return table_assign(0, '', $list);
  96. } else {
  97. return view();
  98. }
  99. }
  100. public function get_codeno($prefix=1){
  101. $no = $prefix . date('YmdHis') . rand(10,99);
  102. return $no;
  103. }
  104. //添加&&编辑
  105. public function add()
  106. {
  107. $param = get_params();
  108. if (request()->isAjax()) {
  109. if (isset($param['sign_time'])) {
  110. $param['sign_time'] = strtotime($param['sign_time']);
  111. }
  112. if (isset($param['start_time'])) {
  113. $param['start_time'] = strtotime($param['start_time']);
  114. }
  115. if (isset($param['end_time'])) {
  116. $param['end_time'] = strtotime($param['end_time']);
  117. if ($param['end_time'] <= $param['start_time']) {
  118. return to_assign(1, "结束时间需要大于开始时间");
  119. }
  120. }
  121. if (!empty($param['id']) && $param['id'] > 0) { //编辑
  122. try {
  123. validate(ContractCheck::class)->scene($param['scene'])->check($param);
  124. } catch (ValidateException $e) {
  125. // 验证失败 输出错误信息
  126. return to_assign(1, $e->getError());
  127. }
  128. $param['update_time'] = time();
  129. $old = Db::name('Contract')->where(['id' => $param['id']])->find();
  130. $auth = isAuth($this->uid,'contract_admin');
  131. if($old['check_status'] == 0 || $old['check_status'] == 4){
  132. if($this->uid!=$old['admin_id'] && $auth==0){
  133. return to_assign(1, "只有录入人员和合同管理员有权限操作");
  134. }
  135. $res = contractList::strict(false)->field(true)->update($param);
  136. if ($res) {
  137. add_log('edit', $param['id'], $param);
  138. to_log($this->uid,$param,$old);
  139. return to_assign();
  140. } else {
  141. return to_assign(1, '操作失败');
  142. }
  143. }
  144. else{
  145. return to_assign(1, "当前状态不允许编辑");
  146. }
  147. } else { //新增
  148. try {
  149. validate(ContractCheck::class)->scene('add')->check($param);
  150. } catch (ValidateException $e) {
  151. // 验证失败 输出错误信息
  152. return to_assign(1, $e->getError());
  153. }
  154. $param['create_time'] = time();
  155. $param['admin_id'] = $this->uid['id'];
  156. // halt($this->uid);
  157. // dump('1111111111111111111111111111111111111');
  158. // dump($param);
  159. $aid = ContractList::strict(false)->field(true)->insertGetId($param);
  160. // dump('2222222222222222222222222222222222222');
  161. if ($aid) {
  162. add_log('add', $aid, $param);
  163. $log_data = array(
  164. 'field' => 'new',
  165. 'action' => 'add',
  166. 'contract_id' => $aid,
  167. 'admin_id' => $param['admin_id'],
  168. 'create_time' => time(),
  169. );
  170. Db::name('ContractLog')->strict(false)->field(true)->insert($log_data);
  171. return to_assign(0, '操作成功');
  172. } else {
  173. return to_assign(1, '操作失败');
  174. }
  175. }
  176. } else {
  177. $id = isset($param['id']) ? $param['id'] : 0;
  178. $type = isset($param['type']) ? $param['type'] : 0;
  179. $pid = isset($param['pid']) ? $param['pid'] : 0;
  180. // halt([$id,$type,$pid]);
  181. $is_customer = 1;
  182. $is_codeno = 1;
  183. $codeno='';
  184. if($is_codeno==1){
  185. $codeno = self::get_codeno(1);
  186. }
  187. View::assign('is_customer', $is_customer);
  188. View::assign('codeno', $codeno);
  189. View::assign('id', $id);
  190. View::assign('type', $type);
  191. View::assign('pid', $pid);
  192. View::assign('auth', 1);
  193. if ($id > 0) {
  194. $detail = (new ContractList())->detail($id);
  195. if($detail['check_status'] == 0 || $detail['check_status'] == 4){
  196. View::assign('detail', $detail);
  197. return view('edit');
  198. }
  199. else{
  200. echo '<div style="text-align:center;color:red;margin-top:20%;">当前状态不开放编辑,请联系合同管理员</div>';exit;
  201. }
  202. }
  203. if($pid>0){
  204. $p_contract = Db::name('Contract')->where(['id' => $pid])->find();
  205. View::assign('p_contract', $p_contract);
  206. }
  207. return view();
  208. }
  209. }
  210. //查看
  211. public function view()
  212. {
  213. $id = get_params("id");
  214. $detail = (new ContractList())->detail($id);
  215. $auth = isAuth($this->uid,'contract_admin');
  216. $is_check_admin = 0;
  217. $is_create_admin = 0;
  218. $check_record = [];
  219. if($auth==0){
  220. $auth_array=[];
  221. if(!empty($detail['share_ids'])){
  222. $share_ids = explode(",",$detail['share_ids']);
  223. $auth_array = array_merge($auth_array,$share_ids);
  224. }
  225. if(!empty($detail['check_admin_ids'])){
  226. $check_admin_ids = explode(",",$detail['check_admin_ids']);
  227. $auth_array = array_merge($auth_array,$check_admin_ids);
  228. }
  229. if(!empty($detail['flow_admin_ids'])){
  230. $flow_admin_ids = explode(",",$detail['flow_admin_ids']);
  231. $auth_array = array_merge($auth_array,$flow_admin_ids);
  232. }
  233. array_push($auth_array,$detail['admin_id'],$detail['prepared_uid'],$detail['sign_uid'],$detail['keeper_uid']);
  234. //部门负责人
  235. $dids = get_department_role($this->uid);
  236. if(!in_array($this->uid,$auth_array) && !in_array($detail['sign_did'],$dids)){
  237. return view('../../base/view/common/roletemplate');
  238. }
  239. }
  240. $detail['create_user'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('name');
  241. $detail['copy_user'] = '-';
  242. if($detail['copy_uids'] !=''){
  243. $copy_user = Db::name('Admin')->where('id','in',$detail['copy_uids'])->column('name');
  244. $detail['copy_user'] = implode(',',$copy_user);
  245. }
  246. if($detail['check_status']==1){
  247. $flows = Db::name('FlowStep')->where(['action_id'=>$detail['id'],'type'=>4,'sort'=>$detail['check_step_sort'],'delete_time'=>0])->find();
  248. $flow_check = get_flow($this->uid,$flows);
  249. $detail['check_user'] = $flow_check['check_user'];
  250. $check_user_ids = $flow_check['check_user_ids'];
  251. if(in_array($this->uid,$check_user_ids)){
  252. $is_check_admin = 1;
  253. if($flows['flow_type'] == 4){
  254. $check_count = Db::name('FlowRecord')->where(['action_id'=>$detail['id'],'type'=>4,'step_id'=>$flows['id'],'check_user_id'=>$this->uid])->count();
  255. if($check_count>0){
  256. $is_check_admin = 0;
  257. }
  258. }
  259. }
  260. }
  261. else{
  262. //获取合同审批流程
  263. $flows = get_type_department_flows(8,$this->did);
  264. $detail['check_user'] = '-';
  265. }
  266. if($detail['admin_id'] == $this->uid){
  267. $is_create_admin = 1;
  268. }
  269. $file_array_other = Db::name('ContractFile')
  270. ->field('cf.id,f.filepath,f.name,f.filesize,f.fileext,f.create_time,f.admin_id')
  271. ->alias('cf')
  272. ->join('File f', 'f.id = cf.file_id', 'LEFT')
  273. ->order('cf.create_time asc')
  274. ->where(array('cf.contract_id' => $id, 'cf.delete_time' => 0))
  275. ->select()->toArray();
  276. $detail['file_array_other'] = $file_array_other;
  277. $check_record = Db::name('FlowRecord')->field('f.*,a.name,a.thumb')
  278. ->alias('f')
  279. ->join('Admin a', 'a.id = f.check_user_id', 'left')
  280. ->where(['f.action_id'=>$detail['id'],'f.type'=>4])
  281. ->order('check_time asc')
  282. ->select()->toArray();
  283. foreach ($check_record as $kk => &$vv) {
  284. $vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
  285. $vv['status_str'] = '提交';
  286. if($vv['status'] == 1){
  287. $vv['status_str'] = '审核通过';
  288. }
  289. else if($vv['status'] == 2){
  290. $vv['status_str'] = '审核拒绝';
  291. }
  292. if($vv['status'] == 3){
  293. $vv['status_str'] = '撤销';
  294. }
  295. }
  296. View::assign('is_check_admin', $is_check_admin);
  297. View::assign('is_create_admin', $is_create_admin);
  298. View::assign('check_record', $check_record);
  299. View::assign('flows', $flows);
  300. View::assign('auth', $auth);
  301. View::assign('detail', $detail);
  302. return view();
  303. }
  304. //删除
  305. public function delete()
  306. {
  307. if (request()->isDelete()) {
  308. $id = get_params("id");
  309. $data['id'] = $id;
  310. $data['delete_time'] = time();
  311. if (Db::name('Contract')->update($data) !== false) {
  312. add_log('delete', $id);
  313. $log_data = array(
  314. 'field' => 'del',
  315. 'action' => 'delete',
  316. 'contract_id' => $id,
  317. 'admin_id' => $this->uid,
  318. 'create_time' => time(),
  319. );
  320. Db::name('ContractLog')->strict(false)->field(true)->insert($log_data);
  321. return to_assign(0, "删除成功");
  322. } else {
  323. return to_assign(1, "删除失败");
  324. }
  325. } else {
  326. return to_assign(1, "错误的请求");
  327. }
  328. }
  329. public function test(){
  330. // $list = Db::name('Contract')->field('pid, code')->select()->toArray();
  331. $param = array();
  332. $where = array();
  333. $whereOr = array();
  334. $model = new ContractList();
  335. $list = $model->get_list($param, $where, $whereOr);
  336. halt($list);
  337. }
  338. }