├── README.md ├── bookSmall ├── pages │ ├── userInfo │ │ ├── userInfo.json │ │ ├── userInfo.wxss │ │ ├── userInfo.wxml │ │ └── userInfo.js │ ├── goods │ │ ├── goods.json │ │ ├── goods.wxml │ │ ├── goods.js │ │ └── goods.wxss │ ├── cart │ │ ├── cart.json │ │ ├── cart.wxml │ │ └── cart.wxss │ ├── pay │ │ ├── pay.json │ │ ├── pay.wxml │ │ ├── pay.wxss │ │ └── pay.js │ ├── personal │ │ ├── personal.json │ │ ├── personal.wxml │ │ ├── personal.wxss │ │ └── personal.js │ ├── orderDetail │ │ ├── orderDetail.json │ │ ├── orderDetail.js │ │ ├── orderDetail.wxml │ │ └── orderDetail.wxss │ ├── main │ │ ├── main.json │ │ ├── main.wxml │ │ ├── main.wxss │ │ └── main.js │ └── order │ │ ├── order.json │ │ ├── order.wxml │ │ ├── order.wxss │ │ └── order.js ├── static │ ├── images │ │ ├── cart.png │ │ ├── home.png │ │ ├── my.png │ │ ├── goright.png │ │ ├── my@selected.png │ │ ├── search-pic.png │ │ ├── cart@selected.png │ │ └── home@selected.png │ └── data │ │ └── data.js ├── config │ └── api.js ├── utils │ ├── check.js │ ├── user.js │ └── util.js ├── app.js ├── app.wxss ├── project.config.json └── app.json └── book_small └── src ├── main ├── java │ └── cn │ │ └── zxhysy │ │ └── booksmall │ │ ├── mapper │ │ ├── BookMapper.java │ │ ├── UserMapper.java │ │ ├── AdminMapper.java │ │ ├── CategoryMapper.java │ │ ├── OrderMasterMapper.java │ │ └── OrderDetailMapper.java │ │ ├── service │ │ ├── CategoryService.java │ │ ├── AdminService.java │ │ ├── OrderService.java │ │ ├── BookService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── CategoryServiceImpl.java │ │ │ ├── AdminServiceImpl.java │ │ │ ├── BookServiceImpl.java │ │ │ ├── OrderServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ ├── BooksmallApplication.java │ │ ├── utils │ │ ├── MD5Util.java │ │ ├── MyPageInfo.java │ │ ├── IDUtil.java │ │ ├── mapper │ │ │ └── MyMapper.java │ │ ├── AesCbcUtil.java │ │ ├── ApiJSONResult.java │ │ ├── component │ │ │ ├── FastDFSClient.java │ │ │ └── RedisOperator.java │ │ ├── HttpClientUtil.java │ │ └── FileUtil.java │ │ ├── config │ │ ├── FastDFSConfig.java │ │ ├── Swagger2.java │ │ └── WebConfig.java │ │ ├── handler │ │ ├── GlobalExceptionHandler.java │ │ └── MyHandlerInterceptor.java │ │ ├── pojo │ │ ├── vo │ │ │ ├── OrderVO.java │ │ │ ├── AdminVO.java │ │ │ └── UserVO.java │ │ ├── Category.java │ │ ├── Admin.java │ │ ├── User.java │ │ ├── OrderDetail.java │ │ ├── Book.java │ │ └── OrderMaster.java │ │ └── controller │ │ ├── CategoryController.java │ │ ├── BasicController.java │ │ ├── OrderController.java │ │ ├── AdminController.java │ │ ├── BookController.java │ │ ├── UserController.java │ │ └── FastdfsController.java └── resources │ ├── mapper │ ├── CategoryMapper.xml │ ├── AdminMapper.xml │ ├── UserMapper.xml │ ├── OrderMasterMapper.xml │ ├── BookMapper.xml │ └── OrderDetailMapper.xml │ └── application.yml └── test └── java └── cn └── zxhysy └── booksmall └── BooksmallApplicationTests.java /README.md: -------------------------------------------------------------------------------- 1 | # wechatBookSmall 2 | springboot&微信小程序项目实战 3 | -------------------------------------------------------------------------------- /bookSmall/pages/userInfo/userInfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "usingComponents": {} 3 | } -------------------------------------------------------------------------------- /bookSmall/pages/goods/goods.json: -------------------------------------------------------------------------------- 1 | { 2 | "navigationBarTitleText": "书本详情" 3 | } -------------------------------------------------------------------------------- /bookSmall/pages/cart/cart.json: -------------------------------------------------------------------------------- 1 | { 2 | "backgroundColor": "#f4f4f4", 3 | "navigationBarTitleText": "购物车" 4 | } -------------------------------------------------------------------------------- /bookSmall/pages/pay/pay.json: -------------------------------------------------------------------------------- 1 | { 2 | "backgroundColor": "#f4f4f4", 3 | "navigationBarTitleText": "下订单" 4 | } -------------------------------------------------------------------------------- /bookSmall/pages/personal/personal.json: -------------------------------------------------------------------------------- 1 | { 2 | "backgroundColor": "#f4f4f4", 3 | "navigationBarTitleText": "个人中心" 4 | } -------------------------------------------------------------------------------- /bookSmall/static/images/cart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yemuysy/wechatBookSmall/HEAD/bookSmall/static/images/cart.png -------------------------------------------------------------------------------- /bookSmall/static/images/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yemuysy/wechatBookSmall/HEAD/bookSmall/static/images/home.png -------------------------------------------------------------------------------- /bookSmall/static/images/my.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yemuysy/wechatBookSmall/HEAD/bookSmall/static/images/my.png -------------------------------------------------------------------------------- /bookSmall/pages/orderDetail/orderDetail.json: -------------------------------------------------------------------------------- 1 | { 2 | "backgroundColor": "#f4f4f4", 3 | "navigationBarTitleText": "订单详情" 4 | } -------------------------------------------------------------------------------- /bookSmall/static/images/goright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yemuysy/wechatBookSmall/HEAD/bookSmall/static/images/goright.png -------------------------------------------------------------------------------- /bookSmall/static/images/my@selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yemuysy/wechatBookSmall/HEAD/bookSmall/static/images/my@selected.png -------------------------------------------------------------------------------- /bookSmall/static/images/search-pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yemuysy/wechatBookSmall/HEAD/bookSmall/static/images/search-pic.png -------------------------------------------------------------------------------- /bookSmall/static/images/cart@selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yemuysy/wechatBookSmall/HEAD/bookSmall/static/images/cart@selected.png -------------------------------------------------------------------------------- /bookSmall/static/images/home@selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yemuysy/wechatBookSmall/HEAD/bookSmall/static/images/home@selected.png -------------------------------------------------------------------------------- /bookSmall/config/api.js: -------------------------------------------------------------------------------- 1 | //访问路径 2 | var WxApiRoot = 'http://localhost:8080/wx/'; 3 | 4 | module.exports = { 5 | AuthLoginByWeixin: WxApiRoot + 'auth/login_by_weixin', 6 | } -------------------------------------------------------------------------------- /bookSmall/pages/main/main.json: -------------------------------------------------------------------------------- 1 | { 2 | "backgroundColor": "#f4f4f4", 3 | "navigationBarTitleText": "校园书店", 4 | "enablePullDownRefresh": true, 5 | "backgroundTextStyle": "dark" 6 | } -------------------------------------------------------------------------------- /bookSmall/pages/order/order.json: -------------------------------------------------------------------------------- 1 | { 2 | "backgroundColor": "#f4f4f4", 3 | "navigationBarTitleText": "我的订单", 4 | "enablePullDownRefresh": true, 5 | "backgroundTextStyle": "dark" 6 | } -------------------------------------------------------------------------------- /bookSmall/utils/check.js: -------------------------------------------------------------------------------- 1 | function isValidPhone(str) { 2 | var myreg = /^[1][3,4,5,7,8][0-9]{9}$/; 3 | if (!myreg.test(str)) { 4 | return false; 5 | } else { 6 | return true; 7 | } 8 | } 9 | 10 | module.exports = { 11 | isValidPhone 12 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/mapper/BookMapper.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.mapper; 2 | 3 | import cn.zxhysy.booksmall.pojo.Book; 4 | import cn.zxhysy.booksmall.utils.mapper.MyMapper; 5 | 6 | public interface BookMapper extends MyMapper { 7 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.mapper; 2 | 3 | import cn.zxhysy.booksmall.pojo.User; 4 | import cn.zxhysy.booksmall.utils.mapper.MyMapper; 5 | 6 | /** 7 | * @className: UserMapper 8 | * @description: 9 | * @author: zxh 10 | * @date: 2019-3-29 10:01:24 11 | */ 12 | public interface UserMapper extends MyMapper { 13 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/mapper/AdminMapper.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.mapper; 2 | 3 | import cn.zxhysy.booksmall.pojo.Admin; 4 | import cn.zxhysy.booksmall.utils.mapper.MyMapper; 5 | 6 | /** 7 | * @className: AdminMapper 8 | * @description: 9 | * @author: zxh 10 | * @date: 2019-3-29 10:00:24 11 | */ 12 | public interface AdminMapper extends MyMapper { 13 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/mapper/CategoryMapper.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.mapper; 2 | 3 | import cn.zxhysy.booksmall.pojo.Category; 4 | import cn.zxhysy.booksmall.utils.mapper.MyMapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @className: CategoryMapper 9 | * @description: 10 | * @author: zxh 11 | * @date: 2019-3-29 10:00:50 12 | */ 13 | public interface CategoryMapper extends MyMapper { 14 | } -------------------------------------------------------------------------------- /bookSmall/app.js: -------------------------------------------------------------------------------- 1 | App({ 2 | serverUrl: "http://www.zxhysy.cn:9090", 3 | //serverUrl: "http://192.168.123.116:9090", 4 | //serverUrl: "http://10.50.131.220:9090", 5 | imgUrl: "http://www.zxhysy.cn:88/zxh/", 6 | 7 | setGlobalUserInfo(user) { 8 | wx.setStorageSync("userInfo", user); 9 | }, 10 | getGlobalUserInfo() { 11 | return wx.getStorageSync("userInfo"); 12 | }, 13 | globalData: { 14 | userInfo: null, 15 | hasLogin: true 16 | } 17 | }) 18 | 19 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/mapper/OrderMasterMapper.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.mapper; 2 | 3 | import cn.zxhysy.booksmall.pojo.OrderMaster; 4 | import cn.zxhysy.booksmall.utils.mapper.MyMapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @className: OrderMasterMapper 9 | * @description: 10 | * @author: zxh 11 | * @date: 2019-3-29 10:01:13 12 | */ 13 | public interface OrderMasterMapper extends MyMapper { 14 | } -------------------------------------------------------------------------------- /book_small/src/test/java/cn/zxhysy/booksmall/BooksmallApplicationTests.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BooksmallApplicationTests { 11 | 12 | @Test 13 | public void aa(){ 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /bookSmall/app.wxss: -------------------------------------------------------------------------------- 1 | .container { 2 | display: flex; 3 | flex-direction: column; 4 | align-items: center; 5 | box-sizing: border-box; 6 | background-color: #F2f2f2; 7 | font-family: PingFangSC-Light, helvetica, 'Heiti SC'; 8 | } 9 | 10 | view, image, text, navigator, button { 11 | box-sizing: border-box; 12 | padding: 0; 13 | margin: 0; 14 | } 15 | 16 | view, text { 17 | font-family: PingFangSC-Light, helvetica, 'Heiti SC'; 18 | font-size: 29rpx; 19 | color: #333; 20 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/mapper/OrderDetailMapper.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.mapper; 2 | 3 | import cn.zxhysy.booksmall.pojo.OrderDetail; 4 | import cn.zxhysy.booksmall.utils.mapper.MyMapper; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @className: OrderDetailMapper 10 | * @description: 11 | * @author: zxh 12 | * @date: 2019-3-29 10:01:01 13 | */ 14 | public interface OrderDetailMapper extends MyMapper { 15 | 16 | Integer inserDetailList(List list); 17 | 18 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/CategoryService.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service; 2 | 3 | import cn.zxhysy.booksmall.pojo.Category; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @className: CategoryService 9 | * @description: 类别服务 10 | * @author: zxh 11 | * @date: 2019年4月1日00:11:42 12 | */ 13 | public interface CategoryService { 14 | 15 | /** 16 | * 获取全部分类信息 17 | * 18 | * @return List 19 | */ 20 | List getAllCategory(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/AdminService.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service; 2 | 3 | 4 | import cn.zxhysy.booksmall.pojo.Admin; 5 | 6 | /** 7 | * @className: AdminService 8 | * @description: 9 | * @author: zxh 10 | * @date: 2019-1-29 9:12:23 11 | */ 12 | public interface AdminService { 13 | 14 | /** 15 | * 管理员登录 16 | * 17 | * @param name 用户名 18 | * @param password 密码 19 | * @return 用户对象 20 | */ 21 | Admin login(String name, String password); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/BooksmallApplication.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall; 2 | 3 | import tk.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | /** 这里需要用的是 tk.的mapperScan */ 9 | @MapperScan("cn.zxhysy.booksmall.mapper") 10 | public class BooksmallApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(BooksmallApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /bookSmall/pages/userInfo/userInfo.wxss: -------------------------------------------------------------------------------- 1 | .avatar { 2 | height: 148rpx; 3 | width: 148rpx; 4 | border-radius: 50%; 5 | } 6 | 7 | .top { 8 | width: 100%; 9 | height: 250rpx; 10 | display: flex; 11 | flex-direction: column; 12 | background-color: #ab956d; 13 | align-items: center; 14 | justify-content: center; 15 | } 16 | 17 | .nickname { 18 | margin-bottom: 10rpx; 19 | text-align: center; 20 | } 21 | 22 | .item { 23 | align-items: center; 24 | height: 70rpx; 25 | margin: 20rpx; 26 | display: flex; 27 | border-radius: 20rpx; 28 | background-color: #f4f4f4; 29 | } 30 | -------------------------------------------------------------------------------- /bookSmall/pages/orderDetail/orderDetail.js: -------------------------------------------------------------------------------- 1 | // pages/pay/pay.js sh 2 | var app = getApp() 3 | Page({ 4 | 5 | /** 6 | * 页面的初始数据 7 | */ 8 | data: { 9 | order: null, // 订单 10 | amount: null, //总价格 11 | orderMaster: {}, // 购买用户信息 12 | imgUrl: null, // 图片根路劲 13 | orderDetailList: null 14 | }, 15 | /** 16 | * 生命周期函数--监听页面加载 17 | */ 18 | onLoad: function (options) { 19 | const orderVO = JSON.parse(decodeURIComponent(options.orderVO)) 20 | this.setData({ 21 | orderMaster: orderVO.orderMaster, 22 | orderDetailList: orderVO.orderDetailList, 23 | imgUrl: app.imgUrl 24 | }) 25 | } 26 | }) -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/MD5Util.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | 5 | import java.security.MessageDigest; 6 | 7 | /** 8 | * @className: MD5Util 9 | * @description: 密码加密工具 10 | * @author: zxh 11 | * @date: 12 | */ 13 | public class MD5Util { 14 | 15 | /** 16 | * 加密 17 | * 18 | * @Description: 对字符串进行md5加密 19 | */ 20 | public static String getMD5Str(String strValue) throws Exception { 21 | MessageDigest md5 = MessageDigest.getInstance("MD5"); 22 | return Base64.encodeBase64String(md5.digest(strValue.getBytes())); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/config/FastDFSConfig.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.config; 2 | 3 | import com.github.tobato.fastdfs.FdfsClientConfig; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableMBeanExport; 6 | import org.springframework.context.annotation.Import; 7 | import org.springframework.jmx.support.RegistrationPolicy; 8 | 9 | 10 | /** 11 | * @className: FastdfsConfig 12 | * @description: jmx 重复注册bean的问题 导入依赖组件 13 | * @author: zxh 14 | * @date: 2018-12-29 09:56:31 15 | */ 16 | @Configuration 17 | @Import(FdfsClientConfig.class) 18 | @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) 19 | public class FastDFSConfig { 20 | } 21 | -------------------------------------------------------------------------------- /book_small/src/main/resources/mapper/CategoryMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/handler/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.handler; 2 | 3 | import cn.zxhysy.booksmall.utils.ApiJSONResult; 4 | import org.springframework.web.bind.annotation.ControllerAdvice; 5 | import org.springframework.web.bind.annotation.ExceptionHandler; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | 8 | /** 9 | * @className: GlobalExceptionHandler 10 | * @description: 11 | * @author: zxh 12 | * @date: 2018-11-20 09:59:51 13 | */ 14 | @ControllerAdvice 15 | public class GlobalExceptionHandler { 16 | 17 | @ResponseBody 18 | @ExceptionHandler(value = Exception.class) 19 | public ApiJSONResult errorHandler(Exception ex) { 20 | 21 | return ApiJSONResult.errorMsg(ex.getMessage()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /bookSmall/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件", 3 | "packOptions": { 4 | "ignore": [] 5 | }, 6 | "setting": { 7 | "urlCheck": false, 8 | "es6": true, 9 | "postcss": true, 10 | "minified": true, 11 | "newFeature": true, 12 | "autoAudits": false 13 | }, 14 | "compileType": "miniprogram", 15 | "libVersion": "2.4.3", 16 | "appid": "wx850124bf2a081fb0", 17 | "projectname": "bookSmall", 18 | "debugOptions": { 19 | "hidedInDevtools": [] 20 | }, 21 | "isGameTourist": false, 22 | "condition": { 23 | "search": { 24 | "current": -1, 25 | "list": [] 26 | }, 27 | "conversation": { 28 | "current": -1, 29 | "list": [] 30 | }, 31 | "game": { 32 | "currentL": -1, 33 | "list": [] 34 | }, 35 | "miniprogram": { 36 | "current": -1, 37 | "list": [] 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /book_small/src/main/resources/mapper/AdminMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /book_small/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service; 2 | 3 | import cn.zxhysy.booksmall.pojo.OrderDetail; 4 | import cn.zxhysy.booksmall.pojo.OrderMaster; 5 | import cn.zxhysy.booksmall.pojo.vo.OrderVO; 6 | import cn.zxhysy.booksmall.utils.MyPageInfo; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @program: book_small 12 | * @className: OrderService 13 | * @description: 订单服务 14 | * @author: zxh 15 | * @date: 2019-04-01 23:28 16 | */ 17 | public interface OrderService { 18 | 19 | /** 20 | * 添加对象信息 21 | * @param orderMaster 表体 22 | * @param orderDetailList 详情 23 | */ 24 | void saveOrder(OrderMaster orderMaster, List orderDetailList); 25 | 26 | /** 27 | * 获取订单列表 28 | * @param pageNum 当前页 29 | * @param pageSize 个数 30 | * @param payStatus 购买状态 31 | * @param openid openid 32 | * @return 对象 33 | */ 34 | MyPageInfo getAllOrder(Integer pageNum, Integer pageSize, Byte payStatus, String openid); 35 | } 36 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/BookService.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service; 2 | 3 | import cn.zxhysy.booksmall.pojo.Book; 4 | import com.github.pagehelper.PageInfo; 5 | 6 | /** 7 | * @className: BookService 8 | * @description: 图书服务 9 | * @author: zxh 10 | * @date: 2019年3月31日23:35:56 11 | */ 12 | public interface BookService { 13 | 14 | /** 15 | * 根据id获取图书BookServer 16 | * 17 | * @param id 图书id 18 | * @return Book 19 | */ 20 | Book getBookById(String id); 21 | 22 | /** 23 | * 根据 类别id 分页查询图书列表 24 | * @param pageNum 当前页 25 | * @param pageSize 显示记录数 26 | * @param categoryId 类别id 27 | * @return PageInfo 28 | */ 29 | PageInfo getBookByCategoryId(Integer pageNum, Integer pageSize, Integer categoryId); 30 | 31 | /** 32 | * 根据书本名称查询书本信息 33 | * 34 | * @param pageNum 当前页 35 | * @param pageSize 个数 36 | * @param name 图书名字 37 | * @return 38 | */ 39 | PageInfo getBookByName(Integer pageNum, Integer pageSize, String name); 40 | } 41 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/UserService.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service; 2 | 3 | import cn.zxhysy.booksmall.pojo.User; 4 | 5 | /** 6 | * @className: UserService 7 | * @description: 8 | * @author: zxh 9 | * @date: 2019-1-29 9:20:23 10 | */ 11 | public interface UserService { 12 | 13 | /** 14 | * 保存用户信息 15 | * 16 | * @param user 用户对象 17 | * @return 返回是否成功 18 | */ 19 | boolean saveUser(User user); 20 | 21 | /** 22 | * 微信登录 23 | * 24 | * @param encryptedData 明文,加密数据 25 | * @param iv 加密算法的初始向量 26 | * @param code code值五分钟限制 27 | * @return 返回用户信息 28 | * @throws Exception 登录失败 29 | */ 30 | User weChatLogin(String encryptedData, String iv, String code) throws Exception; 31 | 32 | /** 33 | * 用户更新 34 | * 35 | * @param user 用户对象 36 | * @return 更新成功或失败 37 | */ 38 | boolean updateUser(User user); 39 | 40 | /** 41 | * 根据 openid 查询对象信息 42 | * 43 | * @param openId 微信openid 44 | * @return 用户对象 45 | */ 46 | User queryUserByOpenid(String openId); 47 | } 48 | -------------------------------------------------------------------------------- /bookSmall/pages/userInfo/userInfo.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 点击更换图像 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
-------------------------------------------------------------------------------- /book_small/src/main/resources/mapper/OrderMasterMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /book_small/src/main/resources/mapper/BookMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /bookSmall/pages/personal/personal.wxml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 个人信息 13 | 14 | 15 | 16 | 17 | 我的订单 18 | 19 | 20 | 21 | 22 | 收货物地址 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/vo/OrderVO.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo.vo; 2 | 3 | import cn.zxhysy.booksmall.pojo.OrderDetail; 4 | import cn.zxhysy.booksmall.pojo.OrderMaster; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @program: book_small 10 | * @className: OrderVO 11 | * @description: 订单视图 12 | * @author: zxh 13 | * @date: 2019-04-01 23:38 14 | */ 15 | public class OrderVO { 16 | 17 | /** 18 | * 订单主表信息 19 | */ 20 | private OrderMaster orderMaster; 21 | /** 22 | * 订单详情表信息 23 | */ 24 | private List orderDetailList; 25 | 26 | public OrderMaster getOrderMaster() { 27 | return orderMaster; 28 | } 29 | 30 | public void setOrderMaster(OrderMaster orderMaster) { 31 | this.orderMaster = orderMaster; 32 | } 33 | 34 | public List getOrderDetailList() { 35 | return orderDetailList; 36 | } 37 | 38 | public void setOrderDetailList(List orderDetailList) { 39 | this.orderDetailList = orderDetailList; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "OrderVO{" + 45 | "orderMaster=" + orderMaster + 46 | ", orderDetailList=" + orderDetailList + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/impl/CategoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service.impl; 2 | 3 | import cn.zxhysy.booksmall.mapper.CategoryMapper; 4 | import cn.zxhysy.booksmall.pojo.Category; 5 | import cn.zxhysy.booksmall.service.CategoryService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Propagation; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @program: book_small 15 | * @className: CategoryServiceImpl 16 | * @description: 类别接口服务 17 | * @author: zxh 18 | * @date: 2019-04-01 00:14 19 | */ 20 | @Service 21 | public class CategoryServiceImpl implements CategoryService { 22 | 23 | private CategoryMapper categoryMapper; 24 | 25 | @Autowired 26 | public CategoryServiceImpl(CategoryMapper categoryMapper) { 27 | this.categoryMapper = categoryMapper; 28 | } 29 | 30 | /** 31 | * 查询类别信息 32 | * 33 | * @return List 34 | */ 35 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) 36 | @Override 37 | public List getAllCategory() { 38 | return categoryMapper.selectAll(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/controller/CategoryController.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.controller; 2 | 3 | import cn.zxhysy.booksmall.pojo.Category; 4 | import cn.zxhysy.booksmall.utils.ApiJSONResult; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiOperation; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @program: book_small 16 | * @className: CategoryController 17 | * @description: 类别操作 18 | * @author: zxh 19 | * @date: 2019-04-01 00:20 20 | */ 21 | @Api(value = "类别接口", tags = "类别操作") 22 | @RestController 23 | @RequestMapping(value = "/category") 24 | public class CategoryController { 25 | 26 | private final BasicController basicController; 27 | 28 | @Autowired 29 | public CategoryController(BasicController basicController) { 30 | this.basicController = basicController; 31 | } 32 | 33 | @ApiOperation(value = "获取全部类别信息") 34 | @GetMapping 35 | public ApiJSONResult showAllCategory(){ 36 | List allCategory = basicController.categoryService.getAllCategory(); 37 | return ApiJSONResult.ok(allCategory); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /bookSmall/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages": [ 3 | "pages/main/main", 4 | "pages/cart/cart", 5 | "pages/order/order", 6 | "pages/personal/personal", 7 | "pages/userInfo/userInfo", 8 | "pages/goods/goods", 9 | "pages/pay/pay", 10 | "pages/orderDetail/orderDetail" 11 | ], 12 | "window": { 13 | "navigationBarBackgroundColor": "#ffffff", 14 | "navigationBarTextStyle": "black", 15 | "navigationBarTitleText": "校园书店", 16 | "backgroundColor": "#eeeeee", 17 | "backgroundTextStyle": "light", 18 | "enablePullDownRefresh": false 19 | }, 20 | "tabBar": { 21 | "backgroundColor": "#fafafa", 22 | "borderStyle": "white", 23 | "selectedColor": "#AB956D", 24 | "color": "#666", 25 | "list": [ 26 | { 27 | "pagePath": "pages/main/main", 28 | "iconPath": "static/images/home.png", 29 | "selectedIconPath": "static/images/home@selected.png", 30 | "text": "首页" 31 | }, 32 | { 33 | "pagePath": "pages/cart/cart", 34 | "iconPath": "static/images/cart.png", 35 | "selectedIconPath": "static/images/cart@selected.png", 36 | "text": "购物车" 37 | }, 38 | { 39 | "pagePath": "pages/personal/personal", 40 | "iconPath": "static/images/my.png", 41 | "selectedIconPath": "static/images/my@selected.png", 42 | "text": "个人" 43 | } 44 | ] 45 | }, 46 | "debug": true 47 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/MyPageInfo.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @program: book_small 7 | * @className: MyPageInfo 8 | * @description: 与PageInfo相同对象 9 | * @author: zxh 10 | * @date: 2019-04-02 13:58 11 | */ 12 | public class MyPageInfo { 13 | /** 当前页数 */ 14 | private int pageNum; 15 | /** 总页数 */ 16 | private int pages; 17 | /** 当前页数 */ 18 | private int pageSize; 19 | /** 总记录数 */ 20 | private long total; 21 | /** 每行显示的内容 */ 22 | private List list; 23 | 24 | public int getPageNum() { 25 | return pageNum; 26 | } 27 | 28 | public void setPageNum(int pageNum) { 29 | this.pageNum = pageNum; 30 | } 31 | 32 | public int getPages() { 33 | return pages; 34 | } 35 | 36 | public void setPages(int pages) { 37 | this.pages = pages; 38 | } 39 | 40 | public int getPageSize() { 41 | return pageSize; 42 | } 43 | 44 | public void setPageSize(int pageSize) { 45 | this.pageSize = pageSize; 46 | } 47 | 48 | public long getTotal() { 49 | return total; 50 | } 51 | 52 | public void setTotal(long total) { 53 | this.total = total; 54 | } 55 | 56 | public List getList() { 57 | return list; 58 | } 59 | 60 | public void setList(List list) { 61 | this.list = list; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/impl/AdminServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service.impl; 2 | 3 | import cn.zxhysy.booksmall.mapper.AdminMapper; 4 | import cn.zxhysy.booksmall.pojo.Admin; 5 | import cn.zxhysy.booksmall.service.AdminService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Propagation; 9 | import org.springframework.transaction.annotation.Transactional; 10 | import tk.mybatis.mapper.entity.Example; 11 | 12 | /** 13 | * @className: AdminServiceImpl 14 | * @description: 15 | * @author: zxh 16 | * @date: 2019-1-29 10:04:23 17 | */ 18 | @Service 19 | public class AdminServiceImpl implements AdminService { 20 | 21 | private AdminMapper adminMapper; 22 | 23 | @Autowired 24 | public AdminServiceImpl(AdminMapper adminMapper) { 25 | this.adminMapper = adminMapper; 26 | } 27 | 28 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) 29 | @Override 30 | public Admin login(String adminName, String adminPassword) { 31 | 32 | Example adminExample = new Example(Admin.class); 33 | Example.Criteria criteria = adminExample.createCriteria(); 34 | criteria.andEqualTo("name", adminName) 35 | .andEqualTo("password", adminPassword); 36 | return adminMapper.selectOneByExample(adminExample); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /bookSmall/pages/order/order.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{item.name}} 6 | 7 | 8 | 9 | 10 | 11 | 12 | {{item.orderMaster.id}} >>> 13 | {{item.orderMaster.createTime}} 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 收件人: 23 | {{item.orderMaster.userName}} 24 | 25 | 26 | 状态: 27 | {{item.orderMaster.payStatus === 1 ? '已付款': item.orderMaster.payStatus === 0 ? '待付款': '已取消' }} 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/IDUtil.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * @className: IDUtil 7 | * @description: 商品id生成工具 8 | * @author: zxh 9 | * @date: 10 | */ 11 | public class IDUtil { 12 | 13 | /** 14 | * 如果采用fastDFS,图片名字是自动生产的 15 | * 图片名生成 16 | */ 17 | public static String genImageName() { 18 | //取当前时间的长整形值包含毫秒 long millis = System.nanoTime() 19 | long millis = System.currentTimeMillis(); 20 | //加上三位随机数 21 | Random random = new Random(); 22 | int end3 = random.nextInt(999); 23 | //如果不足三位前面补0 24 | return millis + String.format("%03d", end3); 25 | } 26 | 27 | /** 28 | * 详情id生成 29 | */ 30 | public static String getDetailId() { 31 | //取当前时间的长整形值包含毫秒 long millis = System.nanoTime() 32 | long millis = System.currentTimeMillis(); 33 | //加上两位随机数 34 | Random random = new Random(); 35 | int end2 = random.nextInt(99); 36 | //如果不足两位前面补0 37 | return "DETAIL"+millis + String.format("%02d", end2); 38 | } 39 | 40 | /** 41 | * 主表id生成 42 | */ 43 | public static String getMasterId() { 44 | //取当前时间的长整形值包含毫秒 long millis = System.nanoTime() 45 | long millis = System.currentTimeMillis(); 46 | //加上两位随机数 47 | Random random = new Random(); 48 | int end2 = random.nextInt(99); 49 | //如果不足两位前面补0 50 | return "MASTER"+millis + String.format("%02d", end2); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /book_small/src/main/resources/mapper/OrderDetailMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | INSERT INTO tb_order_detail ( id, 21 | order_id, book_id, book_name, book_price, book_quantity, book_icon) 22 | VALUES 23 | 24 | ( 25 | #{item.id}, 26 | #{item.orderId}, 27 | #{item.bookId}, 28 | #{item.bookName}, 29 | #{item.bookPrice}, 30 | #{item.bookQuantity}, 31 | #{item.bookIcon} 32 | ) 33 | 34 | 35 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/mapper/MyMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014-2016 abel533@gmail.com 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package cn.zxhysy.booksmall.utils.mapper; 26 | 27 | import tk.mybatis.mapper.common.Mapper; 28 | import tk.mybatis.mapper.common.MySqlMapper; 29 | 30 | /** 31 | * @className: MyMapper 32 | * @description: 33 | * @author: zxh 34 | * @date: 2018-12-29 10:07:11 35 | */ 36 | public interface MyMapper extends Mapper, MySqlMapper { 37 | //TODO 38 | //FIXME 特别注意,该接口不能被扫描到,否则会出错 39 | } 40 | -------------------------------------------------------------------------------- /bookSmall/pages/orderDetail/orderDetail.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{orderMaster.userName}} 8 | {{orderMaster.userPhone}} 9 | 10 | 11 | {{orderMaster.userAddress}} 12 | 13 | 14 | 15 | 16 | 购物清单: 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {{item.bookName}} 29 | ¥{{item.bookPrice}} 30 | 31 | x{{item.bookQuantity}} 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | {{orderMaster.payStatus === 1 ? '已付款': orderMaster.payStatus === 0 ? '待付款': '已取消'}} 41 | 42 | 43 | 44 | 合计: 45 | ¥{{orderMaster.amount}}元 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /bookSmall/pages/order/order.wxss: -------------------------------------------------------------------------------- 1 | /* pages/myOrder/orderList.wxss */ 2 | 3 | page { 4 | height: 100%; 5 | } 6 | 7 | .container { 8 | background-color: #f2f2f2; 9 | width: 100%; 10 | height: auto; 11 | min-height: 100%; 12 | overflow: hidden; 13 | } 14 | 15 | .swiper-tab { 16 | height: 40px; 17 | line-height: 40px; 18 | display: flex; 19 | position: relative; 20 | z-index: 2; 21 | flex-direction: row; 22 | justify-content: center; 23 | align-items: center; 24 | background: white; 25 | width: 100%; 26 | } 27 | 28 | .swiper-tab-list { 29 | margin: 0 30px; 30 | padding: 0 4px; 31 | font-size: 15px; 32 | } 33 | 34 | .on { 35 | border-bottom: 2px solid #4d90fe; 36 | color: black; 37 | } 38 | 39 | .list-group { 40 | display: flex; 41 | flex-direction: column; 42 | width: 100%; 43 | padding-bottom: 20rpx; 44 | } 45 | 46 | .order { 47 | margin-bottom: 20rpx; 48 | background: white; 49 | display: flex; 50 | flex-direction: column; 51 | } 52 | 53 | .orderHeader { 54 | display: flex; 55 | border-bottom: 2px solid #f2f2f2; 56 | line-height: 50rpx; 57 | justify-content: space-around; 58 | } 59 | 60 | .orderCreate { 61 | font-size: 28rpx; 62 | } 63 | 64 | .orderNo { 65 | font-size: 28rpx; 66 | } 67 | 68 | .imgbox { 69 | display: flex; 70 | flex-wrap: nowrap; 71 | width: 100%; 72 | padding-left: 70rpx; 73 | border-bottom: 2px solid #f2f2f2; 74 | } 75 | 76 | .img { 77 | background-color: white; 78 | width: 150rpx; 79 | height: 150rpx; 80 | padding: 15rpx; 81 | } 82 | 83 | .orderFoot { 84 | display: flex; 85 | flex-direction: row; 86 | justify-content: space-between; 87 | padding-left: 65rpx; 88 | padding-right: 40rpx; 89 | } 90 | 91 | /**没有物品 */ 92 | 93 | .no-more-goods { 94 | text-align: center; 95 | font-size: 24rpx; 96 | padding-bottom: 48rpx; 97 | color: #999; 98 | } 99 | -------------------------------------------------------------------------------- /bookSmall/pages/main/main.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | {{item.name}} 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | {{item.name}} 32 | 33 | {{item.author}} 34 | ¥ {{item.price}} 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /bookSmall/pages/pay/pay.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{orderUser.userName}} 8 | {{orderUser.userPhone}} 9 | 10 | 11 | {{orderUser.userAddress}} 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 购物清单: 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | {{item.bookName}} 35 | ¥{{item.bookPrice}} 36 | 37 | x{{item.bookQuantity}} 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 立即付款 47 | 48 | 49 | 50 | 合计: 51 | ¥{{amount}}元 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/controller/BasicController.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.controller; 2 | 3 | import cn.zxhysy.booksmall.service.*; 4 | import cn.zxhysy.booksmall.utils.component.FastDFSClient; 5 | import cn.zxhysy.booksmall.utils.component.RedisOperator; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | import springfox.documentation.annotations.ApiIgnore; 9 | 10 | /** 11 | * @className: BasicController 12 | * @description: 模块化服务 13 | * @author: zxh 14 | * @date: 2018-12-29 09:58:36 15 | */ 16 | @ApiIgnore 17 | @Component 18 | public class BasicController { 19 | public final AdminService adminService; 20 | public final RedisOperator redisService; 21 | public final FastDFSClient fastDFSClient; 22 | public final UserService userService; 23 | public final BookService bookService; 24 | public final CategoryService categoryService; 25 | public final OrderService orderService; 26 | @Autowired 27 | public BasicController(AdminService adminService, RedisOperator redisService, FastDFSClient fastDFSClient, UserService userService,BookService bookService,CategoryService categoryService, OrderService orderService) { 28 | this.adminService = adminService; 29 | this.redisService = redisService; 30 | this.fastDFSClient = fastDFSClient; 31 | this.userService = userService; 32 | this.bookService = bookService; 33 | this.categoryService = categoryService; 34 | this.orderService = orderService; 35 | } 36 | 37 | /** 38 | * 用户登录回话状态钥匙 39 | */ 40 | public static final String USER_REDIS_SESSION = "user_redis_session"; 41 | /** 42 | * 文件保存的命名空间 43 | */ 44 | public static final String FILE_SPACE = "D:/zxh_wenjian"; 45 | /** 46 | * ffmpeg所在目录 47 | */ 48 | public static final String FFMPEG_EXE = "C:\\ffmpeg\\bin\\ffmpeg.exe"; 49 | /** 50 | * 每页分页的记录数 51 | */ 52 | public static final Integer PAGE_SIZE = 5; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bookSmall/utils/user.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 用户相关服务 3 | */ 4 | const util = require('../utils/util.js'); 5 | const api = require('../config/api.js'); 6 | 7 | 8 | /** 9 | * Promise封装wx.checkSession 10 | */ 11 | function checkSession() { 12 | return new Promise(function(resolve, reject) { 13 | wx.checkSession({ 14 | success: function() { 15 | resolve(true); 16 | }, 17 | fail: function() { 18 | reject(false); 19 | } 20 | }) 21 | }); 22 | } 23 | 24 | /** 25 | * Promise封装wx.login 26 | */ 27 | function login() { 28 | return new Promise(function(resolve, reject) { 29 | wx.login({ 30 | success: function(res) { 31 | if (res.code) { 32 | resolve(res); 33 | } else { 34 | reject(res); 35 | } 36 | }, 37 | fail: function(err) { 38 | reject(err); 39 | } 40 | }); 41 | }); 42 | } 43 | 44 | /** 45 | * 调用微信登录 46 | */ 47 | function loginByWeixin(userInfo) { 48 | 49 | return new Promise(function(resolve, reject) { 50 | return login().then((res) => { 51 | //登录远程服务器 52 | util.request(api.AuthLoginByWeixin, { 53 | code: res.code, 54 | userInfo: userInfo 55 | }, 'POST').then(res => { 56 | if (res.errno === 0) { 57 | //存储用户信息 58 | wx.setStorageSync('userInfo', res.data.userInfo); 59 | wx.setStorageSync('token', res.data.token); 60 | 61 | resolve(res); 62 | } else { 63 | reject(res); 64 | } 65 | }).catch((err) => { 66 | reject(err); 67 | }); 68 | }).catch((err) => { 69 | reject(err); 70 | }) 71 | }); 72 | } 73 | 74 | /** 75 | * 判断用户是否登录 76 | */ 77 | function checkLogin() { 78 | return new Promise(function(resolve, reject) { 79 | if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) { 80 | checkSession().then(() => { 81 | resolve(true); 82 | }).catch(() => { 83 | reject(false); 84 | }); 85 | } else { 86 | reject(false); 87 | } 88 | }); 89 | } 90 | 91 | module.exports = { 92 | loginByWeixin, 93 | checkLogin, 94 | }; -------------------------------------------------------------------------------- /bookSmall/pages/personal/personal.wxss: -------------------------------------------------------------------------------- 1 | .btn-info { 2 | width: 100%; 3 | display: flex; 4 | background-color: #ab956d; 5 | } 6 | 7 | /*禁用按钮时的样式*/ 8 | 9 | wx-button[disabled]:not([type]) { 10 | background-color: #ab956d; 11 | } 12 | 13 | .container { 14 | background: #f4f4f4; 15 | height: auto; 16 | overflow: hidden; 17 | width: 100%; 18 | } 19 | 20 | .profile-info { 21 | color: #f4f4f4; 22 | display: flex; 23 | align-items: center; 24 | padding: 30rpx; 25 | font-size: 28rpx; 26 | } 27 | 28 | .profile-info .avatar { 29 | height: 148rpx; 30 | width: 148rpx; 31 | border-radius: 50%; 32 | } 33 | 34 | .profile-info .info { 35 | flex: 1; 36 | height: 85rpx; 37 | padding-left: 31.25rpx; 38 | } 39 | 40 | .profile-info .name { 41 | display: block; 42 | height: 45rpx; 43 | line-height: 45rpx; 44 | color: #fff; 45 | font-size: 37.5rpx; 46 | margin-bottom: 10rpx; 47 | } 48 | 49 | .profile-info .level { 50 | display: block; 51 | height: 30rpx; 52 | line-height: 30rpx; 53 | margin-bottom: 10rpx; 54 | color: #7f7f7f; 55 | font-size: 30rpx; 56 | } 57 | 58 | .separate { 59 | background: #e0e3da; 60 | width: 100%; 61 | height: 6rpx; 62 | } 63 | 64 | .user_row { 65 | /* border: 1px solid black; */ 66 | width: 100%; 67 | height: 100rpx; 68 | line-height: 100rpx; 69 | background: #fff; 70 | border-bottom: 1px solid #fafafa; 71 | } 72 | 73 | .user_row_left { 74 | /* border: 1px solid #757575; */ 75 | float: left; 76 | height: 100rpx; 77 | font-weight: 550; 78 | line-height: 100rpx; 79 | margin-left: 35rpx; 80 | font-size: 26rpx; 81 | letter-spacing: 1rpx; 82 | } 83 | 84 | .user_row_right { 85 | /* border: 1px solid #757575; */ 86 | float: right; 87 | height: 40rpx; 88 | width: 40rpx; 89 | font-weight: 550; 90 | line-height: 86rpx; 91 | margin-top: 28rpx; 92 | margin-right: 30rpx; 93 | } 94 | 95 | .logout { 96 | margin-top: 30rpx; 97 | height: 100rpx; 98 | width: 100%; 99 | line-height: 100rpx; 100 | text-align: center; 101 | background: #fff; 102 | color: red; 103 | font-size: 30rpx; 104 | } 105 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/AesCbcUtil.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | import org.bouncycastle.jce.provider.BouncyCastleProvider; 5 | 6 | import javax.crypto.Cipher; 7 | import javax.crypto.spec.IvParameterSpec; 8 | import javax.crypto.spec.SecretKeySpec; 9 | import java.security.AlgorithmParameters; 10 | import java.security.Security; 11 | 12 | /** 13 | * @className: AesCbcUtil 14 | * @description: AES-128-CBC 可以自己定义“密钥”和“偏移量“。 15 | * AES-128 是jdk自动生成的“密钥”。 16 | * @author: zxh 17 | * @date: 18 | */ 19 | public class AesCbcUtil { 20 | 21 | 22 | static { 23 | //BouncyCastle是一个开源的加解密解决方案,主页在http://www.bouncycastle.org/ 24 | Security.addProvider(new BouncyCastleProvider()); 25 | } 26 | 27 | /** 28 | * AES解密 29 | * 30 | * @param data //密文,被加密的数据 31 | * @param key //秘钥 32 | * @param iv //偏移量 33 | * @param encodingFormat //解密后的结果需要进行的编码 34 | * @return 解密后的字符串 35 | * @throws Exception 解密异常 36 | */ 37 | public static String decrypt(String data, String key, String iv, String encodingFormat) throws Exception { 38 | // initialize(); 39 | 40 | //被加密的数据 41 | byte[] dataByte = Base64.decodeBase64(data); 42 | //加密秘钥 43 | byte[] keyByte = Base64.decodeBase64(key); 44 | //偏移量 45 | byte[] ivByte = Base64.decodeBase64(iv); 46 | 47 | 48 | try { 49 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); 50 | SecretKeySpec spec = new SecretKeySpec(keyByte, "AES"); 51 | AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES"); 52 | parameters.init(new IvParameterSpec(ivByte)); 53 | /* 初始化 */ 54 | cipher.init(Cipher.DECRYPT_MODE, spec, parameters); 55 | byte[] resultByte = cipher.doFinal(dataByte); 56 | if (null != resultByte && resultByte.length > 0) { 57 | return new String(resultByte, encodingFormat); 58 | } 59 | return null; 60 | } catch (Exception e) { 61 | e.printStackTrace(); 62 | throw new Exception(e); 63 | } 64 | } 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /bookSmall/utils/util.js: -------------------------------------------------------------------------------- 1 | var api = require('../config/api.js'); 2 | var app = getApp(); 3 | 4 | function formatTime(date) { 5 | var year = date.getFullYear(); 6 | var month = date.getMonth() + 1; 7 | var day = date.getDate(); 8 | 9 | var hour = date.getHours(); 10 | var minute = date.getMinutes(); 11 | var second = date.getSeconds(); 12 | 13 | 14 | return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':') 15 | } 16 | 17 | function formatNumber(n) { 18 | n = n.toString(); 19 | return n[1] ? n : '0' + n 20 | } 21 | 22 | /** 23 | * 封装微信的的request 24 | */ 25 | function request(url, data = {}, method = "GET") { 26 | return new Promise(function(resolve, reject) { 27 | wx.request({ 28 | url: url, 29 | data: data, 30 | method: method, 31 | header: { 32 | 'Content-Type': 'application/json', 33 | 'X-Litemall-Token': wx.getStorageSync('token') 34 | }, 35 | success: function(res) { 36 | 37 | if (res.statusCode == 200) { 38 | 39 | //判断后台缓存是否存在,如果不存在则返回 40 | if (res.data.errno == 501) { 41 | // 清除登录相关内容 42 | try { 43 | wx.removeStorageSync('userInfo'); 44 | wx.removeStorageSync('token'); 45 | } catch (e) { 46 | // Do something when catch error 47 | } 48 | // 切换到登录页面 49 | wx.navigateTo({ 50 | url: '/pages/personal/personal' 51 | }); 52 | } else { 53 | resolve(res.data); 54 | } 55 | } else { 56 | reject(res.errMsg); 57 | } 58 | 59 | }, 60 | fail: function(err) { 61 | reject(err) 62 | } 63 | }) 64 | }); 65 | } 66 | 67 | function redirect(url) { 68 | 69 | //判断页面是否需要登录 70 | if (false) { 71 | wx.redirectTo({ 72 | url: '/pages/auth/login/login' 73 | }); 74 | return false; 75 | } else { 76 | wx.redirectTo({ 77 | url: url 78 | }); 79 | } 80 | } 81 | 82 | function showErrorToast(msg) { 83 | wx.showToast({ 84 | title: msg, 85 | image: '/static/images/icon_error.png' 86 | }) 87 | } 88 | 89 | module.exports = { 90 | formatTime, 91 | request, 92 | redirect, 93 | showErrorToast 94 | }; -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.controller; 2 | 3 | import cn.zxhysy.booksmall.pojo.OrderDetail; 4 | import cn.zxhysy.booksmall.pojo.OrderMaster; 5 | import cn.zxhysy.booksmall.pojo.vo.OrderVO; 6 | import cn.zxhysy.booksmall.utils.ApiJSONResult; 7 | import cn.zxhysy.booksmall.utils.MyPageInfo; 8 | import io.swagger.annotations.*; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @program: book_small 16 | * @className: OrderController 17 | * @description: 订单服务 18 | * @author: zxh 19 | * @date: 2019-04-02 00:21 20 | */ 21 | @Api(value = "订单接口", tags = "订单操作") 22 | @RestController 23 | @RequestMapping("/order") 24 | public class OrderController { 25 | 26 | private final BasicController basicController; 27 | 28 | @Autowired 29 | public OrderController(BasicController basicController){ 30 | this.basicController = basicController; 31 | } 32 | 33 | @ApiOperation(value = "订单保存", notes = "用户下单") 34 | @PostMapping 35 | public ApiJSONResult saveOrder(@ApiParam(value="订单信息", required = true) @RequestBody OrderVO orderVO){ 36 | OrderMaster orderMaster = orderVO.getOrderMaster(); 37 | List orderDetailList = orderVO.getOrderDetailList(); 38 | basicController.orderService.saveOrder(orderMaster,orderDetailList); 39 | return ApiJSONResult.ok(); 40 | } 41 | 42 | @ApiOperation(value = "订单查询", notes = "用户查询订单信息") 43 | @ApiImplicitParams({ 44 | @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数", required = true, dataType = "Integer"), 45 | @ApiImplicitParam(paramType = "query", name = "pageSize", value = "显示记录数", required = true, dataType = "Integer"), 46 | @ApiImplicitParam(paramType = "query", name = "payStatus", value = "支付状态", required = true, dataType = "String"), 47 | @ApiImplicitParam(paramType = "query", name = "openid", value = "openid", required = true, dataType = "String") 48 | }) 49 | @GetMapping("/openid") 50 | public ApiJSONResult getAllOrder(Integer pageNum, Integer pageSize, String payStatus, String openid){ 51 | MyPageInfo allOrder = basicController.orderService.getAllOrder(pageNum, pageSize, new Byte(payStatus), openid); 52 | return ApiJSONResult.ok(allOrder); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/controller/AdminController.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.controller; 2 | 3 | import cn.zxhysy.booksmall.pojo.Admin; 4 | import cn.zxhysy.booksmall.pojo.vo.AdminVO; 5 | import cn.zxhysy.booksmall.utils.ApiJSONResult; 6 | import cn.zxhysy.booksmall.utils.MD5Util; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import io.swagger.annotations.ApiParam; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.springframework.beans.BeanUtils; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestBody; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RestController; 17 | 18 | import java.util.UUID; 19 | 20 | /** 21 | * @className: AdminController 22 | * @description: 管理员接口 23 | * @author: zxh 24 | * @date: 2018-12-29 09:58:11 25 | */ 26 | @Api(value = "管理员接口", tags = "管理员操作") 27 | @RestController 28 | @RequestMapping(value = "/admin") 29 | public class AdminController { 30 | 31 | /** 32 | * 基本控制器 33 | */ 34 | private final BasicController basicController; 35 | 36 | @Autowired 37 | public AdminController(BasicController basicController) { 38 | this.basicController = basicController; 39 | } 40 | 41 | @ApiOperation(value = "管理员登录", notes = "用户登录接口") 42 | @PostMapping(value = "/login") 43 | public ApiJSONResult login(@ApiParam(value = "管理员对象", required = true) @RequestBody Admin admin) throws Exception { 44 | 45 | if (StringUtils.isBlank(admin.getName()) || StringUtils.isBlank(admin.getPassword())) { 46 | return ApiJSONResult.errorMsg("账号和密码不能为空"); 47 | } 48 | System.out.println(); 49 | Admin adminResult = basicController.adminService.login(admin.getName(), MD5Util.getMD5Str(admin.getPassword())); 50 | 51 | if (null == adminResult) { 52 | return ApiJSONResult.errorMsg("账号或密码错误"); 53 | } 54 | 55 | adminResult.setPassword(""); 56 | String uniqueToken = UUID.randomUUID().toString(); 57 | basicController.redisService.set(BasicController.USER_REDIS_SESSION + ":" + adminResult.getId(), uniqueToken, 1000 * 60 * 30); 58 | 59 | AdminVO adminVO = new AdminVO(); 60 | // 拷贝值 61 | BeanUtils.copyProperties(adminResult, adminVO); 62 | adminVO.setUserToken(uniqueToken); 63 | 64 | return ApiJSONResult.ok(adminVO); 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /bookSmall/pages/orderDetail/orderDetail.wxss: -------------------------------------------------------------------------------- 1 | .container { 2 | background: #f4f4f4; 3 | height: auto; 4 | overflow: hidden; 5 | width: 100%; 6 | } 7 | 8 | .address { 9 | width: 100%; 10 | height: 240rpx; 11 | padding: 20rpx; 12 | /* background:#000; */ 13 | } 14 | 15 | .itembox{ 16 | display: flex; 17 | background: white; 18 | height: 200rpx; 19 | padding: 20rpx; 20 | align-items: center; 21 | border-radius: 20rpx; 22 | } 23 | 24 | .header { 25 | display: flex; 26 | flex-direction: row; 27 | align-items: flex-end; 28 | margin-bottom: 20rpx; 29 | } 30 | .username { 31 | font-size: 34rpx; 32 | margin-right: 15rpx; 33 | } 34 | .phone { 35 | color: #999; 36 | } 37 | 38 | .title { 39 | width: 100%; 40 | margin-top: 10rpx; 41 | margin-bottom: 10rpx; 42 | margin-left: 10rpx; 43 | color: #999; 44 | } 45 | 46 | .goods-list { 47 | display: flex; 48 | flex-direction: column; 49 | width: 100%; 50 | /* margin-bottom: 70rpx; */ 51 | } 52 | 53 | .goods { 54 | width: 100%; 55 | display: flex; 56 | flex-direction: row; 57 | background: white; 58 | justify-content: space-start; 59 | padding-left: 100rpx; 60 | } 61 | 62 | .goods-img { 63 | height: 200rpx; 64 | width: 200rpx; 65 | /* background: black; */ 66 | display: flex; 67 | align-items: center; 68 | margin-right: 30rpx; 69 | } 70 | 71 | .goods-img image { 72 | height: 160rpx; 73 | width: 160rpx; 74 | } 75 | 76 | .infoBox { 77 | display: flex; 78 | flex-direction: row; 79 | justify-content: space-between; 80 | width: 100%; 81 | } 82 | 83 | .info { 84 | display: flex; 85 | flex-direction: column; 86 | justify-content: space-around; 87 | flex: 8; 88 | } 89 | 90 | .buyMunber { 91 | flex: 2; 92 | font-size: 32rpx; 93 | align-self: center; 94 | } 95 | 96 | .separate { 97 | background: #e0e3da; 98 | width: 100%; 99 | height: 5rpx; 100 | } 101 | 102 | .cart-bottom { 103 | position: fixed; 104 | width: 100%; 105 | height: 100rpx; 106 | bottom: 0; 107 | background: white; 108 | } 109 | 110 | .cart-pay { 111 | width: 240rpx; 112 | height: 100%; 113 | background: #405f80; 114 | float: right; 115 | } 116 | 117 | .cart_pay { 118 | display: block; 119 | line-height: 100rpx; 120 | text-align: center; 121 | font-size: 30rpx; 122 | color: white; 123 | } 124 | 125 | .cart-sum { 126 | width: 300rpx; 127 | height: 100%; 128 | line-height: 100rpx; 129 | /* background: red; */ 130 | float: right; 131 | text-align: center; 132 | } 133 | 134 | .sum_color { 135 | color: red; 136 | font-size: 25rpx; 137 | } 138 | 139 | .sum_text { 140 | font-size: 30rpx; 141 | } 142 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/Category.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Id; 5 | import javax.persistence.Table; 6 | import java.util.Date; 7 | /** 8 | * @className: Category 9 | * @description: 10 | * @author: zxh 11 | * @date: 2019-3-29 10:03:35 12 | */ 13 | @Table(name = "tb_category") 14 | public class Category { 15 | /** 16 | * 类目编号 17 | */ 18 | @Id 19 | private Integer id; 20 | 21 | /** 22 | * 类目名字 23 | */ 24 | private String name; 25 | 26 | /** 27 | * 类目图片地址 28 | */ 29 | private String icon; 30 | 31 | /** 32 | * 创建时间 33 | */ 34 | @Column(name = "create_time") 35 | private Date createTime; 36 | 37 | /** 38 | * 修改时间 39 | */ 40 | @Column(name = "update_time") 41 | private Date updateTime; 42 | 43 | /** 44 | * 获取类目编号 45 | * 46 | * @return id - 类目编号 47 | */ 48 | public Integer getId() { 49 | return id; 50 | } 51 | 52 | /** 53 | * 设置类目编号 54 | * 55 | * @param id 类目编号 56 | */ 57 | public void setId(Integer id) { 58 | this.id = id; 59 | } 60 | 61 | /** 62 | * 获取类目名字 63 | * 64 | * @return name - 类目名字 65 | */ 66 | public String getName() { 67 | return name; 68 | } 69 | 70 | /** 71 | * 设置类目名字 72 | * 73 | * @param name 类目名字 74 | */ 75 | public void setName(String name) { 76 | this.name = name; 77 | } 78 | 79 | /** 80 | * 获取类目图片地址 81 | * 82 | * @return icon - 类目图片地址 83 | */ 84 | public String getIcon() { 85 | return icon; 86 | } 87 | 88 | /** 89 | * 设置类目图片地址 90 | * 91 | * @param icon 类目图片地址 92 | */ 93 | public void setIcon(String icon) { 94 | this.icon = icon; 95 | } 96 | 97 | /** 98 | * 获取创建时间 99 | * 100 | * @return create_time - 创建时间 101 | */ 102 | public Date getCreateTime() { 103 | return createTime; 104 | } 105 | 106 | /** 107 | * 设置创建时间 108 | * 109 | * @param createTime 创建时间 110 | */ 111 | public void setCreateTime(Date createTime) { 112 | this.createTime = createTime; 113 | } 114 | 115 | /** 116 | * 获取修改时间 117 | * 118 | * @return update_time - 修改时间 119 | */ 120 | public Date getUpdateTime() { 121 | return updateTime; 122 | } 123 | 124 | /** 125 | * 设置修改时间 126 | * 127 | * @param updateTime 修改时间 128 | */ 129 | public void setUpdateTime(Date updateTime) { 130 | this.updateTime = updateTime; 131 | } 132 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/config/Swagger2.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.service.Contact; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | 15 | /** 16 | * @className: Swagger2 17 | * @description: 18 | * @author: zxh 19 | * @date: 2018-12-29 09:57:00 20 | */ 21 | @Configuration 22 | @EnableSwagger2 23 | public class Swagger2 { 24 | 25 | /** 26 | * @description: swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等 27 | * @param: 28 | * @return: 29 | * @author: zxh 30 | * @date: 2019/3/29 10:18 31 | */ 32 | @Bean 33 | public Docket createRestApi() { 34 | 35 | // 为swagger添加header参数可供输入 36 | // ParameterBuilder userTokenHeader = new ParameterBuilder(); 37 | // ParameterBuilder userIdHeader = new ParameterBuilder(); 38 | // List pars = new ArrayList(); 39 | // userTokenHeader.name("headerUserToken").description("userToken") 40 | // .modelRef(new ModelRef("string")).parameterType("header") 41 | // .required(false).build(); 42 | // userIdHeader.name("headerUserId").description("userId") 43 | // .modelRef(new ModelRef("string")).parameterType("header") 44 | // .required(false).build(); 45 | // pars.add(userTokenHeader.build()); 46 | // pars.add(userIdHeader.build()); 47 | 48 | return new Docket(DocumentationType.SWAGGER_2) 49 | .apiInfo(apiInfo()) 50 | .select() 51 | .apis(RequestHandlerSelectors.basePackage("cn.zxhysy.booksmall.controller")) 52 | .paths(PathSelectors.any()) 53 | .build(); 54 | // .globalOperationParameters(pars); 55 | } 56 | 57 | /** 58 | * @description: 构建 api文档的信息 59 | * @param: 60 | * @return: 61 | * @author: zxh 62 | * @date: 2019/3/29 10:18 63 | */ 64 | private ApiInfo apiInfo() { 65 | return new ApiInfoBuilder() 66 | // 设置页面标题 67 | .title("使用swagger2构建短视频后端api接口文档") 68 | // 设置联系人 69 | .contact(new Contact("zxh", "cn.zxhyys", "1458187661@qq.com")) 70 | // 描述 71 | .description("欢迎访问图书商店接口文档,这里是描述信息") 72 | // 定义版本号 73 | .version("1.0").build(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/impl/BookServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service.impl; 2 | 3 | import cn.zxhysy.booksmall.mapper.BookMapper; 4 | import cn.zxhysy.booksmall.pojo.Book; 5 | import cn.zxhysy.booksmall.service.BookService; 6 | import com.github.pagehelper.PageHelper; 7 | import com.github.pagehelper.PageInfo; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Propagation; 11 | import org.springframework.transaction.annotation.Transactional; 12 | import tk.mybatis.mapper.entity.Example; 13 | import tk.mybatis.mapper.entity.Example.Criteria; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * @program: book_small 19 | * @className: BookServiceImpl 20 | * @description: 图书服务 21 | * @author: zxh 22 | * @date: 2019-03-29 17:02 23 | */ 24 | @Service 25 | public class BookServiceImpl implements BookService { 26 | 27 | private BookMapper bookMapper; 28 | 29 | @Autowired 30 | public BookServiceImpl(BookMapper bookMapper) { 31 | this.bookMapper = bookMapper; 32 | } 33 | 34 | /** 35 | * 根据书本id查询 36 | * 37 | * @param id 书本id 38 | * @return 图书信息 39 | */ 40 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) 41 | @Override 42 | public Book getBookById(String id) { 43 | return bookMapper.selectByPrimaryKey(id); 44 | } 45 | 46 | /** 47 | * 分页类别查询 48 | * 49 | * @param categoryId 类别id 50 | * @return 分页信息 51 | */ 52 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) 53 | @Override 54 | public PageInfo getBookByCategoryId(Integer page, Integer pageSize, Integer categoryId){ 55 | if(categoryId == 0){ 56 | categoryId = null; 57 | } 58 | PageHelper.startPage(page, pageSize); 59 | Example example = new Example(Book.class); 60 | Criteria criteria = example.createCriteria(); 61 | criteria.andEqualTo("categoryId",categoryId); 62 | List bookList = bookMapper.selectByExample(example); 63 | return new PageInfo<>(bookList); 64 | } 65 | 66 | /** 67 | * 根据书本名称查询书本信息 68 | * 69 | * @param pageNum 当前页 70 | * @param pageSize 个数 71 | * @param name 图书名字 72 | * @return 73 | */ 74 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) 75 | @Override 76 | public PageInfo getBookByName(Integer pageNum, Integer pageSize, String name) { 77 | PageHelper.startPage(pageNum, pageSize); 78 | Example example = new Example(Book.class); 79 | Criteria criteria = example.createCriteria(); 80 | criteria.andLike("name", "%"+name+"%"); 81 | 82 | List bookList = bookMapper.selectByExample(example); 83 | return new PageInfo<>(bookList); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /bookSmall/pages/cart/cart.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 书架上空空如也~ 6 | 7 | 8 | 去书店看看 9 | 10 | 11 | 12 | 13 | 14 | {{isEdit ? '完成': '编辑'}} 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | {{item.bookName}} 30 | ¥{{item.bookPrice}} 31 | 32 | 33 | 34 | - 35 | 36 | 37 | 38 | 39 | + 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/ApiJSONResult.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils; 2 | 3 | /** 4 | * @className: ApiJSONResult 5 | * @description: 自定义响应数据结构 6 | * 这个类是提供给门户,ios,安卓,微信商城用的 7 | * 门户接受此类数据后需要使用本类的方法转换成对于的数据类型格式(类,或者list) 8 | * 其他自行处理 9 | * 200:表示成功 10 | * 500:表示错误,错误信息在msg字段中 11 | * 501:bean验证错误,不管多少个错误都以map形式返回 12 | * 502:拦截器拦截到用户token出错 13 | * 555:异常抛出信息 14 | * @author: zxh 15 | * @date: 16 | */ 17 | public class ApiJSONResult { 18 | 19 | /** 20 | * 响应业务状态 21 | */ 22 | private Integer status; 23 | 24 | /** 25 | * 响应消息 26 | */ 27 | private String msg; 28 | 29 | /** 30 | * 响应中的数据 31 | */ 32 | private Object data; 33 | /** 34 | * 不使用,覆盖游览器原返回值ok 35 | */ 36 | private String ok; 37 | 38 | public static ApiJSONResult build(Integer status, String msg, Object data) { 39 | return new ApiJSONResult(status, msg, data); 40 | } 41 | 42 | public static ApiJSONResult ok(Object data) { 43 | return new ApiJSONResult(data); 44 | } 45 | 46 | public static ApiJSONResult ok() { 47 | return new ApiJSONResult(null); 48 | } 49 | 50 | public static ApiJSONResult errorMsg(String msg) { 51 | return new ApiJSONResult(500, msg, null); 52 | } 53 | 54 | public static ApiJSONResult errorMap(Object data) { 55 | return new ApiJSONResult(501, "error", data); 56 | } 57 | 58 | public static ApiJSONResult errorTokenMsg(String msg) { 59 | return new ApiJSONResult(502, msg, null); 60 | } 61 | 62 | public static ApiJSONResult errorException(String msg) { 63 | return new ApiJSONResult(555, msg, null); 64 | } 65 | 66 | public ApiJSONResult() { 67 | 68 | } 69 | 70 | // public static LeeJSONResult build(Integer status, String msg) { 71 | // return new LeeJSONResult(status, msg, null); 72 | // } 73 | 74 | public ApiJSONResult(Integer status, String msg, Object data) { 75 | this.status = status; 76 | this.msg = msg; 77 | this.data = data; 78 | } 79 | 80 | public ApiJSONResult(Object data) { 81 | this.status = 200; 82 | this.msg = "OK"; 83 | this.data = data; 84 | } 85 | 86 | public Boolean isOK() { 87 | return this.status == 200; 88 | } 89 | 90 | public Integer getStatus() { 91 | return status; 92 | } 93 | 94 | public void setStatus(Integer status) { 95 | this.status = status; 96 | } 97 | 98 | public String getMsg() { 99 | return msg; 100 | } 101 | 102 | public void setMsg(String msg) { 103 | this.msg = msg; 104 | } 105 | 106 | public Object getData() { 107 | return data; 108 | } 109 | 110 | public void setData(Object data) { 111 | this.data = data; 112 | } 113 | 114 | public String getOk() { 115 | return ok; 116 | } 117 | 118 | public void setOk(String ok) { 119 | this.ok = ok; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /bookSmall/pages/goods/goods.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | ¥ {{book.price}} 17 | {{book.name}} 18 | 19 | 20 | 21 | {{book.press}} 22 | {{book.author}} 23 | 24 | 25 | 26 | 27 | 作品简介 28 | 29 | {{book.description}} 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ({{shopNum}}) 38 | 我的购物车 39 | 40 | 加入购物车 41 | 42 | 43 | 82 | -------------------------------------------------------------------------------- /bookSmall/pages/pay/pay.wxss: -------------------------------------------------------------------------------- 1 | .container { 2 | background: #f4f4f4; 3 | height: auto; 4 | overflow: hidden; 5 | width: 100%; 6 | } 7 | 8 | .address { 9 | width: 100%; 10 | height: 240rpx; 11 | padding: 20rpx; 12 | /* background:#000; */ 13 | } 14 | 15 | .itembox{ 16 | display: flex; 17 | background: white; 18 | height: 200rpx; 19 | padding: 20rpx; 20 | align-items: center; 21 | border-radius: 20rpx; 22 | } 23 | 24 | .btnBox{ 25 | display: flex; 26 | flex-direction: column; 27 | justify-content: center; 28 | padding: 20rpx; 29 | height: 200rpx; 30 | background: white; 31 | border-radius: 20rpx; 32 | } 33 | .header { 34 | display: flex; 35 | flex-direction: row; 36 | align-items: flex-end; 37 | margin-bottom: 20rpx; 38 | } 39 | .username { 40 | font-size: 34rpx; 41 | margin-right: 15rpx; 42 | } 43 | .phone { 44 | color: #999; 45 | } 46 | 47 | .user_row_right { 48 | /* border: 1px solid #757575; */ 49 | height: 40rpx; 50 | width: 40rpx; 51 | } 52 | 53 | input { 54 | width: 300rpx; 55 | border: 2rpx solid #000; 56 | border-radius: 10rpx; 57 | padding-left: 20rpx; 58 | } 59 | 60 | .title { 61 | width: 100%; 62 | margin-top: 10rpx; 63 | margin-bottom: 10rpx; 64 | margin-left: 10rpx; 65 | color: #999; 66 | } 67 | 68 | .goods-list { 69 | display: flex; 70 | flex-direction: column; 71 | width: 100%; 72 | /* margin-bottom: 70rpx; */ 73 | } 74 | 75 | .goods { 76 | width: 100%; 77 | display: flex; 78 | flex-direction: row; 79 | background: white; 80 | justify-content: space-start; 81 | padding-left: 100rpx; 82 | } 83 | 84 | .goods-img { 85 | height: 200rpx; 86 | width: 200rpx; 87 | /* background: black; */ 88 | display: flex; 89 | align-items: center; 90 | margin-right: 30rpx; 91 | } 92 | 93 | .goods-img image { 94 | height: 160rpx; 95 | width: 160rpx; 96 | } 97 | 98 | .infoBox { 99 | display: flex; 100 | flex-direction: row; 101 | justify-content: space-between; 102 | width: 100%; 103 | } 104 | 105 | .info { 106 | display: flex; 107 | flex-direction: column; 108 | justify-content: space-around; 109 | flex: 8; 110 | } 111 | 112 | .buyMunber { 113 | flex: 2; 114 | font-size: 32rpx; 115 | align-self: center; 116 | } 117 | 118 | .separate { 119 | background: #e0e3da; 120 | width: 100%; 121 | height: 5rpx; 122 | } 123 | 124 | .cart-bottom { 125 | position: fixed; 126 | width: 100%; 127 | height: 100rpx; 128 | bottom: 0; 129 | background: white; 130 | } 131 | 132 | .cart-pay { 133 | width: 240rpx; 134 | height: 100%; 135 | background: #405f80; 136 | float: right; 137 | } 138 | 139 | .cart_pay { 140 | display: block; 141 | line-height: 100rpx; 142 | text-align: center; 143 | font-size: 30rpx; 144 | color: white; 145 | } 146 | 147 | .cart-sum { 148 | width: 300rpx; 149 | height: 100%; 150 | line-height: 100rpx; 151 | /* background: red; */ 152 | float: right; 153 | text-align: center; 154 | } 155 | 156 | .sum_color { 157 | color: red; 158 | font-size: 25rpx; 159 | } 160 | 161 | .sum_text { 162 | font-size: 30rpx; 163 | } 164 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.controller; 2 | 3 | import cn.zxhysy.booksmall.pojo.Book; 4 | import cn.zxhysy.booksmall.utils.ApiJSONResult; 5 | import com.github.pagehelper.PageInfo; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiImplicitParam; 8 | import io.swagger.annotations.ApiImplicitParams; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PathVariable; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | /** 17 | * @program: book_small 18 | * @className: BookServiceController 19 | * @description: 图书操作类 20 | * @author: zxh 21 | * @date: 2019-03-29 17:11 22 | */ 23 | @Api(value = "图书管理接口", tags = "图书操作") 24 | @RestController 25 | @RequestMapping("/book") 26 | public class BookController { 27 | 28 | private final BasicController basicController; 29 | 30 | @Autowired 31 | public BookController(BasicController basicController) { 32 | this.basicController = basicController; 33 | } 34 | 35 | @ApiOperation(value = "根据图书id获取图书信息") 36 | @ApiImplicitParam(paramType = "path", name = "id", value = "图书", required = true, dataType = "String") 37 | @GetMapping("{id}") 38 | public ApiJSONResult getBookById(@PathVariable("id") String id) { 39 | Book book = basicController.bookService.getBookById(id); 40 | return ApiJSONResult.ok(book); 41 | } 42 | 43 | @ApiOperation(value = "根据类别id获取图书信息") 44 | @ApiImplicitParams({ 45 | @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数", required = true, dataType = "Integer"), 46 | @ApiImplicitParam(paramType = "query", name = "pageSize", value = "显示记录数", required = true, dataType = "Integer"), 47 | @ApiImplicitParam(paramType = "query", name = "categoryId", value = "图书类别id", required = true, dataType = "Integer") 48 | }) 49 | @GetMapping("/category") 50 | public ApiJSONResult getPageBookByCategoryId(Integer pageNum, Integer pageSize, Integer categoryId){ 51 | PageInfo list = basicController.bookService.getBookByCategoryId(pageNum,pageSize,categoryId); 52 | return ApiJSONResult.ok(list); 53 | } 54 | @ApiOperation(value = "根据类别id获取图书信息") 55 | @ApiImplicitParams({ 56 | @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数", required = true, dataType = "Integer"), 57 | @ApiImplicitParam(paramType = "query", name = "pageSize", value = "显示记录数", required = true, dataType = "Integer"), 58 | @ApiImplicitParam(paramType = "query", name = "name", value = "图书名字", required = true, dataType = "String") 59 | }) 60 | @GetMapping("/search") 61 | public ApiJSONResult getAllBookByName(Integer pageNum, Integer pageSize, String name){ 62 | PageInfo bookList = basicController.bookService.getBookByName(pageNum, pageSize, name); 63 | return ApiJSONResult.ok(bookList); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.controller; 2 | 3 | import cn.zxhysy.booksmall.pojo.User; 4 | import cn.zxhysy.booksmall.pojo.vo.UserVO; 5 | import cn.zxhysy.booksmall.utils.ApiJSONResult; 6 | import io.swagger.annotations.*; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.springframework.beans.BeanUtils; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import java.util.UUID; 13 | 14 | /** 15 | * @className: UserController 16 | * @description: 17 | * @author: zxh 18 | * @date: 2012-12-29 09:59:22 19 | */ 20 | @Api(value = "用户接口", tags = "用户操作") 21 | @RestController 22 | @RequestMapping("/user") 23 | public class UserController { 24 | 25 | 26 | private final BasicController basicController; 27 | 28 | @Autowired 29 | public UserController(BasicController basicController) { 30 | this.basicController = basicController; 31 | } 32 | 33 | /** 34 | * 用户登录 35 | * paramType: 36 | * header:请求参数放置于Request Header,使用@RequestHeader获取 37 | * query:请求参数放置于请求地址,使用@RequestParam获取 38 | * path:(用于restful接口)-->请求参数的获取:@PathVariable 39 | * 40 | * @param encryptedData 明文,加密数据 41 | * @param iv 加密算法的初始向量 42 | * @param code 用户允许登录后,回调内容会带上 code(有效期五分钟),开发者需要将 code 发送到开发者服务器后台, 43 | * 使用code 换取 session_key api,将 code 换成 openid 和 session_key 44 | * @return 用户信息 45 | */ 46 | @ApiOperation(value = "微信登录", notes = "微信用户登录接口") 47 | @ApiImplicitParams({ 48 | @ApiImplicitParam(paramType = "query", name = "encryptedData", value = "明文", required = true, dataType = "String"), 49 | @ApiImplicitParam(paramType = "query", name = "iv", value = "加密算法的初始向量", required = true, dataType = "String"), 50 | @ApiImplicitParam(paramType = "query", name = "code", value = "临时登录凭证", required = true, dataType = "String") 51 | }) 52 | @PostMapping(value = "/decodeUser") 53 | public ApiJSONResult weChatLogin(String encryptedData, String iv, String code) throws Exception { 54 | if (StringUtils.isBlank(encryptedData + iv + code)) { 55 | throw new Exception("参数不能为空"); 56 | } 57 | User user = basicController.userService.weChatLogin(encryptedData, iv, code); 58 | String uniqueToken = UUID.randomUUID().toString(); 59 | basicController.redisService.set(BasicController.USER_REDIS_SESSION + ":" + user.getId(), uniqueToken, 1000 * 60 * 30); 60 | UserVO userVo = new UserVO(); 61 | BeanUtils.copyProperties(user, userVo); 62 | userVo.setUserToken(uniqueToken); 63 | return ApiJSONResult.ok(userVo); 64 | } 65 | 66 | /** 67 | * 用户更新 68 | * 69 | * @param user 用户对象 70 | * @return 成功与否 71 | */ 72 | @ApiOperation(value = "用户更新", notes = "用户更新") 73 | @PutMapping 74 | public ApiJSONResult updateUser(@ApiParam(value = "用户对象", required = true) @RequestBody User user) { 75 | boolean b = basicController.userService.updateUser(user); 76 | if (b) { 77 | return ApiJSONResult.ok("更新成功"); 78 | } else { 79 | return ApiJSONResult.errorMsg("更新失败"); 80 | } 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/Admin.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Id; 5 | import javax.persistence.Table; 6 | import java.util.Date; 7 | 8 | /** 9 | * @className: Admin 10 | * @description: 11 | * @author: zxh 12 | * @date: 2019-3-29 10:02:48 13 | */ 14 | @SuppressWarnings("ALL") 15 | @Table(name = "tb_admin") 16 | public class Admin { 17 | @Id 18 | private Integer id; 19 | 20 | /** 21 | * 名字 22 | */ 23 | private String name; 24 | 25 | private String password; 26 | 27 | /** 28 | * 电话 29 | */ 30 | private String phone; 31 | 32 | /** 33 | * 常用地址 34 | */ 35 | private String address; 36 | 37 | /** 38 | * 创建时间 39 | */ 40 | @Column(name = "create_time") 41 | private Date createTime; 42 | 43 | /** 44 | * 修改时间 45 | */ 46 | @Column(name = "update_time") 47 | private Date updateTime; 48 | 49 | /** 50 | * @return id 51 | */ 52 | public Integer getId() { 53 | return id; 54 | } 55 | 56 | /** 57 | * @param id 58 | */ 59 | public void setId(Integer id) { 60 | this.id = id; 61 | } 62 | 63 | /** 64 | * 获取名字 65 | * 66 | * @return name - 名字 67 | */ 68 | public String getName() { 69 | return name; 70 | } 71 | 72 | /** 73 | * 设置名字 74 | * 75 | * @param name 名字 76 | */ 77 | public void setName(String name) { 78 | this.name = name; 79 | } 80 | 81 | /** 82 | * @return password 83 | */ 84 | public String getPassword() { 85 | return password; 86 | } 87 | 88 | /** 89 | * @param password 90 | */ 91 | public void setPassword(String password) { 92 | this.password = password; 93 | } 94 | 95 | /** 96 | * 获取电话 97 | * 98 | * @return phone - 电话 99 | */ 100 | public String getPhone() { 101 | return phone; 102 | } 103 | 104 | /** 105 | * 设置电话 106 | * 107 | * @param phone 电话 108 | */ 109 | public void setPhone(String phone) { 110 | this.phone = phone; 111 | } 112 | 113 | /** 114 | * 获取常用地址 115 | * 116 | * @return address - 常用地址 117 | */ 118 | public String getAddress() { 119 | return address; 120 | } 121 | 122 | /** 123 | * 设置常用地址 124 | * 125 | * @param address 常用地址 126 | */ 127 | public void setAddress(String address) { 128 | this.address = address; 129 | } 130 | 131 | /** 132 | * 获取创建时间 133 | * 134 | * @return create_time - 创建时间 135 | */ 136 | public Date getCreateTime() { 137 | return createTime; 138 | } 139 | 140 | /** 141 | * 设置创建时间 142 | * 143 | * @param createTime 创建时间 144 | */ 145 | public void setCreateTime(Date createTime) { 146 | this.createTime = createTime; 147 | } 148 | 149 | /** 150 | * 获取修改时间 151 | * 152 | * @return update_time - 修改时间 153 | */ 154 | public Date getUpdateTime() { 155 | return updateTime; 156 | } 157 | 158 | /** 159 | * 设置修改时间 160 | * 161 | * @param updateTime 修改时间 162 | */ 163 | public void setUpdateTime(Date updateTime) { 164 | this.updateTime = updateTime; 165 | } 166 | } -------------------------------------------------------------------------------- /bookSmall/pages/pay/pay.js: -------------------------------------------------------------------------------- 1 | // pages/pay/pay.js 2 | var app = getApp() 3 | Page({ 4 | 5 | /** 6 | * 页面的初始数据 7 | */ 8 | data: { 9 | showAddress: false, 10 | itemList: null, // 订单列表 11 | amount: null, //总价格 12 | orderUser: {}, // 购买用户信息 13 | imgUrl: null, // 图片路劲 14 | userInfo: null 15 | }, 16 | /** 获取用户收货地址 */ 17 | getAddress() { 18 | wx.chooseAddress({ 19 | success: res => { 20 | if(res){ 21 | const orderUser = this.data.orderUser 22 | orderUser.userName = res.userName 23 | orderUser.userPhone = res.telNumber 24 | orderUser.userAddress = res.provinceName + ' ' + res.cityName + ' ' + res.countyName + ' ' + res.detailInfo 25 | console.log(orderUser) 26 | this.setData({ 27 | showAddress: true, 28 | orderUser 29 | }) 30 | } 31 | } 32 | }) 33 | }, 34 | /** 35 | * 生命周期函数--监听页面加载 36 | */ 37 | onLoad: function (options) { 38 | const {itemList, amount} = JSON.parse(options.order) 39 | const imgUrl = app.imgUrl 40 | 41 | const userInfo = app.getGlobalUserInfo() 42 | this.setData({ 43 | itemList, 44 | amount, 45 | imgUrl, 46 | userInfo 47 | }) 48 | }, 49 | 50 | /** 生成订单消息 */ 51 | createOrder(e) { 52 | const orderUser = this.data.orderUser 53 | if (JSON.stringify(orderUser) === '{}'){ 54 | wx.showToast({ 55 | title: '请先添加收货地址', 56 | icon: 'none' 57 | }) 58 | return 59 | } 60 | const userInfo = this.data.userInfo 61 | orderUser.userOpenid = userInfo.openid 62 | orderUser.amount = this.data.amount 63 | const pay = {} 64 | pay.orderMaster = orderUser 65 | pay.orderDetailList = this.data.itemList 66 | console.log(pay) 67 | 68 | wx.request({ 69 | url: app.serverUrl + "/order", 70 | method: "POST", 71 | header: { 72 | 'content-type': 'application/json', // 默认值 73 | 'userId': userInfo.id, // 用户id 74 | "userToken": userInfo.userToken // 用户 token 75 | }, 76 | data: pay, 77 | success: e => { 78 | if (e.data.status === 200) { 79 | // 清除购物车对应的东西 80 | const shopCarInfo = wx.getStorageSync('shopCarInfo') 81 | let shopList = shopCarInfo.shopList 82 | const itemList = this.data.itemList 83 | // 移除对应购物车数据 84 | itemList.forEach(res => { 85 | shopList.splice(shopList.findIndex(e => { 86 | if (res.bookId === e.bookId) { 87 | // 减掉购物车数量 88 | shopCarInfo.shopNum -= res.bookQuantity 89 | return true 90 | } 91 | }), 1) 92 | }) 93 | wx.setStorageSync('shopCarInfo', shopCarInfo) 94 | wx.showToast({ 95 | title: '支付成功', 96 | icon: 'success', 97 | duration: 2000, 98 | success: res => { 99 | setTimeout(() => { 100 | wx.navigateBack({ 101 | delta: 1 102 | }); 103 | }, 2000) 104 | } 105 | }) 106 | } else if (e.data.status === 500) { 107 | wx.showToast({ 108 | title: result.data.msg, 109 | icon: 'none' 110 | }) 111 | app.setGlobalUserInfo(null) 112 | } 113 | } 114 | }) 115 | } 116 | }) -------------------------------------------------------------------------------- /book_small/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9090 3 | 4 | spring: 5 | #datasource配置 6 | datasource: 7 | url: jdbc:mysql://127.0.0.1:3306/booksmall?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true 8 | username: root 9 | # password: root 10 | password: MYSQLzxh123456... 11 | #mysql新版驱动 12 | driver-class-name: com.mysql.cj.jdbc.Driver 13 | 14 | #连接池配置 15 | druid: 16 | #初始化大小、最小空闲、最大激活 17 | initial-size: 5 18 | min-idle: 5 19 | max-active: 20 20 | #配置获取连接等待超时的时间 21 | max-wait: 60000 22 | # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 23 | time-between-eviction-runs-millis: 60000 24 | # 配置一个连接在池中最小生存的时间,单位是毫秒 25 | min-evictable-idle-time-millis: 300000 26 | validation-query: SELECT 1 FROM DUAL 27 | test-while-idle: true 28 | test-on-borrow: false 29 | test-on-return: false 30 | # 打开PSCache,并且指定每个连接上PSCache的大小 31 | pool-prepared-statements: true 32 | max-pool-prepared-statement-per-connection-size: 20 33 | # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 34 | filters: stat,wall,log4j 35 | # 合并多个DruidDataSource的监控数据 36 | use-global-data-source-stat: true 37 | # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 38 | connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 39 | 40 | #redis 配置 41 | redis: 42 | database: 0 43 | # host: 192.168.106.157 44 | host: 127.0.0.1 45 | port: 6379 46 | password: 123456 47 | # password: 48 | jedis: 49 | pool: 50 | # 连接池最大连接数(使用负值表示没有限制) 51 | max-active: 8 52 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 53 | max-wait: -1 54 | #连接池中的最大空闲链接 55 | max-idle: 5 56 | #连接池中的最小空闲链接 57 | min-idle: 0 58 | timeout: 10000 59 | 60 | 61 | # 设置上传文件大小 62 | servlet: 63 | multipart: 64 | max-file-size: 10MB 65 | max-request-size: 100MB 66 | 67 | 68 | #mybatis相关配置 69 | mybatis: 70 | #当mybatis的xml文件和mapper接口不在相同包下时 71 | #需要用mapperLocations属性指定xml文件的路径。 72 | #*是个通配符,代表所有的文件,**代表所有目录下 73 | mapper-locations: classpath:mapper/*.xml 74 | #指定bean所在包 75 | #在mapper.xml中可以使用别名而不使用类的全路径名 76 | type-aliases-package: cn.zxhysy.booksmall.entry 77 | #配置 78 | configuration: 79 | #驼峰 80 | map-underscore-to-camel-case: true 81 | # 配置控制台打印sql 82 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 83 | #pagehelper分页插件 84 | pagehelper: 85 | helper-dialect: mysql 86 | reasonable: true 87 | params: count=countSql 88 | support-methods-arguments: true 89 | # 通用Mapper 90 | mapper: 91 | 92 | identity: MYSQL 93 | # 这里指向基类 94 | mappers: cn.zxhysy.booksmall.utils.mapper.MyMapper 95 | # 设置 insert 和 update 中,是否判断字符串类型!='' 96 | not-empty: false 97 | # 枚举按简单类型处理 98 | enum-as-simple-type: true 99 | #fastdfs 图片上传 100 | #http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.jpg 101 | #192.168.106.157:22122 这个就是你们图片地址 102 | fdfs: 103 | so-timeout: 1501 104 | connect-timeout: 2000 105 | thumb-image: #缩略图生成参数 106 | height: 80 107 | width: 80 108 | tracker-list: 109 | - 39.108.13.196:22122 110 | #小程序相关配置 111 | wx: 112 | appid: "wx850124bf2a081fb0" 113 | secret: "aa908a2b9b7b2f25700e0e4352e620bb" 114 | grant_type: "authorization_code" 115 | url: "https://api.weixin.qq.com/sns/jscode2session" 116 | -------------------------------------------------------------------------------- /bookSmall/pages/cart/cart.wxss: -------------------------------------------------------------------------------- 1 | page { 2 | height: 100%; 3 | } 4 | 5 | .container { 6 | background: #f4f4f4; 7 | width: 100%; 8 | height: auto; 9 | min-height: 100%; 10 | overflow: hidden; 11 | } 12 | 13 | /** 没有商品样式*/ 14 | 15 | .no-goods-title-box { 16 | width: 100%; 17 | padding-top: 330rpx; 18 | text-align: center; 19 | font-size: 28rpx; 20 | color: #999; 21 | background: url(https://cdn.it120.cc/images/weappshop/icon-cart.png) no-repeat center 205rpx; 22 | background-size: 100rpx auto; 23 | margin-bottom: 50rpx; 24 | } 25 | 26 | .no-goods-to-index-btn { 27 | color: #fff; 28 | background: #4d90fe; 29 | border-radius: 6px; 30 | width: 300rpx; 31 | height: 70rpx; 32 | line-height: 70rpx; 33 | text-align: center; 34 | font-size: 28rpx; 35 | } 36 | 37 | /* 有商品样式 */ 38 | 39 | .goods-list { 40 | display: flex; 41 | flex-direction: column; 42 | width: 100%; 43 | margin-bottom: 70rpx; 44 | } 45 | 46 | .goods { 47 | width: 100%; 48 | display: flex; 49 | flex-direction: row; 50 | background: white; 51 | justify-content: flex-start; 52 | } 53 | 54 | .top-list { 55 | width: 100%; 56 | margin: 10rpx 0rpx; 57 | } 58 | 59 | .edit-btn { 60 | margin-right: 10rpx; 61 | float: right; 62 | color: #999; 63 | height: 100%; 64 | } 65 | .disabledTap { 66 | background: #999; 67 | pointer-events: none; 68 | } 69 | 70 | .goods-icon { 71 | flex: 1; 72 | display: flex; 73 | align-items: center; 74 | justify-content: center; 75 | } 76 | 77 | .goods-img { 78 | height: 200rpx; 79 | width: 200rpx; 80 | /* background: black; */ 81 | display: flex; 82 | align-items: center; 83 | } 84 | 85 | .goods-img image { 86 | height: 180rpx; 87 | width: 180rpx; 88 | } 89 | 90 | .info { 91 | flex: 6; 92 | display: flex; 93 | flex-direction: column; 94 | justify-content: space-around; 95 | } 96 | 97 | .num-box { 98 | display: flex; 99 | } 100 | 101 | .num-jian, .num-input, .num-jia { 102 | width: 80rpx; 103 | height: 64rpx; 104 | line-height: 62rpx; 105 | text-align: center; 106 | border: 1px solid #eee; 107 | } 108 | 109 | .num-input { 110 | font-size: 28rpx; 111 | } 112 | 113 | .num-input input { 114 | height: 100%; 115 | } 116 | 117 | .hui { 118 | background-color: #f5f5f9; 119 | } 120 | 121 | .operation { 122 | display: flex; 123 | flex-direction: row-reverse; 124 | flex: 1; 125 | } 126 | 127 | .separate { 128 | background: #e0e3da; 129 | width: 100%; 130 | height: 5rpx; 131 | } 132 | 133 | .cart-bottom { 134 | position: fixed; 135 | width: 100%; 136 | height: 100rpx; 137 | bottom: 0; 138 | background: white; 139 | } 140 | 141 | .cart-icon { 142 | margin: 18rpx 20rpx; 143 | float: left; 144 | } 145 | 146 | .checkAll { 147 | line-height: 100rpx; 148 | font-size: 28rpx; 149 | } 150 | 151 | .cart-pay { 152 | width: 240rpx; 153 | height: 100%; 154 | background: #405f80; 155 | float: right; 156 | } 157 | 158 | .cart_pay { 159 | display: block; 160 | line-height: 100rpx; 161 | text-align: center; 162 | font-size: 30rpx; 163 | color: white; 164 | } 165 | 166 | .cart_edit { 167 | background: red; 168 | display: block; 169 | line-height: 100rpx; 170 | text-align: center; 171 | font-size: 30rpx; 172 | color: white; 173 | } 174 | 175 | .cart-sum { 176 | width: 300rpx; 177 | height: 100%; 178 | line-height: 100rpx; 179 | /* background: red; */ 180 | float: right; 181 | text-align: center; 182 | } 183 | 184 | .sum_color { 185 | color: red; 186 | font-size: 25rpx; 187 | } 188 | 189 | .sum_text { 190 | font-size: 30rpx; 191 | } 192 | -------------------------------------------------------------------------------- /bookSmall/pages/main/main.wxss: -------------------------------------------------------------------------------- 1 | /* pages/main/main.wxss */ 2 | 3 | .container { 4 | background-color: rgb(255, 255, 255); 5 | min-height: 100%; 6 | } 7 | 8 | /** 9 | 查询样式 10 | */ 11 | 12 | .search-view { 13 | left: 0; 14 | right: 0; 15 | top: 0; 16 | z-index: 500; 17 | width: 100%; 18 | height: 100rpx; 19 | background: gray; 20 | display: flex; 21 | flex-direction: column; 22 | } 23 | 24 | .search-content { 25 | background: #f1f1f1; 26 | width: 650rpx; 27 | display: flex; 28 | flex-direction: row; 29 | align-items: center; 30 | padding-top: auto; 31 | padding-left: 20rpx; 32 | padding-bottom: auto; 33 | margin: auto; 34 | height: 70rpx; 35 | border-radius: 5px 5px; 36 | } 37 | 38 | .search-icon { 39 | width: 40rpx; 40 | height: 40rpx; 41 | margin-right: 20rpx; 42 | } 43 | 44 | .search-input { 45 | width: 500rpx; 46 | font-size: 28rpx; 47 | } 48 | 49 | .search-btn { 50 | width: 150rpx; 51 | height: 70rpx; 52 | margin-right: 0rpx; 53 | background-color: #4d90fe; 54 | font-size: 28rpx; 55 | align-items: center; 56 | border-top-left-radius: 0rpx; 57 | border-bottom-left-radius: 0rpx; 58 | color: #fff; 59 | border: none; 60 | position: relative; 61 | } 62 | 63 | /**导航栏样式*/ 64 | 65 | .type-container { 66 | width: 94.2%; 67 | height: 88rpx; 68 | background-color: #fff; 69 | overflow: hidden; 70 | } 71 | 72 | .type-navbar { 73 | white-space: nowrap; 74 | height: 88rpx; 75 | width: 100%; 76 | background-color: #fff; 77 | } 78 | 79 | .type-box { 80 | width: 160rpx; 81 | box-sizing: content-box; 82 | font-size: 24rpx; 83 | line-height: 84rpx; 84 | text-align: center; 85 | display: inline-block; 86 | overflow: hidden; 87 | } 88 | 89 | .type-navbar-item { 90 | border-bottom: 4rpx solid #fff; 91 | position: relative; 92 | line-height: 84rpx; 93 | text-align: center; 94 | display: inline-block; 95 | overflow: hidden; 96 | } 97 | 98 | .type-item-on { 99 | border-bottom: 4rpx solid #49d; 100 | } 101 | 102 | /** 物品样式 */ 103 | 104 | .goods-container { 105 | display: flex; 106 | /* justify-content: space-between; */ 107 | flex-wrap: wrap; 108 | box-sizing: content-box; 109 | padding: 24rpx; 110 | } 111 | 112 | .goods-box { 113 | width: 300rpx; 114 | height: 472rpx; 115 | background-color: #fff; 116 | overflow: hidden; 117 | margin-left: 20rpx; 118 | margin-right: 28rpx; 119 | margin-bottom: 18rpx; 120 | } 121 | 122 | .goods-box .img-box { 123 | width: 300rpx; 124 | height: 300rpx; 125 | overflow: hidden; 126 | } 127 | 128 | .goods-box .img-box image { 129 | width: 300rpx; 130 | height: 300rpx; 131 | } 132 | 133 | .goods-box .goods-title { 134 | width: 280rpx; 135 | text-overflow: ellipsis; 136 | white-space: nowrap; 137 | overflow: hidden; 138 | /* background-color: green; */ 139 | font-size: 30rpx; 140 | /* padding-left: 24rpx; */ 141 | color: #000; 142 | margin-left: 24rpx; 143 | } 144 | 145 | .goods-box .goods-author { 146 | width: 180rpx; 147 | text-overflow: ellipsis; 148 | white-space: nowrap; 149 | overflow: hidden; 150 | /* background-color: green; */ 151 | font-size: 26rpx; 152 | margin-top: 20rpx; 153 | color: #999; 154 | margin-left: 24rpx; 155 | } 156 | 157 | .goods-box .goods-price { 158 | width: 100rpx; 159 | overflow: hidden; 160 | font-size: 24rpx; 161 | padding: 24rpx 0; 162 | color: #f60; 163 | margin-left: 24rpx; 164 | } 165 | 166 | /**没有物品 */ 167 | 168 | .no-more-goods { 169 | text-align: center; 170 | font-size: 24rpx; 171 | padding-bottom: 48rpx; 172 | color: #999; 173 | } 174 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/component/FastDFSClient.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils.component; 2 | 3 | import com.github.tobato.fastdfs.domain.StorePath; 4 | import com.github.tobato.fastdfs.exception.FdfsUnsupportStorePathException; 5 | import com.github.tobato.fastdfs.service.FastFileStorageClient; 6 | import org.apache.commons.io.FilenameUtils; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import java.io.ByteArrayInputStream; 13 | import java.io.IOException; 14 | import java.nio.charset.Charset; 15 | 16 | /** 17 | * @className: FastDFSClient 18 | * @description: 19 | * @author: zxh 20 | * @date: 2019-2-15 10:05:28 21 | */ 22 | @Component 23 | public class FastDFSClient { 24 | 25 | private FastFileStorageClient storageClient; 26 | 27 | @Autowired 28 | public FastDFSClient(FastFileStorageClient storageClient) { 29 | this.storageClient = storageClient; 30 | } 31 | 32 | /** 33 | * 上传文件 34 | * 35 | * @param file 文件对象 36 | * @return 文件访问地址 37 | * @throws IOException s 38 | */ 39 | public String uploadFile(MultipartFile file) throws IOException { 40 | StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), 41 | FilenameUtils.getExtension(file.getOriginalFilename()), null); 42 | 43 | return storePath.getPath(); 44 | } 45 | 46 | public String uploadFile2(MultipartFile file) throws IOException { 47 | StorePath storePath = storageClient.uploadImageAndCrtThumbImage(file.getInputStream(), file.getSize(), 48 | FilenameUtils.getExtension(file.getOriginalFilename()), null); 49 | 50 | return storePath.getPath(); 51 | } 52 | 53 | public String uploadQRCode(MultipartFile file) throws IOException { 54 | StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), 55 | "png", null); 56 | 57 | return storePath.getPath(); 58 | } 59 | 60 | public String uploadFace(MultipartFile file) throws IOException { 61 | StorePath storePath = storageClient.uploadImageAndCrtThumbImage(file.getInputStream(), file.getSize(), 62 | "png", null); 63 | 64 | return storePath.getPath(); 65 | } 66 | 67 | public String uploadBase64(MultipartFile file) throws IOException { 68 | StorePath storePath = storageClient.uploadImageAndCrtThumbImage(file.getInputStream(), file.getSize(), 69 | "png", null); 70 | 71 | return storePath.getPath(); 72 | } 73 | 74 | /** 75 | * 将一段字符串生成一个文件上传 76 | * 77 | * @param content s 78 | * 文件内容 79 | * @param fileExtension s 80 | * @return s 81 | */ 82 | public String uploadFile(String content, String fileExtension) { 83 | byte[] buff = content.getBytes(Charset.forName("UTF-8")); 84 | ByteArrayInputStream stream = new ByteArrayInputStream(buff); 85 | StorePath storePath = storageClient.uploadFile(stream, buff.length, fileExtension, null); 86 | return storePath.getPath(); 87 | } 88 | 89 | /** 90 | * 删除文件 91 | * 92 | * @param fileUrl 文件访问地址 93 | */ 94 | public void deleteFile(String fileUrl) { 95 | if (StringUtils.isEmpty(fileUrl)) { 96 | return; 97 | } 98 | try { 99 | StorePath storePath = StorePath.praseFromUrl(fileUrl); 100 | storageClient.deleteFile(storePath.getGroup(), storePath.getPath()); 101 | } catch (FdfsUnsupportStorePathException e) { 102 | e.getMessage(); 103 | } 104 | } 105 | } 106 | 107 | -------------------------------------------------------------------------------- /bookSmall/pages/personal/personal.js: -------------------------------------------------------------------------------- 1 | // pages/personal/personal.js 2 | var app = getApp(); 3 | Page({ 4 | 5 | /** 6 | * 页面的初始数据 7 | */ 8 | data: { 9 | disabled: false, 10 | aboutShow: true, 11 | userInfo: null, 12 | }, 13 | /** 14 | * 生命周期函数--监听页面显示 15 | */ 16 | onShow: function () { 17 | let userInfo = app.getGlobalUserInfo() 18 | if (userInfo) { 19 | this.setData({ 20 | userInfo, 21 | disabled: true 22 | }) 23 | } else { 24 | const userInfo = { 25 | nickName: '点击登录', 26 | avatarUrl: 'https://yanxuan.nosdn.127.net/8945ae63d940cc42406c3f67019c5cb6.png' 27 | } 28 | this.setData({ 29 | disabled: false, 30 | userInfo 31 | }) 32 | } 33 | }, 34 | //登录方法 35 | doLogin(e) { 36 | var that = this 37 | //获取授权 38 | if (e.detail.userInfo) { 39 | wx.showLoading({ 40 | title: '请等候' 41 | }) 42 | wx.login({ 43 | fail: res => { 44 | wx.hideLoading({ 45 | title: '与网络断开连接' 46 | }) 47 | }, 48 | success: res => { 49 | //获取临时登录凭证 50 | // console.log("3" + app.serverUrl) 51 | var code = res.code; 52 | if (code) { 53 | //获取用户信息接口 54 | wx.getUserInfo({ 55 | fail: res => { 56 | wx.hideLoading({ 57 | title: '与网络断开连接' 58 | }) 59 | }, 60 | success: e => { 61 | // 向服务器请求获取解密数据 62 | wx.request({ 63 | url: app.serverUrl + "/user/decodeUser", 64 | method: "POST", 65 | header: { 66 | "content-type": "application/x-www-form-urlencoded;charset=utf-8" 67 | }, 68 | data: { 69 | encryptedData: e.encryptedData, 70 | iv: e.iv, 71 | code 72 | }, 73 | fail: res => { 74 | wx.hideLoading({ 75 | title: '与网络断开连接' 76 | }) 77 | }, 78 | success: e => { 79 | if (e.data.status === 200) { 80 | wx.hideLoading() 81 | this.setData({ 82 | userInfo: e.data.data, 83 | disabled: true 84 | }) 85 | app.setGlobalUserInfo(e.data.data) 86 | } else if (e.data.status === 500) { 87 | wx.hideLoading() 88 | wx.showToast({ 89 | title: '登录失败', 90 | icon: 'none', 91 | duration: 1000 92 | }) 93 | } 94 | } 95 | }) 96 | } 97 | }) 98 | } 99 | } 100 | }) 101 | } else { 102 | wx.showToast({ 103 | title: '未授权', 104 | icon: 'none', 105 | duration: 1000 106 | }) 107 | } 108 | }, 109 | goInfo(e) { 110 | let userInfo = this.data.userInfo 111 | if (!userInfo) { 112 | wx.showToast({ 113 | title: '你还未登录', 114 | icon: 'none' 115 | }) 116 | return 117 | } 118 | wx.navigateTo({ 119 | url: '/pages/userInfo/userInfo' 120 | }) 121 | }, 122 | goOrder() { 123 | let userInfo = this.data.userInfo 124 | if (!userInfo) { 125 | wx.showToast({ 126 | title: '你还未登录', 127 | icon: 'none' 128 | }) 129 | return 130 | } 131 | wx.navigateTo({ 132 | url: '../order/order' 133 | }) 134 | }, 135 | goAddress() { 136 | wx.chooseAddress({ 137 | success: res => { 138 | } 139 | }) 140 | } 141 | }) -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/vo/AdminVO.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo.vo; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * @className: AdminVO 7 | * @description: 8 | * @author: zxh 9 | * @date: 2019-3-29 10:01:46 10 | */ 11 | public class AdminVO { 12 | 13 | private Integer id; 14 | 15 | private String userToken; 16 | /** 17 | * 名字 18 | */ 19 | private String name; 20 | 21 | private String password; 22 | 23 | /** 24 | * 电话 25 | */ 26 | private String phone; 27 | 28 | /** 29 | * 常用地址 30 | */ 31 | private String address; 32 | 33 | /** 34 | * 创建时间 35 | */ 36 | private Date createTime; 37 | 38 | /** 39 | * 修改时间 40 | */ 41 | private Date updateTime; 42 | 43 | /** 44 | * @return id 45 | */ 46 | public Integer getId() { 47 | return id; 48 | } 49 | 50 | /** 51 | * @param id 52 | */ 53 | public void setId(Integer id) { 54 | this.id = id; 55 | } 56 | 57 | /** 58 | * 获取名字 59 | * 60 | * @return name - 名字 61 | */ 62 | public String getName() { 63 | return name; 64 | } 65 | 66 | /** 67 | * 设置名字 68 | * 69 | * @param name 名字 70 | */ 71 | public void setName(String name) { 72 | this.name = name; 73 | } 74 | 75 | /** 76 | * @return password 77 | */ 78 | public String getPassword() { 79 | return password; 80 | } 81 | 82 | /** 83 | * @param password 84 | */ 85 | public void setPassword(String password) { 86 | this.password = password; 87 | } 88 | 89 | /** 90 | * 获取电话 91 | * 92 | * @return phone - 电话 93 | */ 94 | public String getPhone() { 95 | return phone; 96 | } 97 | 98 | /** 99 | * 设置电话 100 | * 101 | * @param phone 电话 102 | */ 103 | public void setPhone(String phone) { 104 | this.phone = phone; 105 | } 106 | 107 | /** 108 | * 获取常用地址 109 | * 110 | * @return address - 常用地址 111 | */ 112 | public String getAddress() { 113 | return address; 114 | } 115 | 116 | /** 117 | * 设置常用地址 118 | * 119 | * @param address 常用地址 120 | */ 121 | public void setAddress(String address) { 122 | this.address = address; 123 | } 124 | 125 | /** 126 | * 获取创建时间 127 | * 128 | * @return create_time - 创建时间 129 | */ 130 | public Date getCreateTime() { 131 | return createTime; 132 | } 133 | 134 | /** 135 | * 设置创建时间 136 | * 137 | * @param createTime 创建时间 138 | */ 139 | public void setCreateTime(Date createTime) { 140 | this.createTime = createTime; 141 | } 142 | 143 | /** 144 | * 获取修改时间 145 | * 146 | * @return update_time - 修改时间 147 | */ 148 | public Date getUpdateTime() { 149 | return updateTime; 150 | } 151 | 152 | /** 153 | * 设置修改时间 154 | * 155 | * @param updateTime 修改时间 156 | */ 157 | public void setUpdateTime(Date updateTime) { 158 | this.updateTime = updateTime; 159 | } 160 | 161 | public String getUserToken() { 162 | return userToken; 163 | } 164 | 165 | public void setUserToken(String usertoken) { 166 | this.userToken = usertoken; 167 | } 168 | 169 | @Override 170 | public String toString() { 171 | return "AdminVO{" + 172 | "id=" + id + 173 | ", userToken='" + userToken + '\'' + 174 | ", name='" + name + '\'' + 175 | ", password='" + password + '\'' + 176 | ", phone='" + phone + '\'' + 177 | ", address='" + address + '\'' + 178 | ", createTime=" + createTime + 179 | ", updateTime=" + updateTime + 180 | '}'; 181 | } 182 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/handler/MyHandlerInterceptor.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.handler; 2 | 3 | import cn.zxhysy.booksmall.controller.BasicController; 4 | import cn.zxhysy.booksmall.utils.ApiJSONResult; 5 | import cn.zxhysy.booksmall.utils.component.RedisOperator; 6 | import com.alibaba.fastjson.JSONObject; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.servlet.HandlerInterceptor; 10 | import org.springframework.web.servlet.ModelAndView; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | import java.io.OutputStream; 16 | import java.io.UnsupportedEncodingException; 17 | 18 | /** 19 | * @program: book_small 20 | * @className: MyHandlerInterceptor 21 | * @description: 拦截器 22 | * @author: zxh 23 | * @date: 2019-04-03 01:31 24 | */ 25 | public class MyHandlerInterceptor implements HandlerInterceptor { 26 | 27 | @Autowired 28 | public RedisOperator redisOperator; 29 | /** 30 | * 请求前处理 31 | * 32 | * @param request request 33 | * @param response response 34 | * @param handler handler 35 | * @return true/false true: 放行 36 | * @throws Exception Exception 37 | */ 38 | @Override 39 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 40 | 41 | String userId = request.getHeader("userId"); 42 | String userToken = request.getHeader("userToken"); 43 | if(StringUtils.isNoneBlank(userId) && StringUtils.isNoneBlank(userToken)){ 44 | String token = redisOperator.get(BasicController.USER_REDIS_SESSION + ":" + userId); 45 | if(StringUtils.isBlank(token) && StringUtils.isBlank(token)){ 46 | returnErrorResponse(response,ApiJSONResult.errorMsg("登录超时,请重新登录")); 47 | return false; 48 | } else{ 49 | if(!token.equals(userToken)){ 50 | returnErrorResponse(response,ApiJSONResult.errorMsg("账号被挤出,")); 51 | return false; 52 | } else { 53 | return true; 54 | } 55 | } 56 | 57 | } else { 58 | returnErrorResponse(response,ApiJSONResult.errorMsg("请登录")); 59 | return false; 60 | } 61 | 62 | } 63 | 64 | public void returnErrorResponse(HttpServletResponse response, ApiJSONResult result) 65 | throws IOException, UnsupportedEncodingException { 66 | OutputStream out=null; 67 | try{ 68 | response.setCharacterEncoding("utf-8"); 69 | response.setContentType("text/json"); 70 | out = response.getOutputStream(); 71 | out.write(JSONObject.toJSONString(result).getBytes()); 72 | out.flush(); 73 | } finally{ 74 | if(out!=null){ 75 | out.close(); 76 | } 77 | } 78 | } 79 | 80 | /** 81 | * 请求 Controller 之后 渲染视图之前 82 | * @param request request 83 | * @param response response 84 | * @param handler handler 85 | * @param modelAndView modelAndView 86 | * @throws Exception Exception 87 | */ 88 | @Override 89 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { 90 | 91 | } 92 | 93 | /** 94 | * 请求 Controller 之结束后 渲染视图之后 95 | * @param request request 96 | * @param response response 97 | * @param handler handler 98 | * @param ex ex 99 | * @throws Exception Exception Exception 100 | */ 101 | @Override 102 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { 103 | 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/User.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | import javax.persistence.Table; 7 | import java.util.Date; 8 | 9 | /** 10 | * @className: User 11 | * @description: 12 | * @author: zxh 13 | * @date: 2019-3-29 10:04:08 14 | */ 15 | @Table(name = "tb_user") 16 | public class User { 17 | @Id 18 | private Integer id; 19 | 20 | /** 21 | * 名字 22 | */ 23 | @Column(name = "nick_name") 24 | private String nickName; 25 | 26 | /** 27 | * 电话 28 | */ 29 | private String phone; 30 | 31 | /** 32 | * 常用地址 33 | */ 34 | private String address; 35 | 36 | /** 37 | * 微信openid 38 | */ 39 | private String openid; 40 | 41 | @Column(name = "avatar_url") 42 | private String avatarUrl; 43 | 44 | /** 45 | * 创建时间 46 | */ 47 | @Column(name = "create_time") 48 | private Date createTime; 49 | 50 | /** 51 | * 修改时间 52 | */ 53 | @Column(name = "update_time") 54 | private Date updateTime; 55 | 56 | /** 57 | * @return id 58 | */ 59 | public Integer getId() { 60 | return id; 61 | } 62 | 63 | /** 64 | * @param id 65 | */ 66 | public void setId(Integer id) { 67 | this.id = id; 68 | } 69 | 70 | /** 71 | * 获取名字 72 | * 73 | * @return nick_name - 名字 74 | */ 75 | public String getNickName() { 76 | return nickName; 77 | } 78 | 79 | /** 80 | * 设置名字 81 | * 82 | * @param nickName 名字 83 | */ 84 | public void setNickName(String nickName) { 85 | this.nickName = nickName; 86 | } 87 | 88 | /** 89 | * 获取电话 90 | * 91 | * @return phone - 电话 92 | */ 93 | public String getPhone() { 94 | return phone; 95 | } 96 | 97 | /** 98 | * 设置电话 99 | * 100 | * @param phone 电话 101 | */ 102 | public void setPhone(String phone) { 103 | this.phone = phone; 104 | } 105 | 106 | /** 107 | * 获取常用地址 108 | * 109 | * @return address - 常用地址 110 | */ 111 | public String getAddress() { 112 | return address; 113 | } 114 | 115 | /** 116 | * 设置常用地址 117 | * 118 | * @param address 常用地址 119 | */ 120 | public void setAddress(String address) { 121 | this.address = address; 122 | } 123 | 124 | /** 125 | * 获取微信openid 126 | * 127 | * @return openid - 微信openid 128 | */ 129 | public String getOpenid() { 130 | return openid; 131 | } 132 | 133 | /** 134 | * 设置微信openid 135 | * 136 | * @param openid 微信openid 137 | */ 138 | public void setOpenid(String openid) { 139 | this.openid = openid; 140 | } 141 | 142 | /** 143 | * @return avatar_url 144 | */ 145 | public String getAvatarUrl() { 146 | return avatarUrl; 147 | } 148 | 149 | /** 150 | * @param avatarUrl 151 | */ 152 | public void setAvatarUrl(String avatarUrl) { 153 | this.avatarUrl = avatarUrl; 154 | } 155 | 156 | /** 157 | * 获取创建时间 158 | * 159 | * @return create_time - 创建时间 160 | */ 161 | public Date getCreateTime() { 162 | return createTime; 163 | } 164 | 165 | /** 166 | * 设置创建时间 167 | * 168 | * @param createTime 创建时间 169 | */ 170 | public void setCreateTime(Date createTime) { 171 | this.createTime = createTime; 172 | } 173 | 174 | /** 175 | * 获取修改时间 176 | * 177 | * @return update_time - 修改时间 178 | */ 179 | public Date getUpdateTime() { 180 | return updateTime; 181 | } 182 | 183 | /** 184 | * 设置修改时间 185 | * 186 | * @param updateTime 修改时间 187 | */ 188 | public void setUpdateTime(Date updateTime) { 189 | this.updateTime = updateTime; 190 | } 191 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service.impl; 2 | 3 | import cn.zxhysy.booksmall.mapper.OrderDetailMapper; 4 | import cn.zxhysy.booksmall.mapper.OrderMasterMapper; 5 | import cn.zxhysy.booksmall.pojo.OrderDetail; 6 | import cn.zxhysy.booksmall.pojo.OrderMaster; 7 | import cn.zxhysy.booksmall.pojo.vo.OrderVO; 8 | import cn.zxhysy.booksmall.service.OrderService; 9 | import cn.zxhysy.booksmall.utils.IDUtil; 10 | import cn.zxhysy.booksmall.utils.MyPageInfo; 11 | import com.github.pagehelper.PageHelper; 12 | import com.github.pagehelper.PageInfo; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | import org.springframework.transaction.annotation.Propagation; 16 | import org.springframework.transaction.annotation.Transactional; 17 | import tk.mybatis.mapper.entity.Example; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * @program: book_small 24 | * @className: OrderServiceImpl 25 | * @description: 26 | * @author: zxh 27 | * @date: 2019-04-01 23:41 28 | */ 29 | @Service 30 | public class OrderServiceImpl implements OrderService { 31 | 32 | private final OrderMasterMapper orderMasterMapper; 33 | private final OrderDetailMapper orderDetailMapper; 34 | 35 | @Autowired 36 | public OrderServiceImpl(OrderMasterMapper orderMasterMapper, OrderDetailMapper orderDetailMapper) { 37 | this.orderMasterMapper = orderMasterMapper; 38 | this.orderDetailMapper = orderDetailMapper; 39 | } 40 | 41 | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) 42 | @Override 43 | public void saveOrder(OrderMaster orderMaster, List orderDetailList) { 44 | String itemId = IDUtil.getMasterId(); 45 | orderMaster.setId(itemId); 46 | 47 | orderMaster.setOrderStatus(new Byte("0")); 48 | orderMaster.setPayStatus(new Byte("1")); 49 | for(OrderDetail orderDetail : orderDetailList){ 50 | orderDetail.setOrderId(itemId); 51 | orderDetail.setId(IDUtil.getDetailId()); 52 | } 53 | orderMasterMapper.insert(orderMaster); 54 | orderDetailMapper.inserDetailList(orderDetailList); 55 | 56 | /* 不知道为啥就是差不如 id 列, 打印的sql中少了id列 */ 57 | /* 记录一个通用mapper的一个小坑,MySQLMapper的insertList方法中传入list时,这个Entity的主键必须为自增主键,否则他在执行sql是不会去插入主键,自然就会报一些奇怪的错误了,比如DB2的-407*/ 58 | // orderDetailMapper.insertList(orderDetailList); 59 | } 60 | 61 | @Override 62 | public MyPageInfo getAllOrder(Integer pageNum, Integer pageSize, Byte payStatus, String openid) { 63 | PageHelper.startPage(pageNum,pageSize); 64 | Example exampleMaster = new Example(OrderMaster.class); 65 | exampleMaster.setOrderByClause("create_time DESC"); 66 | Example.Criteria criteria = exampleMaster.createCriteria(); 67 | criteria.andEqualTo("payStatus", payStatus).andEqualTo("userOpenid",openid); 68 | List orderMasters = orderMasterMapper.selectByExample(exampleMaster); 69 | PageInfo pageInfo = new PageInfo<>(orderMasters); 70 | 71 | List orderVOList = new ArrayList<>(); 72 | for (OrderMaster orderMaster: orderMasters){ 73 | Example exampleDetail = new Example(OrderDetail.class); 74 | 75 | Example.Criteria exampleDetailCriteria = exampleDetail.createCriteria(); 76 | exampleDetailCriteria.andEqualTo("orderId", orderMaster.getId()); 77 | List orderDetails = orderDetailMapper.selectByExample(exampleDetail); 78 | OrderVO orderVO = new OrderVO(); 79 | orderVO.setOrderMaster(orderMaster); 80 | orderVO.setOrderDetailList(orderDetails); 81 | orderVOList.add(orderVO); 82 | } 83 | 84 | MyPageInfo myPageInfo = new MyPageInfo<>(); 85 | myPageInfo.setList(orderVOList); 86 | myPageInfo.setPageNum(pageInfo.getPageNum()); 87 | myPageInfo.setPageSize(pageInfo.getPageSize()); 88 | myPageInfo.setTotal(pageInfo.getTotal()); 89 | myPageInfo.setPages(pageInfo.getPages()); 90 | return myPageInfo; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /bookSmall/pages/goods/goods.js: -------------------------------------------------------------------------------- 1 | // pages/main/good/good.js 2 | var app = getApp(); 3 | Page({ 4 | /** 5 | * 页面的初始数据 6 | */ 7 | data: { 8 | book: {}, //商品详情信息 9 | shopNum: 0, //购物车的总商品数量 10 | hideShopPopup: true, //是否显示购买模态框 11 | buyNumber: 0, //加入购物车的数量 12 | buyNumMin: 0, //加入购物车的最小数量 13 | buyNumMax: 100, //加入购物车的最大数量(库存量 14 | shopCarInfo: {}, //购物车信息 15 | pic: '', // 轮播图, 16 | width: 0, // 轮播图宽度, 17 | imgUrl: null //图片地址 18 | }, 19 | /** 20 | * 生命周期函数--监听页面加载 21 | */ 22 | onLoad: function (options) { 23 | // 商品传递过来的数据 24 | // 对对象的特殊数据进行反转义 25 | let item = decodeURIComponent(options.item) 26 | const book = JSON.parse(item) 27 | const width = wx.getSystemInfoSync().screenWidth; //获取屏幕宽度 28 | this.setData({ 29 | book, 30 | width, 31 | pic: book.pic.split(','), 32 | imgUrl: app.imgUrl 33 | }) 34 | //获取本地购物车 35 | wx.getStorage({ 36 | key: 'shopCarInfo', 37 | success: res => { 38 | this.setData({ 39 | shopCarInfo: res.data, 40 | shopNum: res.data.shopNum 41 | }) 42 | } 43 | }) 44 | }, 45 | /** 跳转到购物车*/ 46 | goShopCar() { 47 | wx.reLaunch({ 48 | url: "/pages/cart/cart" 49 | }); 50 | }, 51 | /** 规格选择弹出框*/ 52 | toAddShopCar() { 53 | //规格选择弹出框 54 | this.bindGuiGeTap() 55 | }, 56 | /**规格选择弹出框*/ 57 | bindGuiGeTap() { 58 | this.setData({ 59 | hideShopPopup: false 60 | }) 61 | }, 62 | /**规格选择弹出框隐藏*/ 63 | closePopupTap() { 64 | this.setData({ 65 | hideShopPopup: true 66 | }) 67 | }, 68 | /** 减少购买数量*/ 69 | reduce() { 70 | //判断 71 | let buyNumber = this.data.buyNumber 72 | if (buyNumber > this.data.buyNumMin) { 73 | buyNumber-- 74 | this.setData({ 75 | buyNumber 76 | }) 77 | } 78 | }, 79 | /** 增加购买数量 */ 80 | add() { 81 | let buyNumber = this.data.buyNumber 82 | if (buyNumber < this.data.buyNumMax) { 83 | buyNumber++ 84 | this.setData({ 85 | buyNumber 86 | }) 87 | } 88 | }, 89 | /** 加入购物车 */ 90 | addShopCar() { 91 | if (this.data.buyNumber < 1) { 92 | wx.showModal({ 93 | title: '提示', 94 | content: '购买数量不能为0!', 95 | showCancel: false 96 | }) 97 | return 98 | } 99 | //组建购物车 100 | var shopCarInfo = this.bulidShopCarInfo(); 101 | this.setData({ 102 | shopCarInfo: shopCarInfo, 103 | shopNum: shopCarInfo.shopNum 104 | }) 105 | // 写入本地存储 106 | wx.setStorage({ 107 | key: 'shopCarInfo', 108 | data: shopCarInfo 109 | }) 110 | // 关闭规格框 111 | this.closePopupTap() 112 | wx.showToast({ 113 | title: '加入书单成功', 114 | icon: 'success', 115 | duration: 2000 116 | }) 117 | }, 118 | 119 | /** 组建购物车信息*/ 120 | bulidShopCarInfo() { 121 | // 商品加入购物车时准备的商品信息,单个 122 | var shopCarMap = {} 123 | shopCarMap.bookId = this.data.book.id 124 | shopCarMap.bookIcon = this.data.book.icon 125 | shopCarMap.bookName = this.data.book.name 126 | shopCarMap.bookPrice = this.data.book.price 127 | shopCarMap.active = true // 判断商品是否激活状态 128 | shopCarMap.bookQuantity = this.data.buyNumber 129 | shopCarMap.delActive = false // 判断商品删除时是否激活 130 | 131 | // 获取原的购物车信息 132 | var shopCarInfo = this.data.shopCarInfo 133 | // 判读原购物车信息是否有初始化信息,如果不存在,就初始化数据,设置购买数量为 0 134 | if (!shopCarInfo.shopNum) { 135 | shopCarInfo.shopNum = 0; 136 | } 137 | // 判读原购物车信息是否有初始化信息,如果不存在,就初始化数据,设置购买数量为 0 138 | if (!shopCarInfo.shopList) { 139 | shopCarInfo.shopList = []; 140 | } 141 | // 判断是否有同样的物品 142 | var hasSameBookIndex = -1 143 | for (var i = 0; i < shopCarInfo.shopList.length; i++) { 144 | var tmpShopCarMap = shopCarInfo.shopList[i]; 145 | // 如果在遍历商品列表中,如果id一直,就将购买数量加入 146 | if (tmpShopCarMap.bookId == shopCarMap.bookId) { 147 | hasSameBookIndex = i 148 | // 新的商品购物车信息 149 | shopCarMap.bookQuantity += tmpShopCarMap.bookQuantity 150 | break 151 | } 152 | } 153 | // 购物车购买的总数量,等于原数量加上现在购买的数量 这里不能用 shopCarMap.bookQuantity 的数量 154 | shopCarInfo.shopNum += this.data.buyNumber 155 | if (hasSameBookIndex > -1) { 156 | //如果商品存在,则找到对应商品的位置,删除他,再替换成 新的信息商品 157 | shopCarInfo.shopList.splice(hasSameBookIndex, 1, shopCarMap); 158 | } else { 159 | //不过商品不存在,则 将商品信息直接加入到列表中 160 | shopCarInfo.shopList.push(shopCarMap); 161 | } 162 | //返回购物车信息 163 | return shopCarInfo; 164 | } 165 | }) -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.service.impl; 2 | 3 | import cn.zxhysy.booksmall.mapper.UserMapper; 4 | import cn.zxhysy.booksmall.pojo.User; 5 | import cn.zxhysy.booksmall.service.UserService; 6 | import cn.zxhysy.booksmall.utils.AesCbcUtil; 7 | import cn.zxhysy.booksmall.utils.HttpClientUtil; 8 | import com.alibaba.fastjson.JSONObject; 9 | import org.apache.commons.lang3.StringUtils; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.stereotype.Service; 13 | import org.springframework.transaction.annotation.Propagation; 14 | import org.springframework.transaction.annotation.Transactional; 15 | import tk.mybatis.mapper.entity.Example; 16 | 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | /** 21 | * @className: UserServiceImpl 22 | * @description: 23 | * @author: zxh 24 | * @date: 2019-1-29 10:04:23 25 | */ 26 | @Service 27 | public class UserServiceImpl implements UserService { 28 | 29 | private UserMapper userMapper; 30 | 31 | @Autowired 32 | public UserServiceImpl(UserMapper userMapper) { 33 | this.userMapper = userMapper; 34 | } 35 | 36 | @Value("${wx.appid}") 37 | private String appid; 38 | @Value("${wx.secret}") 39 | private String secret; 40 | @Value("${wx.grant_type}") 41 | private String grantType; 42 | @Value("${wx.url}") 43 | private String url; 44 | 45 | @Override 46 | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) 47 | public boolean saveUser(User user) { 48 | /* 插入的时候回调id列 */ 49 | int i = userMapper.insertUseGeneratedKeys(user); 50 | return i == 1; 51 | } 52 | 53 | @Override 54 | @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class) 55 | public User queryUserByOpenid(String openId) { 56 | Example userExample = new Example(User.class); 57 | Example.Criteria criteria = userExample.createCriteria(); 58 | criteria.andEqualTo("openid", openId); 59 | return userMapper.selectOneByExample(userExample); 60 | } 61 | 62 | @Override 63 | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) 64 | public User weChatLogin(String encryptedData, String iv, String code) throws Exception { 65 | Map param = new HashMap<>(4); 66 | param.put("appid", appid); 67 | param.put("secret", secret); 68 | param.put("js_code", code); 69 | param.put("grant_type", grantType); 70 | 71 | //获取session_id 72 | String sr = HttpClientUtil.doGet(url, param); 73 | // 判断获取的是否有值 74 | if (StringUtils.isBlank(sr)) { 75 | throw new Exception("获取微信数据失败"); 76 | } 77 | //解析相应内容(转换成json对象) 78 | JSONObject json = JSONObject.parseObject(sr); 79 | String openid = json.getString("openid"); 80 | User user = queryUserByOpenid(openid); 81 | if (user != null) { 82 | return user; 83 | } 84 | //获取会话密钥(session_key) 85 | String sessionKey = json.get("session_key").toString(); 86 | //2、对encryptedData加密数据进行AES解密 87 | String result = AesCbcUtil.decrypt(encryptedData, sessionKey, iv, "UTF-8"); 88 | 89 | if (StringUtils.isBlank(result)) { 90 | throw new Exception("解析微信数据失败"); 91 | } 92 | 93 | JSONObject userInfoJSON = JSONObject.parseObject(result); 94 | user = new User(); 95 | user.setOpenid(userInfoJSON.getString("openId")); 96 | user.setNickName(userInfoJSON.getString("nickName")); 97 | user.setAvatarUrl(userInfoJSON.getString("avatarUrl")); 98 | 99 | /* user 使用的是回调 id */ 100 | boolean isSave = saveUser(user); 101 | System.out.println(user.getId()); 102 | if (!isSave) { 103 | throw new Exception("服务器忙碌,请等下再试"); 104 | } 105 | // user = queryUserByOpenid(openid); 106 | return user; 107 | } 108 | 109 | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) 110 | @Override 111 | public boolean updateUser(User user) { 112 | Example userExample = new Example(User.class); 113 | Example.Criteria userExampleCriteria = userExample.createCriteria(); 114 | userExampleCriteria.andEqualTo("id", user.getId()); 115 | 116 | int i = userMapper.updateByExampleSelective(user, userExample); 117 | return i == 1; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /bookSmall/static/data/data.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | categories: [{ 3 | id: 0, 4 | name: '推荐' 5 | }, 6 | { 7 | id: 1, 8 | name: '计算机' 9 | }, 10 | { 11 | id: 2, 12 | name: '语言' 13 | }, 14 | { 15 | id: 3, 16 | name: '心理学' 17 | }, 18 | { 19 | id: 4, 20 | name: '历史' 21 | } 22 | ], 23 | goods: [{ 24 | id: 1, 25 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClyUqFiAd5K9AAFR9Q6qamE284.jpg', 26 | name: '轮一本书如何查询', 27 | price: 50, 28 | categories: 0, 29 | press: 'zxh出版社', 30 | author: 'zxh', 31 | description: '这是一本技改是路劲啦收到利旧电脑', 32 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClyUqFiAd5K9AAFR9Q6qamE284.jpg,http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG' 33 | }, 34 | { 35 | id: 100, 36 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG', 37 | name: '轮一本书如何查询', 38 | price: 50, 39 | categories: 0, 40 | press: 'zxh出版社', 41 | author: 'zxh', 42 | description: '这是一本技改是路劲啦收到利旧电脑', 43 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG,http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG' 44 | }, 45 | { 46 | id: 101, 47 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG', 48 | name: '轮一本书如何查询', 49 | price: 50, 50 | categories: 0, 51 | press: 'zxh出版社', 52 | author: 'zxh', 53 | description: '这是一本技改是路劲啦收到利旧电脑', 54 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG,http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG' 55 | }, 56 | { 57 | id: 2, 58 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG', 59 | name: '轮如何购物', 60 | price: 50, 61 | categories: 1, 62 | press: 'zxh出版社', 63 | author: 'zxh', 64 | description: '这是一本技改是路劲啦收到利旧电脑', 65 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG,http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG' 66 | }, 67 | { 68 | id: 3, 69 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG', 70 | name: '轮如何指明方向', 71 | price: 50, 72 | categories: 2, 73 | press: 'zxh出版社', 74 | author: 'zxh1', 75 | description: '这是一本技改是路劲啦收到利旧电脑', 76 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG,http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG' 77 | }, 78 | { 79 | id: 4, 80 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG', 81 | name: '轮如何才能当家', 82 | price: 50, 83 | categories: 3, 84 | press: 'zxh出版社', 85 | author: 'zxh2', 86 | description: '这是一本技改是路劲啦收到利旧电脑', 87 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG,http://39.108.13.196:88/zxh/M00/00/00/rBIQClySCMmAIpRfAACaOLXAd7I905.PNG' 88 | }, 89 | { 90 | id: 5, 91 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.jpg', 92 | name: '轮自我修养如何养成', 93 | minPrice: 50, 94 | originalPrice: 100, 95 | categories: 1, 96 | press: 'zxh出版社', 97 | author: 'zxh3', 98 | description: '这是一本技改是路劲啦收到利旧电脑', 99 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.jpg,http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.jpg' 100 | }, 101 | { 102 | id: 6, 103 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.jpg', 104 | name: '轮一本书如何查询', 105 | price: 50, 106 | categories: 0, 107 | press: 'zxh出版社', 108 | author: 'zxh34', 109 | description: '这是一本技改是路劲啦收到利旧电脑', 110 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.jpg,http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.jpg' 111 | }, 112 | { 113 | id: 7, 114 | icon: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.jpg', 115 | name: '轮一本书如何查询', 116 | price: 50, 117 | categories: 2, 118 | press: 'zxh出版社', 119 | author: 'zxh5', 120 | description: '这是一本技改是路劲啦收到利旧电脑', 121 | pic: 'http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.j,http://39.108.13.196:88/zxh/M00/00/00/rBIQClyQ7cOANZ11AAC517l7vus265_big.j' 122 | } 123 | ] 124 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/vo/UserVO.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo.vo; 2 | 3 | import java.util.Date; 4 | /** 5 | * @className: UserVO 6 | * @description: 7 | * @author: zxh 8 | * @date: 2019-3-29 10:02:24 9 | */ 10 | public class UserVO { 11 | 12 | private Integer id; 13 | 14 | private String userToken; 15 | /** 16 | * 名字 17 | */ 18 | private String nickName; 19 | 20 | /** 21 | * 电话 22 | */ 23 | private String phone; 24 | 25 | /** 26 | * 常用地址 27 | */ 28 | private String address; 29 | 30 | /** 31 | * 微信openid 32 | */ 33 | private String openid; 34 | 35 | private String avatarUrl; 36 | 37 | /** 38 | * 创建时间 39 | */ 40 | private Date createTime; 41 | 42 | /** 43 | * 修改时间 44 | */ 45 | private Date updateTime; 46 | 47 | /** 48 | * @return id - id 49 | */ 50 | public Integer getId() { 51 | return id; 52 | } 53 | 54 | /** 55 | * @param id id 56 | */ 57 | public void setId(Integer id) { 58 | this.id = id; 59 | } 60 | 61 | /** 62 | * 获取名字 63 | * 64 | * @return nick_name - 名字 65 | */ 66 | public String getNickName() { 67 | return nickName; 68 | } 69 | 70 | /** 71 | * 设置名字 72 | * 73 | * @param nickName 名字 74 | */ 75 | public void setNickName(String nickName) { 76 | this.nickName = nickName; 77 | } 78 | 79 | /** 80 | * 获取电话 81 | * 82 | * @return phone - 电话 83 | */ 84 | public String getPhone() { 85 | return phone; 86 | } 87 | 88 | /** 89 | * 设置电话 90 | * 91 | * @param phone 电话 92 | */ 93 | public void setPhone(String phone) { 94 | this.phone = phone; 95 | } 96 | 97 | /** 98 | * 获取常用地址 99 | * 100 | * @return address - 常用地址 101 | */ 102 | public String getAddress() { 103 | return address; 104 | } 105 | 106 | /** 107 | * 设置常用地址 108 | * 109 | * @param address 常用地址 110 | */ 111 | public void setAddress(String address) { 112 | this.address = address; 113 | } 114 | 115 | /** 116 | * 获取微信openid 117 | * 118 | * @return openid - 微信openid 119 | */ 120 | public String getOpenid() { 121 | return openid; 122 | } 123 | 124 | /** 125 | * 设置微信openid 126 | * 127 | * @param openid 微信openid 128 | */ 129 | public void setOpenid(String openid) { 130 | this.openid = openid; 131 | } 132 | 133 | /** 134 | * @return avatar_url 135 | */ 136 | public String getAvatarUrl() { 137 | return avatarUrl; 138 | } 139 | 140 | /** 141 | * @param avatarUrl 142 | */ 143 | public void setAvatarUrl(String avatarUrl) { 144 | this.avatarUrl = avatarUrl; 145 | } 146 | 147 | /** 148 | * 获取创建时间 149 | * 150 | * @return create_time - 创建时间 151 | */ 152 | public Date getCreateTime() { 153 | return createTime; 154 | } 155 | 156 | /** 157 | * 设置创建时间 158 | * 159 | * @param createTime 创建时间 160 | */ 161 | public void setCreateTime(Date createTime) { 162 | this.createTime = createTime; 163 | } 164 | 165 | /** 166 | * 获取修改时间 167 | * 168 | * @return update_time - 修改时间 169 | */ 170 | public Date getUpdateTime() { 171 | return updateTime; 172 | } 173 | 174 | /** 175 | * 设置修改时间 176 | * 177 | * @param updateTime 修改时间 178 | */ 179 | public void setUpdateTime(Date updateTime) { 180 | this.updateTime = updateTime; 181 | } 182 | 183 | /** 184 | * 设置 token 185 | * @return 获取 token 186 | */ 187 | public String getUserToken() { 188 | return userToken; 189 | } 190 | 191 | /** 192 | * 获取 token 193 | * @param userToken 设置 token 194 | */ 195 | public void setUserToken(String userToken) { 196 | this.userToken = userToken; 197 | } 198 | 199 | @Override 200 | public String toString() { 201 | return "UserVO{" + 202 | "id=" + id + 203 | ", userToken='" + userToken + '\'' + 204 | ", nickName='" + nickName + '\'' + 205 | ", phone='" + phone + '\'' + 206 | ", address='" + address + '\'' + 207 | ", openid='" + openid + '\'' + 208 | ", avatarUrl='" + avatarUrl + '\'' + 209 | ", createTime=" + createTime + 210 | ", updateTime=" + updateTime + 211 | '}'; 212 | } 213 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/controller/FastdfsController.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.controller; 2 | 3 | import cn.zxhysy.booksmall.pojo.User; 4 | import cn.zxhysy.booksmall.utils.ApiJSONResult; 5 | import cn.zxhysy.booksmall.utils.FileUtil; 6 | import io.swagger.annotations.*; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | /** 15 | * @className: FastDFSController 16 | * @description: 17 | * @author: zxh 18 | * @date: 2018-12-29 09:58:59 19 | */ 20 | @Api(value = "文件上传接口", tags = "文件操作") 21 | @RestController 22 | @RequestMapping("/fdfs") 23 | public class FastdfsController { 24 | 25 | private BasicController basicController; 26 | 27 | @Autowired 28 | public FastdfsController(BasicController basicController) { 29 | this.basicController = basicController; 30 | } 31 | 32 | 33 | /** 34 | * 上传文件 35 | * @param file 文件 36 | * @return 文件路径 37 | * @throws Exception 异常 38 | */ 39 | @ApiOperation(value = "文件上传", notes = "上传文件") 40 | @PostMapping 41 | public ApiJSONResult uploadFile2(@ApiParam(value = "上传的文件", required = true) MultipartFile file) throws Exception { 42 | if (file == null) { 43 | throw new Exception("文件不能为空"); 44 | } 45 | String path = basicController.fastDFSClient.uploadFile(file); 46 | 47 | return ApiJSONResult.ok(path); 48 | } 49 | /** 50 | * @param file 上传的文件 51 | * @param userId 用户id 52 | * @return StorePath 53 | * @deprecated 文件上传 54 | * storePath 55 | * "group": "zxh", 56 | * "path": "M00/00/01/wKj4RFvuZlOALpzMAAJZc0IRPSY16.docx", 57 | * fullPath": "group1/M00/00/01/wKj4RFvuZlOALpzMAAJZc0IRPSY16.docx" 58 | */ 59 | @ApiOperation(value = "文件上传", notes = "根据用户id上传文件") 60 | @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Integer", paramType = "query") 61 | @PostMapping(value = "/upload") 62 | public ApiJSONResult uploadFileAndUserId(@ApiParam(value = "上传的文件", required = true) MultipartFile file, Integer userId) throws Exception { 63 | /* 设置文件信息 */ 64 | if (StringUtils.isBlank(userId.toString())) { 65 | throw new Exception("userId不能为空"); 66 | } 67 | 68 | if (file == null) { 69 | throw new Exception("文件不能为空"); 70 | } 71 | 72 | String path = basicController.fastDFSClient.uploadFile(file); 73 | 74 | return getApiJSONResultByImg(userId, path); 75 | } 76 | /** 77 | * @param base64 base64字符串 78 | * @param userId 用户id 79 | * @return 返会图片路径 80 | * @throws Exception 异常 81 | */ 82 | @ApiOperation(value = "图片上传", notes = "base64图片上传") 83 | @ApiImplicitParams({ 84 | @ApiImplicitParam(paramType = "query", name = "base64", value = "图片base64字符串", required = true, dataType = "String"), 85 | @ApiImplicitParam(paramType = "query", name = "userId", value = "用户id", required = true, dataType = "Integer"), 86 | }) 87 | @PostMapping("/uploadFaceBase64") 88 | public ApiJSONResult uploadFaceBase64(String base64, Integer userId) throws Exception { 89 | System.out.println(base64); 90 | System.out.println(userId); 91 | /* 这里可以根据部署服务器,换成对应的服务器就行了 */ 92 | String userFacePath = "E:\\bookSmallImg\\" + userId + "\\userface64.png"; 93 | /* 判读文件是否存在,不存在就创建 */ 94 | FileUtil.isExistFile(userFacePath); 95 | 96 | FileUtil.base64ToFile(userFacePath, base64); 97 | 98 | /*上传文件到fastdfs */ 99 | MultipartFile faceFile = FileUtil.fileToMultipart(userFacePath); 100 | System.out.println(faceFile); 101 | String path = basicController.fastDFSClient.uploadBase64(faceFile); 102 | 103 | return getApiJSONResultByImg(userId, path); 104 | } 105 | 106 | /** 107 | * @description: 根据id查询对象 108 | * @param: userId 109 | * @param: path 110 | * @return: 111 | * @author: zxh 112 | * @date: 2019/3/29 11:58 113 | */ 114 | private ApiJSONResult getApiJSONResultByImg(Integer userId, String path) { 115 | User user = new User(); 116 | user.setAvatarUrl("http://39.108.13.196:88/zxh/" + path); 117 | user.setId(userId); 118 | basicController.userService.updateUser(user); 119 | return ApiJSONResult.ok("http://39.108.13.196:88/zxh/" + path); 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /bookSmall/pages/order/order.js: -------------------------------------------------------------------------------- 1 | // pages/myOrder/orderList.js 2 | let app = getApp() 3 | Page({ 4 | data: { 5 | currtab: 1, // 当前支付状态 也是激活分类信息 6 | swipertab: [{ 7 | name: '已完成', 8 | index: 1 9 | }, { 10 | name: '待付款', 11 | index: 0 12 | }, { 13 | name: '已取消', 14 | index: 2 15 | }], 16 | payStatus: 0, // 支付状态 17 | pageNum: 1, // 当前页 18 | pages: 1, // 总页数 19 | pageSize: 6, 20 | userInfo: null, 21 | orderVOList: null, 22 | imgUrl: null 23 | }, 24 | onLoad: function (options) { 25 | const userInfo = app.getGlobalUserInfo() 26 | this.setData({ 27 | userInfo: userInfo, 28 | imgUrl: app.imgUrl 29 | }) 30 | this.showAllOrder(this.data.pageNum, this.data.pageSize, this.data.currtab, userInfo.openid) 31 | }, 32 | showAllOrder(pageNum, pageSize, payStatus, openid) { 33 | wx.request({ 34 | url: app.serverUrl + "/order/openid", 35 | method: "GET", 36 | header: { 37 | 'content-type': 'application/json', // 默认值 38 | 'userId': this.data.userInfo.id, // 用户id 39 | "userToken": this.data.userInfo.userToken // 用户 token 40 | }, 41 | data: { 42 | pageNum: pageNum, 43 | pageSize: pageSize, 44 | payStatus: payStatus, 45 | openid: openid 46 | }, 47 | fail: res => { 48 | // 隐藏导航栏加载动画 49 | wx.hideNavigationBarLoading() 50 | // 停止下拉刷新的动画 51 | wx.stopPullDownRefresh() 52 | wx.hideLoading({ 53 | title: '与网络断开连接' 54 | }) 55 | }, 56 | success: e => { 57 | // 隐藏导航栏加载动画 58 | wx.hideNavigationBarLoading() 59 | // 停止下拉刷新的动画 60 | wx.stopPullDownRefresh() 61 | if (e.data.status === 200) { 62 | //判断是不是上拉刷新,是的话就将列表数据清空 63 | if (pageNum === 1) { 64 | this.setData({ 65 | orderVOList: [] 66 | }) 67 | } 68 | const pageInfo = e.data.data 69 | 70 | const orderVOList = pageInfo.list 71 | //将图片都存储起来 72 | orderVOList.forEach(orderVO => { 73 | let imgs = [] 74 | orderVO.orderDetailList.forEach(orderDetail => { 75 | imgs.push(orderDetail.bookIcon) 76 | }) 77 | orderVO.orderMaster.imgs = imgs 78 | }) 79 | console.log(orderVOList) 80 | // 将查询出来的拼接上去 81 | const list = this.data.orderVOList.concat(orderVOList) 82 | this.setData({ 83 | pageNum: pageNum, 84 | pages: pageInfo.pages, 85 | orderVOList: list 86 | }) 87 | } else if (e.data.status === 500 ){ 88 | wx.showToast({ 89 | title: e.data.msg, 90 | icon: "none" 91 | }) 92 | app.setGlobalUserInfo(null) 93 | } 94 | } 95 | }) 96 | }, 97 | /** 98 | * @Explain:选项卡点击切换 99 | */ 100 | tabSwitch(e) { 101 | var that = this 102 | if (this.data.currtab === e.target.dataset.current) { 103 | return false 104 | } else { 105 | // 切换类别 106 | const pageNum = 1 107 | const pageSize = this.data.pageSize 108 | const currtab = e.target.dataset.current 109 | const openid = this.data.userInfo.openid 110 | this.showAllOrder(pageNum, pageSize, currtab, openid) 111 | that.setData({ 112 | currtab: e.target.dataset.current 113 | }) 114 | } 115 | }, 116 | toDetail(e) { 117 | let orderVO = this.data.orderVOList[e.currentTarget.dataset.index] 118 | //这里需要将特殊符号进行转义,不然在转换 JSON格式的时候会报错 119 | // encodeURIComponent 转移字符串 主要是 书本描述 120 | orderVO = encodeURIComponent(JSON.stringify(orderVO)) 121 | wx.navigateTo({ 122 | url: "/pages/orderDetail/orderDetail?orderVO=" + orderVO 123 | }) 124 | }, 125 | /** 126 | * 上拉刷新,当页面上拉触底部时出发 127 | */ 128 | onReachBottom: function () { 129 | console.log('') 130 | let currentPage = this.data.pageNum 131 | const pageSize = this.data.pageSize 132 | let pages = this.data.pages 133 | //判断当前页数和总页数是否相等,如果相等的就无需查询 134 | if (pages === currentPage) { 135 | return 136 | } 137 | // 判断是否书名查询 138 | const currtab = this.data.currtab 139 | const openid = this.data.userInfo.openid 140 | currentPage++ 141 | this.showAllOrder(currentPage, pageSize, currtab, openid) 142 | }, 143 | // 下拉刷新 触碰顶部刷新页面 144 | onPullDownRefresh: function () { 145 | const pageSize = this.data.pageSize 146 | const currentPage = 1 147 | // 当前页面显示导航条加载页面 148 | wx.showNavigationBarLoading() 149 | const currtab = this.data.currtab 150 | const openid = this.data.userInfo.openid 151 | this.showAllOrder(currentPage, pageSize, currtab, openid) 152 | } 153 | }) -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/OrderDetail.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo; 2 | 3 | import javax.persistence.*; 4 | import java.math.BigDecimal; 5 | import java.util.Date; 6 | /** 7 | * @className: OrderDetail 8 | * @description: 9 | * @author: zxh 10 | * @date: 2019-3-29 10:03:44 11 | */ 12 | @Table(name = "tb_order_detail") 13 | public class OrderDetail { 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "JDBC") 16 | private String id; 17 | 18 | /** 19 | * 主表id 20 | */ 21 | @Column(name = "order_id") 22 | private String orderId; 23 | 24 | /** 25 | * 书本id 26 | */ 27 | @Column(name = "book_id") 28 | private String bookId; 29 | 30 | /** 31 | * 商品名称 32 | */ 33 | @Column(name = "book_name") 34 | private String bookName; 35 | 36 | /** 37 | * 商品价格 38 | */ 39 | @Column(name = "book_price") 40 | private BigDecimal bookPrice; 41 | 42 | /** 43 | * 商品数量 44 | */ 45 | @Column(name = "book_quantity") 46 | private Integer bookQuantity; 47 | 48 | /** 49 | * 商品小图 50 | */ 51 | @Column(name = "book_icon") 52 | private String bookIcon; 53 | 54 | /** 55 | * 创建时间 56 | */ 57 | @Column(name = "create_time") 58 | private Date createTime; 59 | 60 | /** 61 | * 修改时间 62 | */ 63 | @Column(name = "update_time") 64 | private Date updateTime; 65 | 66 | /** 67 | * @return id 68 | */ 69 | public String getId() { 70 | return id; 71 | } 72 | 73 | /** 74 | * @param id 75 | */ 76 | public void setId(String id) { 77 | this.id = id; 78 | } 79 | 80 | /** 81 | * 获取主表id 82 | * 83 | * @return order_id - 主表id 84 | */ 85 | public String getOrderId() { 86 | return orderId; 87 | } 88 | 89 | /** 90 | * 设置主表id 91 | * 92 | * @param orderId 主表id 93 | */ 94 | public void setOrderId(String orderId) { 95 | this.orderId = orderId; 96 | } 97 | 98 | /** 99 | * 获取书本id 100 | * 101 | * @return book_id - 书本id 102 | */ 103 | public String getBookId() { 104 | return bookId; 105 | } 106 | 107 | /** 108 | * 设置书本id 109 | * 110 | * @param bookId 书本id 111 | */ 112 | public void setBookId(String bookId) { 113 | this.bookId = bookId; 114 | } 115 | 116 | /** 117 | * 获取商品名称 118 | * 119 | * @return book_name - 商品名称 120 | */ 121 | public String getBookName() { 122 | return bookName; 123 | } 124 | 125 | /** 126 | * 设置商品名称 127 | * 128 | * @param bookName 商品名称 129 | */ 130 | public void setBookName(String bookName) { 131 | this.bookName = bookName; 132 | } 133 | 134 | /** 135 | * 获取商品价格 136 | * 137 | * @return book_price - 商品价格 138 | */ 139 | public BigDecimal getBookPrice() { 140 | return bookPrice; 141 | } 142 | 143 | /** 144 | * 设置商品价格 145 | * 146 | * @param bookPrice 商品价格 147 | */ 148 | public void setBookPrice(BigDecimal bookPrice) { 149 | this.bookPrice = bookPrice; 150 | } 151 | 152 | /** 153 | * 获取商品数量 154 | * 155 | * @return book_quantity - 商品数量 156 | */ 157 | public Integer getBookQuantity() { 158 | return bookQuantity; 159 | } 160 | 161 | /** 162 | * 设置商品数量 163 | * 164 | * @param bookQuantity 商品数量 165 | */ 166 | public void setBookQuantity(Integer bookQuantity) { 167 | this.bookQuantity = bookQuantity; 168 | } 169 | 170 | /** 171 | * 获取商品小图 172 | * 173 | * @return book_icon - 商品小图 174 | */ 175 | public String getBookIcon() { 176 | return bookIcon; 177 | } 178 | 179 | /** 180 | * 设置商品小图 181 | * 182 | * @param bookIcon 商品小图 183 | */ 184 | public void setBookIcon(String bookIcon) { 185 | this.bookIcon = bookIcon; 186 | } 187 | 188 | /** 189 | * 获取创建时间 190 | * 191 | * @return create_time - 创建时间 192 | */ 193 | public Date getCreateTime() { 194 | return createTime; 195 | } 196 | 197 | /** 198 | * 设置创建时间 199 | * 200 | * @param createTime 创建时间 201 | */ 202 | public void setCreateTime(Date createTime) { 203 | this.createTime = createTime; 204 | } 205 | 206 | /** 207 | * 获取修改时间 208 | * 209 | * @return update_time - 修改时间 210 | */ 211 | public Date getUpdateTime() { 212 | return updateTime; 213 | } 214 | 215 | /** 216 | * 设置修改时间 217 | * 218 | * @param updateTime 修改时间 219 | */ 220 | public void setUpdateTime(Date updateTime) { 221 | this.updateTime = updateTime; 222 | } 223 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/config/WebConfig.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.config; 2 | 3 | import cn.zxhysy.booksmall.handler.MyHandlerInterceptor; 4 | import com.alibaba.fastjson.serializer.SerializerFeature; 5 | import com.alibaba.fastjson.support.config.FastJsonConfig; 6 | import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.http.converter.HttpMessageConverter; 11 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 12 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 13 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * @className: WebConfig 20 | * @description: web 配置文件 21 | * @author: zxh 22 | * @date: 2018-3-25 09:57:45 23 | */ 24 | @Configuration 25 | public class WebConfig implements WebMvcConfigurer { 26 | /** 27 | * @description: 配置消息转换器--这里我用的是alibaba 开源的 fastjson 28 | * @param: converters 29 | * @return: 30 | * @author: zxh 31 | * @date: 2019/3/29 32 | */ 33 | @Override 34 | public void configureMessageConverters(List> converters) { 35 | //1.需要定义一个convert转换消息的对象; 36 | FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); 37 | //2.添加fastJson的配置信息,比如:是否要格式化返回的json数据; 38 | FastJsonConfig fastJsonConfig = new FastJsonConfig(); 39 | fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat, 40 | SerializerFeature.WriteMapNullValue, 41 | SerializerFeature.WriteNullStringAsEmpty, 42 | SerializerFeature.DisableCircularReferenceDetect, 43 | SerializerFeature.WriteNullListAsEmpty, 44 | SerializerFeature.WriteDateUseDateFormat); 45 | //3处理中文乱码问题 46 | List fastMediaTypes = new ArrayList<>(); 47 | fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); 48 | //4.在convert中添加配置信息. 49 | fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); 50 | fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); 51 | //5.将convert添加到converters当中. 52 | //指定 fastJson 执行顺序,不然可能会用 jsonfast SpringBoot 2.0.1版本中加载WebMvcConfigurer的顺序发生了变动 53 | // 故需使用converters.add(0, converter);指定FastJsonHttpMessageConverter在converters内的顺序,否则在SpringBoot 2.0.1及之后的版本中将优先使用Jackson处理 54 | converters.add(0, fastJsonHttpMessageConverter); 55 | } 56 | 57 | /** 58 | * @description: 配置跨域 59 | * @param: CorsRegistry 60 | * @return: 61 | * @author: zxh 62 | * @date: 2019/3/29 63 | */ 64 | @Override 65 | public void addCorsMappings(CorsRegistry registry) { 66 | registry.addMapping("/**") 67 | .allowedOrigins("*") 68 | .allowCredentials(true) 69 | .allowedMethods("GET", "POST", "DELETE", "PUT") 70 | .maxAge(3600 * 24); 71 | } 72 | 73 | /** 74 | * 这里作用是为了让 MyHandlerInterceptor 里的 redis 能够自动注入 75 | * @return 76 | */ 77 | @Bean 78 | public MyHandlerInterceptor myHandlerInterceptor(){ 79 | return new MyHandlerInterceptor(); 80 | } 81 | 82 | /** 83 | * 拦截器 84 | * @param registry 85 | */ 86 | @Override 87 | public void addInterceptors(InterceptorRegistry registry) { 88 | registry.addInterceptor(myHandlerInterceptor()) 89 | .addPathPatterns("/order/**") 90 | .addPathPatterns("/user") 91 | .addPathPatterns("/fdfs/**"); 92 | } 93 | 94 | /** 95 | * 添加类型转换器和格式化器 96 | * @param registry 97 | */ 98 | /* @Override 99 | public void addFormatters(FormatterRegistry registry) { 100 | registry.addFormatterForFieldType(LocalDate.class, new USLocalDateFormatter()); 101 | }*/ 102 | 103 | /** 104 | * 添加静态资源--过滤swagger-api (开源的在线API文档) 105 | * @param registry 106 | */ 107 | /*@Override 108 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 109 | //过滤swagger 110 | registry.addResourceHandler("swagger-ui.html") 111 | .addResourceLocations("classpath:/META-INF/resources/"); 112 | 113 | registry.addResourceHandler("/webjars/**") 114 | .addResourceLocations("classpath:/META-INF/resources/webjars/"); 115 | 116 | registry.addResourceHandler("/swagger-resources/**") 117 | .addResourceLocations("classpath:/META-INF/resources/swagger-resources/"); 118 | 119 | registry.addResourceHandler("/swagger/**") 120 | .addResourceLocations("classpath:/META-INF/resources/swagger*"); 121 | 122 | registry.addResourceHandler("/v2/api-docs/**") 123 | .addResourceLocations("classpath:/META-INF/resources/v2/api-docs/"); 124 | 125 | }*/ 126 | 127 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/component/RedisOperator.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils.component; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.redis.core.StringRedisTemplate; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.Map; 8 | import java.util.Set; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | /** 12 | * @className: RedisOperator 13 | * @description: 14 | * @author: zxh 15 | * @date: 2019-2-14 10:05:58 16 | */ 17 | @Component 18 | public class RedisOperator { 19 | 20 | /* 21 | @Autowired 22 | private RedisTemplate redisTemplate; 23 | */ 24 | 25 | private StringRedisTemplate redisTemplate; 26 | 27 | @Autowired 28 | public RedisOperator(StringRedisTemplate redisTemplate) { 29 | this.redisTemplate = redisTemplate; 30 | } 31 | 32 | // Key(键),简单的key-value操作 33 | 34 | /** 35 | * 实现命令:TTL key,以秒为单位,返回给定 key的剩余生存时间(TTL, time to live)。 36 | * 37 | * @param key 键 38 | * @return 值 39 | */ 40 | public long ttl(String key) { 41 | return redisTemplate.getExpire(key); 42 | } 43 | 44 | /** 45 | * 实现命令:expire 设置过期时间,单位秒 46 | * 47 | * @param key 键 48 | */ 49 | public void expire(String key, long timeout) { 50 | redisTemplate.expire(key, timeout, TimeUnit.SECONDS); 51 | } 52 | 53 | /** 54 | * 实现命令:INCR key,增加key一次 55 | * 56 | * @param key 键 57 | * @return 加1 58 | */ 59 | public long incr(String key, long delta) { 60 | return redisTemplate.opsForValue().increment(key, delta); 61 | } 62 | 63 | /** 64 | * 实现命令:KEYS pattern,查找所有符合给定模式 pattern的 key 65 | */ 66 | public Set keys(String pattern) { 67 | return redisTemplate.keys(pattern); 68 | } 69 | 70 | /** 71 | * 实现命令:DEL key,删除一个key 72 | * 73 | * @param key 键 74 | */ 75 | public void del(String key) { 76 | redisTemplate.delete(key); 77 | } 78 | 79 | // String(字符串) 80 | 81 | /** 82 | * 实现命令:SET key value,设置一个key-value(将字符串值 value关联到 key) 83 | * 84 | * @param key 键 85 | * @param value 值 86 | */ 87 | public void set(String key, String value) { 88 | redisTemplate.opsForValue().set(key, value); 89 | } 90 | 91 | /** 92 | * 实现命令:SET key value EX seconds,设置key-value和超时时间(秒) 93 | * 94 | * @param key 键 95 | * @param value 值 96 | * @param timeout (以秒为单位) 97 | */ 98 | public void set(String key, String value, long timeout) { 99 | redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS); 100 | } 101 | 102 | /** 103 | * 实现命令:GET key,返回 key所关联的字符串值。 104 | * 105 | * @param key 键 106 | * @return value 值 107 | */ 108 | public String get(String key) { 109 | return (String) redisTemplate.opsForValue().get(key); 110 | } 111 | 112 | // Hash(哈希表) 113 | 114 | /** 115 | * 实现命令:HSET key field value,将哈希表 key中的域 field的值设为 value 116 | * 117 | * @param key 键 118 | * @param field 区域 119 | * @param value 值 120 | */ 121 | public void hset(String key, String field, Object value) { 122 | redisTemplate.opsForHash().put(key, field, value); 123 | } 124 | 125 | /** 126 | * 实现命令:HGET key field,返回哈希表 key中给定域 field的值 127 | * 128 | * @param key 键 129 | * @param field 区域 130 | * @return 值 131 | */ 132 | public String hget(String key, String field) { 133 | return (String) redisTemplate.opsForHash().get(key, field); 134 | } 135 | 136 | /** 137 | * 实现命令:HDEL key field [field ...],删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。 138 | * 139 | * @param key 键 140 | * @param fields 区域 141 | */ 142 | public void hdel(String key, Object... fields) { 143 | redisTemplate.opsForHash().delete(key, fields); 144 | } 145 | 146 | /** 147 | * 实现命令:HGETALL key,返回哈希表 key中,所有的域和值。 148 | * 149 | * @param key 键 150 | * @return Map 151 | */ 152 | public Map hgetall(String key) { 153 | return redisTemplate.opsForHash().entries(key); 154 | } 155 | 156 | // List(列表) 157 | 158 | /** 159 | * 实现命令:LPUSH key value,将一个值 value插入到列表 key的表头 160 | * 161 | * @param key 键 162 | * @param value 值 163 | * @return 执行 LPUSH命令后,列表的长度。 164 | */ 165 | public long lpush(String key, String value) { 166 | return redisTemplate.opsForList().leftPush(key, value); 167 | } 168 | 169 | /** 170 | * 实现命令:LPOP key,移除并返回列表 key的头元素。 171 | * 172 | * @param key 键 173 | * @return 列表key的头元素。 174 | */ 175 | public String lpop(String key) { 176 | return redisTemplate.opsForList().leftPop(key); 177 | } 178 | 179 | /** 180 | * 实现命令:RPUSH key value,将一个值 value插入到列表 key的表尾(最右边)。 181 | * 182 | * @param key 键 183 | * @param value 值 184 | * @return 执行 LPUSH命令后,列表的长度。 185 | */ 186 | public long rpush(String key, String value) { 187 | return redisTemplate.opsForList().rightPush(key, value); 188 | } 189 | 190 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/Book.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Date; 5 | import javax.persistence.*; 6 | 7 | @Table(name = "tb_book") 8 | public class Book { 9 | @Id 10 | private String id; 11 | 12 | /** 13 | * 书本名称 14 | */ 15 | private String name; 16 | 17 | /** 18 | * 书本作者 19 | */ 20 | private String author; 21 | 22 | /** 23 | * 书本单价 24 | */ 25 | private BigDecimal price; 26 | 27 | /** 28 | * 图片、小图地址 29 | */ 30 | private String icon; 31 | 32 | /** 33 | * 书本库存 34 | */ 35 | private Integer stock; 36 | 37 | /** 38 | * 书本类别 39 | */ 40 | @Column(name = "category_id") 41 | private Integer categoryId; 42 | 43 | /** 44 | * 创建时间 45 | */ 46 | @Column(name = "create_time") 47 | private Date createTime; 48 | 49 | /** 50 | * 修改时间 51 | */ 52 | @Column(name = "update_time") 53 | private Date updateTime; 54 | 55 | /** 56 | * 书本描述 57 | */ 58 | private String description; 59 | 60 | /** 61 | * 大图片地址(轮播图未实现) 62 | */ 63 | private String pic; 64 | 65 | /** 66 | * @return id 67 | */ 68 | public String getId() { 69 | return id; 70 | } 71 | 72 | /** 73 | * @param id 74 | */ 75 | public void setId(String id) { 76 | this.id = id; 77 | } 78 | 79 | /** 80 | * 获取书本名称 81 | * 82 | * @return name - 书本名称 83 | */ 84 | public String getName() { 85 | return name; 86 | } 87 | 88 | /** 89 | * 设置书本名称 90 | * 91 | * @param name 书本名称 92 | */ 93 | public void setName(String name) { 94 | this.name = name; 95 | } 96 | 97 | /** 98 | * 获取书本作者 99 | * 100 | * @return author - 书本作者 101 | */ 102 | public String getAuthor() { 103 | return author; 104 | } 105 | 106 | /** 107 | * 设置书本作者 108 | * 109 | * @param author 书本作者 110 | */ 111 | public void setAuthor(String author) { 112 | this.author = author; 113 | } 114 | 115 | /** 116 | * 获取书本单价 117 | * 118 | * @return price - 书本单价 119 | */ 120 | public BigDecimal getPrice() { 121 | return price; 122 | } 123 | 124 | /** 125 | * 设置书本单价 126 | * 127 | * @param price 书本单价 128 | */ 129 | public void setPrice(BigDecimal price) { 130 | this.price = price; 131 | } 132 | 133 | /** 134 | * 获取图片、小图地址 135 | * 136 | * @return icon - 图片、小图地址 137 | */ 138 | public String getIcon() { 139 | return icon; 140 | } 141 | 142 | /** 143 | * 设置图片、小图地址 144 | * 145 | * @param icon 图片、小图地址 146 | */ 147 | public void setIcon(String icon) { 148 | this.icon = icon; 149 | } 150 | 151 | /** 152 | * 获取书本库存 153 | * 154 | * @return stock - 书本库存 155 | */ 156 | public Integer getStock() { 157 | return stock; 158 | } 159 | 160 | /** 161 | * 设置书本库存 162 | * 163 | * @param stock 书本库存 164 | */ 165 | public void setStock(Integer stock) { 166 | this.stock = stock; 167 | } 168 | 169 | /** 170 | * 获取书本类别 171 | * 172 | * @return category_id - 书本类别 173 | */ 174 | public Integer getCategoryId() { 175 | return categoryId; 176 | } 177 | 178 | /** 179 | * 设置书本类别 180 | * 181 | * @param categoryId 书本类别 182 | */ 183 | public void setCategoryId(Integer categoryId) { 184 | this.categoryId = categoryId; 185 | } 186 | 187 | /** 188 | * 获取创建时间 189 | * 190 | * @return create_time - 创建时间 191 | */ 192 | public Date getCreateTime() { 193 | return createTime; 194 | } 195 | 196 | /** 197 | * 设置创建时间 198 | * 199 | * @param createTime 创建时间 200 | */ 201 | public void setCreateTime(Date createTime) { 202 | this.createTime = createTime; 203 | } 204 | 205 | /** 206 | * 获取修改时间 207 | * 208 | * @return update_time - 修改时间 209 | */ 210 | public Date getUpdateTime() { 211 | return updateTime; 212 | } 213 | 214 | /** 215 | * 设置修改时间 216 | * 217 | * @param updateTime 修改时间 218 | */ 219 | public void setUpdateTime(Date updateTime) { 220 | this.updateTime = updateTime; 221 | } 222 | 223 | /** 224 | * 获取书本描述 225 | * 226 | * @return description - 书本描述 227 | */ 228 | public String getDescription() { 229 | return description; 230 | } 231 | 232 | /** 233 | * 设置书本描述 234 | * 235 | * @param description 书本描述 236 | */ 237 | public void setDescription(String description) { 238 | this.description = description; 239 | } 240 | 241 | /** 242 | * 获取大图片地址(轮播图未实现) 243 | * 244 | * @return pic - 大图片地址(轮播图未实现) 245 | */ 246 | public String getPic() { 247 | return pic; 248 | } 249 | 250 | /** 251 | * 设置大图片地址(轮播图未实现) 252 | * 253 | * @param pic 大图片地址(轮播图未实现) 254 | */ 255 | public void setPic(String pic) { 256 | this.pic = pic; 257 | } 258 | } -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/HttpClientUtil.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils; 2 | 3 | import org.apache.http.NameValuePair; 4 | import org.apache.http.client.entity.UrlEncodedFormEntity; 5 | import org.apache.http.client.methods.CloseableHttpResponse; 6 | import org.apache.http.client.methods.HttpGet; 7 | import org.apache.http.client.methods.HttpPost; 8 | import org.apache.http.client.utils.URIBuilder; 9 | import org.apache.http.entity.ContentType; 10 | import org.apache.http.entity.StringEntity; 11 | import org.apache.http.impl.client.CloseableHttpClient; 12 | import org.apache.http.impl.client.HttpClients; 13 | import org.apache.http.message.BasicNameValuePair; 14 | import org.apache.http.util.EntityUtils; 15 | 16 | import java.io.IOException; 17 | import java.net.URI; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * @className: HttpClientUtil 24 | * @description: http 请求 25 | * @author: zxh 26 | * @date: 27 | */ 28 | public class HttpClientUtil { 29 | 30 | public static String doGet(String url, Map param) { 31 | 32 | // 创建Httpclient对象 33 | CloseableHttpClient httpclient = HttpClients.createDefault(); 34 | 35 | String resultString = ""; 36 | CloseableHttpResponse response = null; 37 | try { 38 | // 创建uri 39 | URIBuilder builder = new URIBuilder(url); 40 | if (param != null) { 41 | for (String key : param.keySet()) { 42 | builder.addParameter(key, param.get(key)); 43 | } 44 | } 45 | URI uri = builder.build(); 46 | 47 | // 创建http GET请求 48 | HttpGet httpGet = new HttpGet(uri); 49 | 50 | // 执行请求 51 | response = httpclient.execute(httpGet); 52 | // 判断返回状态是否为200 53 | int state = 200; 54 | if (response.getStatusLine().getStatusCode() == state) { 55 | resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); 56 | } 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } finally { 60 | try { 61 | if (response != null) { 62 | response.close(); 63 | } 64 | httpclient.close(); 65 | } catch (IOException e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | return resultString; 70 | } 71 | 72 | public static String doGet(String url) { 73 | return doGet(url, null); 74 | } 75 | 76 | public static String doPost(String url, Map param) { 77 | // 创建Httpclient对象 78 | CloseableHttpClient httpClient = HttpClients.createDefault(); 79 | CloseableHttpResponse response = null; 80 | String resultString = ""; 81 | try { 82 | // 创建Http Post请求 83 | HttpPost httpPost = new HttpPost(url); 84 | // 创建参数列表 85 | if (param != null) { 86 | List paramList = new ArrayList<>(); 87 | for (String key : param.keySet()) { 88 | paramList.add(new BasicNameValuePair(key, param.get(key))); 89 | } 90 | // 模拟表单 91 | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList); 92 | httpPost.setEntity(entity); 93 | } 94 | // 执行http请求 95 | response = httpClient.execute(httpPost); 96 | resultString = EntityUtils.toString(response.getEntity(), "utf-8"); 97 | } catch (Exception e) { 98 | e.printStackTrace(); 99 | } finally { 100 | try { 101 | if (response != null) { 102 | response.close(); 103 | } 104 | } catch (IOException e) { 105 | e.printStackTrace(); 106 | } 107 | } 108 | 109 | return resultString; 110 | } 111 | 112 | public static String doPost(String url) { 113 | return doPost(url, null); 114 | } 115 | 116 | public static String doPostJson(String url, String json) { 117 | // 创建Httpclient对象 118 | CloseableHttpClient httpClient = HttpClients.createDefault(); 119 | CloseableHttpResponse response = null; 120 | String resultString = ""; 121 | try { 122 | // 创建Http Post请求 123 | HttpPost httpPost = new HttpPost(url); 124 | // 创建请求内容 125 | StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); 126 | httpPost.setEntity(entity); 127 | // 执行http请求 128 | response = httpClient.execute(httpPost); 129 | resultString = EntityUtils.toString(response.getEntity(), "utf-8"); 130 | } catch (Exception e) { 131 | e.printStackTrace(); 132 | } finally { 133 | try { 134 | if (response != null) { 135 | response.close(); 136 | } 137 | } catch (IOException e) { 138 | e.printStackTrace(); 139 | } 140 | } 141 | 142 | return resultString; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/pojo/OrderMaster.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.pojo; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Id; 5 | import javax.persistence.Table; 6 | import java.math.BigDecimal; 7 | import java.util.Date; 8 | 9 | /** 10 | * @className: OrderMaster 11 | * @description: 12 | * @author: zxh 13 | * @date: 2019-3-29 10:03:57 14 | */ 15 | @Table(name = "tb_order_master") 16 | public class OrderMaster { 17 | @Id 18 | private String id; 19 | 20 | /** 21 | * 买家名字 22 | */ 23 | @Column(name = "user_name") 24 | private String userName; 25 | 26 | /** 27 | * 买家电话 28 | */ 29 | @Column(name = "user_phone") 30 | private String userPhone; 31 | 32 | /** 33 | * 买家地址 34 | */ 35 | @Column(name = "user_address") 36 | private String userAddress; 37 | 38 | /** 39 | * 买家微信openid 40 | */ 41 | @Column(name = "user_openid") 42 | private String userOpenid; 43 | 44 | /** 45 | * 订单总额 46 | */ 47 | private BigDecimal amount; 48 | 49 | /** 50 | * 订单状态,默认0:新下单 51 | */ 52 | @Column(name = "order_status") 53 | private Byte orderStatus; 54 | 55 | /** 56 | * 支付状态,默认0:未支付 57 | */ 58 | @Column(name = "pay_status") 59 | private Byte payStatus; 60 | 61 | /** 62 | * 创建时间 63 | */ 64 | @Column(name = "create_time") 65 | private Date createTime; 66 | 67 | /** 68 | * 修改时间 69 | */ 70 | @Column(name = "update_time") 71 | private Date updateTime; 72 | 73 | /** 74 | * @return id 75 | */ 76 | public String getId() { 77 | return id; 78 | } 79 | 80 | /** 81 | * @param id 82 | */ 83 | public void setId(String id) { 84 | this.id = id; 85 | } 86 | 87 | /** 88 | * 获取买家名字 89 | * 90 | * @return user_name - 买家名字 91 | */ 92 | public String getUserName() { 93 | return userName; 94 | } 95 | 96 | /** 97 | * 设置买家名字 98 | * 99 | * @param userName 买家名字 100 | */ 101 | public void setUserName(String userName) { 102 | this.userName = userName; 103 | } 104 | 105 | /** 106 | * 获取买家电话 107 | * 108 | * @return user_phone - 买家电话 109 | */ 110 | public String getUserPhone() { 111 | return userPhone; 112 | } 113 | 114 | /** 115 | * 设置买家电话 116 | * 117 | * @param userPhone 买家电话 118 | */ 119 | public void setUserPhone(String userPhone) { 120 | this.userPhone = userPhone; 121 | } 122 | 123 | /** 124 | * 获取买家地址 125 | * 126 | * @return user_address - 买家地址 127 | */ 128 | public String getUserAddress() { 129 | return userAddress; 130 | } 131 | 132 | /** 133 | * 设置买家地址 134 | * 135 | * @param userAddress 买家地址 136 | */ 137 | public void setUserAddress(String userAddress) { 138 | this.userAddress = userAddress; 139 | } 140 | 141 | /** 142 | * 获取买家微信openid 143 | * 144 | * @return user_openid - 买家微信openid 145 | */ 146 | public String getUserOpenid() { 147 | return userOpenid; 148 | } 149 | 150 | /** 151 | * 设置买家微信openid 152 | * 153 | * @param userOpenid 买家微信openid 154 | */ 155 | public void setUserOpenid(String userOpenid) { 156 | this.userOpenid = userOpenid; 157 | } 158 | 159 | /** 160 | * 获取订单总额 161 | * 162 | * @return amount - 订单总额 163 | */ 164 | public BigDecimal getAmount() { 165 | return amount; 166 | } 167 | 168 | /** 169 | * 设置订单总额 170 | * 171 | * @param amount 订单总额 172 | */ 173 | public void setAmount(BigDecimal amount) { 174 | this.amount = amount; 175 | } 176 | 177 | /** 178 | * 获取订单状态,默认0:新下单 179 | * 180 | * @return order_status - 订单状态,默认0:新下单 181 | */ 182 | public Byte getOrderStatus() { 183 | return orderStatus; 184 | } 185 | 186 | /** 187 | * 设置订单状态,默认0:新下单 188 | * 189 | * @param orderStatus 订单状态,默认0:新下单 190 | */ 191 | public void setOrderStatus(Byte orderStatus) { 192 | this.orderStatus = orderStatus; 193 | } 194 | 195 | /** 196 | * 获取支付状态,默认0:未支付 197 | * 198 | * @return pay_status - 支付状态,默认0:未支付 199 | */ 200 | public Byte getPayStatus() { 201 | return payStatus; 202 | } 203 | 204 | /** 205 | * 设置支付状态,默认0:未支付 206 | * 207 | * @param payStatus 支付状态,默认0:未支付 208 | */ 209 | public void setPayStatus(Byte payStatus) { 210 | this.payStatus = payStatus; 211 | } 212 | 213 | /** 214 | * 获取创建时间 215 | * 216 | * @return create_time - 创建时间 217 | */ 218 | public Date getCreateTime() { 219 | return createTime; 220 | } 221 | 222 | /** 223 | * 设置创建时间 224 | * 225 | * @param createTime 创建时间 226 | */ 227 | public void setCreateTime(Date createTime) { 228 | this.createTime = createTime; 229 | } 230 | 231 | /** 232 | * 获取修改时间 233 | * 234 | * @return update_time - 修改时间 235 | */ 236 | public Date getUpdateTime() { 237 | return updateTime; 238 | } 239 | 240 | /** 241 | * 设置修改时间 242 | * 243 | * @param updateTime 修改时间 244 | */ 245 | public void setUpdateTime(Date updateTime) { 246 | this.updateTime = updateTime; 247 | } 248 | } -------------------------------------------------------------------------------- /bookSmall/pages/goods/goods.wxss: -------------------------------------------------------------------------------- 1 | /* pages/main/good/good.wxss */ 2 | 3 | .container { 4 | background-color: #faf7f7; 5 | min-height: 100%; 6 | padding-bottom: 100rpx; 7 | } 8 | 9 | .swiper-class { 10 | width: 100%; 11 | /* height: 733px; */ 12 | } 13 | 14 | .auto-img { 15 | width: 100%; 16 | height: 600rpx; 17 | display: block; 18 | } 19 | 20 | /**商品信息*/ 21 | 22 | .goods-info { 23 | background-color: #fff; 24 | padding: 35rpx 0; 25 | margin-bottom: 24rpx; 26 | width: 100%; 27 | position: relative; 28 | } 29 | 30 | .goods-info .goods-price { 31 | box-sizing: border-box; 32 | color: #e64340; 33 | font-size: 30rpx; 34 | font-weight: bold; 35 | width: 30%; 36 | float: right; 37 | padding-left: 105rpx; 38 | } 39 | 40 | .goods-info .goods-title { 41 | box-sizing: border-box; 42 | padding: 0 35rpx; 43 | font-size: 38rpx; 44 | line-height: 1.4; 45 | color: #000; 46 | width: 70%; 47 | margin-bottom: 2rpx; 48 | padding-right: 60px; 49 | font-weight: normal; 50 | } 51 | 52 | .goods-info .goods-press { 53 | box-sizing: border-box; 54 | color: #999; 55 | font-size: 28rpx; 56 | float: right; 57 | margin-right: 50rpx; 58 | } 59 | 60 | .goods-info .goods-author { 61 | box-sizing: border-box; 62 | padding: 0 35rpx; 63 | font-size: 30rpx; 64 | line-height: 1.3; 65 | color: #999; 66 | margin-bottom: 2rpx; 67 | padding-right: 60px; 68 | font-weight: normal; 69 | } 70 | 71 | .goods-des-info { 72 | width: 100%; 73 | box-sizing: border-box; 74 | background-color: #fff; 75 | } 76 | 77 | .label-title { 78 | font-size: 32rpx; 79 | color: #49d; 80 | padding: 30rpx; 81 | } 82 | 83 | .goods-text { 84 | padding: 0 30rpx; 85 | font-size: 28rpx; 86 | color: #666; 87 | line-height: 56rpx; 88 | margin-bottom: 30rpx; 89 | } 90 | 91 | /**购物栏*/ 92 | 93 | .footer-box { 94 | width: 100%; 95 | height: 100rpx; 96 | background-color: #fff; 97 | position: fixed; 98 | bottom: 0; 99 | left: 0; 100 | display: flex; 101 | box-shadow: 0 0 0.6rpx 0; 102 | } 103 | 104 | .footer-box .shop-cart-btn { 105 | position: relative; 106 | width: 200rpx; 107 | height: 100%; 108 | display: flex; 109 | flex-direction: column; 110 | align-items: center; 111 | text-align: center; 112 | font-size: 20rpx; 113 | color: #acacb7; 114 | box-sizing: border-box; 115 | background-size: 44rpx auto; 116 | } 117 | 118 | .footer-box .shop-cart-btn .shop-num { 119 | position: absolute; 120 | color: #acc; 121 | left: 120rpx; 122 | top: 10rpx; 123 | } 124 | 125 | .footer-box .join-shop-cart { 126 | text-align: center; 127 | width: 90%; 128 | height: 100%; 129 | line-height: 100rpx; 130 | background-color: #49d; 131 | color: #fff; 132 | font-size: 34rpx; 133 | } 134 | 135 | .footer-box .now-buy { 136 | text-align: center; 137 | height: 100%; 138 | width: 0rpx; 139 | line-height: 100rpx; 140 | background-color: #2ecc71; 141 | color: #fff; 142 | font-size: 34rpx; 143 | } 144 | 145 | .show-popup { 146 | position: fixed; 147 | top: 0; 148 | left: 0; 149 | width: 100%; 150 | height: 100%; 151 | z-index: 4; 152 | } 153 | 154 | .popup-mask { 155 | position: fixed; 156 | top: 0; 157 | left: 0; 158 | width: 100%; 159 | height: 100%; 160 | background-color: rgba(0, 0, 0, 0.5); 161 | z-index: 5; 162 | } 163 | 164 | .popup-contents { 165 | position: fixed; 166 | left: 0; 167 | bottom: 0; 168 | width: 100%; 169 | background-color: #fff; 170 | z-index: 6; 171 | } 172 | 173 | .pop-goods-info { 174 | display: flex; 175 | flex-direction: row; 176 | align-items: center; 177 | margin-left: 30rpx; 178 | padding: 30rpx 0; 179 | border-bottom: 1px solid #eee; 180 | } 181 | 182 | .pop-img-box { 183 | width: 120rpx; 184 | height: 120rpx; 185 | overflow: hidden; 186 | margin-right: 26rpx; 187 | } 188 | 189 | .pop-img-box .goods-thumbnail { 190 | width: 120rpx; 191 | height: 120rpx; 192 | } 193 | 194 | .pop-goods-title { 195 | width: 484rpx; 196 | text-overflow: ellipsis; 197 | white-space: nowrap; 198 | overflow: hidden; 199 | font-size: 26rpx; 200 | color: #000; 201 | } 202 | 203 | .pop-goods-price { 204 | font-size: 26rpx; 205 | color: #e64340; 206 | margin-top: 20rpx; 207 | } 208 | 209 | .pop-goods-close { 210 | width: 36rpx; 211 | height: 36rpx; 212 | flex: 1; 213 | background: url("https://cdn.it120.cc/images/weappshop/popup-close.png") no-repeat center center; 214 | background-size: 36rpx auto; 215 | align-self: flex-start; 216 | margin-top: -10rpx; 217 | } 218 | 219 | .buy-num-box { 220 | display: flex; 221 | justify-content: space-between; 222 | padding: 30rpx 30rpx 48rpx 0; 223 | margin-left: 30rpx; 224 | border-top: 1px solid #eee; 225 | margin-top: 30rpx; 226 | align-items: center; 227 | } 228 | 229 | .num-label { 230 | font-size: 26rpx; 231 | color: #000; 232 | } 233 | 234 | .buy-num-box .num-box { 235 | display: flex; 236 | } 237 | 238 | .buy-num-box .num-box .num-jian, .buy-num-box .num-box .num-input, 239 | .buy-num-box .num-box .num-jia { 240 | width: 80rpx; 241 | height: 64rpx; 242 | line-height: 62rpx; 243 | text-align: center; 244 | border: 1px solid #eee; 245 | } 246 | 247 | .buy-num-box .num-box .num-input { 248 | font-size: 28rpx; 249 | } 250 | 251 | .buy-num-box .num-box .num-input input { 252 | height: 100%; 253 | } 254 | 255 | .popup-join-btn { 256 | width: 100%; 257 | height: 89rpx; 258 | text-align: center; 259 | line-height: 89rpx; 260 | font-size: 34rpx; 261 | color: #fff; 262 | background-color: #49d; 263 | } 264 | 265 | .buy-num-box .num-box .hui { 266 | background-color: #f5f5f9; 267 | } 268 | -------------------------------------------------------------------------------- /bookSmall/pages/userInfo/userInfo.js: -------------------------------------------------------------------------------- 1 | // pages/personal/userInfo/userInfo.js 2 | var app = getApp(); 3 | Page({ 4 | 5 | /** 6 | * 页面的初始数据 7 | */ 8 | data: { 9 | userInfo: null, 10 | hidden: true, 11 | disabled: true 12 | }, 13 | /** 14 | * 生命周期函数--监听页面加载 15 | */ 16 | onLoad: function (options) { 17 | const userInfo = app.getGlobalUserInfo() 18 | console.log(JSON.stringify(userInfo)) 19 | this.setData({ 20 | userInfo 21 | }) 22 | }, 23 | // 点击按钮换手机相册或者电脑本地图片 24 | changeFace() { 25 | wx.chooseImage({ 26 | count: 1, // 默认9 27 | sizeType: ['compressed'], // original 原图 compressed 压缩图,可以指定是原图还是压缩图,默认二者都有 28 | sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 29 | success: res => { 30 | const filePath = res.tempFilePaths[0]; 31 | wx.showLoading({ 32 | title: '上传中...', 33 | }) 34 | wx.uploadFile({ 35 | url: app.serverUrl + "/fdfs/upload", 36 | filePath, 37 | header: { 38 | 'content-type': 'application/json', // 默认值 39 | 'userId': this.data.userInfo.id, // 用户id 40 | "userToken": this.data.userInfo.userToken // 用户 token 41 | }, 42 | name: 'file', 43 | formData: { 44 | userId: this.data.userInfo.id 45 | }, 46 | fail: res => { 47 | wx.hideLoading() 48 | wx.showToast({ 49 | title: '网络断开连接...', 50 | icon: 'none' 51 | }) 52 | }, 53 | success: res => { 54 | // 上传文件,默认不会对返回值进行 json 处理 55 | const result = JSON.parse(res.data) 56 | wx.hideLoading() 57 | console.log(result.status) 58 | 59 | if (result.status === 200) { 60 | this.setData({ 61 | ['userInfo.avatarUrl']: result.data 62 | }) 63 | app.setGlobalUserInfo(this.data.userInfo) 64 | wx.showToast({ 65 | title: '上传成功!~~~', 66 | icon: 'success' 67 | }) 68 | } else if (result.status === 500) { 69 | wx.showToast({ 70 | title: result.data.msg, 71 | icon: 'none' 72 | }) 73 | } 74 | } 75 | }) 76 | } 77 | }) 78 | }, 79 | // 点击按钮换手机相册或者电脑本地图片 版本1.9.9 80 | // changeFaceToBase64: function() { 81 | // wx.chooseImage({ 82 | // count: 1, // 默认9 83 | // sizeType: ['compressed'], // original 原图 compressed 压缩图,可以指定是原图还是压缩图,默认二者都有 84 | // sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 85 | // success: res => { 86 | // wx.getFileSystemManager().readFile({ 87 | // filePath: res.tempFilePaths[0], //选择图片返回的相对路径 88 | // encoding: 'base64', //编码格式 89 | // success: res => { //成功的回调 90 | // const base64 = res.data 91 | // const id = this.data.userInfo.id 92 | // console.log('data:image/png;base64,' + base64) 93 | // console.log(id) 94 | // wx.request({ 95 | // url: app.serverUrl + "/fdfs/uploadFaceBase64", 96 | // method: "POST", 97 | // header: { 98 | // "content-type": "application/x-www-form-urlencoded;charset=utf-8", 99 | // 'userId': this.data.userInfo.id, // 用户id 100 | // "userToken": this.data.userInfo.userToken // 用户 token 101 | // }, 102 | // data: { 103 | // base64, 104 | // userId: id 105 | // }, 106 | // success: res => { 107 | // this.setData({ 108 | // ['userInfo.avatarUrl']: result.data.data 109 | // }) 110 | // app.sesetGlobalUserInfo(this.data.userInfo) 111 | // } 112 | // }) 113 | // } 114 | // }) 115 | 116 | // //以下两行注释的是同步方法,不过我不太喜欢用。 117 | // //let base64 = wx.getFileSystemManager().readFileSync(res.tempFilePaths[0], 'base64') 118 | // //console.log(base64) 119 | // } 120 | // }) 121 | // }, 122 | /** 123 | * 编辑 124 | */ 125 | editUser() { 126 | this.setData({ 127 | hidden: false, 128 | disabled: false 129 | }) 130 | }, 131 | /** 132 | * 保存 133 | */ 134 | saveUser(e) { 135 | let user = e.detail.value 136 | const userInfo = this.data.userInfo 137 | if (user.nickName === userInfo.nickName && user.phone === userInfo.phone && user.address === userInfo.address) { 138 | wx.showToast({ 139 | title: '您未作修改', 140 | icon: 'none' 141 | }) 142 | this.setData({ 143 | hidden: true, 144 | disabled: true 145 | }) 146 | return 147 | } 148 | user['id'] = userInfo.id 149 | wx.request({ 150 | url: app.serverUrl + "/user", 151 | method: 'PUT', 152 | header: { 153 | 'content-type': 'application/json', // 默认值 154 | 'userId': this.data.userInfo.id, // 用户id 155 | "userToken": this.data.userInfo.userToken // 用户 token 156 | }, 157 | data: user, 158 | success: res => { 159 | if (res.data.status === 200) { 160 | userInfo.nickName = user.nickName 161 | userInfo.phone = user.phone 162 | userInfo.address = user.address 163 | this.setData({ 164 | hidden: true, 165 | disabled: true, 166 | userInfo: userInfo 167 | }) 168 | app.setGlobalUserInfo(userInfo) 169 | wx.showToast({ 170 | title: '更新成功', 171 | icon: 'success' 172 | }) 173 | } else if (result.status === 500) { 174 | wx.showToast({ 175 | title: result.data.msg, 176 | icon: 'none' 177 | }) 178 | app.setGlobalUserInfo(null) 179 | } 180 | } 181 | }) 182 | } 183 | }) -------------------------------------------------------------------------------- /book_small/src/main/java/cn/zxhysy/booksmall/utils/FileUtil.java: -------------------------------------------------------------------------------- 1 | package cn.zxhysy.booksmall.utils; 2 | 3 | import org.springframework.mock.web.MockMultipartFile; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.util.Base64Utils; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import java.io.*; 9 | import java.net.HttpURLConnection; 10 | import java.net.URL; 11 | 12 | /** 13 | * @className: FileUtil 14 | * @description: 文件处理,文件转换 15 | * @author: zxh 16 | * @date: 17 | */ 18 | @Service 19 | public class FileUtil { 20 | 21 | /** 22 | * 带文件名的Path:如 D:\\xml2\\2018\\04\\abc.text 23 | * 判断文件是否存在 24 | * 25 | * @param filePath 文件 26 | */ 27 | public static void isExistFile(String filePath) throws Exception { 28 | String[] paths = filePath.split("\\\\"); 29 | String dir = paths[0]; 30 | //注意此处循环的长度 31 | for (int i = 0; i < paths.length - 2; i++) { 32 | File dirFile; 33 | try { 34 | dir = dir + "/" + paths[i + 1]; 35 | dirFile = new File(dir); 36 | if (!dirFile.exists()) { 37 | dirFile.mkdir(); 38 | } 39 | } catch (Exception err) { 40 | System.err.println("文件夹创建发生异常"); 41 | } 42 | } 43 | File file = new File(filePath); 44 | 45 | if (!file.exists()) { 46 | 47 | try { 48 | file.createNewFile(); 49 | } catch (Exception e) { 50 | throw new Exception("文件创建失败"); 51 | } 52 | } 53 | } 54 | 55 | /** 56 | * 根据url拿取file 57 | * 58 | * @param url 路径 59 | * @param suffix 文件后缀名 60 | */ 61 | public static File createFileByUrl(String url, String suffix) { 62 | byte[] byteFile = getImageFromNetByUrl(url); 63 | if (byteFile != null) { 64 | return getFileFromBytes(byteFile, suffix); 65 | } else { 66 | return null; 67 | } 68 | } 69 | 70 | /** 71 | * 根据地址获得数据的字节流 72 | * 73 | * @param strUrl 路径 74 | * 网络连接地址 75 | * @return 数据字节流 76 | */ 77 | private static byte[] getImageFromNetByUrl(String strUrl) { 78 | try { 79 | URL url = new URL(strUrl); 80 | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 81 | conn.setRequestMethod("GET"); 82 | conn.setConnectTimeout(5 * 1000); 83 | // 通过输入流获取图片数据 84 | InputStream inStream = conn.getInputStream(); 85 | // 得到图片的二进制数据 86 | return readInputStream(inStream); 87 | } catch (Exception e) { 88 | e.printStackTrace(); 89 | } 90 | return null; 91 | } 92 | 93 | /** 94 | * 从输入流中获取数据 95 | * 96 | * @param inStream 输入流 97 | * @return 字节流数据 byte[] 98 | * @throws Exception 异常 99 | */ 100 | private static byte[] readInputStream(InputStream inStream) throws Exception { 101 | ByteArrayOutputStream outStream = new ByteArrayOutputStream(); 102 | byte[] buffer = new byte[1024]; 103 | int len; 104 | while ((len = inStream.read(buffer)) != -1) { 105 | outStream.write(buffer, 0, len); 106 | } 107 | inStream.close(); 108 | return outStream.toByteArray(); 109 | } 110 | 111 | /** 112 | * 创建临时文件 113 | * 114 | * @param b 字节流 byte[] 115 | * @param suffix 后缀 116 | * @return 文件 117 | */ 118 | private static File getFileFromBytes(byte[] b, String suffix) { 119 | BufferedOutputStream stream = null; 120 | File file = null; 121 | try { 122 | file = File.createTempFile("pattern", "." + suffix); 123 | System.out.println("临时文件位置:" + file.getCanonicalPath()); 124 | FileOutputStream fstream = new FileOutputStream(file); 125 | stream = new BufferedOutputStream(fstream); 126 | stream.write(b); 127 | } catch (Exception e) { 128 | e.printStackTrace(); 129 | } finally { 130 | if (stream != null) { 131 | try { 132 | stream.close(); 133 | } catch (IOException e) { 134 | e.printStackTrace(); 135 | } 136 | } 137 | } 138 | return file; 139 | } 140 | 141 | public static MultipartFile createImg(String url) { 142 | try { 143 | // File转换成MutipartFile 144 | File file = FileUtil.createFileByUrl(url, "jpg"); 145 | return new MockMultipartFile(file.getName(), new FileInputStream(file)); 146 | } catch (IOException e) { 147 | e.printStackTrace(); 148 | return null; 149 | } 150 | } 151 | 152 | public static MultipartFile fileToMultipart(String filePath) { 153 | try { 154 | // File转换成MutipartFile 155 | File file = new File(filePath); 156 | FileInputStream inputStream = new FileInputStream(file); 157 | return new MockMultipartFile(file.getName(), "png", "image/png", inputStream); 158 | } catch (IOException e) { 159 | e.printStackTrace(); 160 | return null; 161 | } 162 | } 163 | 164 | public static boolean base64ToFile(String filePath, String base64Data) throws Exception { 165 | /* 166 | 167 | String dataPrix = ""; 168 | 169 | * */ 170 | 171 | String data; 172 | 173 | if (base64Data == null || "".equals(base64Data)) { 174 | return false; 175 | } else { 176 | String[] d = base64Data.split("base64,"); 177 | int i = 2; 178 | if (i == d.length) { 179 | // dataPrix = d[0]; 180 | data = d[1]; 181 | } else { 182 | return false; 183 | } 184 | } 185 | 186 | // 因为BASE64Decoder的jar问题,此处使用spring框架提供的工具包 187 | byte[] bs = Base64Utils.decodeFromString(data); 188 | // 使用apache提供的工具类操作流 189 | org.apache.commons.io.FileUtils.writeByteArrayToFile(new File(filePath), bs); 190 | 191 | return true; 192 | } 193 | } 194 | 195 | 196 | -------------------------------------------------------------------------------- /bookSmall/pages/main/main.js: -------------------------------------------------------------------------------- 1 | // pages/main/main.js 2 | // const datas = require('../../static/data/data'); 3 | const app = getApp(); 4 | Page({ 5 | /** 6 | * 页面的初始数据 7 | */ 8 | data: { 9 | activeCategoryId: 1, //激活的类别id 10 | books: [], // 展示的图书列表 11 | categories: [], // 分类导航数据 12 | imgUrl: app.imgUrl, //图片路劲 13 | pageNum: 1, // 当前页 14 | pageSize: 8, // 显示数据个数 15 | pages: 1, // 所有页 16 | hasNextPage: true, //判断是否还有下一页 17 | searchInput: null, // 查询的内容 18 | isSearchName: false // 判断是否是查询 19 | }, 20 | /** 21 | * 生命周期函数--监听页面加载 22 | */ 23 | onLoad: function (options) { 24 | const pageNum = this.data.pageNum 25 | const pageSize = this.data.pageSize 26 | const activeCategoryId = this.data.activeCategoryId 27 | //获取所有的分类 28 | this.getAllCategorie() 29 | //获取当前分类的书籍 30 | this.getAllCategorieForbookList(pageNum, pageSize, activeCategoryId) 31 | }, 32 | /**跳转到详情页面 */ 33 | toDetailsTap(e) { 34 | // 获取当前自定义属性数据 35 | const index = e.currentTarget.dataset.index 36 | let item = this.data.books[index] 37 | //这里需要将特殊符号进行转义,不然在转换 JSON格式的时候会报错 38 | // encodeURIComponent 转移字符串 主要是 书本描述 39 | item = encodeURIComponent(JSON.stringify(item)) 40 | wx.navigateTo({ 41 | url: "/pages/goods/goods?item=" + item 42 | }) 43 | }, 44 | 45 | /**点击分类获取分类物品 */ 46 | tabClick(e) { 47 | // 初始化pageNum 和 activeCategoryId 48 | const pageNum = 1 49 | const activeCategoryId = e.currentTarget.dataset.id 50 | const pageSize = this.data.pageSize 51 | this.setData({ 52 | activeCategoryId 53 | }) 54 | this.getAllCategorieForbookList(pageNum, pageSize, activeCategoryId) 55 | }, 56 | /** 获取全部类别 */ 57 | getAllCategorie() { 58 | wx.request({ 59 | url: app.serverUrl + "/category", 60 | method: "GET", 61 | header: { 62 | 'content-type': 'application/json', // 默认值 63 | }, 64 | fail: res => { 65 | wx.hideLoading({ 66 | title: '与网络断开连接' 67 | }) 68 | }, 69 | success: e => { 70 | // e.data.data 分类对象数据 71 | this.setData({ 72 | categories: e.data.data 73 | }) 74 | } 75 | }) 76 | }, 77 | /** 获取同个类别的书籍 */ 78 | getAllCategorieForbookList(pageNum, pageSize, categoryId) { 79 | wx.request({ 80 | url: app.serverUrl + "/book/category", 81 | method: "GET", 82 | header: { 83 | 'content-type': 'application/json', // 默认值 84 | }, 85 | data: { 86 | pageNum, 87 | pageSize, 88 | categoryId 89 | }, 90 | fail: res => { 91 | // 隐藏导航栏加载动画 92 | wx.hideNavigationBarLoading() 93 | // 停止下拉刷新的动画 94 | wx.stopPullDownRefresh() 95 | wx.hideLoading({ 96 | title: '与网络断开连接' 97 | }) 98 | }, 99 | success: e => { 100 | // 隐藏导航栏加载动画 101 | wx.hideNavigationBarLoading() 102 | // 停止下拉刷新的动画 103 | wx.stopPullDownRefresh() 104 | // 判断是不是上拉刷新,是的话就将列表数据清空 也是说判断当前是否是第一页,第一页就刷新 105 | if (pageNum === 1) { 106 | this.setData({ 107 | books: [] 108 | }) 109 | } 110 | // 分页对象数据 list 书籍列表 pages 总页码 hasNextPage 是否有下一页 111 | const { pages, hasNextPage, list } = e.data.data 112 | // 将查询出来的拼接上去 113 | const books = this.data.books.concat(list) 114 | this.setData({ 115 | books, 116 | pageNum, 117 | pages, 118 | hasNextPage, 119 | isSearchName: false 120 | }) 121 | } 122 | }) 123 | }, 124 | /** 125 | * 上拉刷新,当页面上拉触底部时出发 126 | */ 127 | onReachBottom: function () { 128 | let currentPage = this.data.pageNum 129 | const pageSize = this.data.pageSize 130 | let pages = this.data.pages 131 | let isSearchName = this.data.isSearchName 132 | 133 | //判断当前页数和总页数是否相等,如果相等的就无需查询 134 | if (pages === currentPage) { 135 | return 136 | } 137 | // 判断是否书名查询 138 | if (!isSearchName) { 139 | const activeCategoryId = this.data.activeCategoryId 140 | currentPage++ 141 | this.getAllCategorieForbookList(currentPage, pageSize, activeCategoryId) 142 | } else { 143 | const searchInput = this.data.searchInput 144 | currentPage++ 145 | this.search(currentPage, pageSize, searchInput) 146 | } 147 | }, 148 | // 下拉刷新 触碰顶部刷新页面 149 | onPullDownRefresh: function () { 150 | const pageSize = this.data.pageSize 151 | const currentPage = 1 152 | const isSearchName = this.data.isSearchName 153 | // 当前页面显示导航条加载页面 154 | wx.showNavigationBarLoading() 155 | if (!isSearchName) { 156 | const activeCategoryId = this.data.activeCategoryId 157 | this.getAllCategorieForbookList(currentPage, pageSize, activeCategoryId) 158 | } else { 159 | const searchInput = this.data.searchInput 160 | this.search(currentPage, pageSize, searchInput) 161 | } 162 | }, 163 | // 监听查询输入的内容 164 | listenerSearchInput(e) { 165 | const searchInput = e.detail.value 166 | this.setData({ 167 | searchInput: searchInput 168 | }) 169 | }, 170 | // 跳转查询 171 | toSearch() { 172 | const searchInput = this.data.searchInput 173 | if (!searchInput) { 174 | wx.showToast({ 175 | title: '查询内容不能为空', 176 | icon: 'none' 177 | }) 178 | return 179 | } 180 | //每次查询清空数据 181 | this.setData({ 182 | books: [] 183 | }) 184 | const pageNum = 1 185 | const pageSize = this.data.pageSize 186 | this.search(pageNum, pageSize, searchInput) 187 | }, 188 | // 查询方法 189 | search(pageNum, pageSize, name) { 190 | wx.request({ 191 | url: app.serverUrl + '/book/search', 192 | method: "GET", 193 | header: { 194 | 'content-type': 'application/json', // 默认值 195 | }, 196 | data: { 197 | pageNum, 198 | pageSize, 199 | name 200 | }, 201 | success: e => { 202 | // 隐藏导航栏加载动画 203 | wx.hideNavigationBarLoading() 204 | // 停止下拉刷新的动画 205 | wx.stopPullDownRefresh() 206 | // 分行数据 207 | const { pages, list, hasNextPage} = e.data.data 208 | // 判断查询时是否是第一页,第一页就清空之前数据 209 | if (pageNum === 1) { 210 | this.setData({ 211 | books: [] 212 | }) 213 | } 214 | // 将查询出来的拼接上去 215 | const books = this.data.books.concat(list) 216 | this.setData({ 217 | books, 218 | pageNum, 219 | pages, 220 | hasNextPage, 221 | isSearchName: true 222 | }) 223 | } 224 | }) 225 | } 226 | }) --------------------------------------------------------------------------------