|
@@ -5,9 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.shawn.model.dto.ResultMessage;
|
|
|
import com.shawn.model.entity.*;
|
|
|
import com.shawn.model.param.TPromoCodeParam;
|
|
|
-import com.shawn.service.interfac.TAdminServiceInterface;
|
|
|
-import com.shawn.service.interfac.TEquipmentServiceInterface;
|
|
|
-import com.shawn.service.interfac.TPromoCodeServiceInterface;
|
|
|
+import com.shawn.service.interfac.*;
|
|
|
import com.shawn.util.JoinpayConstant;
|
|
|
import com.shawn.web.controller.base.BaseController;
|
|
|
import lombok.extern.apachecommons.CommonsLog;
|
|
@@ -18,11 +16,13 @@ import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@CommonsLog
|
|
|
@RestController
|
|
@@ -42,6 +42,10 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
|
|
|
private TAdminServiceInterface tAdminServiceInterface;
|
|
|
@Autowired
|
|
|
private TEquipmentServiceInterface tEquipmentServiceInterface;
|
|
|
+ @Autowired
|
|
|
+ private TProportionServiceInterface tProportionServiceInterface;
|
|
|
+ @Autowired
|
|
|
+ private TOrderServiceInterface tOrderServiceInterface;
|
|
|
/**
|
|
|
* 优惠码列表
|
|
|
* @param
|
|
@@ -93,43 +97,44 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/buy")
|
|
|
- public ResponseEntity<?> buy(int number,Long id) {
|
|
|
- TAdmin admin = tAdminServiceInterface.selectEntityById(id);
|
|
|
+ public ResponseEntity<?> buy(String day,Long adminId,Double pri) {
|
|
|
+ TAdmin admin = tAdminServiceInterface.selectEntityById(adminId);
|
|
|
+ //获取机器
|
|
|
TEquipmentExample tEquipmentExample = new TEquipmentExample();
|
|
|
TEquipmentExample.Criteria criteria = tEquipmentExample.createCriteria();
|
|
|
- criteria.andAdminIdEqualTo(id);
|
|
|
+ criteria.andAdminIdEqualTo(adminId);
|
|
|
List<TEquipment> equipmentList = tEquipmentServiceInterface.selectByOption(tEquipmentExample);
|
|
|
+
|
|
|
TEquipment equipment = equipmentList.get(0);
|
|
|
Long equipmentId = equipment.getId();
|
|
|
- TProportion proportion = proportionService.getUniqueness(equipment.getAdminId());
|
|
|
- TProportion.Type type = proportion.getType();
|
|
|
- Order.Type orderType = null;
|
|
|
+ //获取分销比例
|
|
|
+ TProportionExample tProportionExample = new TProportionExample();
|
|
|
+ TProportionExample.Criteria criteria1 = tProportionExample.createCriteria();
|
|
|
+ criteria1.andAdminIdEqualTo(adminId);
|
|
|
+ List<TProportion> tProportions = tProportionServiceInterface.selectByOption(tProportionExample);
|
|
|
+
|
|
|
+ TProportion proportion = tProportions.get(0);
|
|
|
+ int type = proportion.getType();
|
|
|
+ int orderType = 3;
|
|
|
Long agencyId = admin.getAgencyId();
|
|
|
Long merchantId = admin.getMerchantId();
|
|
|
Long personageId = admin.getPersonageId();
|
|
|
switch (type) {
|
|
|
- case agency:
|
|
|
- orderType = Order.Type.agency;
|
|
|
+ case 1:
|
|
|
+ orderType = 1;
|
|
|
break;
|
|
|
- case merchant:
|
|
|
- orderType = Order.Type.merchant;
|
|
|
+ case 2:
|
|
|
+ orderType = 2;
|
|
|
break;
|
|
|
- case personage:
|
|
|
- orderType = Order.Type.personage;
|
|
|
+ case 3:
|
|
|
+ orderType = 3;
|
|
|
break;
|
|
|
}
|
|
|
- Double money = null;
|
|
|
- List<Price> prices = priceService.findAll();
|
|
|
- for(Price price:prices){
|
|
|
- if(price.getName().equals("优惠码")){
|
|
|
- money = price.getPrice();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- String sn = orderService.initSn(equipmentId);
|
|
|
+ String sn = initSn(equipmentId);
|
|
|
String orderNo = sn;
|
|
|
String productName = "优惠码";
|
|
|
- BigDecimal price = BigDecimal.valueOf(money*number);
|
|
|
+ BigDecimal price = BigDecimal.valueOf(pri);
|
|
|
BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
|
|
|
BigDecimal amount = cutPrice;
|
|
|
String productDesc = "";
|
|
@@ -148,10 +153,10 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
|
|
|
String altUrl = null;
|
|
|
BigDecimal marketingAmount = null;
|
|
|
|
|
|
-// com.hboxs.entity.Order order = new com.hboxs.entity.Order(sn, product.getId(), productName, price, equipment.getClientId(), equipmentId,
|
|
|
-// orderType, admin.getId(), agencyId, merchantId, personageId,
|
|
|
-// frpCode, altInfo.toString(), adminProportion, agencyProportion, merchantProportion, personageProportion, Order.Status.unpay);
|
|
|
- Order order1 = new Order();
|
|
|
+ String str = String.valueOf(pri);
|
|
|
+ Float pric = Float.parseFloat(str);
|
|
|
+ String frpCode = "WEIXIN_NATIVE";
|
|
|
+ TOrder order1 = new TOrder();
|
|
|
order1.setSn(sn);
|
|
|
order1.setType(orderType);
|
|
|
order1.setAgencyId(agencyId);
|
|
@@ -159,17 +164,20 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
|
|
|
order1.setPersonageId(personageId);
|
|
|
order1.setAdminId(admin.getId());
|
|
|
order1.setProductName(productName);
|
|
|
- order1.setPrice(price);
|
|
|
+ order1.setPrice(pric);
|
|
|
order1.setEquipmentId(equipmentId);
|
|
|
order1.setClientId(equipment.getClientId());
|
|
|
- order1.setStatus(Order.Status.unpay);
|
|
|
- order1.setFrp_code(frpCode);
|
|
|
- orderService.create(order1);
|
|
|
+ order1.setStatus(0);
|
|
|
+ order1.setTrxNo(day);
|
|
|
+ order1.setCreateDate(new Date());
|
|
|
+ order1.setModifyDate(new Date());
|
|
|
+ order1.setFrpCode(frpCode);
|
|
|
+ tOrderServiceInterface.insert(order1);
|
|
|
|
|
|
JSONArray altInfo = new JSONArray();
|
|
|
String result = null;
|
|
|
- try {
|
|
|
- result = tradeService.uniPay(
|
|
|
+
|
|
|
+ result = tPromoCodeService.uniPay(
|
|
|
|
|
|
orderNo, amount, productName, productDesc,
|
|
|
commonParameter, returnUrl, notifyUrl, frpCode,
|
|
@@ -177,24 +185,135 @@ public class TPromoCodeController extends BaseController<TPromoCode, TPromoCodeE
|
|
|
buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
|
|
|
);
|
|
|
|
|
|
- } catch (
|
|
|
- UnsupportedEncodingException e) {
|
|
|
- e.printStackTrace();
|
|
|
+
|
|
|
// return JsonMessage.error("申请支付失败");
|
|
|
- return "申请支付失败";
|
|
|
- }
|
|
|
+// return ResponseEntity.status(HttpStatus.OK)
|
|
|
+// .body(new ResultMessage().setCode(true).setData("申请支付失败").setMessage("SUCCESS"));
|
|
|
+
|
|
|
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
// 汇聚支付支付申请返回支付二维码图片
|
|
|
String rd_Pic = resultJson.getString("rd_Pic");
|
|
|
|
|
|
if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
|
|
|
- return "找不到支付图片";
|
|
|
+ return ResponseEntity.status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage().setCode(true).setData("找不到支付图片").setMessage("SUCCESS"));
|
|
|
+// return "找不到支付图片";
|
|
|
}
|
|
|
// ModelMap model = new ModelMap();
|
|
|
- model.addAttribute("image", rd_Pic);
|
|
|
- model.addAttribute("price", price);
|
|
|
+// model.addAttribute("image", rd_Pic);
|
|
|
+// model.addAttribute("price", price);
|
|
|
return ResponseEntity.status(HttpStatus.OK)
|
|
|
- .body(new ResultMessage().setCode(true).setData(price).setMessage("SUCCESS"));
|
|
|
+ .body(new ResultMessage().setCode(true).setData(rd_Pic).setMessage("SUCCESS"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String initSn(Long equipmentId) {
|
|
|
+ StringBuilder number = new StringBuilder();
|
|
|
+ if (equipmentId != null) {
|
|
|
+ Random random = new Random();
|
|
|
+ /**
|
|
|
+ * 6位随机
|
|
|
+ */
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ number.append(String.valueOf(random.nextInt(10)));
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 设备id
|
|
|
+ */
|
|
|
+ number.append(equipmentId.toString());
|
|
|
+ /**
|
|
|
+ * 日期
|
|
|
+ */
|
|
|
+ number.append(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
|
|
|
+ }
|
|
|
+ return number.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优惠码支付成功回调
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/promoCodeNotify", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public Object promoCoderefund(HttpServletRequest request) {
|
|
|
+
|
|
|
+ String r6_Status = request.getParameter("r6_Status");
|
|
|
+
|
|
|
+ // 订单号
|
|
|
+ String sn = request.getParameter("r2_OrderNo");
|
|
|
+ //价格
|
|
|
+ String price = request.getParameter("r3_Amount");
|
|
|
+ Double pri = tPromoCodeService.findPrice();
|
|
|
+ //生成优惠码的个数
|
|
|
+ double num = Double.parseDouble(price)/pri;
|
|
|
+ int number = (int) num;
|
|
|
+
|
|
|
+ TOrderExample tOrderExample = new TOrderExample();
|
|
|
+ TOrderExample.Criteria criteria = tOrderExample.createCriteria();
|
|
|
+ criteria.andSnEqualTo(sn);
|
|
|
+ List<TOrder> tOrders = tOrderServiceInterface.selectByOption(tOrderExample);
|
|
|
+ TOrder order = tOrders.get(0);
|
|
|
+ String day = order.getTrxNo();
|
|
|
+ if(order.getStatus()!=0){
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
+ if(JoinpayConstant.r6_Status_100.equals(r6_Status)){
|
|
|
+
|
|
|
+ // 已支付
|
|
|
+ order.setStatus(1);
|
|
|
+
|
|
|
+ // 支付平台产生的流水号
|
|
|
+ String r7_TrxNo = request.getParameter("r7_TrxNo");
|
|
|
+ order.setTrxNo(r7_TrxNo);
|
|
|
+
|
|
|
+ // 格式:YYYY-MM-DD HH:mm:ss
|
|
|
+ String ra_PayTime = request.getParameter("ra_PayTime");
|
|
|
+
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
|
|
|
+ order.setPayDate(payDate);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ tOrderServiceInterface.updateById(order);
|
|
|
+ TAdmin admin = tAdminServiceInterface.selectEntityById(order.getAdminId());
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
+ kindData.put("sn" , order.getSn());
|
|
|
+ kindData.put("productName" , order.getProductName());
|
|
|
+ List<String> codes =new ArrayList<>();
|
|
|
+ for(int i=0;i<number;i++){
|
|
|
+ String code = initSn(order.getEquipmentId());
|
|
|
+ StringBuffer str = new StringBuffer();
|
|
|
+ str.append(code.substring(0,6));
|
|
|
+ codes.add(str.toString());
|
|
|
+ }
|
|
|
+ Long data = Calendar.getInstance().getTimeInMillis();
|
|
|
+ Long da = Long.valueOf(day);
|
|
|
+ Long month = da*24L*60L*60L*1000L;
|
|
|
+ Long d = data + month;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String sd = sdf.format(new Date(Long.parseLong(String.valueOf(d))));
|
|
|
+ Date lastUseDate = new Date(Long.parseLong(String.valueOf(d)));
|
|
|
+ for(String code : codes){
|
|
|
+ TPromoCode promoCode = new TPromoCode();
|
|
|
+ promoCode.setCode(Long.parseLong(code));
|
|
|
+ promoCode.setAdminId(String.valueOf(order.getAdminId()));
|
|
|
+ promoCode.setIsUse("0");
|
|
|
+ promoCode.setLastUseDate(lastUseDate);
|
|
|
+ promoCode.setCreateDate(new Date());
|
|
|
+ promoCode.setUserName(admin.getUsername());
|
|
|
+ tPromoCodeService.insert(promoCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ return "支付成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ return "success";
|
|
|
}
|
|
|
}
|