|
@@ -15,12 +15,11 @@ import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.common.utils.uuid.CommonUtils;
|
|
|
import com.miaxis.feign.dto.FilmDTO;
|
|
|
import com.miaxis.film.domain.FilmOrder;
|
|
|
-import com.miaxis.film.dto.CinemaData;
|
|
|
-import com.miaxis.film.dto.FilmOrderCreateDTO;
|
|
|
-import com.miaxis.film.dto.FilmOrderListDTO;
|
|
|
+import com.miaxis.film.dto.*;
|
|
|
import com.miaxis.film.service.IFilmOrderService;
|
|
|
import com.miaxis.question.domain.QuestionInfo;
|
|
|
import com.miaxis.system.service.ISysConfigService;
|
|
|
+import com.miaxis.system.service.ISysDictDataService;
|
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.Data;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -32,6 +31,7 @@ import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
@@ -76,6 +76,9 @@ public class FilmController extends BaseController {
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDictDataService dictDataService;
|
|
|
+
|
|
|
@Value("${app.appid}")
|
|
|
private String appid;
|
|
|
@Value("${film.appKey}")
|
|
@@ -119,24 +122,33 @@ public class FilmController extends BaseController {
|
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
-
|
|
|
UserInfo student = SecurityUtils.getLoginUser().getStudent();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //生成预订单
|
|
|
+ //1 本地创建订单
|
|
|
+ FilmOrder order = new FilmOrder();
|
|
|
Long id = student.getId();
|
|
|
String orderCode = getOrderCode(id);
|
|
|
+ order.setOutTradeNo(orderCode);
|
|
|
+ order.setOpenid(student.getOpenid());
|
|
|
+ dictDataService.selectDictLabel("goods_type",filmOrderCreateDTO.getGoodsType());
|
|
|
+ order.setGoodsType(filmOrderCreateDTO.getGoodsType());
|
|
|
+ order.setGoodsPictureUrl(filmOrderCreateDTO.getGoodsPictureUrl());
|
|
|
+ FilmOrderJsonData filmOrderJsonData = new FilmOrderJsonData();
|
|
|
+ filmOrderCreateDTO.setThirdOrderId(orderCode);
|
|
|
+ filmOrderJsonData.setFilmOrderCreateDTO(filmOrderCreateDTO);
|
|
|
//通过影院api 获取单票价格
|
|
|
- Integer price = getPrice(filmOrderCreateDTO.getCinemaId(),filmOrderCreateDTO.getShowId());
|
|
|
+ Integer price = getPrice(filmOrderCreateDTO.getCinemaId(),filmOrderCreateDTO.getShowId(),filmOrderJsonData);
|
|
|
int number = filmOrderCreateDTO.getSeat().split(",").length;
|
|
|
+ order.setOrderDataJson(JSONObject.toJSONString(filmOrderJsonData));
|
|
|
+ filmOrderService.save(order);
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+ // 2 调用微信接口生成预订单
|
|
|
ObjectNode rootNode = objectMapper.createObjectNode();
|
|
|
rootNode.put("mchid",wxpayConfig.getMerchantId())
|
|
|
.put("appid", appid)
|
|
|
- .put("description", "电影票")
|
|
|
+ .put("description", filmOrderCreateDTO.getGoodsType())
|
|
|
.put("notify_url", notifyUrl)
|
|
|
.put("out_trade_no", orderCode);
|
|
|
rootNode.putObject("amount")
|
|
@@ -152,19 +164,8 @@ public class FilmController extends BaseController {
|
|
|
throw new CustomException(JSONObject.parseObject(bodyAsString).get("message").toString());
|
|
|
}
|
|
|
|
|
|
- //本地创建订单
|
|
|
- FilmOrder order = new FilmOrder();
|
|
|
- order.setShowId(filmOrderCreateDTO.getShowId());
|
|
|
- order.setOutTradeNo(orderCode);
|
|
|
- order.setSeat(filmOrderCreateDTO.getSeat());
|
|
|
- order.setAcceptChangeSeat(filmOrderCreateDTO.getAcceptChangeSeat());
|
|
|
- order.setSeatId(filmOrderCreateDTO.getSeatId());
|
|
|
- order.setSeatNo(filmOrderCreateDTO.getSeatNo());
|
|
|
- order.setReservedPhone(filmOrderCreateDTO.getReservedPhone());
|
|
|
- order.setOpenid(student.getOpenid());
|
|
|
- filmOrderService.save(order);
|
|
|
-
|
|
|
|
|
|
+ //3 生成前端小程序调用调起微信支付所需参数
|
|
|
String packageStr = "prepay_id="+JSONObject.parseObject(bodyAsString).get("prepay_id");
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("package",packageStr);
|
|
@@ -195,7 +196,10 @@ public class FilmController extends BaseController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private Integer getPrice(String cinemaId, String showId) {
|
|
|
+
|
|
|
+
|
|
|
+ private Integer getPrice(String cinemaId, String showId, FilmOrderJsonData filmOrderJsonData) {
|
|
|
+
|
|
|
FilmDTO filmDTO = new FilmDTO();
|
|
|
filmDTO.setUrl("movieapi/movie-info/get-schedule-list");
|
|
|
StringBuffer paramData = new StringBuffer();
|
|
@@ -208,7 +212,9 @@ public class FilmController extends BaseController {
|
|
|
JSONArray list = data.getJSONArray("list");
|
|
|
List<CinemaData> cinemaData = list.toJavaList(CinemaData.class);
|
|
|
List<CinemaData> listdata = cinemaData.stream().filter(a -> showId.equals(a.getShowId())).collect(Collectors.toList());
|
|
|
- Integer netPrice = listdata.get(0).getNetPrice();
|
|
|
+ CinemaData realCinemaData = listdata.get(0);
|
|
|
+ filmOrderJsonData.setCinemaData(realCinemaData);
|
|
|
+ Integer netPrice = realCinemaData.getNetPrice();
|
|
|
Double upDiscountRate = discountRule.getDouble("upDiscountRate");
|
|
|
Double downDiscountRate = discountRule.getDouble("downDiscountRate");
|
|
|
String film_discount = configService.selectConfigByKey("film_discount");
|
|
@@ -251,41 +257,47 @@ public class FilmController extends BaseController {
|
|
|
/**
|
|
|
* 获取电影订单详细信息
|
|
|
*/
|
|
|
- @GetMapping(value = "/{id}")
|
|
|
+ @GetMapping(value = "/{outTradeNo}")
|
|
|
@ApiOperation("获取电影订单详细信息")
|
|
|
public Response<FilmOrder> getInfo(
|
|
|
- @ApiParam(name = "id", value = "电影订单参数", required = true)
|
|
|
- @PathVariable("id") Long id
|
|
|
+ @ApiParam(name = "outTradeNo", value = "电影订单参数", required = true)
|
|
|
+ @PathVariable("outTradeNo") String outTradeNo
|
|
|
){
|
|
|
- return Response.success(filmOrderService.getById(id));
|
|
|
+ FilmOrder filmOrder = filmOrderService.getByOutTradeNo(outTradeNo);
|
|
|
+ if (!filmOrder.getOpenid().equals(SecurityUtils.getLoginUser().getStudent().getOpenid())){
|
|
|
+ throw new CustomException("该用户无访问此订单权限");
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 微信支付查单接口
|
|
|
- */
|
|
|
- @GetMapping(value = "/wxorder/{outTradeNo}")
|
|
|
- @ApiOperation("根据订单号查询订单状态")
|
|
|
- public Response<String> getOrderInfo(
|
|
|
- @ApiParam(name = "outTradeNo", value = "商户订单号", required = true)
|
|
|
- @PathVariable("outTradeNo") String outTradeNo
|
|
|
- ) throws IOException {
|
|
|
- HttpGet get = new HttpGet("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/"
|
|
|
- +outTradeNo+"?mchid="+wxpayConfig.getMerchantId());
|
|
|
- get.addHeader("Accept", "application/json");
|
|
|
- HttpResponse response = httpClient.execute(get);
|
|
|
- String bodyAsString = EntityUtils.toString(response.getEntity());
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(bodyAsString);
|
|
|
- int statusCode = response.getStatusLine().getStatusCode();
|
|
|
- if (statusCode == 200) {
|
|
|
- return Response.success(jsonObject.getString("trade_state"));
|
|
|
- } else {
|
|
|
- throw new CustomException(EntityUtils.toString(response.getEntity()));
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 微信支付查单接口
|
|
|
+// */
|
|
|
+// @GetMapping(value = "/wxorder/{outTradeNo}")
|
|
|
+// @ApiOperation("根据订单号查询订单状态")
|
|
|
+// public Response<String> getOrderInfo(
|
|
|
+// @ApiParam(name = "outTradeNo", value = "商户订单号", required = true)
|
|
|
+// @PathVariable("outTradeNo") String outTradeNo
|
|
|
+// ) throws IOException {
|
|
|
+// HttpGet get = new HttpGet("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/"
|
|
|
+// +outTradeNo+"?mchid="+wxpayConfig.getMerchantId());
|
|
|
+// get.addHeader("Accept", "application/json");
|
|
|
+// HttpResponse response = httpClient.execute(get);
|
|
|
+// String bodyAsString = EntityUtils.toString(response.getEntity());
|
|
|
+// JSONObject jsonObject = JSONObject.parseObject(bodyAsString);
|
|
|
+// int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+// if (statusCode == 200) {
|
|
|
+// return Response.success(jsonObject.getString("trade_state"));
|
|
|
+// } else {
|
|
|
+// throw new CustomException(EntityUtils.toString(response.getEntity()));
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|