Contract.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. namespace app\admin\model;
  8. use think\facade\Db;
  9. use think\Model;
  10. //use function app\contract\model\countDays;
  11. class Contract extends Model
  12. {
  13. const ZERO = 0;
  14. const ONE = 1;
  15. const TWO = 2;
  16. const THREE = 3;
  17. const FORE = 4;
  18. const FIVE = 5;
  19. const SIX = 6;
  20. const SEVEN = 7;
  21. public static $Type = [
  22. self::ZERO => '未设置',
  23. self::ONE => '普通合同',
  24. self::TWO => '框架合同',
  25. self::THREE => '补充协议',
  26. self::FORE => '其他合同',
  27. ];
  28. public static $Status = [
  29. self::ZERO => '待审核',
  30. self::ONE => '审核中',
  31. self::TWO => '审核通过',
  32. self::THREE => '审核拒绝',
  33. self::FORE => '已撤销',
  34. self::FIVE => '已中止',
  35. self::SIX => '已作废',
  36. self::SEVEN => '修改中',
  37. ];
  38. public static $ArchiveStatus = [
  39. self::ZERO => '未归档',
  40. self::ONE => '已归档',
  41. ];
  42. //列表检索
  43. public function get_list($param = [], $where = [], $whereOr=[])
  44. {
  45. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  46. $list = self::where($where)
  47. ->where(function ($query) use($whereOr) {
  48. $query->whereOr($whereOr);
  49. })
  50. ->field('a.*,a.type as type_a, c.title as cate_title,d.title as sign_department')
  51. ->alias('a')
  52. ->join('contract_cate c', 'a.cate_id = c.id')
  53. ->join('department d', 'a.sign_did = d.id','LEFT')
  54. ->order('a.create_time desc')
  55. ->paginate($rows, false, ['query' => $param])
  56. ->each(function ($item, $key) {
  57. $item->keeper_name = Db::name('Admin')->where(['id' => $item->keeper_uid])->value('nickname');
  58. $item->sign_name = Db::name('Admin')->where(['id' => $item->sign_uid])->value('nickname');
  59. $item->sign_time = date('Y-m-d', $item->sign_time);
  60. $item->interval_time = date('Y-m-d', $item->start_time) . ' 至 ' . date('Y-m-d', $item->end_time);
  61. $item->type_name = self::$Type[(int)$item->type_a];
  62. $item->status_name = self::$Status[(int)$item->check_status];
  63. $item->delay = countDays(date("Y-m-d"),date('Y-m-d', $item->end_time));
  64. if($item->cost == 0){
  65. $item->cost = '-';
  66. }
  67. });
  68. return $list;
  69. }
  70. // 获取合同详情
  71. public function detail($id)
  72. {
  73. $detail = self::where(['id' => $id])->find();
  74. if (!empty($detail)) {
  75. $detail['status_name'] = self::$Status[(int) $detail['check_status']];
  76. $detail['archive_status_name'] = self::$ArchiveStatus[(int) $detail['archive_status']];
  77. $detail['sign_time'] = date('Y-m-d', $detail['sign_time']);
  78. $detail['start_time'] = date('Y-m-d', $detail['start_time']);
  79. $detail['end_time'] = date('Y-m-d', $detail['end_time']);
  80. $detail['cate_title'] = Db::name('ContractCate')->where(['id' => $detail['cate_id']])->value('title');
  81. $detail['sign_department'] = Db::name('Department')->where(['id' => $detail['sign_did']])->value('title');
  82. $detail['sign_name'] = Db::name('Admin')->where(['id' => $detail['sign_uid']])->value('nickname');
  83. $detail['admin_name'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('nickname');
  84. $detail['prepared_name'] = Db::name('Admin')->where(['id' => $detail['prepared_uid']])->value('nickname');
  85. $detail['keeper_name'] = Db::name('Admin')->where(['id' => $detail['keeper_uid']])->value('nickname');
  86. $share_names = Db::name('Admin')->where([['id','in',$detail['share_ids']]])->column('nickname');
  87. $detail['share_names'] = implode(',',$share_names);
  88. //审核信息
  89. if($detail['check_uid'] > 0){
  90. $detail['check_name'] = Db::name('Admin')->where(['id' => $detail['check_uid']])->value('nickname');
  91. $detail['check_time'] = date('Y-m-d', $detail['check_time']);
  92. }
  93. //中止信息
  94. if($detail['stop_uid'] > 0){
  95. $detail['stop_name'] = Db::name('Admin')->where(['id' => $detail['stop_uid']])->value('nickname');
  96. $detail['stop_time'] = date('Y-m-d', $detail['stop_time']);
  97. }
  98. //作废信息
  99. if($detail['void_uid'] > 0){
  100. $detail['void_name'] = Db::name('Admin')->where(['id' => $detail['void_uid']])->value('nickname');
  101. $detail['voidtime'] = date('Y-m-d', $detail['void_time']);
  102. }
  103. //归档信息
  104. if($detail['archive_status'] == 1){
  105. $detail['archive_name'] = Db::name('Admin')->where(['id' => $detail['archive_uid']])->value('nickname');
  106. $detail['archive_time'] = date('Y-m-d', $detail['archive_time']);
  107. }
  108. if($detail['pid']>0){
  109. $detail['pname'] = self::where(['id' => $detail['pid']])->value('name');
  110. }
  111. if($detail['file_ids'] !=''){
  112. $fileArray = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  113. if(!$fileArray->isEmpty()){
  114. $fileArray = $fileArray->toArray();
  115. }
  116. $detail['fileArray'] = $fileArray;
  117. }
  118. }
  119. return $detail;
  120. }
  121. }