yuhaitao14 7 years ago
parent
commit
896c089241

+ 18 - 2
shop/src/main/java/com/zskk/shop/controller/AbstractController.java

@@ -45,6 +45,9 @@ public class AbstractController {
 
 
 	@Value("${zskk.myhost}")
 	@Value("${zskk.myhost}")
 	private String myhost;
 	private String myhost;
+	
+	@Value("${zskk.companyid}")
+	private String companyid;
 
 
 	/**
 	/**
 	 * 获取当前登录用户 未登录抛异常
 	 * 获取当前登录用户 未登录抛异常
@@ -94,8 +97,21 @@ public class AbstractController {
 		}
 		}
 	}
 	}
 
 
-	public void isLogin() {
-		this.getUser();
+	/**
+	 * 是否已登录
+	 * @return
+	 */
+	public boolean isLogin() {
+		return this.getUserNoException() != null;
+	}
+	
+	public void wxInitUser(Model model, String redirect){
+		UserBean user = getUserNoException();
+		model.addAttribute("islogin", user != null);
+		if (user != null) {
+			model.addAttribute("user", user);
+		}
+		model.addAttribute("loginurl", uccenter + "wx/enter/" + companyid + "?redirect=" + urlEncoding(myhost));
 	}
 	}
 
 
 	public void initUser(Model model) {
 	public void initUser(Model model) {

+ 76 - 0
shop/src/main/java/com/zskk/shop/controller/h5/H5BuyOrderController.java

@@ -0,0 +1,76 @@
+/**
+* @版权信息 (@copyright Copyright 2017-XXXX JDJR.COM All Right Reserved);
+* @see
+* @author 于海涛 京东金融【技术研发部-证券及营销平台研发部-营销平台研发部】
+* @version 1.0
+* @date 2018年6月27日
+*/
+
+package com.zskk.shop.controller.h5;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import com.zskk.shop.controller.AbstractController;
+import com.zskk.shop.controller.bean.ControllerResult;
+import com.zskk.shop.controller.bean.UserBean;
+import com.zskk.shop.dao.entry.BuyOrder;
+import com.zskk.shop.dao.entry.GoodBase;
+import com.zskk.shop.dao.entry.GoodPrice;
+import com.zskk.shop.service.BuyOrderService;
+import com.zskk.shop.service.GoodService;
+import com.zskk.shop.service.UserCenterService;
+
+@Controller
+@RequestMapping("/h5")
+public class H5BuyOrderController extends AbstractController{
+
+	@Autowired
+	private BuyOrderService buyOrderService;
+	
+	@Autowired
+	private GoodService goodService;
+	
+	@Autowired
+	private UserCenterService userCenterService;
+	
+	/**
+	 * 购买
+	 * @param gid
+	 * @param num
+	 * @return
+	 */
+	@RequestMapping("/buy/{gid}")
+	public String buy(Model model, @PathVariable("gid") Integer gid){
+		UserBean userBean 	= this.getUser();
+		String uid 			= userBean.getUserid();
+		String uname 		= userBean.getName();
+		String uphone		= userBean.getPhone();
+		Integer num			= 1;	
+		
+		GoodBase goodBase 	= goodService.queryOneGoodBase(gid);
+		GoodPrice goodPrice = goodService.queryGoodPrice(gid);
+		
+		BuyOrder buyOrder = buyOrderService.buy(uid, uname, uphone, goodBase, goodPrice, num);
+		
+		Integer paytype = 2; //微信支付
+		String orderid	= buyOrderService.createOrderId(buyOrder, paytype);
+		buyOrderService.saveOrderId(buyOrder, orderid, paytype);
+		
+		// 用户中心下H5 支付单
+		ControllerResult ucResult = userCenterService.createH5Pay(buyOrder, goodBase, goodPrice);
+		if (ucResult.getCode() == 0){
+			return "redirect:" +  ucResult.getObj().toString();
+		}else{
+			return "/h5/error";
+		}
+	}
+	
+	@RequestMapping("/buy/paySuccess")
+	public String paySuccess(Model model){
+		return "/h5/";
+	}
+}

+ 5 - 2
shop/src/main/java/com/zskk/shop/controller/h5/H5IndexController.java

@@ -13,6 +13,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -48,6 +49,9 @@ public class H5IndexController extends AbstractController {
 	@Autowired
 	@Autowired
 	private BannerService  bannerService;
 	private BannerService  bannerService;
 	
 	
+	@Value("${zskk.myhost}")
+	private String myhost;
+	
 	@RequestMapping("/index")
 	@RequestMapping("/index")
 	public String index(Model model, @RequestParam(name="label", required=false) Integer label){
 	public String index(Model model, @RequestParam(name="label", required=false) Integer label){
 		List<GoodBean> beans 		= this.getGoodList(label);
 		List<GoodBean> beans 		= this.getGoodList(label);
@@ -68,12 +72,11 @@ public class H5IndexController extends AbstractController {
 		List<GoodAd> ads 				= goodService.queryGoodAds(gid);
 		List<GoodAd> ads 				= goodService.queryGoodAds(gid);
 		List<GoodDescribe> describes 	= goodService.queryGoodDescribes(gid);
 		List<GoodDescribe> describes 	= goodService.queryGoodDescribes(gid);
 		List<String> tjCheckList		= tjCenterService.getDJDetail(base.getPackageid());
 		List<String> tjCheckList		= tjCenterService.getDJDetail(base.getPackageid());
-
 		
 		
 		GoodBean bean = goodService.toDetailGoodBean(base, price, ads, describes);
 		GoodBean bean = goodService.toDetailGoodBean(base, price, ads, describes);
 		model.addAttribute("good", bean);
 		model.addAttribute("good", bean);
 		model.addAttribute("checklist", tjCheckList);
 		model.addAttribute("checklist", tjCheckList);
-		this.initUser(model);
+		this.wxInitUser(model, myhost + "detail/" + gid);
 		return "/h5/detail";
 		return "/h5/detail";
 	}
 	}
 	
 	

+ 33 - 3
shop/src/main/java/com/zskk/shop/service/UserCenterService.java

@@ -12,13 +12,11 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
-import java.util.TreeMap;
 import java.util.UUID;
 import java.util.UUID;
 
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
@@ -28,10 +26,10 @@ import com.zskk.shop.controller.bean.UserBean;
 import com.zskk.shop.dao.entry.BuyOrder;
 import com.zskk.shop.dao.entry.BuyOrder;
 import com.zskk.shop.dao.entry.BuyOrderItem;
 import com.zskk.shop.dao.entry.BuyOrderItem;
 import com.zskk.shop.dao.entry.GoodBase;
 import com.zskk.shop.dao.entry.GoodBase;
+import com.zskk.shop.dao.entry.GoodPrice;
 import com.zskk.shop.exception.ErrorConstant;
 import com.zskk.shop.exception.ErrorConstant;
 import com.zskk.shop.utils.HttpClient;
 import com.zskk.shop.utils.HttpClient;
 import com.zskk.shop.utils.LogUtil;
 import com.zskk.shop.utils.LogUtil;
-import com.zskk.shop.utils.ToolsUtil;
 
 
 @Service
 @Service
 public class UserCenterService {
 public class UserCenterService {
@@ -118,7 +116,39 @@ public class UserCenterService {
 		}
 		}
 	}
 	}
 	
 	
+	public ControllerResult createH5Pay(BuyOrder order, GoodBase goods, GoodPrice price){
+		Map<String, String> params = new HashMap<>();
+		params.put("companyid", companyid);
+		params.put("apporderid", order.getOrderid());
+		params.put("name", goods.getName());
+		params.put("describe", goods.getDescribe());
+		params.put("money", price.getDiscountPrice().toString());
+		params.put("callback", myhost + "payed");
+		params.put("redirect", myhost + "h5/paySuccess");
+		params.put("extend", "");
+		params.put("sign", this.sign(params));
+		
+		try{
+			String content = HttpClient.doPost(uccenter + "pay/createH5PayQrcode", params);
+			return JSON.parseObject(content, ControllerResult.class);
+		}catch (Exception e) {
+			e.printStackTrace();
+			LogUtil.sysError(e.getMessage(), e);
+			return new ControllerResult(ErrorConstant.SERVER_ERROR);
+		}
+	}
+	
+	public String getWXPayUrl(BuyOrder order){
+		Map<String, String> params = new HashMap<>();
+		params.put("companyid", this.companyid);
+		params.put("apporderid", order.getOrderid());
+		String sign = this.sign(params);
+		
+		return uccenter + "callback/h5Pay?companyid=" + companyid + "&apporderid=" + order.getOrderid() + "&sign=" + sign; 
+	}
+	
 	public String sign(Map<String, String> params){
 	public String sign(Map<String, String> params){
 		return signService.sign(params, secret);
 		return signService.sign(params, secret);
 	}
 	}
+	
 }
 }

+ 13 - 4
shop/src/main/resource/templates/h5/detail.html

@@ -23,14 +23,12 @@
 		</div>
 		</div>
 	</div>
 	</div>
 	<div class="line-10-EEE"></div>
 	<div class="line-10-EEE"></div>
-	<a class="v-tel" href="#"><div>400-899-9999</div></a>
-	<div class="line-10-EEE"></div>
 	<div class="v-title mt10">
 	<div class="v-title mt10">
 		<span>详细介绍</span>
 		<span>详细介绍</span>
 	</div>
 	</div>
 	<div>
 	<div>
 		<img th:each="desc : ${good.describes}"
 		<img th:each="desc : ${good.describes}"
-			th:attr="src=${desc.content},title=${desc.title}" style="width: 100%"/>
+			th:attr="src=${desc.content},title=${desc.title}" style="width: 100%" />
 	</div>
 	</div>
 	<div class="v-title mt10">
 	<div class="v-title mt10">
 		<span>体检内容</span>
 		<span>体检内容</span>
@@ -58,8 +56,19 @@
 	<div style="height: 60px;"></div>
 	<div style="height: 60px;"></div>
 	<div class="v-bottom">
 	<div class="v-bottom">
 		<div>
 		<div>
-			<button>立即预约</button>
+			<form th:attr="action='/h5/buy/' + ${good.gid}" th:if="${islogin}" >
+				<button id="buy" type="submit">立即购买</button>
+			</form>
+			<button th:if="${!islogin}" id="login">立即购买</button>
 		</div>
 		</div>
 	</div>
 	</div>
+
+	<script src="/h5/js/jquery-2.1.1.min.js"></script>
+	<script>
+		$(function(){
+			$("#login").click(function(){
+			});
+		});
+	</script>
 </body>
 </body>
 </html>
 </html>

+ 32 - 0
shop/src/main/resource/templates/h5/error.html

@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
+    <title>黑龙江昆仑盛和安体检中心</title>
+    <link rel="stylesheet" type="text/css" href="/style/common.css"/>
+    <link rel="stylesheet" type="text/css" href="/style/shop.css"/>
+    <!--[if lt IE 9]> 
+<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script> 
+<![endif]-->
+    <!--窗口自适应适配低端IE-->
+    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
+    <style type="text/css">
+    	.content {
+    		text-align: center;
+    		margin-top: 100px;
+    	}
+    	.title {
+    		margin-top: 20px;
+    	}
+	</style>
+</head>
+
+<body>
+	<div class="content">
+    	<h1>系统开小差啦!</h1>
+    	<h3 class="title">对您造成的困扰尽情谅解,我们会马上解决。返回<a href="/">"首页"</a></h3>
+    </div>
+</body>
+</html>

+ 1 - 1
shop/src/main/resource/templates/h5/index.html

@@ -55,7 +55,7 @@
     <div style="height:60px; "></div>
     <div style="height:60px; "></div>
 	<table class="n-tab">
 	<table class="n-tab">
     	<tr>
     	<tr>
-        	<td><a href="#" class="n-1-c">首页</a></td>
+        	<td><a href="/h5/index" class="n-1-c">首页</a></td>
             <td><a href="#" class="n-2">报告</a></td>
             <td><a href="#" class="n-2">报告</a></td>
             <td><a href="#" class="n-3">我的</a></td>
             <td><a href="#" class="n-3">我的</a></td>
         </tr>
         </tr>

+ 10 - 0
shop/src/main/resource/templates/h5/paySuccess.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+支付成功
+</body>
+</html>