OrderController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Themes\Pro\modunawa\app\Http\Controllers\MyPage;
  3. use App\Helpers\ResponseConverter;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\CallApiService;
  6. use Illuminate\Pagination\LengthAwarePaginator;
  7. class OrderController extends Controller
  8. {
  9. private $callApiService;
  10. public function __construct(CallApiService $callApiService)
  11. {
  12. $this->callApiService = $callApiService;
  13. }
  14. public function list()
  15. {
  16. $limit = (int)request('limit', 5);
  17. $page = (int)request('page', 1);
  18. $status = request('filter', '');
  19. $listType1Book = $this->callApiService->callApi([
  20. 'url' => 'list-type1-book',
  21. 'data' => [
  22. 'Book' => [
  23. [
  24. 'QueryVars' => [
  25. 'QueryName' => 'pro:shop/sorder',
  26. 'IsntPagination' => false,
  27. 'SimpleFilter' => $status === '' ? '' : "mx.status = '$status'"
  28. ],
  29. 'ListType1Vars' => [
  30. 'OrderBy' => 'mx.sorder_no desc'
  31. ],
  32. 'PageVars' => [
  33. 'Limit' => $limit,
  34. 'Offset' => ($page - 1) * $limit
  35. ]
  36. ],
  37. [
  38. 'QueryVars' => [
  39. 'QueryName' => 'pro:shop/sorder-bd',
  40. 'IsntPagination' => true,
  41. 'SimpleFilter' => "",
  42. 'SubSimpleFilter' => "image_type = 'thumb'",
  43. ],
  44. 'PageVars' => [
  45. 'Limit' => 100000
  46. ]
  47. ],
  48. ]
  49. ]
  50. ]);
  51. // dump($listType1Book);
  52. if ($this->callApiService->verifyApiError($listType1Book)) {
  53. notify()->error($listType1Book['body'], 'Error', 'bottomRight');
  54. return redirect()->back();
  55. }
  56. $orderCharge['count'] = collect($listType1Book['Book'][0]['Page'])->count();
  57. $hd = $listType1Book['Book'][0];
  58. $orderPage = ResponseConverter::joinFor($hd['Page'], $listType1Book['Book'][1]['Page']);
  59. $hd['Page'] = new LengthAwarePaginator($orderPage, $hd['PageVars']['QueryCnt'],
  60. $limit, $page, ['path' => request()->url()]);
  61. // dump($hd);
  62. return view('views.my-page.order-list', compact('orderCharge', 'hd'))->with('codeTitle', [
  63. "status('sorder')",
  64. ]);
  65. }
  66. }