1
0
فهرست منبع

小程序首页修改切换门店逻辑,后台新增生成门店二维码功能

hyq 6 سال پیش
والد
کامیت
150d7a5249

+ 114 - 0
kmall-admin/src/main/java/com/kmall/admin/controller/StoreController.java

@@ -4,16 +4,41 @@ import com.google.common.collect.ImmutableBiMap;
 import com.kmall.admin.entity.StoreEntity;
 import com.kmall.admin.service.StoreService;
 import com.kmall.admin.utils.ParamUtils;
+import com.kmall.api.service.pay.wxpay.WxPayPropertiesBuilder;
 import com.kmall.common.entity.SysUserEntity;
+import com.kmall.common.fileserver.util.FileManager;
 import com.kmall.common.utils.*;
+import com.kmall.common.utils.wechat.AccessToken;
+import com.kmall.common.utils.wxtemplate.WxTemplateUtil;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.disk.DiskFileItem;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.util.EntityUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.*;
+import java.nio.file.Files;
 import java.util.List;
 import java.util.Map;
 
+import java.util.HashMap;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.protocol.HTTP;
+
+import com.alibaba.fastjson.JSON;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+
 /**
  * Controller
  *
@@ -161,4 +186,93 @@ public class StoreController {
         List<StoreEntity> list = storeService.queryList(params);
         return R.ok().put("list", list);
     }
+
+    @RequestMapping("/qrcodeCanvas/{storeId}")
+    @RequiresPermissions("store:qrcodeCanvas")
+    @ResponseBody
+    public R qrcodeCanvas(@PathVariable("storeId") Integer storeId) {
+        StoreEntity store = storeService.queryObject(storeId);
+        if(store==null){
+            throw new RRException("门店信息不存在");
+        }
+        AccessToken accessToken = WxTemplateUtil.getAccessToken(WxPayPropertiesBuilder.instance().getAppId(),WxPayPropertiesBuilder.instance().getSecret());
+        if(accessToken == null){
+            throw new RRException("token获取失败");
+        }
+        String token = accessToken.getToken();
+
+        //构建请求参数
+        Map<Object, Object> params = new HashMap<Object, Object>();
+        params.put("scene", "text");//参数
+        params.put("page", "pages/index/index");//页面
+        params.put("width", 430);
+        String mapToXml = JSON.toJSONString(params);
+
+        try {
+            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+
+            HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token);
+            httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
+            StringEntity entity = new StringEntity(mapToXml);
+            entity.setContentType("image/png");
+
+            httpPost.setEntity(entity);
+            HttpResponse response = httpClient.execute(httpPost);
+            InputStream inputStream = response.getEntity().getContent();
+
+            String fileName = System.currentTimeMillis()+"_"+storeId+".png";
+            String dirName = "\\upload";
+            File dirFile = new File(dirName);
+            //删除之前的图片文件夹
+            deleteFile(dirFile);
+            if(!dirFile.exists()){
+                dirFile.mkdirs();
+            }
+
+            File file = new File(dirName, fileName);// 可以是任何图片格式.jpg,.png等
+            FileOutputStream fos = new FileOutputStream(file);
+            if (inputStream != null) {
+                try {
+                    byte[] b = new byte[1024];
+                    int nRead = 0;
+                    while ((nRead = inputStream.read(b)) != -1) {
+                        fos.write(b, 0, nRead);
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                } finally {
+
+                    try {
+                        fos.flush();
+                        fos.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+            FileItem fileItem = new DiskFileItem("mainFile", Files.probeContentType(file.toPath()), false,
+                    file.getName(), (int) file.length(), file.getParentFile());
+            try (InputStream input = new FileInputStream(file); OutputStream os = fileItem.getOutputStream();) {
+                IOUtils.copy(input, os);
+                MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
+                String url = FileManager.upload(multipartFile);
+                return R.ok().put("url", url);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return R.ok().put("url", "");
+    }
+
+    private void deleteFile(File dirFile){
+        if(dirFile.exists()){
+            if(dirFile.isFile()){
+                dirFile.delete();
+            }else {
+                for(File file:dirFile.listFiles()){
+                    deleteFile(file);
+                }
+            }
+        }
+    }
 }

+ 1 - 1
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -323,7 +323,7 @@ public class GoodsServiceImpl implements GoodsService {
         if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
             for (ProductStoreRelaEntity productStoreRela : productStoreRelaEntityList) {
                 //修改该商品的所属商户信息,如在该商户门店中有该上架的商品信息,则提示该商品不能修改
-                if(productStoreRela.getMerchSn().equalsIgnoreCase(goods.getMerchSn())
+                if(org.apache.commons.lang3.StringUtils.isNotEmpty(productStoreRela.getMerchSn()) && productStoreRela.getMerchSn().equalsIgnoreCase(goods.getMerchSn())
                         && goods.getIsOnSale() == Integer.parseInt(Dict.isOnSale.item_1.getItem())) {
                     if (goods.getRetailPrice() != null) {
                         productStoreRela.setRetailPrice(goods.getRetailPrice());

+ 6 - 0
kmall-admin/src/main/webapp/WEB-INF/page/shop/store.html

@@ -99,6 +99,12 @@
         </i-form>
     </Card>
 </div>
+<div id="qrcode" style="display: none;padding: 10px;">
+    <div id="qrcodeCanvas" style="margin: 20px 0 0 55px"></div>
+</div>
+<div id="qrcImg" style="display:none">
+    <img class="qrcImg align-center" height="300px" width="300px" src="">
+</div>
 
 <script src="${rc.contextPath}/js/shop/store.js?_${date.systemTime}"></script>
 </body>

+ 34 - 1
kmall-admin/src/main/webapp/js/shop/store.js

@@ -17,7 +17,14 @@ $(function () {
             {label: '纬度', name: 'latitude', index: 'latitude', width: 80},
             {label: '经度', name: 'longitude', index: 'longitude', width: 80},
             {label: '配送半径(km)', name: 'coverRadius', index: 'cover_radius', width: 80},
-            {label: '备注', name: 'remark', index: 'remark', width: 80}],
+            {label: '备注', name: 'remark', index: 'remark', width: 80},
+            {
+                label: '操作', width: 60, align: 'center', sortable: false, formatter: function (value, col, row) {
+                    let htmlStr = "<button class='btn btn-outline btn-primary' " +
+                        "onclick='vm.qrcodeCanvas(" + row.id + ")'><i class='fa fa-qrcode'></i>二维码</button>";
+                    return htmlStr;
+                }
+            }],
         viewrecords: true,
         height: 385,
         rowNum: 10,
@@ -160,6 +167,32 @@ let vm = new Vue({
             }).trigger("reloadGrid");
             vm.handleReset('formValidate');
         },
+        qrcodeCanvas: function(storeId) {
+            $("#qrcodeCanvas").html("");
+            $.get("../store/qrcodeCanvas/" + storeId, function (r) {
+                console.log(r.url);
+                var qrcSrc = r.url;
+                $("#qrcImg .qrcImg").attr("src", qrcSrc);
+                // $("#qrcImg").show();//隐藏canvas部分
+
+                $("#qrcodeCanvas").html($("#qrcImg").html());
+
+                openWindow({
+                    title: "二维码",
+                    area: ['450px', '450px'],
+                    content: jQuery("#qrcode"),
+                    btn: ["打印"],
+                    btn1: function (index) {
+                        $("#qrcImg").show();
+                        $("#qrcImg").print({});
+                        $("#qrcImg").hide();
+                        layer.close(index);
+                    }
+                });
+            });
+
+            $("#qrcImg").hide();
+        },
         handleSubmit: function (name) {
             handleSubmitValidate(this, name, function () {
                 vm.saveOrUpdate()

+ 1 - 0
kmall-admin/src/main/webapp/js/shop/storeProductStock.js

@@ -332,6 +332,7 @@ var vm = new Vue({
             });
 
             var qrcSrc = $("canvas")[0].toDataURL();
+            console.log(qrcSrc);
             $("#qrcImg .qrcImg").attr("src", qrcSrc);
             var upLogSrc = "../../statics/img/logo.jpg";
             $("#qrcImg .upLogo").attr("src", upLogSrc);

+ 1 - 0
kmall-admin/src/main/webapp/statics/mpdswl/CMmUrfS5RI.txt

@@ -0,0 +1 @@
+cf0d165db21e8f2f26803b15bdd53b0c

+ 4 - 1
kmall-api/src/main/java/com/kmall/api/api/ApiAuthController.java

@@ -139,8 +139,11 @@ public class ApiAuthController extends ApiBaseAction {
      */
     @GetMapping("nearbyList")
     @IgnoreAuth
