ExamineRecord.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 (in_array($param['types'], ['crm_contract', 'crm_receivables', 'crm_invoice']) && !empty($param['is_record'])) {
  55. $model = db($param['types']);
  56. $primaryKey = null;
  57. if ($param['types'] == 'crm_contract') $primaryKey = 'contract_id';
  58. if ($param['types'] == 'crm_receivables') $primaryKey = 'receivables_id';
  59. if ($param['types'] == 'crm_invoice') $primaryKey = 'invoice_id';
  60. $info = $model->field(['create_time', 'owner_user_id'])->where($primaryKey, $param['types_id'])->find();
  61. $userInfo = $userModel->getUserById($info['owner_user_id']);
  62. $result[] = [
  63. 'check_date' => date('Y-m-d H:i:s', $info['create_time']),
  64. 'check_time' => $info['create_time'],
  65. 'check_user_id' => $info['owner_user_id'],
  66. 'check_user_id_info' => $userInfo,
  67. 'content' => '',
  68. 'flow_id' => 0,
  69. 'is_end' => 0,
  70. 'order_id' => 0,
  71. 'record_id' => 0,
  72. 'status' => 3,
  73. 'types' => $param['types'],
  74. 'types_id' => $param['types_id']
  75. ];
  76. }
  77. unset($param['is_record']);
  78. $list = db('admin_examine_record')->where($param)->order('check_time asc')->select();
  79. foreach ($list as $k=>$v) {
  80. $list[$k]['check_user_id_info'] = $userModel->getUserById($v['check_user_id']);
  81. $list[$k]['check_date'] = date('Y-m-d H:i:s', $v['check_time']);
  82. $result[] = $list[$k];
  83. }
  84. return !empty($result) ? $result : [];
  85. }
  86. /**
  87. * 审批意见(标记无效,撤销审批时使用)
  88. * @param types 关联对象
  89. * @param types_id 关联对象ID
  90. * @return
  91. */
  92. public function setEnd($param)
  93. {
  94. if (empty($param['types']) || empty($param['types_id'])) {
  95. $this->error = '参数错误';
  96. return false;
  97. }
  98. $res = $this->where(['types' => $param['types'],'types_id' => $param['types_id']])->update(['is_end' => 1]);
  99. return true;
  100. }
  101. }