UserController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Modules\Mini\Controllers;
  3. use App\Base\BaseController;
  4. use App\Models\User\UserAddress;
  5. use App\Models\User\UserFav;
  6. use App\Modules\Mini\Services\AddressService;
  7. use App\Modules\Mini\Services\CompanyService;
  8. use App\Modules\Mini\Services\FavService;
  9. use Illuminate\Support\Facades\Auth;
  10. class UserController extends BaseController
  11. {
  12. public function company()
  13. {
  14. $params = $this->valid([
  15. "name" => "required",
  16. "tax_no" => "",
  17. "department" => "",
  18. "tel" => "",
  19. "address" => "",
  20. "linkman" => "",
  21. ]);
  22. return $this->ok(app(CompanyService::class)->company(Auth::user(), $params));
  23. }
  24. public function fav()
  25. {
  26. $params = $this->valid([
  27. "page_size" => "",
  28. ]);
  29. return $this->ok(app(FavService::class)->paginate(Auth::user(), $params));
  30. }
  31. public function favDel()
  32. {
  33. $params = $this->valid([
  34. "ids" => "array|required",
  35. ]);
  36. return $this->ok([
  37. "row" => UserFav::whereIn("id", $params['ids'])->where("user_id", Auth::id())->delete(),
  38. ]);
  39. }
  40. public function address()
  41. {
  42. $params = $this->valid([
  43. "page_size" => "",
  44. ]);
  45. return $this->ok(app(AddressService::class)->paginate(Auth::user(), $params));
  46. }
  47. public function addressDel()
  48. {
  49. $params = $this->valid([
  50. "id" => "required",
  51. ]);
  52. $row = UserAddress::where("user_id", Auth::id())->where("id", $params['id'])->delete();
  53. return $this->ok([
  54. "row" => $row,
  55. ]);
  56. }
  57. public function addressStore()
  58. {
  59. $params = $this->valid([
  60. "id" => "int",
  61. "is_default" => "",
  62. "name" => "required",
  63. "address" => "required",
  64. 'phone' => "required",
  65. "area" => "required",
  66. ]);
  67. return $this->ok(app(AddressService::class)->store(Auth::user(), $params));
  68. }
  69. }