AddressAddController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace Themes\Pro\modunawa\app\Http\Controllers\Shop;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. class AddressAddController extends Controller
  6. {
  7. private $callApiService;
  8. public function __construct(CallApiService $callApiService)
  9. {
  10. $this->callApiService = $callApiService;
  11. }
  12. public function index()
  13. {
  14. return view('views.shop.checkout.address.index')->with('codeTitle', [
  15. "sort('company-destina-bd')",
  16. ]);
  17. }
  18. public function store()
  19. {
  20. $response = $this->callApiService->callApi([
  21. 'url' => 'company-destina-bd-act',
  22. 'data' => [
  23. 'Page' => [
  24. [
  25. 'Id' => 0,
  26. 'ZipCode' => request('zip_code'),
  27. 'Addr1' => request('addr1'),
  28. 'Addr2' => request('addr2'),
  29. 'SeqNo' => (int)request('seq_no'),
  30. 'Sort' => request('sort'),
  31. ]
  32. ]
  33. ]
  34. ]);
  35. if ($this->callApiService->verifyApiError($response)) {
  36. notify()->error($response['body'], 'Error', 'bottomRight');
  37. return redirect()->back();
  38. }
  39. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  40. return redirect()->back();
  41. }
  42. public function show($id)
  43. {
  44. $response = $this->callApiService->callApi([
  45. 'url' => 'company-destina-bd-pick',
  46. 'data' => [
  47. 'Page' => [
  48. [
  49. 'Id' => (int)$id,
  50. ]
  51. ]
  52. ]
  53. ]);
  54. if ($this->callApiService->verifyApiError($response)) {
  55. notify()->error($response['body'], 'Error', 'bottomRight');
  56. echo "<script>window.top.location.href = '" . url()->previous() . "'</script>";
  57. return false;
  58. }
  59. $address = reset($response['Page']);
  60. return view('views.shop.checkout.address.show', compact('address'))->with('codeTitle', [
  61. "sort('company-destina-bd')",
  62. ]);
  63. }
  64. public function update($id)
  65. {
  66. $response = $this->callApiService->callApi([
  67. 'url' => 'company-destina-bd-act',
  68. 'data' => [
  69. 'Page' => [
  70. [
  71. 'Id' => (int)$id,
  72. 'ZipCode' => request('zip_code'),
  73. 'Addr1' => request('addr1'),
  74. 'Addr2' => request('addr2'),
  75. 'Sort' => request('sort'),
  76. ]
  77. ]
  78. ]
  79. ]);
  80. if ($this->callApiService->verifyApiError($response)) {
  81. notify()->error($response['body'], 'Error', 'bottomRight');
  82. return redirect()->back();
  83. }
  84. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  85. return redirect()->back();
  86. }
  87. public function destroy($id){
  88. $response = $this->callApiService->callApi([
  89. 'url' => 'company-destina-bd-act',
  90. 'data' => [
  91. 'Page' => [
  92. [
  93. 'Id' => (int)-$id,
  94. ]
  95. ]
  96. ]
  97. ]);
  98. if ($this->callApiService->verifyApiError($response)) {
  99. return response($response, 200);
  100. }
  101. return response($response, 200);
  102. }
  103. }