UserInviteTmpCodeBgDownBatchAction.php 2.0 KB

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