| @@ -1,6 +1,4 @@ | |||||
| .idea/** | .idea/** | ||||
| mallinkAdmin/target/** | |||||
| mallinkApi/target/** | |||||
| mallinkService/target/** | |||||
| */target/** | |||||
| logs/** | logs/** | ||||
| uploads/** | uploads/** | ||||
| @@ -1,26 +1,39 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.util.Assert; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.Result; | import com.simple.common.Result; | ||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.WxCoupon; | import com.simple.domain.po.WxCoupon; | ||||
| import com.simple.domain.po.WxMerchant; | |||||
| import com.simple.service.WxCouponService; | import com.simple.service.WxCouponService; | ||||
| import com.simple.service.WxMerchantService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| @RestController | @RestController | ||||
| @RequestMapping("wxCoupon") | @RequestMapping("wxCoupon") | ||||
| @Api(description="优惠券接口") | |||||
| public class WxCouponController extends BaseController | public class WxCouponController extends BaseController | ||||
| { | { | ||||
| @Autowired | @Autowired | ||||
| private WxCouponService wxCouponService; | private WxCouponService wxCouponService; | ||||
| @Autowired | |||||
| private WxMerchantService wxMerchantService; | |||||
| private Logger logger = Logger.getLogger(WxCouponController.class); | private Logger logger = Logger.getLogger(WxCouponController.class); | ||||
| @@ -43,13 +56,24 @@ public class WxCouponController extends BaseController | |||||
| public ResultData add(@RequestBody WxCoupon wxCoupon) { | public ResultData add(@RequestBody WxCoupon wxCoupon) { | ||||
| //Assert.notNull(wxCoupon.getName(), "角色名不能为空"); | //Assert.notNull(wxCoupon.getName(), "角色名不能为空"); | ||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | ||||
| wxCouponService.saveOrUpdate(wxCoupon); | |||||
| if(StringUtils.isNotBlank(wxCoupon.getBusiness())) { | |||||
| String[] arys = wxCoupon.getBusiness().split(","); | |||||
| wxCoupon.setBusiness(JSON.toJSONString(arys)); | |||||
| } | |||||
| wxCouponService.saveOrUpdate(wxCoupon); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @ApiOperation("根据id更新接口") | @ApiOperation("根据id更新接口") | ||||
| @PostMapping("update") | @PostMapping("update") | ||||
| public ResultData update(@RequestBody WxCoupon wxCoupon) { | public ResultData update(@RequestBody WxCoupon wxCoupon) { | ||||
| if(wxCoupon.getId()==null) { | |||||
| return new ResultData(ResultData.ERROR,"缺少id"); | |||||
| } | |||||
| if(StringUtils.isNotBlank(wxCoupon.getBusiness())) { | |||||
| String[] arys = wxCoupon.getBusiness().split(","); | |||||
| wxCoupon.setBusiness(JSON.toJSONString(arys)); | |||||
| } | |||||
| wxCouponService.saveOrUpdate(wxCoupon); | wxCouponService.saveOrUpdate(wxCoupon); | ||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -66,7 +90,10 @@ public class WxCouponController extends BaseController | |||||
| @GetMapping("/findById") | @GetMapping("/findById") | ||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | ||||
| public ResultData findById(Long id) { | public ResultData findById(Long id) { | ||||
| return new ResultData(Result.SUCCESS,"查询成功",wxCouponService.getById(id)); | |||||
| WxCoupon c = wxCouponService.getById(id); | |||||
| WxMerchant merchant = wxMerchantService.getById(c.getMerchantId()); | |||||
| c.setWxMerchant(merchant); | |||||
| return new ResultData(Result.SUCCESS,"查询成功",c); | |||||
| } | } | ||||
| @@ -0,0 +1,36 @@ | |||||
| package com.simple.controller; | |||||
| import com.simple.common.Result; | |||||
| import com.simple.common.ResultData; | |||||
| import com.simple.domain.dto.WxUserCouponDto; | |||||
| import com.simple.service.WxUserCouponService; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| /** | |||||
| * Created by syf on 2018/8/10. | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("wxUserCoupon") | |||||
| public class WxUserCouponController { | |||||
| @Autowired | |||||
| private WxUserCouponService wxUserCouponService; | |||||
| @ApiOperation("查询用户卡券接口") | |||||
| @PostMapping("findByStatus") | |||||
| public ResultData findByStatus(@RequestBody WxUserCouponDto wxUserCoupon) { | |||||
| //根据用户id,用户卡券状态查找 | |||||
| if(wxUserCoupon==null||wxUserCoupon.getcUserId()==null||wxUserCoupon.getCouponStatus()==null){ | |||||
| return new ResultData(Result.ERROR,"查询失败"); | |||||
| } | |||||
| return new ResultData(Result.SUCCESS,"查询成功",wxUserCouponService.findList(wxUserCoupon.getcUserId(),wxUserCoupon.getCouponStatus())); | |||||
| } | |||||
| } | |||||
| @@ -20,8 +20,8 @@ spring: | |||||
| poolPreparedStatements: true | poolPreparedStatements: true | ||||
| maxOpenPreparedStatements: 20 | maxOpenPreparedStatements: 20 | ||||
| connectionProperties: "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=6000" | connectionProperties: "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=6000" | ||||
| jackson: | |||||
| date-format: yyyy-MM-dd HH:mm:ss | |||||
| #jackson: | |||||
| #date-format: yyyy-MM-dd HH:mm:ss | |||||
| # REDIS | # REDIS | ||||
| redis: | redis: | ||||
| @@ -3,13 +3,13 @@ | |||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
| <modelVersion>4.0.0</modelVersion> | <modelVersion>4.0.0</modelVersion> | ||||
| <parent> | |||||
| <parent> | |||||
| <artifactId>mallink</artifactId> | <artifactId>mallink</artifactId> | ||||
| <groupId>com.simple</groupId> | <groupId>com.simple</groupId> | ||||
| <version>1.0</version> | <version>1.0</version> | ||||
| </parent> | </parent> | ||||
| <artifactId>mallinkApi</artifactId> | |||||
| <artifactId>mallinkCclientApi</artifactId> | |||||
| <dependencies> | <dependencies> | ||||
| <dependency> | <dependency> | ||||
| @@ -22,12 +22,10 @@ | |||||
| <build> | <build> | ||||
| <plugins> | <plugins> | ||||
| <plugin> | <plugin> | ||||
| <groupId>org.apache.maven.plugins</groupId> | |||||
| <artifactId>maven-compiler-plugin</artifactId> | |||||
| <version>3.1</version> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-maven-plugin</artifactId> | |||||
| <configuration> | <configuration> | ||||
| <source>1.8</source> | |||||
| <target>1.8</target> | |||||
| <executable>true</executable> | |||||
| </configuration> | </configuration> | ||||
| </plugin> | </plugin> | ||||
| </plugins> | </plugins> | ||||
| @@ -1,7 +1,7 @@ | |||||
| spring: | spring: | ||||
| # JDBC | # JDBC | ||||
| datasource: | datasource: | ||||
| url: jdbc:mysql://202.165.179.86:63306/mallink?characterEncoding=UTF-8&useSSL=false | |||||
| url: jdbc:mysql://202.165.179.86:3306/mallink?characterEncoding=UTF-8&useSSL=false | |||||
| username: mallone | username: mallone | ||||
| password: m@1l0ne123@# | password: m@1l0ne123@# | ||||
| type: com.alibaba.druid.pool.DruidDataSource | type: com.alibaba.druid.pool.DruidDataSource | ||||
| @@ -19,12 +19,12 @@ spring: | |||||
| testOnReturn: false | testOnReturn: false | ||||
| poolPreparedStatements: true | poolPreparedStatements: true | ||||
| maxOpenPreparedStatements: 20 | maxOpenPreparedStatements: 20 | ||||
| jackson: | |||||
| date-format: yyyy-MM-dd HH:mm:ss | |||||
| #jackson: | |||||
| #date-format: yyyy-MM-dd HH:mm:ss | |||||
| # REDIS | # REDIS | ||||
| redis: | redis: | ||||
| host: 127.0.0.1 | |||||
| host: 202.165.179.86 | |||||
| port: 6789 | port: 6789 | ||||
| password: JGtest123 | password: JGtest123 | ||||
| timeout: 0 | timeout: 0 | ||||
| @@ -33,7 +33,6 @@ spring: | |||||
| max-active: 8 | max-active: 8 | ||||
| max-idle: 8 | max-idle: 8 | ||||
| max-wait: -1 | max-wait: -1 | ||||
| min-idle: 0 | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| @@ -1,6 +1,6 @@ | |||||
| server: | server: | ||||
| port: 9001 | |||||
| context-path: / | |||||
| port: 8000 | |||||
| context-path: /C | |||||
| spring: | spring: | ||||
| application: | application: | ||||
| @@ -0,0 +1,95 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <configuration> | |||||
| <!-- 修改一下路径--> | |||||
| <property name="PATH" value="logs"></property> | |||||
| <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |||||
| <encoder> | |||||
| <Pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] --%mdc{client}%msg%n</Pattern> | |||||
| </encoder> | |||||
| </appender> | |||||
| <appender name="TRACE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| <file>${PATH}/trace.log</file> | |||||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||||
| <FileNamePattern>logs/trace.%d{yyyy-MM-dd}.log</FileNamePattern> | |||||
| </rollingPolicy> | |||||
| <layout> | |||||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||||
| </layout> | |||||
| </appender> | |||||
| <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| <file>${PATH}/info.log</file> | |||||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||||
| <FileNamePattern>logs/info.%d{yyyy-MM-dd}.log</FileNamePattern> | |||||
| </rollingPolicy> | |||||
| <layout> | |||||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||||
| </layout> | |||||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||||
| <level>INFO</level> | |||||
| <onMatch>ACCEPT</onMatch> | |||||
| <onMismatch>DENY</onMismatch> | |||||
| </filter> | |||||
| </appender> | |||||
| <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| <file>${PATH}/debug.log</file> | |||||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||||
| <FileNamePattern>logs/debug.%d{yyyy-MM-dd}.log</FileNamePattern> | |||||
| </rollingPolicy> | |||||
| <layout> | |||||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||||
| </layout> | |||||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||||
| <level>DEBUG</level> | |||||
| <onMatch>ACCEPT</onMatch> | |||||
| <onMismatch>DENY</onMismatch> | |||||
| </filter> | |||||
| </appender> | |||||
| <appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| <file>${PATH}/warn.log</file> | |||||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||||
| <FileNamePattern>logs/warn.%d{yyyy-MM-dd}.log</FileNamePattern> | |||||
| </rollingPolicy> | |||||
| <layout> | |||||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||||
| </layout> | |||||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||||
| <level>WARN</level> | |||||
| <onMatch>ACCEPT</onMatch> | |||||
| <onMismatch>DENY</onMismatch> | |||||
| </filter> | |||||
| </appender> | |||||
| <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| <file>${PATH}/error.log</file> | |||||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||||
| <FileNamePattern>logs/error.%d{yyyy-MM-dd}.log</FileNamePattern> | |||||
| </rollingPolicy> | |||||
| <layout> | |||||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||||
| </layout> | |||||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||||
| <level>ERROR</level> | |||||
| <onMatch>ACCEPT</onMatch> | |||||
| <onMismatch>DENY</onMismatch> | |||||
| </filter> | |||||
| </appender> | |||||
| <root level="TRACE"> | |||||
| <appender-ref ref="TRACE_FILE" /> | |||||
| <appender-ref ref="INFO_FILE" /> | |||||
| <!-- <appender-ref ref="DEBUG_FILE" /> --> | |||||
| <!-- <appender-ref ref="WARN_FILE" /> --> | |||||
| <appender-ref ref="ERROR_FILE" /> | |||||
| </root> | |||||
| <root level="INFO"> | |||||
| <appender-ref ref="STDOUT" /> | |||||
| </root> | |||||
| </configuration> | |||||
| @@ -0,0 +1,69 @@ | |||||
| package com.simple.domain.dto; | |||||
| import java.io.Serializable; | |||||
| import java.util.Date; | |||||
| /** | |||||
| * Created by syf on 2018/8/10. | |||||
| * 用户卡券 | |||||
| */ | |||||
| public class WxUserCouponDto implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private Integer couponStatus; | |||||
| private Long orderId; | |||||
| private Long cUserId; | |||||
| private Long couponId; | |||||
| private String couponTitle; | |||||
| private Date validDate; | |||||
| public WxUserCouponDto(){ | |||||
| } | |||||
| public Integer getCouponStatus() { | |||||
| return couponStatus; | |||||
| } | |||||
| public void setCouponStatus(Integer couponStatus) { | |||||
| this.couponStatus = couponStatus; | |||||
| } | |||||
| public Long getOrderId() { | |||||
| return orderId; | |||||
| } | |||||
| public void setOrderId(Long orderId) { | |||||
| this.orderId = orderId; | |||||
| } | |||||
| public Long getcUserId() { | |||||
| return cUserId; | |||||
| } | |||||
| public void setcUserId(Long cUserId) { | |||||
| this.cUserId = cUserId; | |||||
| } | |||||
| public Long getCouponId() { | |||||
| return couponId; | |||||
| } | |||||
| public void setCouponId(Long couponId) { | |||||
| this.couponId = couponId; | |||||
| } | |||||
| public String getCouponTitle() { | |||||
| return couponTitle; | |||||
| } | |||||
| public void setCouponTitle(String couponTitle) { | |||||
| this.couponTitle = couponTitle; | |||||
| } | |||||
| public Date getValidDate() { | |||||
| return validDate; | |||||
| } | |||||
| public void setValidDate(Date validDate) { | |||||
| this.validDate = validDate; | |||||
| } | |||||
| } | |||||
| @@ -119,6 +119,18 @@ public class WxCoupon implements Serializable { | |||||
| /*业态**/ | /*业态**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="业态",name="business") | @io.swagger.annotations.ApiModelProperty(value="业态",name="business") | ||||
| private String business; | private String business; | ||||
| @Transient | |||||
| private WxMerchant wxMerchant; | |||||
| public WxMerchant getWxMerchant() { | |||||
| return wxMerchant; | |||||
| } | |||||
| public void setWxMerchant(WxMerchant wxMerchant) { | |||||
| this.wxMerchant = wxMerchant; | |||||
| } | |||||
| public String getTenantId() { | public String getTenantId() { | ||||
| return tenantId; | return tenantId; | ||||
| } | } | ||||
| @@ -1,9 +1,9 @@ | |||||
| package com.simple.pay; | package com.simple.pay; | ||||
| /** | /** | ||||
| * Created by fanglong on 2017/8/14. | |||||
| * Created by Stormeye on 2018/8/10. | |||||
| */ | */ | ||||
| public class WxPayOrder { | |||||
| public class WxPayOrderP { | |||||
| private String appid; // 公众账号ID | private String appid; // 公众账号ID | ||||
| private String mch_id; // 商户号 | private String mch_id; // 商户号 | ||||
| private String nonce_str; // 随机字符串 | private String nonce_str; // 随机字符串 | ||||
| @@ -0,0 +1,94 @@ | |||||
| package com.simple.pay; | |||||
| /** | |||||
| * Created by Stormeye on 2018/8/10. | |||||
| */ | |||||
| public class WxRefundOrder { | |||||
| private String appid; // 公众账号ID | |||||
| private String mch_id; // 商户号 | |||||
| private String nonce_str; // 随机字符串 | |||||
| private String sign; // 签名 | |||||
| private String out_trade_no; // 商户订单号 | |||||
| private String out_refund_no; // 商户退款单号 | |||||
| private Integer total_fee; // 支付金额 | |||||
| private Integer refund_fee; // 退款金额 | |||||
| public String getAppid() { | |||||
| return appid; | |||||
| } | |||||
| public void setAppid(String appid) { | |||||
| this.appid = appid; | |||||
| } | |||||
| public String getMch_id() { | |||||
| return mch_id; | |||||
| } | |||||
| public void setMch_id(String mch_id) { | |||||
| this.mch_id = mch_id; | |||||
| } | |||||
| public String getNonce_str() { | |||||
| return nonce_str; | |||||
| } | |||||
| public void setNonce_str(String nonce_str) { | |||||
| this.nonce_str = nonce_str; | |||||
| } | |||||
| public String getSign() { | |||||
| return sign; | |||||
| } | |||||
| public void setSign(String sign) { | |||||
| this.sign = sign; | |||||
| } | |||||
| public String getOut_trade_no() { | |||||
| return out_trade_no; | |||||
| } | |||||
| public void setOut_trade_no(String out_trade_no) { | |||||
| this.out_trade_no = out_trade_no; | |||||
| } | |||||
| public String getOut_refund_no() { | |||||
| return out_refund_no; | |||||
| } | |||||
| public void setOut_refund_no(String out_refund_no) { | |||||
| this.out_refund_no = out_refund_no; | |||||
| } | |||||
| public Integer getTotal_fee() { | |||||
| return total_fee; | |||||
| } | |||||
| public void setTotal_fee(Integer total_fee) { | |||||
| this.total_fee = total_fee; | |||||
| } | |||||
| public Integer getRefund_fee() { | |||||
| return refund_fee; | |||||
| } | |||||
| public void setRefund_fee(Integer refund_fee) { | |||||
| this.refund_fee = refund_fee; | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| final StringBuilder sb = new StringBuilder("WxRefundOrder{"); | |||||
| sb.append("appid='").append(appid).append('\''); | |||||
| sb.append(", mch_id='").append(mch_id).append('\''); | |||||
| sb.append(", nonce_str='").append(nonce_str).append('\''); | |||||
| sb.append(", sign='").append(sign).append('\''); | |||||
| sb.append(", out_trade_no='").append(out_trade_no).append('\''); | |||||
| sb.append(", out_refund_no='").append(out_refund_no).append('\''); | |||||
| sb.append(", total_fee=").append(total_fee); | |||||
| sb.append(", refund_fee=").append(refund_fee); | |||||
| sb.append('}'); | |||||
| return sb.toString(); | |||||
| } | |||||
| } | |||||
| @@ -52,6 +52,13 @@ public interface WxOrderService { | |||||
| * @param id | * @param id | ||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| /** | |||||
| * 条件查询不分页 | |||||
| * @param record | |||||
| * @return | |||||
| */ | |||||
| List<WxOrder> findList(WxOrder record); | |||||
| @@ -0,0 +1,15 @@ | |||||
| package com.simple.service; | |||||
| import com.simple.domain.dto.WxUserCouponDto; | |||||
| import java.util.List; | |||||
| /** | |||||
| * Created by syf on 2018/8/10. | |||||
| */ | |||||
| public interface WxUserCouponService { | |||||
| List<WxUserCouponDto> findList(Long userId, int status); | |||||
| } | |||||
| @@ -128,12 +128,11 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| wxOrderMapper.deleteByPrimaryKey(id); | wxOrderMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public List<WxOrder> findList(WxOrder record) { | |||||
| return wxOrderMapper.findList(record); | |||||
| } | |||||
| } | } | ||||
| @@ -15,9 +15,12 @@ import com.simple.exception.BizMessageException; | |||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.mapper.WxOrderMapper; | import com.simple.mapper.WxOrderMapper; | ||||
| import com.simple.mapper.WxPayOrderMapper; | import com.simple.mapper.WxPayOrderMapper; | ||||
| import com.simple.pay.WxPay; | |||||
| import com.simple.pay.WxPayOrderP; | |||||
| import com.simple.pay.WxPayment; | import com.simple.pay.WxPayment; | ||||
| import com.simple.service.WxOrderService; | import com.simple.service.WxOrderService; | ||||
| import com.simple.service.WxPayOrderService; | import com.simple.service.WxPayOrderService; | ||||
| import com.simple.utils.BeanUtils; | |||||
| import com.simple.utils.Utility; | import com.simple.utils.Utility; | ||||
| import com.simple.utils.XmlUtil; | import com.simple.utils.XmlUtil; | ||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| @@ -44,6 +47,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| @Override | @Override | ||||
| public ResultData createPayOrder(WxPayOrder record, EnumPayWay payWay) { | public ResultData createPayOrder(WxPayOrder record, EnumPayWay payWay) { | ||||
| String partnerKey = null; | |||||
| try { | try { | ||||
| // 1. check 订单 | // 1. check 订单 | ||||
| WxOrder order = wxOrderMapper.selectByPrimaryKey(record.getOrderId()); | WxOrder order = wxOrderMapper.selectByPrimaryKey(record.getOrderId()); | ||||
| @@ -55,6 +59,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| logger.warn("pay order, order status not allow, repaymentReq: " + order.toString() + " , payWay: " + payWay.toString()); | logger.warn("pay order, order status not allow, repaymentReq: " + order.toString() + " , payWay: " + payWay.toString()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_PAY); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_PAY); | ||||
| } | } | ||||
| // TODO body | |||||
| String body = ""; | |||||
| // 2. 创建支付订单 | // 2. 创建支付订单 | ||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| final IdWorker idworker = IdWorker.get(); | final IdWorker idworker = IdWorker.get(); | ||||
| @@ -73,9 +79,48 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| record.setPayOrderStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); | record.setPayOrderStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); | ||||
| wxPayOrderMapper.insertSelective(record); | wxPayOrderMapper.insertSelective(record); | ||||
| // 统一下单 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||||
| //wxPayOrderP.setAppid(wechatAppId); | |||||
| //wxPayOrderP.setMch_id(wechatMchId); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| //wxPayOrderP.setBody(body); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| BigDecimal llp = order.getPayment().multiply(new BigDecimal(100)); | |||||
| wxPayOrderP.setTotal_fee(llp.intValue()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| //wxPayOrderP.setNotify_url(wxpayNotifyUrl); | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.APP.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime)); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentTime + 15 * 60)); // 15分钟结束 | |||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), partnerKey)); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, wxPayOrder:" + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| if ("SUCCESS".equals(returnMap.get("result_code"))) { | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = new HashMap<>(); | |||||
| sighMap.put("appid", returnMap.get("appid")); | |||||
| sighMap.put("partnerid", returnMap.get("mch_id")); | |||||
| sighMap.put("prepayid", returnMap.get("prepay_id")); | |||||
| sighMap.put("package", "Sign=WXPay"); | |||||
| sighMap.put("noncestr", noncestr); | |||||
| sighMap.put("timestamp", timestamp); | |||||
| String signAgent = WxPayment.createSign(sighMap, partnerKey); | |||||
| returnMap.put("timestamp", timestamp); | |||||
| returnMap.put("nonce_str", noncestr); | |||||
| returnMap.put("package", "Sign=WXPay"); | |||||
| returnMap.put("sign", signAgent); | |||||
| return new ResultData(200, "创建支付订单成功", returnMap); | |||||
| } | |||||
| return new ResultData(record); | return new ResultData(record); | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| throw new MallinkException(ErrorCode.PAYORDER_ERROR); | throw new MallinkException(ErrorCode.PAYORDER_ERROR); | ||||
| } catch (Exception e) { | |||||
| throw new MallinkException(ErrorCode.PAYORDER_ERROR); | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,65 @@ | |||||
| package com.simple.service.impl; | |||||
| import com.simple.domain.dto.WxUserCouponDto; | |||||
| import com.simple.domain.po.WxCoupon; | |||||
| import com.simple.domain.po.WxOrder; | |||||
| import com.simple.mapper.WxCouponMapper; | |||||
| import com.simple.service.WxOrderService; | |||||
| import com.simple.service.WxUserCouponService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import java.util.stream.Collectors; | |||||
| /** | |||||
| * Created by syf on 2018/8/10. | |||||
| */ | |||||
| @Service | |||||
| public class WxUserCouponServiceImpl implements WxUserCouponService { | |||||
| @Autowired | |||||
| private WxOrderService wxOrderService; | |||||
| @Autowired | |||||
| private WxCouponMapper wxCouponMapper; | |||||
| /** | |||||
| * | |||||
| * @param userId 用户id | |||||
| * @param status 用户卡券状态 | |||||
| * @return | |||||
| */ | |||||
| @Override | |||||
| public List<WxUserCouponDto> findList(Long userId, int status) { | |||||
| //TODO 待测试优化 | |||||
| List<WxUserCouponDto> wxUserCoupons = new ArrayList<>(); | |||||
| //查询订单表 | |||||
| WxOrder wxOrder = new WxOrder(); | |||||
| wxOrder.setCUserId(userId); | |||||
| wxOrder.setCouponStatus(status); | |||||
| List<WxOrder> orders = wxOrderService.findList(wxOrder); | |||||
| List<String> ids = orders.stream().map(p->p.getCouponId()+"").distinct().collect(Collectors.toList()); | |||||
| if(ids.size()>0){ | |||||
| //查询WxCoupon | |||||
| WxCoupon wxCoupon = new WxCoupon(); | |||||
| wxCoupon.setIds(ids); | |||||
| List<WxCoupon> wxCoupons = wxCouponMapper.findList(wxCoupon); | |||||
| Map<Long,String> couponNamesMap = wxCoupons.stream().collect(Collectors.toMap(WxCoupon::getId,p->p.getTitle())); | |||||
| for (WxOrder temp:orders) { | |||||
| wxUserCoupons.add(getWxUserCoupon(temp,couponNamesMap.get(temp.getCouponId()))); | |||||
| } | |||||
| } | |||||
| return wxUserCoupons; | |||||
| } | |||||
| public WxUserCouponDto getWxUserCoupon(WxOrder wxOrder, String title){ | |||||
| WxUserCouponDto wxUserCoupon = new WxUserCouponDto(); | |||||
| wxUserCoupon.setOrderId(wxOrder.getId()); | |||||
| wxUserCoupon.setcUserId(wxOrder.getCUserId()); | |||||
| wxUserCoupon.setCouponId(wxOrder.getCouponId()); | |||||
| wxUserCoupon.setCouponStatus(wxOrder.getCouponStatus()); | |||||
| wxUserCoupon.setValidDate(wxOrder.getValidDate()); | |||||
| wxUserCoupon.setCouponTitle(title); | |||||
| return wxUserCoupon; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,167 @@ | |||||
| package com.simple.utils; | |||||
| import com.google.gson.internal.LinkedTreeMap; | |||||
| import java.beans.BeanInfo; | |||||
| import java.beans.IntrospectionException; | |||||
| import java.beans.Introspector; | |||||
| import java.beans.PropertyDescriptor; | |||||
| import java.lang.reflect.InvocationTargetException; | |||||
| import java.lang.reflect.Method; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import java.util.Objects; | |||||
| import java.util.stream.Collectors; | |||||
| /** | |||||
| * Created by Stormeye on 2018/8/10. | |||||
| */ | |||||
| public class BeanUtils { | |||||
| /** | |||||
| * 如果是null,将返回字符串0 | |||||
| * | |||||
| * @param param | |||||
| * @return | |||||
| */ | |||||
| public static String ifNullTo0(String param) { | |||||
| if (param == null || param.equals("null")) { | |||||
| return "0"; | |||||
| } | |||||
| return param; | |||||
| } | |||||
| public static Object getValue(Object obj, String pro) throws NoSuchMethodException { | |||||
| return getValue(obj, pro, null); | |||||
| } | |||||
| /** | |||||
| * 根据属性名称获取JavaBean中对应的属性值 | |||||
| * | |||||
| * @param obj 对象 | |||||
| * @param pro 对应属性名称 | |||||
| * @param num 整型参数 | |||||
| * @return 对象对应属性值 | |||||
| */ | |||||
| public static Object getValue(Object obj, String pro, Integer num) throws NoSuchMethodException { | |||||
| Class<?> clazz = obj.getClass(); | |||||
| do { | |||||
| try { | |||||
| String methodName = "getSimpleRegionModel" + pro.substring(0, 1).toUpperCase() + pro.substring(1); | |||||
| Method method; | |||||
| if (!Objects.isNull(num)) { | |||||
| method = clazz.getDeclaredMethod(methodName, Integer.class); | |||||
| return method.invoke(obj, num); | |||||
| } else { | |||||
| method = clazz.getDeclaredMethod(methodName); | |||||
| return method.invoke(obj); | |||||
| } | |||||
| } catch (NoSuchMethodException e) { | |||||
| clazz = clazz.getSuperclass(); | |||||
| } catch (InvocationTargetException | IllegalAccessException e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } while (clazz != Object.class); | |||||
| throw new NoSuchMethodException("no such method name : " + "getSimpleRegionModel" + pro.substring(0, 1).toUpperCase() + pro.substring(1)); | |||||
| } | |||||
| public static void transMap2Bean2(Map<String, Object> map, Object obj) { | |||||
| if (map == null || obj == null) { | |||||
| return; | |||||
| } | |||||
| try { | |||||
| org.apache.commons.beanutils.BeanUtils.populate(obj, map); | |||||
| } catch (Exception e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * 根据key数组和value数组拼接json | |||||
| * | |||||
| * @param keys key数组 | |||||
| * @param values value数据 | |||||
| * @return json | |||||
| * @throws Exception | |||||
| */ | |||||
| public static String wrapToJsonByKeyValue(String[] keys, String[] values) throws Exception { | |||||
| StringBuilder stringBuilder = new StringBuilder(); | |||||
| if (keys.length != values.length) { | |||||
| throw new Exception("长度不匹配,不能进行JSON格式的转换"); | |||||
| } | |||||
| for (int i = 0; i < keys.length; i++) { | |||||
| stringBuilder.append("\"").append(keys[i]).append("\":\"").append(values[i]).append("\","); | |||||
| } | |||||
| return "{" + stringBuilder.substring(0, stringBuilder.length() - 1) + "}"; | |||||
| } | |||||
| /** | |||||
| * Converts a JavaBean to a map | |||||
| * | |||||
| * @param bean JavaBean to convert | |||||
| * @return map converted | |||||
| * @throws IntrospectionException failed to get class fields | |||||
| * @throws IllegalAccessException failed to instant JavaBean | |||||
| * @throws InvocationTargetException failed to call setters | |||||
| */ | |||||
| public static final Map<String, Object> toMap(Object bean) | |||||
| throws Exception { | |||||
| Map<String, Object> returnMap = new LinkedTreeMap(); | |||||
| if (bean instanceof Map) { | |||||
| returnMap.putAll((Map<String, Object>)bean); | |||||
| return returnMap; | |||||
| } | |||||
| BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); | |||||
| PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); | |||||
| for (int i = 0; i< propertyDescriptors.length; i++) { | |||||
| PropertyDescriptor descriptor = propertyDescriptors[i]; | |||||
| String propertyName = descriptor.getName(); | |||||
| if (!propertyName.equals("class")) { | |||||
| Method readMethod = descriptor.getReadMethod(); | |||||
| Object result = readMethod.invoke(bean, new Object[0]); | |||||
| if (result != null) { | |||||
| returnMap.put(propertyName, result); | |||||
| } else { | |||||
| returnMap.put(propertyName, ""); | |||||
| } | |||||
| } | |||||
| } | |||||
| return returnMap; | |||||
| } | |||||
| /** | |||||
| * Converts a JavaBean to a map | |||||
| * | |||||
| * @param bean JavaBean to convert | |||||
| * @return map converted | |||||
| * @throws IntrospectionException failed to get class fields | |||||
| * @throws IllegalAccessException failed to instant JavaBean | |||||
| * @throws InvocationTargetException failed to call setters | |||||
| */ | |||||
| public static final Map<String, String> toStringMap(Object bean) | |||||
| throws Exception { | |||||
| Map<String, String> returnMap = new LinkedTreeMap(); | |||||
| if (bean instanceof Map) { | |||||
| returnMap.putAll((Map<String, String>)bean); | |||||
| return returnMap; | |||||
| } | |||||
| BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); | |||||
| PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); | |||||
| for (int i = 0; i< propertyDescriptors.length; i++) { | |||||
| PropertyDescriptor descriptor = propertyDescriptors[i]; | |||||
| String propertyName = descriptor.getName(); | |||||
| if (!propertyName.equals("class")) { | |||||
| Method readMethod = descriptor.getReadMethod(); | |||||
| Object result = readMethod.invoke(bean, new Object[0]); | |||||
| if (result != null) { | |||||
| returnMap.put(propertyName, String.valueOf(result)); | |||||
| } else { | |||||
| returnMap.put(propertyName, ""); | |||||
| } | |||||
| } | |||||
| } | |||||
| return returnMap; | |||||
| } | |||||
| } | |||||
| @@ -13,7 +13,7 @@ | |||||
| <modules> | <modules> | ||||
| <module>mallinkService</module> | <module>mallinkService</module> | ||||
| <module>mallinkAdmin</module> | <module>mallinkAdmin</module> | ||||
| <module>mallinkApi</module> | |||||
| <module>mallinkCclientApi</module> | |||||
| </modules> | </modules> | ||||
| <parent> | <parent> | ||||
| @@ -200,6 +200,13 @@ | |||||
| <artifactId>dom4j</artifactId> | <artifactId>dom4j</artifactId> | ||||
| <version>2.1.1</version> | <version>2.1.1</version> | ||||
| </dependency> | </dependency> | ||||
| <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> | |||||
| <dependency> | |||||
| <groupId>com.google.code.gson</groupId> | |||||
| <artifactId>gson</artifactId> | |||||
| <version>2.8.5</version> | |||||
| </dependency> | |||||