-    public Object nearbyList(@RequestParam BigDecimal latitude, @RequestParam BigDecimal longitude) {
+    public Object nearbyList(@RequestParam BigDecimal latitude, @RequestParam BigDecimal longitude,@RequestParam String storeId) {
         Map param = new HashMap();
+        if(org.apache.commons.lang3.StringUtils.isNotEmpty(storeId)){
+            param.put("storeId", storeId);
+        }
         param.put("latitude", latitude);
         param.put("longitude", longitude);
         List<StoreVo> storeVoList = apiStoreService.queryNearbyList(param);

+ 3 - 0
kmall-api/src/main/resources/mybatis/mapper/ApiStoreMapper.xml

@@ -175,6 +175,9 @@
         <if test="county_name != null and county_name.trim() != ''">
             AND county_name = #{county_name}
         </if>
+        <if test="storeId != null ">
+            AND a.id = #{storeId}
+        </if>
         ) tmp
         order by distance asc
         limit 0, 10

+ 15 - 1
wx-mall/pages/index/index.js

@@ -72,6 +72,16 @@ Page({
   onLoad: function (options) {
     let that = this;
     wx.setStorageSync("navUrl", "/pages/index/index");
+    if (options.scene) {
+      console.log("has scene");
+      var scene = decodeURIComponent(options.scene);
+      console.log("scene is ", scene);
+      that.setData({
+        storeId: scene
+      });
+    } else {
+      console.log("no scene");
+    }
   },
   onReady: function () {
     // 页面渲染完成
@@ -164,9 +174,13 @@ Page({
     //获取附件门店信息
     util.getLocation((lng, lat) => {
       wx.setStorageSync('location', JSON.stringify({ lng, lat }));
-      util.request(api.NearbyList, { longitude: lng, latitude: lat }).then((res) => {
+      util.request(api.NearbyList, { longitude: lng, latitude: lat, storeId: that.data.storeId }).then((res) => {
         let nlist = res.data;
         // console.log(nlist);
+        wx.removeStorageSync('nearStoreList');
+        wx.removeStorageSync('storeId');
+        wx.removeStorageSync('storeVo');
+        wx.removeStorageSync('currentCategory');
         if (!nlist.length) {
           wx.removeStorageSync('nearStoreList');
         } else {

+ 2 - 1
wx-mall/pages/index/index.wxml

@@ -24,7 +24,8 @@
     <image src="../../static/images/service-sao.png" class="search-icon-shop" bindtap="scanGoodsCode"></image>
   </view>
   <view class="home-header">
-    <view bindtap="handleStore" class="current-store arrow arrow-down">{{ storeName }}</view>
+    <!-- <view bindtap="handleStore" class="current-store arrow arrow-down">{{ storeName }}</view> -->
+    <view class="current-store">{{ storeName }}</view>
   </view>
 
   <swiper class="banner" indicator-dots="true" autoplay="true" interval="15000" duration="750">