Goods.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\controller\v2;
  3. use app\extra\basic\Base;
  4. use app\middleware\AuthMiddleware;
  5. use app\model\saas\SaasGoods;
  6. use DI\Attribute\Inject;
  7. use LinFly\Annotation\Attributes\Route\Controller;
  8. use LinFly\Annotation\Attributes\Route\GetMapping;
  9. use LinFly\Annotation\Attributes\Route\Middleware;
  10. use support\Request;
  11. use support\Response;
  12. #[Controller("/v2/goods"),Middleware(AuthMiddleware::class)]
  13. class Goods extends Base
  14. {
  15. #[Inject]
  16. protected SaasGoods $model;
  17. protected array $noNeedLogin = ["getGoodsData"];
  18. #[GetMapping("data")]
  19. public function getGoodsData(Request $request): Response
  20. {
  21. try {
  22. $param = $this->_valid([
  23. "goods.require" => trans("empty.require"),
  24. "spm.default" => "",
  25. "option.default" => ""
  26. ],$request->method());
  27. if (!is_array($param)) return error($param);
  28. $data = $this->model->where("goods_id",$param['goods'])->with(['poi' => function ($query) {
  29. $query->field("poi_id,poi_name,poi_address,longitude,latitude,service_mobile,start_at,end_at,status");
  30. },'skuSpecs'])->append(['otherImg'])->withAttr(['otherImg' => function ($qu,$resp) {
  31. $img = json_decode($resp['image_list'],true);
  32. return array_map(function ($v) {
  33. return $v['url'];
  34. }, $img);
  35. }])->findOrEmpty();
  36. if ($data->isEmpty()) return errorTrans("empty.data");
  37. if ($data['poi']['status'] <> 1) return error("该店铺已关闭,请联系管理员");
  38. if (!empty($data['content'])) {
  39. $data['content'] = filterHtmlTags($data['content'],[
  40. 'img' => [
  41. 'remove' => ['width', 'height'],
  42. 'style' => ['width' => '100%']
  43. ],
  44. 'p' => [
  45. 'style' => ['margin' => '0']
  46. ]
  47. ]);
  48. }
  49. return $this->encode("success",$data->toArray());
  50. } catch (\Throwable $th) {
  51. return error($th->getMessage());
  52. }
  53. }
  54. }