ソースを参照

商品详情提供二维码扫码进入展示所有按钮

luolinsong 1 ヶ月 前
コミット
38051d8102

+ 68 - 0
fs-admin/src/main/java/com/fs/hisStore/controller/FsStoreProductScrmController.java

@@ -5,13 +5,21 @@ import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
+import com.fs.common.core.domain.entity.SysUser;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
+import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.SecurityUtils;
+import com.fs.common.utils.http.HttpUtils;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.company.domain.CompanyUser;
+import com.fs.hisStore.domain.StoreCompanyCode;
+import com.fs.hisStore.service.IFsStoreCompanyCodeService;
 import com.fs.hisStore.vo.FsStoreProductAttrValueVO;
 import com.fs.hisStore.vo.FsStoreProductExportVO;
 import com.fs.hisStore.vo.FsStoreProductListVO;
 import com.fs.hisStore.vo.FsStoreTuiProductAttrValueVO;
+import com.fs.live.domain.LiveCompanyCode;
 import com.fs.statis.dto.ModifyMoreDTO;
 import com.fs.hisStore.domain.FsStoreProductScrm;
 import com.fs.hisStore.domain.FsStoreProductAttrScrm;
@@ -22,6 +30,10 @@ import com.fs.hisStore.service.IFsStoreProductAttrScrmService;
 import com.fs.hisStore.service.IFsStoreProductAttrValueScrmService;
 import com.fs.hisStore.service.IFsStoreProductScrmService;
 import com.fs.statis.dto.ProductAuditDTO;
+import com.fs.system.oss.OSSFactory;
+import com.fs.wx.miniapp.config.WxMaProperties;
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
 import com.mysql.cj.util.StringUtils;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -33,8 +45,11 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 商品Controller
@@ -56,6 +71,9 @@ public class FsStoreProductScrmController extends BaseController
     @Autowired
     private IFsStoreProductAttrValueScrmService attrValueService;
 
+    @Autowired
+    private IFsStoreCompanyCodeService fsStoreCompanyCodeService;
+
 
     /**
      * 批量修改商品
@@ -234,4 +252,54 @@ public class FsStoreProductScrmController extends BaseController
         return R.ok().put("data",list);
     }
 
+    @Autowired
+    private WxMaProperties properties;
+    @ApiOperation("生成微信小程序码")
+    @GetMapping("/getWxaCodeUnLimit")
+    //@PreAuthorize("@ss.hasPermi('live:live:edit')")
+    public R getWxaCodeUnLimit(@RequestParam(value = "productId") Long productId) {
+        StoreCompanyCode companyCode = fsStoreCompanyCodeService.selectByproductIdAndUserId(productId);
+        if (companyCode == null) {
+            String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
+            HashMap<String, String> map = new HashMap<>();
+            map.put("grant_type", "client_credential");
+
+            // 百域承品
+            map.put("appid", properties.getConfigs().get(0).getAppid());
+            map.put("secret", properties.getConfigs().get(0).getSecret());
+            String accessToken = HttpUtils.endApi(url, null, map);
+            // 创建Gson对象
+            Gson gson = new Gson();
+            // 将JSON字符串解析为Java对象
+            Map<String, String> accessTokenMap = gson.fromJson(accessToken, new TypeToken<Map<String, Object>>() {
+            }.getType());
+            String codeUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessTokenMap.get("access_token");
+            HashMap<String, String> jsonMap = new HashMap<>();
+            jsonMap.put("page", "pages/shopping/productDetails");
+
+
+            String scene = "productId=" + productId + "&isShow=1";
+            jsonMap.put("scene", scene);
+            //正式版为 "release",体验版为 "trial",开发版为 "develop"
+            jsonMap.put("env_version", "release");
+            byte[] bytes = HttpUtils.getWechatQrcodeByHttpURL(codeUrl, jsonMap);
+            if (bytes.length == 0) return R.error("生成二维码失败");
+
+            if (bytes.length > 0 && bytes.length < 500) {
+                String errorCode = new String(bytes, StandardCharsets.UTF_8);
+                logger.error(errorCode);
+                return R.error("生成二维码失败");
+            }
+            // 保存
+            String saveUrl = OSSFactory.build().uploadSuffix(bytes, ".png");
+            Date nowDate = DateUtils.getNowDate();
+            companyCode = new StoreCompanyCode();
+            companyCode.setProductCodeUrl(saveUrl);
+            companyCode.setProductId(productId);
+            companyCode.setUpdateTime(nowDate);
+            companyCode.setCreateTime(nowDate);
+            fsStoreCompanyCodeService.insertLiveCompanyCode(companyCode);
+        }
+        return R.ok().put("data", companyCode);
+    }
 }

+ 22 - 0
fs-service/src/main/java/com/fs/hisStore/domain/StoreCompanyCode.java

@@ -0,0 +1,22 @@
+package com.fs.hisStore.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fs.common.annotation.Excel;
+import com.fs.common.core.domain.BaseEntity;
+import lombok.Data;
+/**
+ * 商品小程序二维码 store_company_code
+ *
+ * @date 2026-01-06
+ */
+@Data
+@TableName("store_company_code")
+public class StoreCompanyCode extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 主键
+     */
+    private Long id;
+    private Long productId;//商品唯一标识
+    private String productCodeUrl;
+}

