ContractLog.php 4.9 KB

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