ContractLog.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2022 勾股工作室
  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\model;
  9. use think\facade\Db;
  10. use think\Model;
  11. class ContractLog extends Model
  12. {
  13. public static $Sourse = [
  14. 'type' => ['', '未设置', '普通合同', '框架合同', '补充协议', '其他合同'],
  15. 'check_status' => ['待审核', '审核中', '审核通过', '审核拒绝', '已撤销', '已中止', '已作废'],
  16. 'action' => [
  17. 'add' => '添加',
  18. 'edit' => '修改',
  19. 'delete' => '删除',
  20. 'upload' => '上传',
  21. ],
  22. 'field_array' => [
  23. 'code' => '编号',
  24. 'name' => '名称',
  25. 'cate_id' => '类别',
  26. 'type' => '性质',
  27. 'subject_id' => '签约主体',
  28. 'customer' => '客户名称',
  29. 'customer_name' => '客户代表姓名',
  30. 'customer_mobile' => '客户电话',
  31. 'customer_address'=> '客户地址',
  32. 'start_time' => '开始时间',
  33. 'end_time' => '结束时间',
  34. 'prepared_uid' => '制定人',
  35. 'sign_uid' => '签订人',
  36. 'keeper_uid' => '保管人',
  37. 'share_ids' => '共享人员',
  38. 'sign_time' => '签订时间',
  39. 'cost' => '金额',
  40. 'is_tax' => '是否含税',
  41. 'tax' => '税点',
  42. 'check_status' => '状态',
  43. 'status' => '状态',
  44. 'archive_status' => '归档状态',
  45. 'file_ids' => '合同附件',
  46. 'file' => '合同附件',
  47. 'remark' => '备注信息',
  48. 'new' => '新增',
  49. 'del' => '删除',
  50. ]
  51. ];
  52. public function contract_log($param = [])
  53. {
  54. $where = [];
  55. $where[] = ['a.contract_id', '=', $param['contract_id']];
  56. $page = intval($param['page']);
  57. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  58. $content = Db::name('ContractLog')
  59. ->field('a.*,u.name,u.thumb')
  60. ->alias('a')
  61. ->join('Admin u', 'u.id = a.admin_id')
  62. ->order('a.create_time desc')
  63. ->where($where)
  64. ->page($page, $rows)
  65. ->select()->toArray();
  66. $data = [];
  67. $sourse = self::$Sourse;
  68. $field_array = $sourse['field_array'];
  69. $action = $sourse['action'];
  70. foreach ($content as $k => $v) {
  71. if (isset($sourse[$v['field']])) {
  72. $v['old_content'] = $sourse[$v['field']][$v['old_content']];
  73. $v['new_content'] = $sourse[$v['field']][$v['new_content']];
  74. }
  75. if (strpos($v['field'], '_time') !== false) {
  76. if ($v['old_content'] == '') {
  77. $v['old_content'] = '未设置';
  78. }
  79. $v['new_content'] = date('Y-m-d', (int) $v['new_content']);
  80. }
  81. if (strpos($v['field'], '_uid') !== false) {
  82. $v['old_content'] = Db::name('Admin')->where(['id' => $v['old_content']])->value('name');
  83. $v['new_content'] = Db::name('Admin')->where(['id' => $v['new_content']])->value('name');
  84. }
  85. if ($v['field'] == 'cate_id') {
  86. $v['old_content'] = Db::name('ContractCate')->where(['id' => $v['old_content']])->value('title');
  87. $v['new_content'] = Db::name('ContractCate')->where(['id' => $v['new_content']])->value('title');
  88. }
  89. if ($v['field'] == 'subject_id') {
  90. $v['old_content'] = Db::name('InvoiceSubject')->where(['id' => $v['old_content']])->value('title');
  91. $v['new_content'] = Db::name('InvoiceSubject')->where(['id' => $v['new_content']])->value('title');
  92. }
  93. if ($v['field'] == 'tax') {
  94. $v['old_content'] = $v['old_content'] . '%';
  95. $v['new_content'] = $v['new_content'] . '%';
  96. }
  97. if ($v['field'] == 'is_tax') {
  98. $v['old_content'] = $v['old_content'] == 1?'是':'否';
  99. $v['new_content'] = $v['new_content'] == 1?'是':'否';
  100. }
  101. if ($v['field'] == 'archive_status') {
  102. $v['old_content'] = $v['old_content'] == 1?'已归档':'未归档';
  103. $v['new_content'] = $v['new_content'] == 1?'已归档':'未归档';
  104. }
  105. if (strpos($v['field'], '_ids') !== false) {
  106. $old_ids = Db::name('Admin')->where('id', 'in', $v['old_content'])->column('name');
  107. $v['old_content'] = implode(',', $old_ids);
  108. $new_ids = Db::name('Admin')->where('id', 'in', $v['new_content'])->column('name');
  109. $v['new_content'] = implode(',', $new_ids);
  110. }
  111. if ($v['old_content'] == '' || $v['old_content'] == null) {
  112. $v['old_content'] = '未设置';
  113. }
  114. if ($v['new_content'] == '' || $v['new_content'] == null) {
  115. $v['new_content'] = '未设置';
  116. }
  117. $v['action'] = $action[$v['action']];
  118. $v['title'] = $field_array[$v['field']];
  119. $v['times'] = time_trans($v['create_time']);
  120. $v['create_time'] = date('Y-m-d', $v['create_time']);
  121. $data[] = $v;
  122. }
  123. return $data;
  124. }
  125. }