ApproveFlow.php 3.3 KB

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