StoreProductPresell.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\store\product;
  12. use app\common\repositories\system\CacheRepository;
  13. use think\App;
  14. use crmeb\basic\BaseController;
  15. use app\common\repositories\store\product\ProductPresellRepository;
  16. class StoreProductPresell extends BaseController
  17. {
  18. use BindSpreadTrait;
  19. protected $repository;
  20. protected $userInfo;
  21. /**
  22. * StoreProductPresell constructor.
  23. * @param App $app
  24. * @param repository $repository
  25. */
  26. public function __construct(App $app, ProductPresellRepository $repository)
  27. {
  28. parent::__construct($app);
  29. $this->repository = $repository;
  30. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  31. }
  32. /**
  33. * 获取列表数据
  34. *
  35. * 本函数用于根据请求参数获取对应列表的分页数据。
  36. * 通过解析请求中的参数,确定查询条件,进而调用仓库层的方法获取数据。
  37. * 返回的数据格式化为JSON,用于前端展示。
  38. *
  39. * @return \think\response\Json
  40. */
  41. public function lst()
  42. {
  43. // 解析并获取当前请求的分页信息
  44. [$page, $limit] = $this->getPage();
  45. // 从请求中获取查询参数,包括类型(type),星级(star)和商户ID(mer_id)
  46. $where = $this->request->params([['type',4],'star','mer_id']);
  47. // 调用仓库层的getApiList方法获取数据,并返回格式化后的JSON响应
  48. return app('json')->success($this->repository->getApiList($where, $page, $limit));
  49. }
  50. /**
  51. * 获取详细信息
  52. *
  53. * 通过指定的ID从仓库中获取资源的详细信息。此方法封装了与仓库的交互,
  54. * 以及成功获取数据后的响应处理。它使用了依赖注入来获取必要的依赖项,
  55. * 并依赖于应用程序容器来返回JSON响应。
  56. *
  57. * @param int $id 资源的唯一标识符。转换为整数类型以确保数据类型安全。
  58. * @return \Illuminate\Http\JsonResponse 成功获取数据时返回的JSON响应,包含获取的数据。
  59. */
  60. public function detail($id)
  61. {
  62. $this->bindSpread($this->userInfo);
  63. // 通过ID和用户信息从仓库中获取资源的详细信息
  64. $data = $this->repository->apiDetail((int)$id, $this->userInfo);
  65. // 返回成功的JSON响应,包含获取的资源详细信息
  66. return app('json')->success($data);
  67. }
  68. /**
  69. * 获取预售协议内容
  70. *
  71. * 本方法用于获取系统预设的预售协议内容。通过缓存机制获取协议文本,提高获取速度并减少对数据库的直接访问。
  72. * 返回的内容是经过成功处理的JSON数据,方便前端直接解析展示。
  73. *
  74. * @return \Illuminate\Http\JsonResponse 返回包含预售协议内容的JSON响应
  75. */
  76. public function getAgree()
  77. {
  78. // 通过依赖注入的方式创建并获取缓存仓库实例
  79. $make = app()->make(CacheRepository::class);
  80. // 返回成功状态的JSON响应,其中包含从缓存中获取的预售协议内容
  81. return app('json')->success($make->getResult('sys_product_presell_agree'));
  82. }
  83. }