ApproveFlowService.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\common\service;
  3. use app\common\constant\CommonConstant;
  4. use app\common\model\ApproveFlow;
  5. use app\common\model\User;
  6. /**
  7. * 审批流程服务类
  8. */
  9. class ApproveFlowService
  10. {
  11. /**
  12. * 获取流程
  13. *
  14. * @param integer $module 模块类型
  15. * @param mixed $user 用户信息
  16. **/
  17. public static function get_data($module, $user)
  18. {
  19. $userid = $user['userid'];
  20. $field = 'id,user_ids';
  21. // 审批
  22. $approve = ApproveFlow::get_where($module, CommonConstant::TYPE_1, CommonConstant::IS_SPECIAL_1, $userid)
  23. ->field($field)
  24. ->find();
  25. if ($approve) {
  26. $approve_user_ids = $approve['user_ids'];
  27. } else {
  28. $approve_info = ApproveFlow::get_where($module, CommonConstant::TYPE_1, CommonConstant::IS_SPECIAL_0)
  29. ->field($field)
  30. ->find();
  31. $approve_user_ids = $approve_info ? $approve_info['user_ids'] : [];
  32. }
  33. $approve_user = self::get_user_list($approve_user_ids);
  34. // 抄送
  35. $name = 'is_copy_' . $module;
  36. $is_copy = sysconf($name); // 是否允许用户自己添加抄送人 0=否,1=是
  37. $copy_user = [];
  38. if (!$is_copy) {
  39. $copy = ApproveFlow::get_where($module, CommonConstant::TYPE_2, CommonConstant::IS_SPECIAL_1, $userid)
  40. ->field($field)
  41. ->find();
  42. if ($copy) {
  43. $copy_user_ids = $copy['user_ids'];
  44. } else {
  45. $copy_info = ApproveFlow::get_where($module, CommonConstant::TYPE_2, CommonConstant::IS_SPECIAL_0)
  46. ->field($field)
  47. ->find();
  48. $copy_user_ids = $copy_info ? $copy_info['user_ids'] : [];
  49. }
  50. $copy_user = self::get_user_list($copy_user_ids);
  51. }
  52. return compact('approve_user', 'copy_user', 'is_copy');
  53. }
  54. protected static function get_user_list($user_ids)
  55. {
  56. if (!$user_ids) {
  57. return [];
  58. }
  59. return User::field('userid,headimg,name')->where('userid', 'in', $user_ids)->select();
  60. }
  61. }