Browse Source

chore[litemall-wx, litemall-wx-api]: 帮助API、足迹API和收藏API调整及文档

Junling Bu 6 years ago
parent
commit
95efbbec98

+ 254 - 0
doc/api.md

@@ -1263,6 +1263,97 @@ API应该存在版本控制,以保证兼容性。
     
 ### 2.10 收藏服务
 
+#### 2.10.1 收藏列表
+
+应用场景
+
+    收藏列表
+    
+接口链接
+
+    GET /wx/collect/list
+    
+请求参数
+    
+    type: 收藏类型,如果是0则是商品收藏,如果是1则是专题收藏
+    page: 请求页码
+    limit: 每一页数量
+    sort: 排序字段
+    order: 升序降序   
+    
+响应内容
+
+    {
+      "errno": 0,
+      "data": {
+        "total": 2,
+        "pages": 1,
+        "limit": 10,
+        "page": 1,
+        "list": [
+          {
+            "brief": "酥脆奶香,甜酸回味",
+            "picUrl": "http://yanxuan.nosdn.127.net/767b370d07f3973500db54900bcbd2a7.png",
+            "valueId": 1116011,
+            "name": "蔓越莓曲奇 200克",
+            "id": 3,
+            "type": 0,
+            "retailPrice": 36.00
+          },
+          {
+            "brief": "MUJI供应商携手打造",
+            "picUrl": "http://yanxuan.nosdn.127.net/c5be2604c0e4186a4e7079feeb742cee.png",
+            "valueId": 1109008,
+            "name": "云端沙发组合",
+            "id": 2,
+            "type": 0,
+            "retailPrice": 3999.00
+          }
+        ]
+      },
+      "errmsg": "成功"
+    }
+    
+错误码
+    
+    略
+    
+
+#### 2.10.2 收藏添加或删除
+
+应用场景
+
+    用户收藏添加或删除
+
+说明
+
+    如果用户已经收藏,则请求API会删除已收藏商品或专题;
+    如果用户未收藏,则请求API会添加新的商品或专题收藏记录。
+        
+接口链接
+
+    POST /wx/collect/addordelete
+    
+请求参数
+    
+    type: 收藏类型,如果是0则是商品收藏,如果是1则是专题收藏
+    valueId: 收藏对象ID,如果type=0则设置商品ID,如果type=1则设置专题ID
+    
+例如
+    
+    {
+      "type": 0,
+      "valueId": 1116011
+    }
+
+    
+响应内容
+
+    
+错误码
+    
+    略
+        
 ### 2.11 评论服务
 
 #### 2.11.1 评论数量
@@ -1419,6 +1510,101 @@ API应该存在版本控制,以保证兼容性。
 
 ### 2.14 足迹服务
 
