ApproveFlowService.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. use think\Db;
  7. use think\Exception;
  8. /**
  9. * 审批流程服务类
  10. */
  11. class ApproveFlowService
  12. {
  13. /**
  14. * 获取流程
  15. *
  16. * @param $module
  17. * @param $user
  18. **/
  19. public static function get_data($module, $user)
  20. {
  21. $userid = $user['userid'];
  22. $field = 'id,user_ids';
  23. // 审批
  24. $approve = ApproveFlow::where('module', $module)
  25. ->where('type', CommonConstant::TYPE_1)
  26. ->where('is_special', CommonConstant::IS_SPECIAL_1)
  27. ->where('special_user_id', $userid)
  28. ->field($field)
  29. ->find();
  30. if ($approve) {
  31. $approve_user_ids = $approve['user_ids'];
  32. } else {
  33. $approve_info = ApproveFlow::where('module', $module)
  34. ->where('type', CommonConstant::TYPE_1)
  35. ->where('is_special', CommonConstant::IS_SPECIAL_0)
  36. ->field($field)
  37. ->find();
  38. $approve_user_ids = $approve_info['user_ids'];
  39. }
  40. $approve_user = self::get_user_list($approve_user_ids);
  41. // 抄送
  42. $copy = ApproveFlow::where('module', $module)
  43. ->where('type', CommonConstant::TYPE_2)
  44. ->where('is_special', CommonConstant::IS_SPECIAL_1)
  45. ->where('special_user_id', $userid)
  46. ->field($field)
  47. ->find();
  48. if ($copy) {
  49. $copy_user_ids = $copy['user_ids'];
  50. } else {
  51. $copy_info = ApproveFlow::where('module', $module)
  52. ->where('type', CommonConstant::TYPE_2)
  53. ->where('is_special', CommonConstant::IS_SPECIAL_0)
  54. ->field($field)
  55. ->find();
  56. $copy_user_ids = $copy_info['user_ids'];
  57. }
  58. $copy_user = self::get_user_list($copy_user_ids);
  59. return compact('approve_user', 'copy_user');
  60. }
  61. protected static function get_user_list($user_ids)
  62. {
  63. if (!$user_ids) {
  64. return [];
  65. }
  66. return User::field('userid,headimg,name')->where('userid', 'in', $user_ids)->select();
  67. }
  68. }