diff --git a/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java b/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java index 652b97b..4040991 100644 --- a/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java +++ b/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java @@ -432,6 +432,14 @@ public class ChannelController { return result; } + @RequestMapping(value = "openAddress",method = RequestMethod.GET) + @ApiOperation(value = "开启配送,或者关闭配送") + public BaseDto openAddress(int id){ + ChannelProduct channelProduct = channelProductService.getDetail(id); + channelProductService.updateProductOpenAddress(channelProduct.getOpenAddress()==1?0:1,id); + return new BaseDto(); + } + @RequestMapping(value = "GetDiscountPackage",method = RequestMethod.GET) @ApiOperation(value = "获取商品详情") public BaseDto GetDiscountPackage(int id){ @@ -589,6 +597,7 @@ public class ChannelController { object.put("score_id",0); object.put("channelId",order.getChannelId()); object.put("agentId",order.getAgentId()); + object.put("address",order.getAddress()); JSONObject jsonObject = HttpClientUtils.httpPostJson(domain+"/University/GetAddOrderDetail",object.toJSONString()); String data = jsonObject.getString("data"); result.setData(JSON.parseObject(data,new TypeReference>(){})); diff --git a/src/main/java/com/sincere/wechatbusiness/controller/CodeController.java b/src/main/java/com/sincere/wechatbusiness/controller/CodeController.java new file mode 100644 index 0000000..7c6f003 --- /dev/null +++ b/src/main/java/com/sincere/wechatbusiness/controller/CodeController.java @@ -0,0 +1,58 @@ +//package com.sincere.wechatbusiness.controller; +// +//import com.alibaba.fastjson.JSONObject; +//import com.sincere.wechatbusiness.utils.HttpClientUtils; +//import org.springframework.web.bind.annotation.RestController; +// +//import java.io.*; +//import java.net.HttpURLConnection; +//import java.net.URL; +// +//@RestController +//public class CodeController { +// +// private static String appId = "wxd055a716238e1bd7"; +// private static String secret = "c6912d34732b65116b8b4e9d5f8a81a5"; +// +// public static void main(String[] args){ +// String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret; +// JSONObject object = HttpClientUtils.httpGet(url) ; +// String token = object.get("access_token").toString(); +// try { +// URL imgUrl = new URL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token); +// HttpURLConnection httpURLConnection = (HttpURLConnection) imgUrl.openConnection(); +// httpURLConnection.setRequestMethod("POST");// 提交模式 +// // conn.setConnectTimeout(10000);//连接超时 单位毫秒 +// // conn.setReadTimeout(2000);//读取超时 单位毫秒 +// // 发送POST请求必须设置如下两行 +// httpURLConnection.setDoOutput(true); +// httpURLConnection.setDoInput(true); +// // 获取URLConnection对象对应的输出流 +// PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream()); +// // 发送请求参数 +// JSONObject paramJson = new JSONObject(); +// paramJson.put("scene", "channel=2"); +// paramJson.put("page", "pages/index/index"); +// paramJson.put("width", 430); +// paramJson.put("auto_color", true); +// printWriter.write(paramJson.toString()); +// // flush输出流的缓冲 +// printWriter.flush(); +// //开始获取数据 +// BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream()); +// OutputStream os = new FileOutputStream(new File("C:\\Users\\chen\\Desktop\\abc.png")); +// int len; +// byte[] arr = new byte[1024]; +// while ((len = bis.read(arr)) != -1) +// { +// os.write(arr, 0, len); +// os.flush(); +// } +// os.close(); +// } +// catch (Exception e) +// { +// e.printStackTrace(); +// } +// } +//} diff --git a/src/main/java/com/sincere/wechatbusiness/controller/TestController.java b/src/main/java/com/sincere/wechatbusiness/controller/TestController.java new file mode 100644 index 0000000..640e18b --- /dev/null +++ b/src/main/java/com/sincere/wechatbusiness/controller/TestController.java @@ -0,0 +1,107 @@ +//package com.sincere.wechatbusiness.controller; +// +//import com.sincere.wechatbusiness.dto.BaseDto; +//import com.sincere.wechatbusiness.mapper.ChannelMapper; +//import com.sincere.wechatbusiness.model.Banner; +//import com.sincere.wechatbusiness.model.BannerNext; +//import com.sincere.wechatbusiness.model.ChannelProduct; +//import com.sincere.wechatbusiness.service.BannerService; +//import com.sincere.wechatbusiness.service.ChannelProductService; +//import com.sincere.wechatbusiness.service.ChannelService; +//import org.apache.commons.lang3.StringUtils; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.web.bind.annotation.RequestMapping; +//import org.springframework.web.bind.annotation.RequestMethod; +//import org.springframework.web.bind.annotation.RestController; +// +//import java.io.BufferedReader; +//import java.io.FileReader; +//import java.io.IOException; +//import java.util.List; +// +//@RestController +//public class TestController { +// +// @Autowired +// ChannelService channelService ; +// +// @Autowired +// ChannelProductService channelProductService ; +// +// @Autowired +// BannerService bannerService ; +// +// @Autowired +// ChannelMapper channelMapper ; +// +// +// public static void main(String[] args){ +// try { +// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); +// BufferedReader bf = new BufferedReader(fr); +// String str; +// // 按行读取字符串 +// while ((str = bf.readLine()) != null) { +// String[] message = str.split("="); +// System.out.println(message[0]+"="+ message[1] +"="+ java.net.URLEncoder.encode(message[2], "UTF-8")); +// } +// bf.close(); +// fr.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// +// @RequestMapping(value = "copy",method = RequestMethod.GET) +// public BaseDto copyChannel(){ +// int sourceId = 1025 ; +// ChannelProduct channelProduct = channelProductService.getList(sourceId).get(0); +// List banners = bannerService.getList(sourceId); +// List bannerNexts = bannerService.getBannerNextList(sourceId); +// +// try { +// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); +// BufferedReader bf = new BufferedReader(fr); +// String str; +// // 按行读取字符串 +// while ((str = bf.readLine()) != null) { +// int channelId = 0; +// try{ +// channelId = channelMapper.getByName(str.trim() + "团购").getId(); +// }catch (Exception e){ +// System.out.println(str); +// e.printStackTrace(); +// } +// int channelProductId = 0 ; +// List products = channelProductService.getList(channelId); +// for(ChannelProduct product : products){ +// channelProductId = product.getId(); +// product.setTitle(channelProduct.getTitle()); +// product.setCaption(channelProduct.getCaption()); +// product.setChannelPrice(channelProduct.getChannelPrice()); +// channelProductService.update(product); +// } +// +// bannerService.deleteChannelBanner(channelId); +// bannerService.deleteChannelBannerNext(channelId); +// for(Banner banner : banners){ +// banner.setChannelId(channelId); +// if(StringUtils.isNotBlank(banner.getLinkUrl())){ +// banner.setLinkUrl("http://market.myjxt.com/wap/index.html#/CommodityDetail?id="+channelProductId+"&productId=1"); +// } +// bannerService.copy(banner); +// } +// for(BannerNext bannerNext : bannerNexts){ +// bannerNext.setChannelId(channelId); +// bannerService.copyBannerNext(bannerNext); +// } +// } +// bf.close(); +// fr.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// return new BaseDto(); +// } +//} diff --git a/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java b/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java new file mode 100644 index 0000000..41057b9 --- /dev/null +++ b/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java @@ -0,0 +1,91 @@ +package com.sincere.wechatbusiness.controller; + +import com.alibaba.fastjson.JSONObject; +import com.sincere.wechatbusiness.model.AccessToken; +import com.sincere.wechatbusiness.model.Token; +import com.sincere.wechatbusiness.service.ChannelService; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Calendar; +import java.util.Date; + +@RestController +public class TokenController { + + @Autowired + ChannelService channelService ; + + @ApiOperation(value = "获取分享token") + @RequestMapping(value = "getToken",method = RequestMethod.GET) + public String getToken(){ + AccessToken accessToken=channelService.getAccessToken(); + Token token=new Token(); + if(accessToken!=null) { + Calendar dateOne=Calendar.getInstance(); + Calendar dateTwo=Calendar.getInstance(); + dateOne.setTime(new Date()); + dateTwo.setTime(accessToken.getCreateTime()); + long timeOne=dateOne.getTimeInMillis(); + long timeTwo=dateTwo.getTimeInMillis(); + long minute=(timeOne-timeTwo)/(1000*60); + + if(minute<60) token.setAccess_token(accessToken.getAccessToken()); + else{ + token=getAccessToken("wx6078ff3f67524996","8a0465b8ad0f000f568f48853e2818c8"); + accessToken.setAccessToken(token.getAccess_token()); + channelService.insertAccessToken(accessToken); + } + } + else { + token=getAccessToken("wx6078ff3f67524996","8a0465b8ad0f000f568f48853e2818c8"); + accessToken=new AccessToken(); + accessToken.setAccessToken(token.getAccess_token()); + channelService.insertAccessToken(accessToken); + } + return accessToken.getAccessToken() ; + } + + public Token getAccessToken(String appID, String appScret) { + Token token = new Token(); + String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret=" + + appScret; + try { + URL getUrl=new URL(url); + HttpURLConnection http=(HttpURLConnection)getUrl.openConnection(); + http.setRequestMethod("GET"); + http.setRequestProperty("Content-Type", + "application/x-www-form-urlencoded"); + http.setDoOutput(true); + http.setDoInput(true); + + + http.connect(); + InputStream is = http.getInputStream(); + int size = is.available(); + byte[] b = new byte[size]; + is.read(b); + + String message = new String(b, "UTF-8"); + JSONObject json = JSONObject.parseObject(message); + + + token.setAccess_token(json.getString("access_token")); + token.setExpires_in(new Integer(json.getString("expires_in"))); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return token; + } + +} diff --git a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java index 37154e9..a456845 100644 --- a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java +++ b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java @@ -8,6 +8,8 @@ import java.util.List; public interface ChannelMapper { + Channel getByName(String name); + List getListByTemplate(int templateId); List getList(Channel channel); diff --git a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelProductMapper.java b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelProductMapper.java index f72ccbb..42be35d 100644 --- a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelProductMapper.java +++ b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelProductMapper.java @@ -1,6 +1,7 @@ package com.sincere.wechatbusiness.mapper; import com.sincere.wechatbusiness.model.ChannelProduct; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -16,4 +17,6 @@ public interface ChannelProductMapper { ChannelProduct getDetail(int id); int updateChannelProductMsg(ChannelProduct channelProduct); + + int updateProductOpenAddress(@Param("openAddress") int openAddress , @Param("id") int id); } diff --git a/src/main/java/com/sincere/wechatbusiness/model/ChannelProduct.java b/src/main/java/com/sincere/wechatbusiness/model/ChannelProduct.java index 0b93dc3..aed4b15 100644 --- a/src/main/java/com/sincere/wechatbusiness/model/ChannelProduct.java +++ b/src/main/java/com/sincere/wechatbusiness/model/ChannelProduct.java @@ -32,6 +32,16 @@ public class ChannelProduct { private String channelRequire ; private String channelExplain ; + private int openAddress ; + + public int getOpenAddress() { + return openAddress; + } + + public void setOpenAddress(int openAddress) { + this.openAddress = openAddress; + } + public String getChannelTitle() { return channelTitle; } diff --git a/src/main/java/com/sincere/wechatbusiness/service/ChannelProductService.java b/src/main/java/com/sincere/wechatbusiness/service/ChannelProductService.java index df53161..6a299cb 100644 --- a/src/main/java/com/sincere/wechatbusiness/service/ChannelProductService.java +++ b/src/main/java/com/sincere/wechatbusiness/service/ChannelProductService.java @@ -1,6 +1,7 @@ package com.sincere.wechatbusiness.service; import com.sincere.wechatbusiness.model.ChannelProduct; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -16,4 +17,6 @@ public interface ChannelProductService { ChannelProduct getDetail(int id); int updateChannelProductMsg(ChannelProduct channelProduct); + + int updateProductOpenAddress(int openAddress ,int id); } diff --git a/src/main/java/com/sincere/wechatbusiness/service/impl/ChannelProductServiceImpl.java b/src/main/java/com/sincere/wechatbusiness/service/impl/ChannelProductServiceImpl.java index 6961407..7e2004a 100644 --- a/src/main/java/com/sincere/wechatbusiness/service/impl/ChannelProductServiceImpl.java +++ b/src/main/java/com/sincere/wechatbusiness/service/impl/ChannelProductServiceImpl.java @@ -32,4 +32,9 @@ public class ChannelProductServiceImpl implements ChannelProductService { public int updateChannelProductMsg(ChannelProduct channelProduct) { return channelProductMapper.updateChannelProductMsg(channelProduct); } + + @Override + public int updateProductOpenAddress(int openAddress, int id) { + return channelProductMapper.updateProductOpenAddress(openAddress,id); + } } diff --git a/src/main/resources/mapper/BannerMapper.xml b/src/main/resources/mapper/BannerMapper.xml index 59e5511..f6bff97 100644 --- a/src/main/resources/mapper/BannerMapper.xml +++ b/src/main/resources/mapper/BannerMapper.xml @@ -43,7 +43,7 @@ update banner set state=0 where id = #{id} - - update banner set state=0 where channelId = #{channelId} - + + delete banner where channelId = #{channelId} + \ No newline at end of file diff --git a/src/main/resources/mapper/ChannelMapper.xml b/src/main/resources/mapper/ChannelMapper.xml index 0f3006d..68040b0 100644 --- a/src/main/resources/mapper/ChannelMapper.xml +++ b/src/main/resources/mapper/ChannelMapper.xml @@ -16,6 +16,10 @@ + + diff --git a/src/main/resources/mapper/ChannelProductMapper.xml b/src/main/resources/mapper/ChannelProductMapper.xml index 68b6b18..f8bf25b 100644 --- a/src/main/resources/mapper/ChannelProductMapper.xml +++ b/src/main/resources/mapper/ChannelProductMapper.xml @@ -19,7 +19,7 @@ - +