ApproveFlowService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. if (!$is_copy) {
  38. $copy = ApproveFlow::get_where($module, CommonConstant::TYPE_2, CommonConstant::IS_SPECIAL_1, $userid)
  39. ->field($field)
  40. ->find();
  41. if ($copy) {
  42. $copy_user_ids = $copy['user_ids'];
  43. } else {
  44. $copy_info = ApproveFlow::get_where($module, CommonConstant::TYPE_2, CommonConstant::IS_SPECIAL_0)
  45. ->field($field)
  46. ->find();
  47. $copy_user_ids = $copy_info ? $copy_info['user_ids'] : [];
  48. }
  49. $copy_user = self::get_user_list($copy_user_ids);
  50. } else {
  51. $copy_user = [];
  52. }
  53. return compact('approve_user', 'copy_user');
  54. }
  55. protected static function get_user_list($user_ids)
  56. {
  57. if (!$user_ids) {
  58. return [];
  59. }
  60. return User::field('userid,headimg,name')->where('userid', 'in', $user_ids)->select();
  61. }
  62. }