+#### 2.14.1 用户足迹列表
+
+应用场景
+
+    用户足迹列表
+    
+接口链接
+
+    GET /wx/footprint/list
+    
+请求参数
+    
+    page: 请求页码
+    limit: 每一页数量 
+    
+响应内容
+
+    {
+      "errno": 0,
+      "data": {
+        "total": 22,
+        "pages": 6,
+        "limit": 4,
+        "page": 1,
+        "list": [
+          {
+            "brief": "酥脆奶香,甜酸回味",
+            "picUrl": "http://yanxuan.nosdn.127.net/767b370d07f3973500db54900bcbd2a7.png",
+            "addTime": "2019-05-09 10:10:01",
+            "goodsId": 1116011,
+            "name": "蔓越莓曲奇 200克",
+            "id": 22,
+            "retailPrice": 36.00
+          },
+          {
+            "brief": "MUJI供应商携手打造",
+            "picUrl": "http://yanxuan.nosdn.127.net/c5be2604c0e4186a4e7079feeb742cee.png",
+            "addTime": "2019-05-09 10:09:49",
+            "goodsId": 1109008,
+            "name": "云端沙发组合",
+            "id": 21,
+            "retailPrice": 3999.00
+          },
+          {
+            "brief": "酥脆奶香,甜酸回味",
+            "picUrl": "http://yanxuan.nosdn.127.net/767b370d07f3973500db54900bcbd2a7.png",
+            "addTime": "2019-05-08 22:40:55",
+            "goodsId": 1116011,
+            "name": "蔓越莓曲奇 200克",
+            "id": 20,
+            "retailPrice": 36.00
+          },
+          {
+            "brief": "MUJI供应商携手打造",
+            "picUrl": "http://yanxuan.nosdn.127.net/c5be2604c0e4186a4e7079feeb742cee.png",
+            "addTime": "2019-05-07 14:35:41",
+            "goodsId": 1109008,
+            "name": "云端沙发组合",
+            "id": 19,
+            "retailPrice": 3999.00
+          }
+        ]
+      },
+      "errmsg": "成功"
+    }
+        
+错误码
+    
+    略
+    
+#### 2.14.2 用户足迹删除
+
+应用场景
+
+    用户足迹删除
+    
+接口链接
+
+    POST /wx/footprint/delete
+    
+请求参数
+    
+    id: 用户足迹ID
+    
+响应内容
+
+    {
+      "errno": 0,
+      "errmsg": "成功"
+    }
+        
+错误码
+    
+    略
+        
 ### 2.15 团购服务
 
 注意
@@ -1505,6 +1691,74 @@ API应该存在版本控制,以保证兼容性。
                                                                   
 ### 2.16 帮助服务
 
+#### 2.16.1 帮助列表
+
+应用场景
+
+    帮助列表
+    
+接口链接
+
+    GET /wx/issue/list
+    
+请求参数
+    
+    page: 请求页码
+    limit: 每一页数量
+    sort: 排序字段
+    order: 升序降序    
+
+响应内容
+
+    {
+      "errno": 0,
+      "data": {
+        "total": 4,
+        "pages": 1,
+        "limit": 10,
+        "page": 1,
+        "list": [
+          {
+            "id": 1,
+            "question": "购买运费如何收取?",
+            "answer": "单笔订单金额(不含运费)满88元免邮费;不满88元,每单收取10元运费。\n(港澳台地区需满",
+            "addTime": "2018-02-01 00:00:00",
+            "updateTime": "2018-02-01 00:00:00",
+            "deleted": false
+          },
+          {
+            "id": 2,
+            "question": "使用什么快递发货?",
+            "answer": "严选默认使用顺丰快递发货(个别商品使用其他快递),配送范围覆盖全国大部分地区(港澳台地区除",
+            "addTime": "2018-02-01 00:00:00",
+            "updateTime": "2018-02-01 00:00:00",
+            "deleted": false
+          },
+          {
+            "id": 3,
+            "question": "如何申请退货?",
+            "answer": "1.自收到商品之日起30日内,顾客可申请无忧退货,退款将原路返还,不同的银行处理时间不同,",
+            "addTime": "2018-02-01 00:00:00",
+            "updateTime": "2018-02-01 00:00:00",
+            "deleted": false
+          },
+          {
+            "id": 4,
+            "question": "如何开具发票?",
+            "answer": "1.如需开具普通发票,请在下单时选择“我要开发票”并填写相关信息(APP仅限2.4.0及以",
+            "addTime": "2018-02-01 00:00:00",
+            "updateTime": "2018-02-01 00:00:00",
+            "deleted": false
+          }
+        ]
+      },
+      "errmsg": "成功"
+    }
+    
+错误码
+    
+    无
+              
 ### 2.17 搜索服务
 
 ### 2.18 专题服务

+ 14 - 4
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java

@@ -22,11 +22,21 @@ public class LitemallCollectService {
         return (int) collectMapper.countByExample(example);
     }
 
