ExamineRecord.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 审批意见
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\model;
  8. use think\Db;
  9. use app\admin\model\Common;
  10. use think\Request;
  11. use think\Validate;
  12. class ExamineRecord extends Common
  13. {
  14. /**
  15. * 为了数据库的整洁,同时又不影响Model和Controller的名称
  16. * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
  17. */
  18. protected $name = 'admin_examine_record';
  19. /**
  20. * 审批意见(创建)
  21. * @param types 关联对象
  22. * @param types_id 联对象ID
  23. * @param flow_id 审批流程ID
  24. * @param step_id 审批步骤ID
  25. * @param user_id 审批人ID
  26. * @param status 1通过0驳回
  27. * @return
  28. */
  29. public function createData($param)
  30. {
  31. if ($this->data($param)->allowField(true)->save()) {
  32. $data = [];
  33. $data['record_id'] = $this->record_id;
  34. return $data;
  35. } else {
  36. $this->error = '添加失败';
  37. return false;
  38. }
  39. }
  40. /**
  41. * 审批意见(列表)
  42. * @param types 关联对象
  43. * @param types_id 联对象ID
  44. * @return
  45. */
  46. public function getDataList($param)
  47. {
  48. $userModel = new \app\admin\model\User();
  49. if (empty($param['types']) || empty($param['types_id'])) {
  50. return [];
  51. }
  52. $result = [];
  53. # 获取创建者信息(办公审批)
  54. if ($param['types'] == 'oa_examine' && !empty($param['is_record'])) {
  55. $info = db('oa_examine')->field(['create_time', 'create_user_id'])->where('examine_id', $param['types_id'])->find();
  56. $userInfo = $userModel->getUserById($info['create_user_id']);
  57. $result[] = [
  58. 'check_date' => date('Y-m-d H:i:s', $info['create_time']),
  59. 'check_time' => $info['create_time'],
  60. 'check_user_id' => $info['create_user_id'],
  61. 'check_user_id_info' => $userInfo,
  62. 'content' => '',
  63. 'flow_id' => 0,
  64. 'is_end' => 0,
  65. 'order_id' => 1,
  66. 'record_id' => 0,
  67. 'status' => 3,
  68. 'types' => $param['types'],
  69. 'types_id' => $param['types_id']
  70. ];
  71. }
  72. # 获取创建者信息(业务审批)
  73. if (in_array($param['types'], ['crm_contract', 'crm_receivables', 'crm_invoice']) && !empty($param['is_record'])) {
  74. $model = db($param['types']);
  75. $primaryKey = null;
  76. if ($param['types'] == 'crm_contract') $primaryKey = 'contract_id';
  77. if ($param['types'] == 'crm_receivables') $primaryKey = 'receivables_id';
  78. if ($param['types'] == 'crm_invoice') $primaryKey = 'invoice_id';
  79. $info = $model->field(['create_time', 'owner_user_id'])->where($primaryKey, $param['types_id'])->find();
  80. $userInfo = $userModel->getUserById($info['owner_user_id']);
  81. $result[] = [
  82. 'check_date' => date('Y-m-d H:i:s', $info['create_time']),
  83. 'check_time' => $info['create_time'],
  84. 'check_user_id' => $info['owner_user_id'],
  85. 'check_user_id_info' => $userInfo,
  86. 'content' => '',
  87. 'flow_id' => 0,
  88. 'is_end' => 0,
  89. 'order_id' => 1,
  90. 'record_id' => 0,
  91. 'status' => 3,
  92. 'types' => $param['types'],
  93. 'types_id' => $param['types_id']
  94. ];
  95. }
  96. unset($param['is_record']);
  97. $list = db('admin_examine_record')->where($param)->order('check_time asc')->select();
  98. foreach ($list as $k=>$v) {
  99. $list[$k]['check_user_id_info'] = $userModel->getUserById($v['check_user_id']);
  100. $list[$k]['check_date'] = date('Y-m-d H:i:s', $v['check_time']);
  101. $list[$k]['order_id'] = $k + 2;
  102. $result[] = $list[$k];
  103. }
  104. return !empty($result) ? $result : [];
  105. }
  106. /**
  107. * 审批意见(标记无效,撤销审批时使用)
  108. * @param types 关联对象
  109. * @param types_id 关联对象ID
  110. * @return
  111. */
  112. public function setEnd($param)
  113. {
  114. if (empty($param['types']) || empty($param['types_id'])) {
  115. $this->error = '参数错误';
  116. return false;
  117. }
  118. $res = $this->where(['types' => $param['types'],'types_id' => $param['types_id']])->update(['is_end' => 1]);
  119. return true;
  120. }
  121. }