ApproveFlow.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 审批流程设置模型
  6. */
  7. class ApproveFlow extends Model
  8. {
  9. /**
  10. * 获取流程条件
  11. *
  12. * @param integer $module 模块类型
  13. * @param integer $type 流程类型
  14. * @param integer $is_special 是否特殊:0=通用,1=特殊
  15. * @param string $userid 特殊的用户userid
  16. **/
  17. public static function get_where($module, $type, $is_special, $userid = '')
  18. {
  19. return self::where('module', $module)
  20. ->where('type', $type)
  21. ->where('is_special', $is_special)
  22. ->when($userid, function ($query) use ($userid) {
  23. $query->where('special_user_id', $userid);
  24. });
  25. }
  26. protected $module_desc = [
  27. '1' => '请假',
  28. '2' => '用车',
  29. '3' => '出差',
  30. '4' => '呈批',
  31. '5' => '维修',
  32. '6' => '学校文件',
  33. '7' => '合同',
  34. ];
  35. // 获取审批人
  36. public static function getApproveUser($module, $user_id)
  37. {
  38. $check_flow = ApproveFlow::where('user_id', $user_id)->where('type', 1)->where('module', $module)->find();
  39. $where = [];
  40. $where[] = ['l.type', '=', 1];
  41. $where[] = ['l.module', '=', $module];
  42. if ($check_flow) $where[] = ['l.sort', '>', $check_flow->sort];
  43. $list = static::field('l.user_id,u.name user_name,u.headimg')->alias('l')
  44. ->where($where)
  45. ->order('l.sort asc')
  46. ->leftJoin('StoreMember u', 'u.id = l.user_id')
  47. ->select()->toArray();
  48. return $list;
  49. }
  50. // 获取抄送人
  51. public static function getCopyTo($module, $user_id)
  52. {
  53. $check_flow = ApproveFlow::where('user_id', $user_id)->where('type', 2)->where('module', $module)->find();
  54. $where = [];
  55. $where[] = ['l.type', '=', 2];
  56. $where[] = ['l.module', '=', $module];
  57. if ($check_flow) $where[] = ['l.sort', '>', $check_flow->sort];
  58. $list = ApproveFlow::field('l.user_id,u.name user_name,u.headimg')
  59. ->alias('l')
  60. ->where($where)
  61. ->order('l.sort asc')
  62. ->leftJoin('StoreMember u', 'u.id = l.user_id')
  63. ->select()->toArray();
  64. return $list;
  65. }
  66. // 获取审批流程数据
  67. public static function getApproveData($flow_user, $copy_user, $info_id)
  68. {
  69. $flow_data = [];// 审批流程
  70. $flow_num = 0;
  71. // 审批人
  72. foreach (explode(',', $flow_user) as $fk => $fv) {
  73. if (!$fv) continue;
  74. $flow_num++;
  75. $flow_data[] = [
  76. 'info_id' => $info_id,
  77. 'approve_user' => $fv,
  78. 'flow' => $flow_num,
  79. 'create_at' => date('Y-m-d H:i:s'),
  80. 'start_time' => $flow_num == 1 ? date('Y-m-d H:i:s') : null,
  81. 'status' => $flow_num == 1 ? 1 : 0,
  82. ];
  83. }
  84. // 抄送人
  85. foreach (explode(',', $copy_user) as $ck => $cv) {
  86. if (!$cv) continue;
  87. $flow_data[] = [
  88. 'info_id' => $info_id,
  89. 'approve_user' => $cv,
  90. 'approve_type' => 2
  91. ];
  92. }
  93. return ['flow_data' => $flow_data, 'flow_num' => $flow_num];
  94. }
  95. }