|
@@ -1,27 +1,40 @@
|
|
|
package com.ygj.yuemum.service.pay;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ygj.yuemum.component.Constant;
|
|
|
import com.ygj.yuemum.dao.equipment.EquipmenteHireDetailDao;
|
|
|
import com.ygj.yuemum.dao.equipment.EquipmenteHireHeadDao;
|
|
|
import com.ygj.yuemum.dao.pay.CustomerPayDao;
|
|
|
import com.ygj.yuemum.domain.equipment.EquipmentLog;
|
|
|
import com.ygj.yuemum.domain.equipment.EquipmenteHireDetail;
|
|
|
import com.ygj.yuemum.domain.equipment.EquipmenteHireHead;
|
|
|
+import com.ygj.yuemum.domain.order.YSOrder;
|
|
|
import com.ygj.yuemum.domain.pay.CustomerPay;
|
|
|
import com.ygj.yuemum.service.equipment.EquipmentInfoService;
|
|
|
import com.ygj.yuemum.service.equipment.EquipmentLogService;
|
|
|
import com.ygj.yuemum.service.order.YSOrderService;
|
|
|
+import com.ygj.yuemum.utils.QrCodeUtils;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+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.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
public class CustomerPayService {
|
|
|
+ public String CREATEQRURL = Constant.CREATEQRURL;
|
|
|
|
|
|
@Autowired
|
|
|
-
|
|
|
private CustomerPayDao customerPayDao;
|
|
|
@Autowired
|
|
|
private EquipmentInfoService equipmentInfoService;
|
|
@@ -39,14 +52,21 @@ public class CustomerPayService {
|
|
|
public List<CustomerPay> selectCustomerPay(String cp_orderno) {
|
|
|
return customerPayDao.selectCustomerPay(cp_orderno);
|
|
|
}
|
|
|
- public CustomerPay queryYSOrderPay (CustomerPay customerPay){
|
|
|
+
|
|
|
+ public List<CustomerPay> queryCustomerPayAndVoucher(String cp_orderno) {
|
|
|
+ return customerPayDao.queryCustomerPayAndVoucher(cp_orderno);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CustomerPay queryYSOrderPay(CustomerPay customerPay) {
|
|
|
return customerPayDao.queryYSOrderPay(customerPay);
|
|
|
}
|
|
|
- public int checkCustomerPay (CustomerPay customerPay) {
|
|
|
+
|
|
|
+ public int checkCustomerPay(CustomerPay customerPay) {
|
|
|
return customerPayDao.checkCustomerPay(customerPay);
|
|
|
}
|
|
|
+
|
|
|
public int insertCustomerPay(CustomerPay customerPay) {
|
|
|
- try{
|
|
|
+ try {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
customerPayDao.insertCustomerPay(customerPay);
|
|
|
EquipmenteHireHead equipmenteHireHead = new EquipmenteHireHead();
|
|
@@ -65,7 +85,7 @@ public class CustomerPayService {
|
|
|
equipmentLogService.insertEquipmentLog(equipmentLog);
|
|
|
}
|
|
|
|
|
|
- }catch (Exception ex){
|
|
|
+ } catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
return 0;
|
|
|
}
|
|
@@ -73,9 +93,9 @@ public class CustomerPayService {
|
|
|
}
|
|
|
|
|
|
public int insertCustomerPayOnLine(CustomerPay customerPay) {
|
|
|
- try{
|
|
|
+ try {
|
|
|
customerPayDao.insertCustomerPay(customerPay);
|
|
|
- }catch (Exception ex){
|
|
|
+ } catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
return 0;
|
|
|
}
|
|
@@ -83,22 +103,56 @@ public class CustomerPayService {
|
|
|
}
|
|
|
|
|
|
public int insertYsOrderPay(CustomerPay customerPay) {
|
|
|
- try{
|
|
|
- //验证是否已经付款
|
|
|
- int payCount = customerPayDao.checkCustomerPay(customerPay);
|
|
|
- if (payCount <= 0) {
|
|
|
- customerPayDao.insertCustomerPay(customerPay);
|
|
|
- //找到支付名称 保存氚云
|
|
|
- String payName = payMentsService.getPayName(customerPay.getCp_paytype());
|
|
|
- //锁定月嫂库存,增加介绍人返现金额,增加介绍人日志记录,变成介绍人(参加免单季),修改订单待付金额,传值CRM
|
|
|
- ysOrderService.updateYsOrderStatus(customerPay.getCp_orderno(),customerPay.getCp_orderstatus(),customerPay.getCp_payamount(),customerPay.getOd_biz_user(),payName);
|
|
|
- } else {
|
|
|
- return 9;
|
|
|
+ try {
|
|
|
+ int paySum = customerPayDao.queryPaySumByOrderNo(customerPay.getCp_orderno());
|
|
|
+ YSOrder ysOrder = ysOrderService.selectByOdNo(customerPay.getCp_orderno());
|
|
|
+ if (ysOrder.getOd_order_pay_amount() == paySum + customerPay.getCp_payamount()) {
|
|
|
+ customerPay.setCp_orderstatus(3);
|
|
|
}
|
|
|
- }catch (Exception ex){
|
|
|
+ customerPayDao.insertCustomerPay(customerPay);
|
|
|
+ //找到支付名称 保存氚云
|
|
|
+ String payName = payMentsService.getPayName(customerPay.getCp_paytype());
|
|
|
+ //锁定月嫂库存,增加介绍人返现金额,增加介绍人日志记录,变成介绍人(参加免单季),修改订单待付金额,传值CRM
|
|
|
+ ysOrderService.updateYsOrderStatus(customerPay.getCp_orderno(), customerPay.getCp_orderstatus(), customerPay.getCp_payamount(), customerPay.getOd_biz_user(), payName);
|
|
|
+ } catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
return 0;
|
|
|
}
|
|
|
return 1;
|
|
|
}
|
|
|
+
|
|
|
+ public BufferedImage createPayQrCode(String orderNo, String channel, Float price, Float originPrice, String title, String productName, Integer productId) throws Exception {
|
|
|
+ //调用支付接口
|
|
|
+ QrCodeUtils qrCodeUtils = new QrCodeUtils();
|
|
|
+ String url = null;
|
|
|
+ HttpPost httpPost = new HttpPost(CREATEQRURL);
|
|
|
+ CloseableHttpClient client = HttpClients.createDefault();
|
|
|
+ String respContent = null;
|
|
|
+ JSONObject jsonParam = new JSONObject();
|
|
|
+ jsonParam.put("orderNo", orderNo);
|
|
|
+ jsonParam.put("channel", channel);
|
|
|
+ jsonParam.put("price", price);
|
|
|
+ jsonParam.put("originPrice", originPrice);
|
|
|
+ jsonParam.put("title", title);
|
|
|
+ jsonParam.put("productName", productName);
|
|
|
+ jsonParam.put("productId", productId);
|
|
|
+ StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8");//解决中文乱码问题
|
|
|
+ entity.setContentEncoding("UTF-8");
|
|
|
+ entity.setContentType("application/json");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ HttpResponse resp = client.execute(httpPost);
|
|
|
+ HttpEntity he = resp.getEntity();
|
|
|
+ respContent = EntityUtils.toString(he, "UTF-8");
|
|
|
+ org.json.JSONObject jsonObject = new org.json.JSONObject(respContent);
|
|
|
+ if (channel.equals("alipay_qr")) {
|
|
|
+ url = jsonObject.getString("body");
|
|
|
+ } else if (channel.equals("wx_pub_qr")) {
|
|
|
+ url = jsonObject.getJSONObject("body").getString("codeUrl");
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //生成二维码
|
|
|
+
|
|
|
+ return qrCodeUtils.encodeIO(url, true);
|
|
|
+ }
|
|
|
}
|