-    public List<LitemallCollect> queryByType(Integer userId, Byte type, Integer page, Integer size) {
+    public List<LitemallCollect> queryByType(Integer userId, Byte type, Integer page, Integer limit, String sort, String order) {
         LitemallCollectExample example = new LitemallCollectExample();
-        example.or().andUserIdEqualTo(userId).andTypeEqualTo(type).andDeletedEqualTo(false);
-        example.setOrderByClause(LitemallCollect.Column.addTime.desc());
-        PageHelper.startPage(page, size);
+        LitemallCollectExample.Criteria criteria = example.createCriteria();
+
+        if (type != null) {
+            criteria.andTypeEqualTo(type);
+        }
+        criteria.andUserIdEqualTo(userId);
+        criteria.andDeletedEqualTo(false);
+
+        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
+            example.setOrderByClause(sort + " " + order);
+        }
+
+        PageHelper.startPage(page, limit);
         return collectMapper.selectByExample(example);
     }
 

+ 8 - 14
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java

@@ -5,6 +5,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.linlinjava.litemall.core.util.JacksonUtil;
 import org.linlinjava.litemall.core.util.ResponseUtil;
+import org.linlinjava.litemall.core.validator.Order;
+import org.linlinjava.litemall.core.validator.Sort;
 import org.linlinjava.litemall.db.domain.LitemallCollect;
 import org.linlinjava.litemall.db.domain.LitemallGoods;
 import org.linlinjava.litemall.db.service.LitemallCollectService;
