Goods.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 app\model\saas\SaasUserOpen;
  7. use DI\Attribute\Inject;
  8. use LinFly\Annotation\Attributes\Route\Controller;
  9. use LinFly\Annotation\Attributes\Route\GetMapping;
  10. use LinFly\Annotation\Attributes\Route\Middleware;
  11. use support\Request;
  12. use support\Response;
  13. #[Controller("/v2/goods"),Middleware(AuthMiddleware::class)]
  14. class Goods extends Base
  15. {
  16. #[Inject]
  17. protected SaasGoods $model;
  18. protected array $noNeedLogin = ["getGoodsData"];
  19. #[GetMapping("data")]
  20. public function getGoodsData(Request $request): Response
  21. {
  22. try {
  23. $param = $this->_valid([
  24. "goods.require" => trans("empty.require"),
  25. "spm.default" => "",
  26. "option.default" => ""
  27. ],$request->method());
  28. if (!is_array($param)) return error($param);
  29. $data = $this->model->where("goods_id",$param['goods'])->with(['poi' => function ($query) {
  30. $query->field("poi_id,poi_name,poi_address,longitude,latitude,service_mobile,start_at,end_at,status");
  31. },'skuSpecs'])->append(['otherImg'])->withAttr(['otherImg' => function ($qu,$resp) {
  32. $img = json_decode($resp['image_list'],true);
  33. return array_map(function ($v) {
  34. return $v['url'];
  35. }, $img);
  36. }])->findOrEmpty();
  37. if ($data->isEmpty()) return errorTrans("empty.data");
  38. if ($data['poi']['status'] <> 1) return error("该店铺已关闭,请联系管理员");
  39. if (!empty($data['content'])) {
  40. $data['content'] = filterHtmlTags($data['content'],[
  41. 'img' => [
  42. 'remove' => ['width', 'height'],
  43. 'style' => ['width' => '100%']
  44. ],
  45. 'p' => [
  46. 'style' => ['margin' => '0']
  47. ]
  48. ]);
  49. }
  50. return $this->encode("success",$data->toArray());
  51. } catch (\Throwable $th) {
  52. return error($th->getMessage());
  53. }
  54. }
  55. #[GetMapping("check")]
  56. public function checkGoodsUser (Request $request): Response
  57. {
  58. try {
  59. $user = (new SaasUserOpen)->where(['openid' => $request->user['openid']])->findOrEmpty();
  60. if ($user->isEmpty()) return error("数据错误");
  61. $userState = 1;
  62. if (empty($user['avatar'])) {
  63. $userState = 0;
  64. }
  65. return success("ok",['user' => $userState]);
  66. } catch (\Throwable $throwable) {
  67. return error($throwable->getMessage());
  68. }
  69. }
  70. }