MemberEditController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace Themes\kbgolf\pro\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 MemberEditController extends Controller
  8. {
  9. private $callApiService;
  10. public function __construct(CallApiService $callApiService)
  11. {
  12. $this->callApiService = $callApiService;
  13. }
  14. public function index()
  15. {
  16. $memberId = session('member')['MemberId'];
  17. $listType1Book = $this->callApiService->callApi([
  18. 'url' => 'list-type1-book',
  19. 'data' => [
  20. 'Book' => [
  21. [
  22. 'QueryVars' => [
  23. 'QueryName' => 'pro:shop/company-contact-bd',
  24. 'IsntPagination' => true,
  25. ],
  26. 'ListType1Vars' => [
  27. 'OrderBy' => 'sort asc'
  28. ],
  29. 'PageVars' => [
  30. 'Limit' => 100000
  31. ]
  32. ],
  33. [
  34. 'QueryVars' => [
  35. 'QueryName' => 'pro:shop/company-destina-bd',
  36. 'IsntPagination' => true,
  37. ],
  38. 'ListType1Vars' => [
  39. 'OrderBy' => 'sort asc'
  40. ],
  41. 'PageVars' => [
  42. 'Limit' => 100000
  43. ]
  44. ],
  45. [
  46. 'QueryVars' => [
  47. 'QueryName' => 'pro/member-company-single',
  48. 'SimpleFilter' => "mx.id = $memberId",
  49. 'IsntPagination' => true,
  50. ],
  51. 'PageVars' => [
  52. 'Limit' => 100000
  53. ]
  54. ],
  55. ]
  56. ]
  57. ]);
  58. if ($this->callApiService->verifyApiError($listType1Book)) {
  59. notify()->error($listType1Book['body'], 'Error', 'bottomRight');
  60. return redirect()->back();
  61. }
  62. $member = $listType1Book['Book'][2]['Page'][0];
  63. // dump($member);
  64. return view('views.my-page.member-edit', compact('listType1Book', 'member'))
  65. ->with('codeTitle', [
  66. "sort('company-contact-bd')", "sort('company-destina-bd')", "paymethod('sorder')",
  67. ]);
  68. }
  69. public function show()
  70. {
  71. $memberId = session('member')['MemberId'];
  72. $response = $this->callApiService->callApi([
  73. 'url' => 'list-type1-page',
  74. 'data' => [
  75. 'QueryVars' => [
  76. 'QueryName' => 'pro/member-company-single',
  77. 'SimpleFilter' => "mx.id = $memberId",
  78. 'IsntPagination' => true,
  79. ],
  80. 'PageVars' => [
  81. 'Limit' => 100000
  82. ]
  83. ],
  84. ]);
  85. if ($this->callApiService->verifyApiError($response)) {
  86. notify()->error($response['body'], 'Error', 'bottomRight');
  87. echo "<script>window.top.location.href = '" . url()->previous() . "'</script>";
  88. return false;
  89. }
  90. $member = reset($response['Page']);
  91. // dump($member);
  92. return view('views.my-page.member-edit.show', compact('member'));
  93. }
  94. public function update($id)
  95. {
  96. $response = $this->callApiService->callApi([
  97. 'url' => 'member-act',
  98. 'data' => [
  99. 'Page' => [
  100. [
  101. 'Id' => (int)$id,
  102. 'FirstName' => request('first_name'),
  103. ]
  104. ]
  105. ]
  106. ]);
  107. if ($this->callApiService->verifyApiError($response)) {
  108. notify()->error($response['body'], 'Error', 'bottomRight');
  109. return redirect()->back();
  110. }
  111. if (request('van')) {
  112. $company_json = json_encode([
  113. 'Van' => request('van'),
  114. 'VanId' => request('van_id'),
  115. 'VanPw' => request('van_pw'),
  116. ]);
  117. }
  118. // dd($company_json);
  119. $response = $this->callApiService->callApi([
  120. 'url' => 'company-act',
  121. 'data' => [
  122. 'Page' => [
  123. [
  124. 'Id' => (int)session('member')['MemberId'],
  125. 'TaxNo' => request('tax_no'),
  126. 'CompanyJson' => $company_json ?? ''
  127. ]
  128. ]
  129. ]
  130. ]);
  131. if ($this->callApiService->verifyApiError($response)) {
  132. notify()->error($response['body'], 'Error', 'bottomRight');
  133. return redirect()->back();
  134. }
  135. // notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  136. return redirect()->back();
  137. }
  138. }