| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace app\controller\v2;
- use app\extra\basic\Base;
- use app\extra\ip2region\IpSearch;
- use app\middleware\AuthMiddleware;
- use app\model\saas\SaasGoods;
- use app\model\saas\SaasOrderArea;
- use app\model\saas\SaasUserOpen;
- use DI\Attribute\Inject;
- use LinFly\Annotation\Attributes\Route\Controller;
- use LinFly\Annotation\Attributes\Route\GetMapping;
- use LinFly\Annotation\Attributes\Route\Middleware;
- use support\Request;
- use support\Response;
- #[Controller("/v2/goods"),Middleware(AuthMiddleware::class)]
- class Goods extends Base
- {
- #[Inject]
- protected SaasGoods $model;
- protected array $noNeedLogin = ["getGoodsData"];
- #[GetMapping("data")]
- public function getGoodsData(Request $request): Response
- {
- try {
- $param = $this->_valid([
- "goods.require" => trans("empty.require"),
- "spm.default" => "",
- "option.default" => ""
- ],$request->method());
- if (!is_array($param)) return error($param);
- $data = $this->model->where("goods_id",$param['goods'])->with(['poi' => function ($query) {
- $query->field("poi_id,poi_name,poi_address,longitude,latitude,service_mobile,start_at,end_at,status");
- },'skuSpecs'])->append(['otherImg'])->withAttr(['otherImg' => function ($qu,$resp) {
- $img = json_decode($resp['image_list'],true);
- return array_map(function ($v) {
- return $v['url'];
- }, $img);
- }])->findOrEmpty();
- if ($data->isEmpty()) return errorTrans("empty.data");
- if ($data['poi']['status'] <> 1) return error("该店铺已关闭,请联系管理员");
- if (!empty($data['content'])) {
- $data['content'] = filterHtmlTags($data['content'],[
- 'img' => [
- 'remove' => ['width', 'height'],
- 'style' => ['width' => '100%']
- ],
- 'p' => [
- 'style' => ['margin' => '0']
- ]
- ]);
- }
- return $this->encode("success",$data->toArray());
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- #[GetMapping("check")]
- public function checkGoodsUser (Request $request): Response
- {
- try {
- $param = $this->_valid([
- "poi.default" => ""
- ],$request->method());
- if (!is_array($param)) return error($param);
- $user = (new SaasUserOpen)->where(['openid' => $request->user['openid']])->findOrEmpty();
- if ($user->isEmpty()) return error("数据错误");
- $userState = 1;
- $isBuy = 1;
- if (empty($user['avatar'])) {
- $userState = 0;
- }
- if ($user['is_black'] == 1) {
- $isBuy = 0;
- }
- // 查询IP
- $userIp = $request->getRealIp();
- $ipRegion = (new IpSearch)->getIpArea($userIp);
- if (isset($ipRegion[2]) && !empty($param['poi'])) {
- $areaBlack = (new SaasOrderArea)->where(['poi_id' => $param['poi'],'name' => $ipRegion[2]])->findOrEmpty();
- if (!$areaBlack->isEmpty()) {
- $isBuy = 0;
- }
- }
- $msg = "当前门店无库存,请咨询客服";
- return success("ok",['user' => $userState,'buy' => $isBuy,'msg' => $msg]);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|