+ 2 - 1
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreProductScrmMapper.java

@@ -76,8 +76,9 @@ public interface FsStoreProductScrmMapper
      */
     public int deleteFsStoreProductByIds(Long[] productIds);
     @Select({"<script> " +
-            "select p.*,pc.cate_name, fs.store_name from fs_store_product_scrm p left join fs_store_product_category_scrm pc on p.cate_id=pc.cate_id  " +
+            "select p.*,pc.cate_name, fs.store_name ,scc.product_code_url from fs_store_product_scrm p left join fs_store_product_category_scrm pc on p.cate_id=pc.cate_id  " +
             "left join fs_store fs on fs.store_id = p.store_id " +
+            "left join store_company_code scc on scc.product_id = p.product_id " +
             "where 1=1 " +
             "<if test = 'maps.productName != null and  maps.productName !=\"\"    '> " +
             "and p.product_name like CONCAT('%',#{maps.productName},'%') " +

+ 13 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/IFsStoreCompanyCodeMapper.java

@@ -0,0 +1,13 @@
+package com.fs.hisStore.mapper;
+
+import com.fs.hisStore.domain.StoreCompanyCode;
+import org.apache.ibatis.annotations.Param;
+
+public interface IFsStoreCompanyCodeMapper {
+
+    StoreCompanyCode selectByproductIdAndUserId(@Param("productId") Long productId);
+
+    void insertLiveCompanyCode(StoreCompanyCode companyCode);
+
+    void updateLiveCompanyCode(StoreCompanyCode companyCode);
+}

+ 12 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreCompanyCodeService.java

@@ -0,0 +1,12 @@
+package com.fs.hisStore.service;
+
+import com.fs.hisStore.domain.StoreCompanyCode;
+
+public interface IFsStoreCompanyCodeService {
+
+    StoreCompanyCode selectByproductIdAndUserId(Long productId);
+
+    void insertLiveCompanyCode(StoreCompanyCode companyCode);
+
+    void updateLiveCompanyCode(StoreCompanyCode companyCode);
+}

+ 32 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/IFsStoreCompanyCodeServiceImpl.java

@@ -0,0 +1,32 @@
+package com.fs.hisStore.service.impl;
+
+import com.fs.hisStore.domain.StoreCompanyCode;
+import com.fs.hisStore.mapper.IFsStoreCompanyCodeMapper;
+import com.fs.hisStore.service.IFsStoreCompanyCodeService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+@Service
+@Slf4j
+public class IFsStoreCompanyCodeServiceImpl  implements IFsStoreCompanyCodeService {
+
+    @Autowired
+    private IFsStoreCompanyCodeMapper fsStoreCompanyCodeMapper;
+
+    @Override
+    public StoreCompanyCode selectByproductIdAndUserId(Long productId) {
+        return fsStoreCompanyCodeMapper.selectByproductIdAndUserId(productId);
+    }
+
+    @Override
+    public void insertLiveCompanyCode(StoreCompanyCode companyCode) {
+        fsStoreCompanyCodeMapper.insertLiveCompanyCode(companyCode);
+    }
+
+    @Override
+    public void updateLiveCompanyCode(StoreCompanyCode companyCode) {
+        fsStoreCompanyCodeMapper.updateLiveCompanyCode(companyCode);
+    }
+}

+ 1 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreProductListVO.java

@@ -117,4 +117,5 @@ public class FsStoreProductListVO  implements Serializable
     private String storeId;
     private String storeName;
 
+    private String productCodeUrl;
 }

+ 54 - 0
fs-service/src/main/resources/mapper/hisStore/FsStoreCompanyCodeMapper.xml

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.hisStore.mapper.IFsStoreCompanyCodeMapper">
+
+    <resultMap type="StoreCompanyCode" id="StoreCompanyCodeResult">
+        <result property="id" column="id"/>
+        <result property="productId" column="product_id"/>
+        <result property="productCodeUrl" column="product_code_url"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateTime" column="update_time"/>
+    </resultMap>
+
+    <sql id="selectFsStoreRecommendScrmVo">
+        select * from store_company_code
+    </sql>
+    <insert id="insertLiveCompanyCode">
+        insert into store_company_code
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">id,</if>
+            <if test="productId != null">product_id,</if>
+            <if test="productCodeUrl != null">product_code_url,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateTime != null">update_time,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">#{id},</if>
+            <if test="productId != null">#{productId},</if>
+            <if test="productCodeUrl != null">#{productCodeUrl},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+        </trim>
+    </insert>
+
+
+    <update id="updateLiveCompanyCode">
+        update store_company_code
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="productId != null">product_id = #{productId},</if>
+
+            <if test="productCodeUrl != null">product_code_url = #{productCodeUrl},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <select id="selectByproductIdAndUserId" resultType="com.fs.hisStore.domain.StoreCompanyCode">
+        select * from store_company_code where product_id = #{productId}
+    </select>
+
+
+</mapper>