Ver Fonte

修改调整新增积分订单

jk-GitHub-coder há 4 anos atrás
pai
commit
79f269ffec

+ 46 - 11
YijiaRestful/src/main/java/com/platform/yijia/controller/IntegralOrderController.java

@@ -6,6 +6,8 @@ import com.platform.yijia.service.*;
 import com.platform.yijia.utils.CodeMsg;
 import com.platform.yijia.utils.ResultData;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
@@ -14,10 +16,11 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.Random;
 
 /*
- * <Title> IntegralWaresController </Title>
+ * <Title> IntegralOrderController </Title>
  * <Description> 油站积分商城 </Description>
  * @Author JK
  * @Date 2021年2月24日
@@ -25,12 +28,15 @@ import java.util.Random;
 @Controller
 @RequestMapping("/api")
 public class IntegralOrderController {
+    private static Logger logger =(Logger) LoggerFactory.getLogger(IntegralOrderController.class);
     @Resource
     private IntegralWaresService integralWaresService;
     @Resource
     private IntegralOrderService integralOrderService;
     @Resource
     private CustomerPointsService customerPointsService;
+    @Resource
+    private StationService stationService;
 
     //获取油站积分商品信息
     @RequestMapping(value = "/getIntegralWaresInfoList", method = RequestMethod.GET)
@@ -51,10 +57,10 @@ public class IntegralOrderController {
     }
 
     //生成积分订单
-    @RequestMapping(value = "/insertIntegralOrder", method = RequestMethod.GET)
+    @RequestMapping(value = "/insertIntegralOrder", method = RequestMethod.POST)
     @ResponseBody
     @Transactional
-    public String insertIntegralOrder(@RequestParam IntegralOrder request){
+    public String insertIntegralOrder(@RequestBody IntegralOrder request){
         Gson gson =new Gson();
         //返回结果集
         ResultData resultData = null;
@@ -68,29 +74,58 @@ public class IntegralOrderController {
         if(request.getExchangeNum() != null){
             integralOrder.setExchangeNum(request.getExchangeNum());
         }
+        if(request.getStationId() != null){
+            integralOrder.setStationId(request.getStationId());
+        }
+        if(request.getWaresId() !=null){
+            integralOrder.setWaresId(request.getWaresId());
+        }
         if(StringUtils.isNotBlank(request.getUnionId())){
             integralOrder.setUnionId(request.getUnionId());
         }
+        if(request.getIntegral() !=null){
+            integralOrder.setIntegral(request.getIntegral());
+        }
+
+        integralOrder.setStatus("1");   //订单状态
+
         //订单规则 时间+6位随机数
         Random random = new Random();
         String str="";
         for(int i=0; i<6; i++){
             str+=random.nextInt(10);
         }
-        integralOrder.setIntegralOrderNo(Integer.valueOf(System.nanoTime()+str));
+        integralOrder.setIntegralOrderNo(System.nanoTime()+str);
         integralOrder.setExchangeTime(new Date());
 
         //更新用户积分
         CustomerPoints customerPoints = new CustomerPoints();
         customerPoints.setUnionId(request.getUnionId());
         CustomerPoints customerPointsInfo = customerPointsService.getCustomerPointsInfo(customerPoints);
-        //用户剩余积分
-        BigDecimal points = new BigDecimal(customerPointsInfo.getPoints()).subtract(new BigDecimal(request.getIntegral()));
-        customerPoints.setPoints(Integer.valueOf(points.toString()));
-        //用户已消费积分累积
-        BigDecimal consumptionPoints = new BigDecimal(customerPointsInfo.getConsumptionPoints()).add(new BigDecimal(request.getIntegral()));
-        customerPoints.setConsumptionPoints(Integer.valueOf(consumptionPoints.toString()));
-        customerPointsService.updateCustomerPointsInfo(customerPoints);
+        if(customerPointsInfo !=null){
+            //用户剩余积分
+            BigDecimal points = new BigDecimal(customerPointsInfo.getPoints()).subtract(new BigDecimal(request.getIntegral()));
+            customerPoints.setPoints(Integer.valueOf(points.toString()));
+            //用户已消费积分累积
+            BigDecimal consumptionPoints = new BigDecimal(customerPointsInfo.getConsumptionPoints()).add(new BigDecimal(request.getIntegral()));
+            customerPoints.setConsumptionPoints(Integer.valueOf(consumptionPoints.toString()));
+            customerPointsService.updateCustomerPointsInfo(customerPoints);
+        }
+
+        //油站名称
+        Map<String, String> m = stationService.getStationAppIdAndAppSecret(request.getStationId());
+        if(m !=null && m.containsKey("stationName")){
+            integralOrder.setStationName(m.get("stationName"));
+        }
+
+        IntegralWares integralWares = new IntegralWares();
+        integralWares.setId(request.getWaresId());
+        List<IntegralWares> integralWaresInfoList = integralWaresService.getIntegralWaresInfoList(integralWares);
+        if(integralWaresInfoList !=null && integralWaresInfoList.size() ==1){
+            //更新商品已售数量
+            integralWares.setWaresOutCount(integralWaresInfoList.get(0).getWaresOutCount()+1);
+            integralWaresService.updateIntegralWaresInfo(integralWares);
+        }
 
         boolean b = integralOrderService.insertIntegralOrder(integralOrder);
         if (b){

+ 3 - 0
YijiaRestful/src/main/java/com/platform/yijia/dao/IntegralWaresMapper.java

@@ -8,4 +8,7 @@ import java.util.List;
 public interface IntegralWaresMapper {
     //获取油站积分商品信息
     List<IntegralWares> getIntegralWaresInfoList(IntegralWares integralWares);
+
+    //更新商品
+    void updateIntegralWaresInfo(IntegralWares integralWares);
 }

+ 5 - 3
YijiaRestful/src/main/java/com/platform/yijia/pojo/IntegralOrder.java

@@ -10,14 +10,16 @@ import java.util.Date;
 @Data
 public class IntegralOrder {
     private  Integer id;                 //'积分订单id',
-    private  Integer integralOrderNo;    //'积分订单号',
+    private  String integralOrderNo;    //'积分订单号',
     private  String waresType;           //'商品类型',
     private  String waresName;           //'商品名称',
+    private  Integer waresId;           //'商品名称',
     private  String unionId;             //'微信唯一标识',
     private  String customerName;        //'会员名称',
     private  Integer exchangeNum;        //'兑换数量',
     private  Date exchangeTime;          //'兑换时间',
     private  String status;              //'订单状态(1已完成,2已取消)',
-    private Integer integral;           //订单消耗积分
-    private Integer stationId;          //油站ID
+    private  Integer integral;           //订单消耗积分
+    private  Integer stationId;          //油站ID
+    private  String stationName;        //'会员名称',
 }

+ 3 - 1
YijiaRestful/src/main/java/com/platform/yijia/pojo/IntegralWares.java

@@ -17,13 +17,15 @@ public class IntegralWares {
     private BigDecimal saleIntegral;    //'消费积分',
     private String waresPic;            //'商品图片',
     private String waresDetail;         //'商品详情',
+    private Integer waresCount;         //库存
+    private Integer waresOutCount;      //已售物品数量;
     private String waresStatus;         //'商品状态(1上架,2下架)',
     private Date createTime;            //'创建时间',
     private String createBy;            //'创建人id',
     private String createName;          //'创建人名称',
     private Date updateTime;            //'更新时间',
     private String updateBy;            //'更新人id',
-    private String updateName;            //'更新人名称',
+    private String updateName;          //'更新人名称',
     private Integer stationId;          //'油站ID',
     private String stationName;         //油站名称
 }

+ 3 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/IntegralWaresService.java

@@ -10,4 +10,7 @@ public interface IntegralWaresService {
     //获取油站积分商品信息
     List<IntegralWares> getIntegralWaresInfoList(IntegralWares integralWares);
 
+    //更新商品
+    void updateIntegralWaresInfo(IntegralWares integralWares);
+
 }

+ 6 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/impl/IntegralWaresServiceImpl.java

@@ -17,4 +17,10 @@ public class IntegralWaresServiceImpl implements IntegralWaresService {
     public List<IntegralWares> getIntegralWaresInfoList(IntegralWares integralWares) {
         return integralWaresMapper.getIntegralWaresInfoList(integralWares);
     }
+
+    //更新商品
+    @Override
+    public void updateIntegralWaresInfo(IntegralWares integralWares) {
+        integralWaresMapper.updateIntegralWaresInfo(integralWares);
+    }
 }

+ 16 - 3
YijiaRestful/src/main/resources/mapper/IntegralOrderMapper.xml

@@ -3,10 +3,11 @@
 <mapper namespace="com.platform.yijia.dao.IntegralOrderMapper">
   <!--返回结果-->
   <resultMap id="BaseResultMap" type="com.platform.yijia.pojo.IntegralOrder">
-    <id column="id"                     jdbcType="INTEGER" property="id" />
-    <result column="integral_order_no"  jdbcType="INTEGER" property="integralOrderNo" />
+    <id     column="id"                 jdbcType="INTEGER" property="id" />
+    <result column="integral_order_no"  jdbcType="VARCHAR" property="integralOrderNo" />
     <result column="wares_type"         jdbcType="VARCHAR" property="waresType" />
     <result column="wares_name"         jdbcType="VARCHAR" property="waresName" />
+    <result column="wares_id"           jdbcType="INTEGER" property="waresId" />
     <result column="union_id"           jdbcType="VARCHAR" property="unionId" />
     <result column="customer_name"      jdbcType="VARCHAR" property="customerName" />
     <result column="exchange_num"       jdbcType="INTEGER" property="exchangeNum" />
@@ -18,7 +19,7 @@
 
   <!--查询列-->
   <sql id="Base_Column_List">
-    id, integral_order_no, wares_type, wares_name, wares_name, union_id, customer_name, exchange_num, exchange_time,
+    id, integral_order_no, wares_type, wares_name, wares_name, wares_id, union_id, customer_name, exchange_num, exchange_time,
     status, integral, station_id
   </sql>
 
@@ -47,6 +48,9 @@
       <if test="waresName !=null">
         wares_name,
       </if>
+      <if test="waresId !=null">
+        wares_id,
+      </if>
       <if test="unionId !=null">
         union_id,
       </if>
@@ -68,6 +72,9 @@
       <if test="stationId !=null">
         station_id,
       </if>
+      <if test="stationName !=null">
+        station_name,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="integralOrderNo !=null">
@@ -79,6 +86,9 @@
       <if test="waresName !=null">
         #{waresName},
       </if>
+      <if test="waresId !=null">
+        #{waresId},
+      </if>
       <if test="unionId !=null">
         #{unionId},
       </if>
@@ -100,6 +110,9 @@
       <if test="stationId !=null">
         #{stationId},
       </if>
+      <if test="stationName !=null">
+        #{stationName},
+      </if>
     </trim>
   </insert>
 

+ 34 - 16
YijiaRestful/src/main/resources/mapper/IntegralWaresMapper.xml

@@ -3,26 +3,28 @@
 <mapper namespace="com.platform.yijia.dao.IntegralWaresMapper">
   <!--返回结果-->
   <resultMap id="BaseResultMap" type="com.platform.yijia.pojo.IntegralWares">
-    <id     column="id"             jdbcType="INTEGER"    property="id" />
-    <result column="wares_type"     jdbcType="VARCHAR"    property="waresType" />
-    <result column="wares_name"     jdbcType="VARCHAR"    property="waresName" />
-    <result column="sale_integral"  jdbcType="DECIMAL"    property="saleIntegral" />
-    <result column="wares_pic"      jdbcType="VARCHAR"    property="waresPic" />
-    <result column="wares_detail"   jdbcType="VARCHAR"    property="waresDetail" />
-    <result column="wares_status"   jdbcType="VARCHAR"    property="waresStatus" />
-    <result column="create_time"    jdbcType="TIMESTAMP"  property="createTime" />
-    <result column="create_by"      jdbcType="VARCHAR"    property="createBy" />
-    <result column="create_name"    jdbcType="VARCHAR"    property="createName" />
-    <result column="update_time"    jdbcType="TIMESTAMP"  property="updateTime" />
-    <result column="update_by"      jdbcType="VARCHAR"    property="updateBy" />
-    <result column="update_name"    jdbcType="VARCHAR"    property="updateName" />
-    <result column="station_id"     jdbcType="INTEGER"    property="stationId" />
-    <result column="station_name"   jdbcType="VARCHAR"    property="stationName" />
+    <id     column="id"              jdbcType="INTEGER"    property="id" />
+    <result column="wares_type"      jdbcType="VARCHAR"    property="waresType" />
+    <result column="wares_name"      jdbcType="VARCHAR"    property="waresName" />
+    <result column="sale_integral"   jdbcType="DECIMAL"    property="saleIntegral" />
+    <result column="wares_pic"       jdbcType="VARCHAR"    property="waresPic" />
+    <result column="wares_detail"    jdbcType="VARCHAR"    property="waresDetail" />
+    <result column="wares_count"     jdbcType="INTEGER"    property="waresCount" />
+    <result column="wares_out_count" jdbcType="INTEGER"    property="waresOutCount" />
+    <result column="wares_status"    jdbcType="VARCHAR"    property="waresStatus" />
+    <result column="create_time"     jdbcType="TIMESTAMP"  property="createTime" />
+    <result column="create_by"       jdbcType="VARCHAR"    property="createBy" />
+    <result column="create_name"     jdbcType="VARCHAR"    property="createName" />
+    <result column="update_time"     jdbcType="TIMESTAMP"  property="updateTime" />
+    <result column="update_by"       jdbcType="VARCHAR"    property="updateBy" />
+    <result column="update_name"     jdbcType="VARCHAR"    property="updateName" />
+    <result column="station_id"      jdbcType="INTEGER"    property="stationId" />
+    <result column="station_name"    jdbcType="VARCHAR"    property="stationName" />
   </resultMap>
 
   <!--查询列-->
   <sql id="Base_Column_List">
-    id, wares_type, wares_name, sale_integral, wares_pic, wares_detail, wares_status, create_time,
+    id, wares_type, wares_name, sale_integral, wares_pic, wares_detail, wares_count, wares_out_count, wares_status, create_time,
     create_by, create_name, update_time, update_by, update_name, station_name
   </sql>
 
@@ -39,5 +41,21 @@
     </where>
   </select>
 
+  <!--更新油站商品已售数量-->
+  <update id="updateIntegralWaresInfo" parameterType="com.platform.yijia.pojo.IntegralWares">
+    UPDATE
+        integral_wares
+    <set>
+      <if test="waresOutCount !=null">
+        wares_out_count = #{waresOutCount}
+      </if>
+    </set>
+    <where>
+      <if test="id !=null and id != ''">
+        id = #{id}
+      </if>
+    </where>
+  </update>
+
 
 </mapper>