ApproveService.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\common\service;
  3. use app\common\constant\CommonConstant;
  4. use app\common\model\Approve;
  5. use app\common\model\ApproveInfo;
  6. use app\common\model\User;
  7. use think\Db;
  8. use think\Exception;
  9. /**
  10. * 审批服务类
  11. */
  12. class ApproveService
  13. {
  14. /**
  15. * 列表
  16. *
  17. * @param $module
  18. * @param $status
  19. * @param $start_time
  20. * @param $end_time
  21. * @param $search
  22. * @param $offset
  23. * @param $length
  24. * @param $user
  25. **/
  26. public static function get_list($module, $status, $start_time, $end_time, $search, $offset, $length, $user)
  27. {
  28. if (!array_key_exists($module, CommonConstant::get_module_list())) {
  29. return [];
  30. }
  31. if (!in_array($status, [1, 2, 3])) {
  32. return [];
  33. }
  34. $userid = $user['userid'];
  35. $aliasName = 'approve.';
  36. // $jobName = 'approveInfo.';
  37. $field = 'id,info_id,status,create_at';
  38. $joinField = 'id,user_id,order_no,apply_date,reason,type,desc,start_time,end_time';
  39. $list = Approve::field($field)
  40. ->when($status, function ($query) use ($aliasName,$status) {
  41. if ($status == 1) {
  42. $query->where($aliasName.'status', 'in',[CommonConstant::STATUS_1,CommonConstant::STATUS_2]);
  43. }
  44. if ($status == 2) {
  45. $query->where($aliasName.'status', 'in', [CommonConstant::STATUS_3,CommonConstant::STATUS_4]);
  46. }
  47. })
  48. ->where($aliasName.'is_deleted', CommonConstant::IS_DELETED_0)
  49. ->where($aliasName.'approve_user', $userid)
  50. ->withJoin(['approveInfo' => function ($query) use ($joinField) {
  51. $query->withField($joinField)
  52. ->where('is_deleted',CommonConstant::IS_DELETED_0);
  53. }]);
  54. // $list = self::get_with($list, $module, $status);
  55. $list = $list->limit($offset, $length)
  56. ->order('id desc')
  57. ->select();
  58. return $list;
  59. }
  60. public static function get_with($list, $module, $status)
  61. {
  62. switch ($module) {
  63. case CommonConstant::MODULE_5:
  64. $list = $list->with(['peer_user' => function ($query) {
  65. $query->field('id,info_id,name');
  66. }, 'approve_info' => function ($query) use ($status) {
  67. $query->field('id,info_id,status,approve_user')
  68. ->where('status', $status)
  69. ->with(['user' => function ($query) {
  70. $query->field('userid,name');
  71. }]);
  72. }]);
  73. break;
  74. }
  75. return $list;
  76. }
  77. /**
  78. * 拼接查询字段
  79. */
  80. public static function getAliasField($field, $aliasName)
  81. {
  82. $field = explode(',', $field);
  83. foreach ($field as &$value) {
  84. $value = $aliasName . $value;
  85. }
  86. return $field;
  87. }
  88. }