@@ -47,14 +49,14 @@ public class WxCollectController {
     public Object list(@LoginUser Integer userId,
                        @NotNull Byte type,
                        @RequestParam(defaultValue = "1") Integer page,
-                       @RequestParam(defaultValue = "10") Integer limit) {
+                       @RequestParam(defaultValue = "10") Integer limit,
+                       @Sort @RequestParam(defaultValue = "add_time") String sort,
+                       @Order @RequestParam(defaultValue = "desc") String order) {
         if (userId == null) {
             return ResponseUtil.unlogin();
         }
 
-        List<LitemallCollect> collectList = collectService.queryByType(userId, type, page, limit);
-        int count = collectService.countByType(userId, type);
-        int totalPages = (int) Math.ceil((double) count / limit);
+        List<LitemallCollect> collectList = collectService.queryByType(userId, type, page, limit, sort, order);
 
         List<Object> collects = new ArrayList<>(collectList.size());
         for (LitemallCollect collect : collectList) {
@@ -72,10 +74,7 @@ public class WxCollectController {
             collects.add(c);
         }
 
-        Map<String, Object> result = new HashMap<String, Object>();
-        result.put("collectList", collects);
-        result.put("totalPages", totalPages);
-        return ResponseUtil.ok(result);
+        return ResponseUtil.okList(collects, collectList);
     }
 
     /**
@@ -101,12 +100,9 @@ public class WxCollectController {
 
         LitemallCollect collect = collectService.queryByTypeAndValue(userId, type, valueId);
 
-        String handleType = null;
         if (collect != null) {
-            handleType = "delete";
             collectService.deleteById(collect.getId());
         } else {
-            handleType = "add";
             collect = new LitemallCollect();
             collect.setUserId(userId);
             collect.setValueId(valueId);
@@ -114,8 +110,6 @@ public class WxCollectController {
             collectService.add(collect);
         }
 
-        Map<String, Object> data = new HashMap<String, Object>();
-        data.put("type", handleType);
-        return ResponseUtil.ok(data);
+        return ResponseUtil.ok();
     }
 }

+ 2 - 7
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFootprintController.java

@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -82,8 +83,6 @@ public class WxFootprintController {
         }
 
         List<LitemallFootprint> footprintList = footprintService.queryByAddTime(userId, page, limit);
-        long count = PageInfo.of(footprintList).getTotal();
-        int totalPages = (int) Math.ceil((double) count / limit);
 
         List<Object> footprintVoList = new ArrayList<>(footprintList.size());
         for (LitemallFootprint footprint : footprintList) {
@@ -101,11 +100,7 @@ public class WxFootprintController {
             footprintVoList.add(c);
         }
 
-
-        Map<String, Object> result = new HashMap<>();
-        result.put("footprintList", footprintVoList);
-        result.put("totalPages", totalPages);
-        return ResponseUtil.ok(result);
+        return ResponseUtil.okList(footprintVoList, footprintList);
     }
 
 }

+ 1 - 5
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxIssueController.java

@@ -35,11 +35,7 @@ public class WxIssueController {
                        @Sort @RequestParam(defaultValue = "add_time") String sort,
                        @Order @RequestParam(defaultValue = "desc") String order) {
         List<LitemallIssue> issueList = issueService.querySelective(question, page, size, sort, order);
-        long total = PageInfo.of(issueList).getTotal();
-        Map<String, Object> data = new HashMap<String, Object>();
-        data.put("data", issueList);
-        data.put("count", total);
-        return ResponseUtil.ok(data);
+        return ResponseUtil.okList(issueList);
     }
 
 }

+ 2 - 2
litemall-wx/pages/help/help.js

@@ -98,9 +98,9 @@ Page({
       if (res.errno === 0) {
 
         that.setData({
-          issueList: res.data.data,
+          issueList: res.data.list,
           showPage: true,
-          count: res.data.count
+          count: res.data.total
         });
       }
     });

+ 2 - 2
litemall-wx/pages/ucenter/collect/collect.js

@@ -23,8 +23,8 @@ Page({
     }).then(function(res) {
       if (res.errno === 0) {
         that.setData({
-          collectList: that.data.collectList.concat(res.data.collectList),
-          totalPages: res.data.totalPages
+          collectList: that.data.collectList.concat(res.data.list),
+          totalPages: res.data.pages
         });
       }
       wx.hideLoading();

+ 6 - 5
litemall-wx/pages/ucenter/footprint/footprint.js

@@ -7,7 +7,7 @@ Page({
   data: {
     footprintList: [],
     page: 1,
-    size: 10,
+    limit: 10,
     totalPages: 1
   },
   getFootprintList() {
@@ -17,14 +17,15 @@ Page({
     let that = this;
     util.request(api.FootprintList, {
       page: that.data.page,
-      size: that.data.size
+      limit: that.data.limit
     }).then(function(res) {
       if (res.errno === 0) {
         let f1 = that.data.footprintList;
-        let f2 = res.data.footprintList;
+        let f2 = res.data.list;
         for (let i = 0; i < f2.length; i++) {
+          f2[i].addDate = f2[i].addTime.substring(0, 10)
           let last = f1.length - 1;
-          if (last >= 0 && f1[last][0].addTime === f2[i].addTime) {
+          if (last >= 0 && f1[last][0].addDate === f2[i].addDate) {
             f1[last].push(f2[i]);
           } else {
             let tmp = [];
@@ -35,7 +36,7 @@ Page({
 
         that.setData({
           footprintList: f1,
-          totalPages: res.data.totalPages
+          totalPages: res.data.pages
         });
       }
       wx.hideLoading();

+ 1 - 1
litemall-wx/pages/ucenter/footprint/footprint.wxml

@@ -7,7 +7,7 @@
   </view>
   <view class="footprint" wx:if="{{footprintList.length > 0}}">
     <view class="day-item" wx:for="{{footprintList}}" wx:key="*this" wx:for-index="index">
-      <view class="day-hd" wx:if="{{item.length > 0}}">{{item[0].addTime}}</view>
+      <view class="day-hd" wx:if="{{item.length > 0}}">{{item[0].addDate}}</view>
       <view class="day-list" wx:if="{{item.length > 0}}">
         <view class="item" data-index="{{index}}" data-iindex="{{iindex}}" bindtouchstart="touchStart" bindtouchend="touchEnd" bindtap="deleteItem" wx:for="{{item}}" wx:for-index="iindex" wx:for-item="iitem" wx:key="id">
           <image class="img" src="{{iitem.picUrl}}"></image>

+ 0 - 1
renard-wx/app.json

@@ -10,7 +10,6 @@
     "pages/ucenter/order/order",
     "pages/ucenter/orderDetail/orderDetail",
     "pages/ucenter/coupon/coupon",
-    "pages/ucenter/collect/collect",
     "pages/auth/login/login",
     "pages/payResult/payResult",
     "pages/commentPost/commentPost",

+ 0 - 3
renard-wx/config/api.js

@@ -38,9 +38,6 @@ module.exports = {
   CartGoodsCount: WxApiRoot + 'cart/goodscount', // 获取购物车商品件数
   CartCheckout: WxApiRoot + 'cart/checkout', // 下单前信息确认
 
-  CollectList: WxApiRoot + 'collect/list', //收藏列表
-  CollectAddOrDelete: WxApiRoot + 'collect/addordelete', //添加或取消收藏
-
   CommentPost: WxApiRoot + 'comment/post', //发表评论
 
   TopicList: WxApiRoot + 'topic/list', //专题列表

+ 0 - 149
renard-wx/pages/ucenter/collect/collect.js

@@ -1,149 +0,0 @@
-var util = require('../../../utils/util.js');
-var api = require('../../../config/api.js');
-
-var app = getApp();
-
-Page({
-  data: {
-    type: 0,
-    collectList: [],
-    page: 1,
-    size: 10,
-    totalPages: 1
-  },
-
-  onPullDownRefresh() {
-    wx.showNavigationBarLoading() //在标题栏中显示加载
-    this.getCollectList();
-    wx.hideNavigationBarLoading() //完成停止加载
-    wx.stopPullDownRefresh() //停止下拉刷新
-  },
-
-  getCollectList() {
-    wx.showLoading({
-      title: '加载中...',
-    });
-    let that = this;
-    util.request(api.CollectList, {
-      type: that.data.type,
-      page: that.data.page,
-      size: that.data.size
-    }).then(function(res) {
-      if (res.errno === 0) {
-        that.setData({
-          collectList: res.data.collectList,
-          totalPages: res.data.totalPages
-        });
-      }
-      wx.hideLoading();
-    });
-  },
-  getAndAddCollectList() {
-    wx.showLoading({
-      title: '加载中...',
-    });
-    let that = this;
-    util.request(api.CollectList, {
-      type: that.data.type,
-      page: that.data.page,
-      size: that.data.size
-    }).then(function(res) {
-      if (res.errno === 0) {
-        that.setData({
-          collectList: that.data.collectList.concat(res.data.collectList),
-          totalPages: res.data.totalPages
-        });
-      }
-      wx.hideLoading();
-    });
-  },
-  onLoad: function(options) {
-    this.getCollectList();
-  },
-  onReachBottom() {
-    if (this.data.totalPages > this.data.page) {
-      this.setData({
-        page: this.data.page + 1
-      });
-      this.getAndAddCollectList();
-    } else {
-      wx.showToast({
-        title: '没有更多用户收藏了',
-        icon: 'none',
-        duration: 2000
-      });
-      return false;
-    }
-  },
-  onReady: function() {
-
-  },
-  onShow: function() {
-
-  },
-  onHide: function() {
-    // 页面隐藏
-
-  },
-  onUnload: function() {
-    // 页面关闭
-  },
-  openGoods(event) {
-
-    let that = this;
-    let index = event.currentTarget.dataset.index;
-    let goodsId = this.data.collectList[index].valueId;
-
-    //触摸时间距离页面打开的毫秒数  
-    var touchTime = that.data.touchEnd - that.data.touchStart;
-    console.log(touchTime);
-    //如果按下时间大于350为长按  
-    if (touchTime > 350) {
-      wx.showModal({
-        title: '',
-        content: '确定删除吗?',
-        success: function(res) {
-          if (res.confirm) {
-
-            util.request(api.CollectAddOrDelete, {
-              type: that.data.type,
-              valueId: goodsId
-            }, 'POST').then(function(res) {
-              if (res.errno === 0) {
-                console.log(res.data);
-                wx.showToast({
-                  title: '删除成功',
-                  icon: 'success',
-                  duration: 2000
-                });
-                that.data.collectList.splice(index, 1)
-                that.setData({
-                  collectList: that.data.collectList
-                });
-              }
-            });
-          }
-        }
-      })
-    } else {
-
-      wx.navigateTo({
-        url: '/pages/goods/goods?id=' + goodsId,
-      });
-    }
-  },
-  //按下事件开始  
-  touchStart: function(e) {
-    let that = this;
-    that.setData({
-      touchStart: e.timeStamp
-    })
-  },
-  //按下事件结束  
-  touchEnd: function(e) {
-    let that = this;
-    that.setData({
-      touchEnd: e.timeStamp
-    })
-  },
-})

+ 0 - 3
renard-wx/pages/ucenter/collect/collect.json

@@ -1,3 +0,0 @@
-{
-  "navigationBarTitleText": "我的收藏"
-}

+ 0 - 19
renard-wx/pages/ucenter/collect/collect.wxml

@@ -1,19 +0,0 @@
-<view class="container">
-  <view class="no-collect" wx:if="{{collectList.length <= 0}}">
-    <view class="c">
-      <image src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/noCart-a8fe3f12e5.png" />
-      <text>还没有收藏</text>
-    </view>
-  </view>
-  <view class="collect-list" wx:else>
-    <view class="item" bindtap="openGoods" bindtouchstart="touchStart" bindtouchend="touchEnd" wx:for="{{collectList}}" wx:key="id" data-index="{{index}}">
-      <image class="img" src="{{item.picUrl}}"></image>
-      <view class="info">
-        <view class="name">{{item.name}}</view>
-        <view class="subtitle">{{item.brief}}</view>
-        <view class="price">¥{{item.retailPrice}}</view>
-      </view>
-    </view>
-  </view>
-
-</view>

+ 0 - 100
renard-wx/pages/ucenter/collect/collect.wxss

@@ -1,100 +0,0 @@
-page {
-  background: #f4f4f4;
-  min-height: 100%;
-}
-
-.container {
-  background: #f4f4f4;
-  min-height: 100%;
-  width: 100%;
-  height: auto;
-  overflow: hidden;
-}
-
-.no-collect {
-  width: 100%;
-  height: auto;
-  margin: 0 auto;
-}
-
-.no-collect .c {
-  width: 100%;
-  height: auto;
-  margin-top: 200rpx;
-}
-
-.no-collect .c image {
-  margin: 0 auto;
-  display: block;
-  text-align: center;
-  width: 258rpx;
-  height: 258rpx;
-}
-
-.no-collect .c text {
-  margin: 0 auto;
-  display: block;
-  width: 258rpx;
-  height: 29rpx;
-  line-height: 29rpx;
-  text-align: center;
-  font-size: 29rpx;
-  color: #999;
-}
-
-.collect-list {
-  width: 100%;
-  height: auto;
-  overflow: hidden;
-  background: #fff;
-  padding-left: 30rpx;
-  border-top: 1px solid #e1e1e1;
-}
-
-.item {
-  height: 212rpx;
-  width: 720rpx;
-  background: #fff;
-  padding: 30rpx 30rpx 30rpx 0;
-  border-bottom: 1px solid #e1e1e1;
-}
-
-.item:last-child {
-  border-bottom: 1px solid #fff;
-}
-
-.item .img {
-  float: left;
-  width: 150rpx;
-  height: 150rpx;
-}
-
-.item .info {
-  float: right;
-  width: 540rpx;
-  height: 150rpx;
-  display: flex;
-  flex-direction: column;
-  justify-content: center;
-  padding-left: 20rpx;
-}
-
-.item .info .name {
-  font-size: 28rpx;
-  color: #333;
-  line-height: 40rpx;
-}
-
-.item .info .subtitle {
-  margin-top: 8rpx;
-  font-size: 24rpx;
-  color: #888;
-  line-height: 40rpx;
-}
-
-.item .info .price {
-  margin-top: 8rpx;
-  font-size: 28rpx;
-  color: #333;
-  line-height: 40rpx;
-}