Merchant.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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\merchant;
  12. use app\controller\api\store\product\BindSpreadTrait;
  13. use app\common\repositories\store\service\StoreServiceRepository;
  14. use app\common\repositories\user\UserMerchantRepository;
  15. use think\App;
  16. use crmeb\basic\BaseController;
  17. use app\common\repositories\system\merchant\MerchantRepository as repository;
  18. class Merchant extends BaseController
  19. {
  20. use BindSpreadTrait;
  21. protected $repository;
  22. protected $userInfo;
  23. /**
  24. * ProductCategory constructor.
  25. * @param App $app
  26. * @param repository $repository
  27. */
  28. public function __construct(App $app, repository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. $this->userInfo =$this->request->isLogin() ? $this->request->userInfo():null;
  33. }
  34. /**
  35. * 获取列表数据
  36. * 本函数旨在根据用户请求的参数,获取对应的数据列表。支持通过关键字、排序方式、最佳标识、位置、类别ID、类型ID和商家标识等条件进行筛选。
  37. * @return json 返回一个包含获取的数据列表的JSON对象,其中列表数据由repository层的getList方法提供。
  38. */
  39. public function lst()
  40. {
  41. // 解构获取当前页码和每页显示数量
  42. [$page, $limit] = $this->getPage();
  43. // 从请求中获取查询参数
  44. $where = $this->request->params(['keyword', 'order', 'is_best', 'location', 'category_id', 'type_id','is_trader']);
  45. // 调用getList方法获取数据列表,并返回成功响应的JSON对象
  46. return app('json')->success($this->repository->getList($where, $page, $limit, $this->userInfo));
  47. }
  48. /**
  49. * 获取店铺详情
  50. *
  51. * 本函数通过传入的店铺ID,获取该店铺的详细信息并返回给调用者。
  52. * 如果店铺已关闭,则返回错误信息;如果用户已登录,更新用户访问店铺的时间。
  53. * 最后,返回店铺的详细信息。
  54. *
  55. * @param int $id 店铺的唯一标识ID
  56. * @return json 返回包含店铺详情的JSON数据
  57. */
  58. public function detail($id)
  59. {
  60. $this->bindSpread();
  61. // 检查店铺是否营业,若不营业则返回错误信息
  62. if (!$this->repository->apiGetOne($id))
  63. return app('json')->fail('店铺已打烊');
  64. // 如果用户已登录,更新用户访问该店铺的最后时间
  65. if ($this->request->isLogin()) {
  66. app()->make(UserMerchantRepository::class)->updateLastTime($this->request->uid(), intval($id));
  67. }
  68. // 返回店铺的详细信息
  69. return app('json')->success($this->repository->detail($id, $this->userInfo));
  70. }
  71. /**
  72. * 获取系统详情信息
  73. *
  74. * 本函数用于获取系统的详细配置信息,并以特定格式返回给调用者。
  75. * 主要包括站点的logo、名称以及登录页面的logo等信息。返回的数据结构中,
  76. * 各项信息被组织成一个便于使用的数组,以便前端或其他调用者能够轻松访问。
  77. *
  78. * @return \Illuminate\Http\JsonResponse 系统详情信息的JSON响应
  79. */
  80. public function systemDetail()
  81. {
  82. // 从系统配置中提取特定的配置项,包括站点logo、站点名称和登录logo
  83. $config = systemConfig(['site_logo', 'site_name','login_logo']);
  84. // 构建并返回包含系统详情的JSON响应,其中mer_id固定为0,各项评分默认为5.0
  85. return app('json')->success([
  86. 'mer_avatar' => $config['site_logo'], // 站点logo
  87. 'mer_name' => $config['site_name'], // 站点名称
  88. 'mer_id' => 0, // 商户ID,此处固定为0
  89. 'postage_score' => '5.0', // 物流评分,默认为5.0
  90. 'product_score' => '5.0', // 产品评分,默认为5.0
  91. 'service_score' => '5.0', // 服务评分,默认为5.0
  92. ]);
  93. }
  94. /**
  95. * @Author:Qinii
  96. * @Date: 2020/5/29
  97. * @param $id
  98. * @return mixed
  99. */
  100. public function productList($id)
  101. {
  102. [$page, $limit] = $this->getPage();
  103. $where = $this->request->params(['keyword','order','mer_cate_id','cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid']);
  104. if(!$this->repository->apiGetOne($id)) return app('json')->fail(' 店铺已打烊');
  105. return app('json')->success($this->repository->productList($id,$where, $page, $limit,$this->userInfo));
  106. }
  107. /**
  108. * @Author:Qinii
  109. * @Date: 2020/5/29
  110. * @param int $id
  111. * @return mixed
  112. */
  113. public function categoryList($id)
  114. {
  115. if(!$this->repository->merExists((int)$id))
  116. return app('json')->fail('店铺已打烊');
  117. return app('json')->success($this->repository->categoryList($id));
  118. }
  119. public function qrcode($id)
  120. {
  121. if(!$this->repository->merExists((int)$id))
  122. return app('json')->fail('店铺已打烊');
  123. $url = $this->request->param('type') == 'routine' ? $this->repository->routineQrcode(intval($id)) : $this->repository->wxQrcode(intval($id));
  124. return app('json')->success(compact('url'));
  125. }
  126. public function localLst()
  127. {
  128. [$page, $limit] = $this->getPage();
  129. $where = $this->request->params(['keyword', 'order', 'is_best', 'location', 'category_id', 'type_id']);
  130. $where['delivery_way'] = 1;
  131. return app('json')->success($this->repository->getList($where, $page, $limit, $this->userInfo));
  132. }
  133. public function localDetail(int $id)
  134. {
  135. $params = $this->request->params(['latitude', 'longitude']);
  136. if(!$params['latitude'] || !$params['longitude']){
  137. return app('json')->fail('缺少经纬度');
  138. }
  139. return app('json')->success($this->repository->getDistance($id, $params));
  140. }
  141. }