From 2b00033917b4157e3d40843d15a7188e34a6d63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=8D=9A?= Date: Thu, 14 Nov 2024 17:24:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shapelight/common/config/GlobalValue.java | 2 + .../controller/AppParentWxController.java | 111 +++++++++++ .../modules/fegin/OpFeignClient.java | 4 + .../shapelight/modules/fegin/OpHystrix.java | 5 + .../modules/mobile/entity/MobilePackage.java | 4 +- .../mobile/entity/MobilePackageOrder.java | 173 +----------------- .../src/main/resources/application.yml | 1 + .../mapper/mobile/MobilePackageMapper.xml | 2 +- .../mobile/MobilePackageOrderMapper.xml | 4 +- 9 files changed, 129 insertions(+), 177 deletions(-) create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/appparent/controller/AppParentWxController.java diff --git a/shapelight-admin/src/main/java/net/shapelight/common/config/GlobalValue.java b/shapelight-admin/src/main/java/net/shapelight/common/config/GlobalValue.java index 43fe6ea..e2319bb 100644 --- a/shapelight-admin/src/main/java/net/shapelight/common/config/GlobalValue.java +++ b/shapelight-admin/src/main/java/net/shapelight/common/config/GlobalValue.java @@ -94,6 +94,8 @@ public class GlobalValue { private String wxSecret; @Value("${global.wx.url}") private String wxUrl; + @Value("${global.wx.mchid}") + private String mchid; @Value("${global.app.key}") private String appKey; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/appparent/controller/AppParentWxController.java b/shapelight-admin/src/main/java/net/shapelight/modules/appparent/controller/AppParentWxController.java new file mode 100644 index 0000000..2054435 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/appparent/controller/AppParentWxController.java @@ -0,0 +1,111 @@ +package net.shapelight.modules.appparent.controller; + +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import net.shapelight.common.config.GlobalValue; +import net.shapelight.common.utils.IpUtils; +import net.shapelight.common.utils.SnowflakeIdWorker; +import net.shapelight.modules.app.annotation.Login; +import net.shapelight.modules.app.annotation.LoginUser; +import net.shapelight.modules.fegin.OpFeignClient; +import net.shapelight.modules.mobile.entity.MobilePackage; +import net.shapelight.modules.mobile.entity.MobilePackageOrder; +import net.shapelight.modules.mobile.service.MobilePackageOrderService; +import net.shapelight.modules.mobile.service.MobilePackageService; +import net.shapelight.modules.ten.entity.TenParent; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@RestController +@RequestMapping("/wx") +public class AppParentWxController { + + @Autowired + MobilePackageOrderService orderService; + @Autowired + MobilePackageService packageService; + @Autowired + GlobalValue globalValue; + @Qualifier("net.shapelight.modules.fegin.OpFeignClient") + @Autowired + private OpFeignClient opFeignClient; + + @Login + @PostMapping("创建订单") + @ApiImplicitParams({ + @ApiImplicitParam(name="openId",value = "客户唯一标识",paramType = "query",dataType = "String",required = true), + @ApiImplicitParam(name="package_id",value = "套餐ID",paramType = "query",dataType = "String",required = true), + }) + public String createOrder(@LoginUser TenParent parent, @RequestParam Map params) { + MobilePackage mobilePackage = packageService.getById(params.get("package_id").toString()); + MobilePackageOrder packageOrder = new MobilePackageOrder(); + Long id = new SnowflakeIdWorker().nextId(); + packageOrder.setOrderId(id); + packageOrder.setPackageId(mobilePackage.getPackageId()); + packageOrder.setParentId(parent.getId()); + packageOrder.setPayment(mobilePackage.getPrice().multiply(mobilePackage.getDiscount())); + packageOrder.setPayStatus(0); + Date currentDate = new Date(); + if(mobilePackage.getEffectType().equals(0)) { + // 获取当前时间 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(currentDate); + packageOrder.setEffectiveDate(currentDate); + packageOrder.setStatus(1); + calendar.add(Calendar.MONTH, 1); + Date result = calendar.getTime(); + packageOrder.setExpireTime(result); + } else { + // 获取当前时间 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(currentDate); + calendar.add(Calendar.MONTH, 1); + Date result = calendar.getTime(); + packageOrder.setEffectiveDate(result); + packageOrder.setStatus(0); + calendar.add(Calendar.MONTH, 1); + packageOrder.setExpireTime(calendar.getTime()); + } + if(mobilePackage.getPackageModel().equals(0)) { + packageOrder.setRemainderTime(mobilePackage.getDuration()); + } else if (mobilePackage.getPackageModel().equals(1)) { + packageOrder.setRemainderCount(mobilePackage.getCallCount()); + } + Map wxParams = new HashMap<>(); + wxParams.put("appid",globalValue.getWxAppid()); + wxParams.put("mchid",globalValue.getMchid()); + wxParams.put("description",mobilePackage.getPackageName()); + wxParams.put("out_trade_no",packageOrder.getOrderId()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(currentDate); + calendar.add(Calendar.SECOND, 30); + wxParams.put("time_expire",calendar.getTime()); + wxParams.put("attach",packageOrder.getOrderId()); + wxParams.put("notify_url", IpUtils.getHostIp()+"/cell/wx/pay"); + wxParams.put("goods_tag","xg"); + wxParams.put("support_fapiao",true); + Map amount = new HashMap<>(); + amount.put("total",packageOrder.getPayment().intValue()); + amount.put("currency","CNY"); + wxParams.put("amount",amount); + Map payer = new HashMap<>(); + payer.put("openid",params.get("openId").toString()); + wxParams.put("payer",payer); + JSONObject jsonObject = opFeignClient.createOrder(wxParams); + return jsonObject.getString("prepay_id"); + + } +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpFeignClient.java b/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpFeignClient.java index 0d7cba8..4d2efd2 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpFeignClient.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpFeignClient.java @@ -75,6 +75,10 @@ public interface OpFeignClient { JSONObject getLicenseDeviceInfo(@RequestBody Map params); + @PostMapping("v3/pay/transactions/jsapi") + JSONObject createOrder(@RequestBody Map params); + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpHystrix.java b/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpHystrix.java index 552f761..6e603e6 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpHystrix.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/fegin/OpHystrix.java @@ -62,6 +62,11 @@ public class OpHystrix implements FallbackFactory { public JSONObject getLicenseDeviceInfo(Map params) { return null; } + + @Override + public JSONObject createOrder(Map params) { + return null; + } }; } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackage.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackage.java index d544dc1..0ccaf98 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackage.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackage.java @@ -76,10 +76,8 @@ public class MobilePackage implements Serializable { /** * 套餐模式 */ - @Size(max= 10,message="编码长度不能超过10") @ApiModelProperty("套餐模式") - @Length(max= 10,message="编码长度不能超过10") - private String packageModel; + private Integer packageModel; /** * 折扣 */ diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackageOrder.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackageOrder.java index 6336635..08a6805 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackageOrder.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/entity/MobilePackageOrder.java @@ -33,7 +33,7 @@ public class MobilePackageOrder implements Serializable { * 学生ID */ @ApiModelProperty("学生ID") - private Long personId; + private Long parentId; /** * 套餐ID */ @@ -80,180 +80,11 @@ public class MobilePackageOrder implements Serializable { @Size(max= 20,message="编码长度不能超过20") @ApiModelProperty("学生姓名") @Length(max= 20,message="编码长度不能超过20") - private String personName; + private String parentName; /** * 到期时间 */ @ApiModelProperty("到期时间") private Date expireTime; - /** - * 订单ID - */ - private void setOrderId(Long orderId){ - this.orderId = orderId; - } - - /** - * 学生ID - */ - private void setPersonId(Long personId){ - this.personId = personId; - } - - /** - * 套餐ID - */ - private void setPackageId(Long packageId){ - this.packageId = packageId; - } - - /** - * 支付金额 - */ - private void setPayment(BigDecimal payment){ - this.payment = payment; - } - - /** - * 付款时间 - */ - private void setPayTime(Date payTime){ - this.payTime = payTime; - } - - /** - * 支付状态(1已支付0未支付) - */ - private void setPayStatus(Integer payStatus){ - this.payStatus = payStatus; - } - - /** - * 生效时间 - */ - private void setEffectiveDate(Date effectiveDate){ - this.effectiveDate = effectiveDate; - } - - /** - * 剩余时长 - */ - private void setRemainderTime(Integer remainderTime){ - this.remainderTime = remainderTime; - } - - /** - * 剩余次数 - */ - private void setRemainderCount(Integer remainderCount){ - this.remainderCount = remainderCount; - } - - /** - * 生效状态 - */ - private void setStatus(Integer status){ - this.status = status; - } - - /** - * 学生姓名 - */ - private void setPersonName(String personName){ - this.personName = personName; - } - - /** - * 到期时间 - */ - private void setExpireTime(Date expireTime){ - this.expireTime = expireTime; - } - - - /** - * 订单ID - */ - private Long getOrderId(){ - return this.orderId; - } - - /** - * 学生ID - */ - private Long getPersonId(){ - return this.personId; - } - - /** - * 套餐ID - */ - private Long getPackageId(){ - return this.packageId; - } - - /** - * 支付金额 - */ - private BigDecimal getPayment(){ - return this.payment; - } - - /** - * 付款时间 - */ - private Date getPayTime(){ - return this.payTime; - } - - /** - * 支付状态(1已支付0未支付) - */ - private Integer getPayStatus(){ - return this.payStatus; - } - - /** - * 生效时间 - */ - private Date getEffectiveDate(){ - return this.effectiveDate; - } - - /** - * 剩余时长 - */ - private Integer getRemainderTime(){ - return this.remainderTime; - } - - /** - * 剩余次数 - */ - private Integer getRemainderCount(){ - return this.remainderCount; - } - - /** - * 生效状态 - */ - private Integer getStatus(){ - return this.status; - } - - /** - * 学生姓名 - */ - private String getPersonName(){ - return this.personName; - } - - /** - * 到期时间 - */ - private Date getExpireTime(){ - return this.expireTime; - } - } diff --git a/shapelight-admin/src/main/resources/application.yml b/shapelight-admin/src/main/resources/application.yml index 1d65e06..d046762 100644 --- a/shapelight-admin/src/main/resources/application.yml +++ b/shapelight-admin/src/main/resources/application.yml @@ -109,6 +109,7 @@ global: appid: wx313273bb23519704 secret: a9162ffebee8e9892418bb78d86d7a80 url: https://api.weixin.qq.com/ + mchid: 1684613818 tcp_server: port: 8086 app: diff --git a/shapelight-admin/src/main/resources/mapper/mobile/MobilePackageMapper.xml b/shapelight-admin/src/main/resources/mapper/mobile/MobilePackageMapper.xml index cde99cd..b29b687 100644 --- a/shapelight-admin/src/main/resources/mapper/mobile/MobilePackageMapper.xml +++ b/shapelight-admin/src/main/resources/mapper/mobile/MobilePackageMapper.xml @@ -7,7 +7,7 @@ - + diff --git a/shapelight-admin/src/main/resources/mapper/mobile/MobilePackageOrderMapper.xml b/shapelight-admin/src/main/resources/mapper/mobile/MobilePackageOrderMapper.xml index 50584f0..14d5a85 100644 --- a/shapelight-admin/src/main/resources/mapper/mobile/MobilePackageOrderMapper.xml +++ b/shapelight-admin/src/main/resources/mapper/mobile/MobilePackageOrderMapper.xml @@ -6,7 +6,7 @@ - + @@ -15,7 +15,7 @@ - + From e0e0e8e9535c4111f367602f0ce5577af7ae4bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=8D=9A?= Date: Thu, 14 Nov 2024 18:00:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shapelight/modules/mobile/mapper/MobileCallLogsMapper.java | 2 ++ .../modules/mobile/mapper/MobileDeviceGroupMapper.java | 2 ++ .../shapelight/modules/mobile/mapper/MobileDeviceMapper.java | 2 ++ .../shapelight/modules/mobile/mapper/MobilePackageMapper.java | 2 ++ .../modules/mobile/mapper/MobilePackageOrderMapper.java | 2 ++ 5 files changed, 10 insertions(+) diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileCallLogsMapper.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileCallLogsMapper.java index 86cb6a0..73a3359 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileCallLogsMapper.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileCallLogsMapper.java @@ -2,6 +2,7 @@ package net.shapelight.modules.mobile.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import net.shapelight.modules.mobile.entity.MobileCallLogs; +import org.apache.ibatis.annotations.Mapper; /** * @author zhangbo @@ -9,6 +10,7 @@ import net.shapelight.modules.mobile.entity.MobileCallLogs; * @createDate 2024-11-14 09:51:55 * @Entity net.shapelight.modules.mobile.entity.MobileCallLogs */ +@Mapper public interface MobileCallLogsMapper extends BaseMapper { } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileDeviceGroupMapper.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileDeviceGroupMapper.java index 2837d7b..9fc84fd 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileDeviceGroupMapper.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileDeviceGroupMapper.java @@ -2,6 +2,7 @@ package net.shapelight.modules.mobile.mapper; import net.shapelight.modules.mobile.entity.MobileDeviceGroup; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; /** * @author zhangbo @@ -9,6 +10,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; * @createDate 2024-11-13 11:50:36 * @Entity net.shapelight.modules.mobile.entity.MobileDeviceGroup */ +@Mapper public interface MobileDeviceGroupMapper extends BaseMapper { } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileDeviceMapper.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileDeviceMapper.java index 6f307ce..d4fbe15 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileDeviceMapper.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobileDeviceMapper.java @@ -2,6 +2,7 @@ package net.shapelight.modules.mobile.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import net.shapelight.modules.mobile.entity.MobileDevice; +import org.apache.ibatis.annotations.Mapper; /** * @author zhangbo @@ -9,6 +10,7 @@ import net.shapelight.modules.mobile.entity.MobileDevice; * @createDate 2024-11-13 14:36:39 * @Entity net.shapelight.modules.mobile.entity.MobileDevice */ +@Mapper public interface MobileDeviceMapper extends BaseMapper { } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobilePackageMapper.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobilePackageMapper.java index 6e60a93..391be3c 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobilePackageMapper.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobilePackageMapper.java @@ -2,6 +2,7 @@ package net.shapelight.modules.mobile.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import net.shapelight.modules.mobile.entity.MobilePackage; +import org.apache.ibatis.annotations.Mapper; /** * @author zhangbo @@ -9,6 +10,7 @@ import net.shapelight.modules.mobile.entity.MobilePackage; * @createDate 2024-11-14 09:50:19 * @Entity net.shapelight.modules.mobile.entity.MobilePackage */ +@Mapper public interface MobilePackageMapper extends BaseMapper { } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobilePackageOrderMapper.java b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobilePackageOrderMapper.java index b2a0669..b1b7b4c 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobilePackageOrderMapper.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/mobile/mapper/MobilePackageOrderMapper.java @@ -2,6 +2,7 @@ package net.shapelight.modules.mobile.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import net.shapelight.modules.mobile.entity.MobilePackageOrder; +import org.apache.ibatis.annotations.Mapper; /** * @author zhangbo @@ -9,6 +10,7 @@ import net.shapelight.modules.mobile.entity.MobilePackageOrder; * @createDate 2024-11-14 09:51:08 * @Entity net.shapelight.modules.mobile.entity.MobilePackageOrder */ +@Mapper public interface MobilePackageOrderMapper extends BaseMapper { }