UserInviteTmpCodeDownBatchAction.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Admin\Actions\Grid\User;
  3. use App\Admin\Utils\DownUtils;
  4. use App\Models\User\WxUserInviteTempCode;
  5. use Dcat\Admin\Actions\Response;
  6. use Dcat\Admin\Grid\BatchAction;
  7. use Dcat\Admin\Traits\HasPermissions;
  8. use Illuminate\Contracts\Auth\Authenticatable;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Http\Request;
  11. class UserInviteTmpCodeDownBatchAction extends BatchAction
  12. {
  13. /**
  14. * @return string
  15. */
  16. protected $title = '批量下载';
  17. /**
  18. * Handle the action request.
  19. *
  20. * @param Request $request
  21. *
  22. * @return Response
  23. */
  24. public function handle(Request $request)
  25. {
  26. $ids = $this->getKey();
  27. if(_empty_($ids)){
  28. return $this->response()->warning('没有勾选');
  29. }
  30. $codes = WxUserInviteTempCode::whereIn('id', $ids)
  31. ->get(['id', 'code'])
  32. ->map(function ($item) {
  33. return [
  34. 'name' => 'id-'.$item->id,
  35. 'url' => $item->code
  36. ];
  37. })->toArray();
  38. if($codes){
  39. $zip_file_path = DownUtils::down_invite_temp_code($codes);
  40. return $this->response()->download($zip_file_path);
  41. }else{
  42. return $this->response()->error('下载程序出错');
  43. }
  44. }
  45. /**
  46. * @return string|array|void
  47. */
  48. public function confirm()
  49. {
  50. return ['确定下载选中的推广码?'];
  51. }
  52. /**
  53. * @param Model|Authenticatable|HasPermissions|null $user
  54. *
  55. * @return bool
  56. */
  57. protected function authorize($user): bool
  58. {
  59. return true;
  60. }
  61. /**
  62. * @return array
  63. */
  64. protected function parameters()
  65. {
  66. return [];
  67. }
  68. }