FlowController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace App\Http\Controllers\Wap;
  3. use App\Http\Models\FlowInfoTpl;
  4. use App\Http\Models\FlowPlan;
  5. use App\Http\Models\Role;
  6. use App\Http\Models\Site;
  7. use App\Http\Models\User;
  8. use App\Http\Models\FlowStage;
  9. use App\Http\Controllers\Controller;
  10. class FlowController extends Controller
  11. {
  12. //流程报告
  13. public function index($siteIdBase64)
  14. {
  15. $siteId = base64_decode($siteIdBase64);
  16. $site = Site::query()->select(['id', 'cn_title'])->where(['id' => $siteId])->first();
  17. if (!$site) {
  18. return abort(404);
  19. }
  20. $roleScope = array_keys(FlowInfoTpl::RoleScope);
  21. unset($roleScope[1]); //删除客户
  22. $mapUsers = User::query()->select(['id', 'role_id', 'nickname'])->whereIn('role_id', $roleScope)->get()->keyBy('id')->toArray();
  23. $site = Site::query()->select(['cn_title'])->find($siteId);
  24. $mapUsers['-1'] = ['id' => -1, 'role_id' => -1, 'nickname' => $site->cn_title ?? '站点名称'];
  25. $stageList = FlowStage::query()->where(['site_id' => $siteId])
  26. ->with('infoList')->orderBy('sort')->get();
  27. $week = date('YW');
  28. $nowPlanList = FlowPlan::query()->where(['site_id' => $siteId, 'week' => $week])->get();
  29. $nextWeek = date('YW', strtotime('+1 week'));
  30. $nextPlanList = FlowPlan::query()->where(['site_id' => $siteId, 'week' => $nextWeek])->get();
  31. $historyPlanList = FlowPlan::query()->where([['site_id', '=', $siteId], ['week', '<', $week]])->get();
  32. foreach ($nowPlanList as $key => $value) {
  33. $nowPlanList[$key]->usernameList = $this->getUserInfo($value, $siteId);
  34. }
  35. foreach ($nextPlanList as $key => $value) {
  36. $nextPlanList[$key]->usernameList = $this->getUserInfo($value, $siteId);
  37. }
  38. foreach ($historyPlanList as $key => $value) {
  39. $historyPlanList[$key]->usernameList = $this->getUserInfo($value, $siteId);
  40. }
  41. return view('wap.flow', [
  42. 'site' => $site,
  43. 'stageList' => $stageList,
  44. 'mapUsers' => $mapUsers,
  45. 'nowPlanList' => $nowPlanList ?? [],
  46. 'nextPlanList' => $nextPlanList ?? [],
  47. 'historyPlanList' => $historyPlanList ?? [],
  48. ]);
  49. }
  50. public function getUserInfo($user, $siteId)
  51. {
  52. $list = [];
  53. $userList = $this->getUserList($user->user_ids, $siteId);
  54. if (!empty($userList)) {
  55. foreach ($userList as $kk => $vv) {
  56. $list[] = $vv;
  57. }
  58. }
  59. if (!empty($user->username)) {
  60. $list[] = $user->username;
  61. }
  62. return $list;
  63. }
  64. /**
  65. * 用户列表
  66. * @param $userIds
  67. * @param $siteId
  68. * @return array
  69. */
  70. protected function getUserList($userIds, $siteId)
  71. {
  72. $userList = [];
  73. $condition = explode(',', $userIds);
  74. $roleList = Role::query()->pluck('name', 'id')->toArray() ?? [];
  75. foreach ($condition as $key => $value) {
  76. if ($value == '-1') {
  77. $account = Site::query()->where('id', $siteId)->value('cn_title');
  78. if (!empty($account)) {
  79. $userList[] = $account . '【客户】';
  80. }
  81. unset($condition[$key]);
  82. }
  83. }
  84. foreach ($condition as $key => $value) {
  85. $userInfo = User::query()->where('id', $value)->first();
  86. if (!empty($userInfo)) {
  87. $roleId = $userInfo->role_id;
  88. $nickname = $userInfo->nickname;
  89. $nickname = $nickname . '【' . $roleList[$roleId] . '】';
  90. $userList[] = $nickname;
  91. }
  92. }
  93. return $userList;
  94. }
  95. }