├── .gitignore ├── README.md ├── server ├── README.md ├── doc │ ├── admin.md │ ├── user.md │ ├── 刮刮卡.md │ ├── 彩票.md │ └── 点餐.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── topschool │ │ │ └── xm │ │ │ ├── configuration │ │ │ └── RestApiControlAdvice.java │ │ │ ├── controller │ │ │ ├── admin │ │ │ │ ├── FoodManageController.java │ │ │ │ ├── IndexController.java │ │ │ │ └── MenuManageController.java │ │ │ ├── user │ │ │ │ ├── LoginController.java │ │ │ │ └── PartnerController.java │ │ │ └── wechatapplet │ │ │ │ ├── OrderFoodController.java │ │ │ │ └── ScratchCardController.java │ │ │ ├── dao │ │ │ ├── PartnerMapper.java │ │ │ ├── orderfood │ │ │ │ ├── FoodMapper.java │ │ │ │ ├── OrderLogMapper.java │ │ │ │ └── RestaurantMapper.java │ │ │ └── scratchcard │ │ │ │ └── ScratchLogMapper.java │ │ │ ├── dto │ │ │ └── ScratchResult.java │ │ │ ├── exception │ │ │ ├── BrandNotFoundException.java │ │ │ ├── FoodNotExistException.java │ │ │ ├── ScratchCardException.java │ │ │ └── UserNameNotFoundException.java │ │ │ ├── interceptor │ │ │ ├── AdminInterceptor.java │ │ │ └── WxApiInterceptor.java │ │ │ ├── model │ │ │ ├── Partner.java │ │ │ ├── orderfood │ │ │ │ ├── Food.java │ │ │ │ ├── OrderLog.java │ │ │ │ ├── OrderPool.java │ │ │ │ └── Restaurant.java │ │ │ └── scratchcard │ │ │ │ ├── Card.java │ │ │ │ ├── CardPool.java │ │ │ │ └── ScratchLog.java │ │ │ ├── service │ │ │ ├── MenuItemService.java │ │ │ ├── MenuService.java │ │ │ ├── OrderFoodService.java │ │ │ ├── PartnerService.java │ │ │ ├── ScratchCardService.java │ │ │ └── impl │ │ │ │ ├── DefaultMenuAndItemServiceImpl.java │ │ │ │ ├── DefaultOrderFoodServiceImpl.java │ │ │ │ ├── DefaultPartnerServiceImpl.java │ │ │ │ └── DefaultScratchCardServiceImpl.java │ │ │ ├── task │ │ │ └── ScratchCardTask.java │ │ │ └── util │ │ │ ├── AESUtil.java │ │ │ ├── HttpUtil.java │ │ │ └── RandomUtil.java │ ├── resources │ │ ├── configuration │ │ │ ├── application.xml │ │ │ ├── db.properties │ │ │ ├── mybatis-conf.xml │ │ │ ├── spring-mvc.xml │ │ │ ├── spring-mybatis.xml │ │ │ └── spring-task.xml │ │ └── mapper │ │ │ ├── foodMapper.xml │ │ │ ├── orderLogMapper.xml │ │ │ ├── partnerMapper.xml │ │ │ ├── restaurantMapper.xml │ │ │ └── scratchLogMapper.xml │ └── webapp │ │ └── WEB-INF │ │ ├── templates │ │ ├── admin │ │ │ ├── foodList.html │ │ │ ├── index.html │ │ │ └── login.html │ │ └── index.html │ │ └── web.xml │ └── test │ ├── java │ └── com │ │ └── topschool │ │ └── xm │ │ ├── BaseTest.java │ │ ├── dao │ │ ├── ScratchLogMapperTest.java │ │ └── orderfood │ │ │ ├── FoodMapperTest.java │ │ │ ├── OrderLogMapperTest.java │ │ │ └── RestaurantMapperTest.java │ │ ├── service │ │ └── impl │ │ │ ├── DefaultOrderFoodServiceImplTest.java │ │ │ ├── DefaultPartnerServiceImplTest.java │ │ │ └── DefaultScratchCardServiceImplTest.java │ │ └── util │ │ ├── AESTest.java │ │ ├── HttpUtilTest.java │ │ ├── RandomUtilTest.java │ │ └── TimeTest.java │ └── resources │ ├── application.xml │ ├── mybatis-conf.xml │ └── spring-mybatis.xml └── 订餐打卡系统 ├── app.js ├── app.json ├── app.wxss ├── images ├── 001.jpg ├── 001.png ├── 002.jpg ├── 002.png ├── 003.png ├── 004.png ├── 005.png ├── 006.png └── 007.png ├── pages ├── dinnerOrder │ ├── dinnerOrder.js │ ├── dinnerOrder.json │ ├── dinnerOrder.wxml │ └── dinnerOrder.wxss ├── homepage │ ├── homepage.js │ ├── homepage.json │ ├── homepage.wxml │ └── homepage.wxss ├── index │ ├── index.js │ ├── index.wxml │ └── index.wxss ├── login │ ├── login.js │ ├── login.json │ ├── login.wxml │ └── login.wxss ├── logs │ ├── logs.js │ ├── logs.json │ ├── logs.wxml │ └── logs.wxss ├── scratch_card │ ├── scratch_card.js │ ├── scratch_card.json │ ├── scratch_card.wxml │ └── scratch_card.wxss └── waiting │ ├── waiting.js │ ├── waiting.json │ ├── waiting.wxml │ └── waiting.wxss ├── project.config.json └── utils └── util.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iws 3 | *.iml 4 | *.ipr 5 | */.idea 6 | */.target 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Xiaomai 2 | 小卖部小程序项目:包含微信小程序+Java后台服务端 3 | -------------------------------------------------------------------------------- /server/README.md: -------------------------------------------------------------------------------- 1 | ### api 2 | 3 | --- 4 | 5 | 1) 刮刮卡 6 | 7 | 2) 点餐 8 | 9 | 3) 彩票 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /server/doc/admin.md: -------------------------------------------------------------------------------- 1 | 2 | 初始化订餐 `POST` 3 | `uri`: `/admin/food/select_brand` 4 | `params`: 5 | ```json 6 | { 7 | "id": 1 8 | } 9 | ``` 10 | > `id`为选择的品牌`id` 11 | 12 | `return`: 13 | ```json 14 | 15 | ``` -------------------------------------------------------------------------------- /server/doc/user.md: -------------------------------------------------------------------------------- 1 | ### 入伙 2 | 3 | 1 通过`code`向服务器获取uid `POST` 4 | `uri`: `/user/get_uid` 5 | `params`: 6 | ```json 7 | { 8 | "code": "code" 9 | } 10 | ``` 11 | `return`: 12 | ```json 13 | { 14 | "data":"test_uid" 15 | } 16 | ``` 17 | > `test_uid`为uid 18 | 19 | 20 | 2 提交`uid`,`username`,`invitationCode`,`area`注册 `POST` 21 | `uri`: `/user/sign_up` 22 | `params`: 23 | ```json 24 | { 25 | "uid": "test_uid", 26 | "username":"test_username", 27 | "invitationCode":"test_invitationCode", 28 | "area":0 29 | } 30 | ``` 31 | > `area`: 0->北京 1->上海 2->南京 3->无锡 32 | `return`: 33 | ```json 34 | { 35 | "data":{ 36 | "uid": "test_uid", 37 | "username":"test_username" 38 | } 39 | } 40 | ``` 41 | -------------------------------------------------------------------------------- /server/doc/刮刮卡.md: -------------------------------------------------------------------------------- 1 | 2 | #### 初始化 3 | 4 | `url`: `/wechat_applet_api/scratch-card` 5 | 6 | `params`: 7 | 8 | ```json 9 | { 10 | "id": "zhangsan", 11 | "isScratch":true 12 | } 13 | ``` 14 | > 请求参数 15 | > `id` 微信id 16 | > `isScratch` 是否为刮卡请求 (1, -1) 17 | 18 | `return`: 19 | ```json 20 | { 21 | "data":{ 22 | "curUserGroup": 1, 23 | "currentScratchResult": null, 24 | "lastList": [], 25 | "partnerStatus": 1, 26 | "todayList": [ 27 | { 28 | "imgUrl": "http://ts-dingup-onlinetest.oss-cn-beijing.aliyuncs.com/img/shop/4.jpg", 29 | "money": 4, 30 | "nickname": "李四", 31 | "id": "1234567890" 32 | }, 33 | { 34 | "imgUrl": "http://ts-dingup-onlinetest.oss-cn-beijing.aliyuncs.com/img/shop/4.jpg", 35 | "money": 4, 36 | "nickname": "张三", 37 | "id": "abcdefg" 38 | } 39 | ], 40 | "topList": [], 41 | "totalNum": 8, 42 | "totalTop": [ 43 | { 44 | "money": 4, 45 | "id": "abcdefg", 46 | "username": "张三" 47 | }, 48 | { 49 | "money": 4, 50 | "id": "859c3765a5504c01aeb07888aa070660", 51 | "username": "强个锤子" 52 | }, 53 | { 54 | "money": 4, 55 | "id": "c6f7473cfc9c4c07bf61b5bfb92177ab", 56 | "username": "王五" 57 | } 58 | ] 59 | } 60 | } 61 | ``` 62 | 63 | > 返回参数: 64 | > `partnerStatus` 用户当日刮卡状态 -1表示未刮卡,0表示正在刮卡,1表示已经刮卡 65 | > `curUserGroup` 当前用户组 66 | > `lastList` 今日最低 67 | > `topList` 今日最高 68 | > `todayList` 今日所有刮卡信息 69 | > `totalNum` 今日收到总捐款 70 | > `totalTop` 本月最佳 71 | 72 | #### 生成随机池 73 | 74 | 最大: 8元 1个 75 | 6元 1个 76 | 3~5元 n 77 | 1~2元 n 78 | 最小: 0元 2个 79 | 80 | -------------------------------------------------------------------------------- /server/doc/彩票.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/server/doc/彩票.md -------------------------------------------------------------------------------- /server/doc/点餐.md: -------------------------------------------------------------------------------- 1 | 2 | ### API 3 | 4 | --- 5 | 6 | 获取菜单:`GET` 7 | `uri`: `/wechat_applet_api/order_food/food_list` 8 | `params`: 9 | ```json 10 | { 11 | "uid":"abcd" 12 | } 13 | ``` 14 | > `id`为用户身份唯一标识 15 | `return`: 16 | ```json 17 | { 18 | "data":{ 19 | "foods":[ 20 | { 21 | "price": 14, 22 | "imageUrl": "http://official-web.oss-cn-beijing.aliyuncs.com/xiaomai/xishaoye.jpg", 23 | "name": "凉皮", 24 | "difference": null, 25 | "id": 12 26 | }, 27 | { 28 | "price": 12, 29 | "imageUrl": "http://official-web.oss-cn-beijing.aliyuncs.com/xiaomai/xishaoye.jpg", 30 | "name": "小豆花", 31 | "difference": null, 32 | "id": 13 33 | }, 34 | { 35 | "price": 14, 36 | "imageUrl": "http://official-web.oss-cn-beijing.aliyuncs.com/xiaomai/xishaoye.jpg", 37 | "name": "酸辣粉", 38 | "difference": null, 39 | "id": 14 40 | } 41 | ], 42 | "systemStatus": true 43 | } 44 | } 45 | ``` 46 | 47 | 48 | 预定: `POST` 49 | `uri`:`/wechat_applet_api/order_food/booking` 50 | `params`: 51 | ```json 52 | { 53 | "uid":"abcd", 54 | "foodId": 1024 55 | } 56 | ``` 57 | > `id`为用户身份唯一标识 58 | `return`: 59 | ```json 60 | { 61 | "data":"订餐成功" 62 | } 63 | ``` 64 | 65 | 取消预定: `POST` 66 | `uri`:`/wechat_applet_api/order_food/cancel` 67 | `params`: 68 | ```json 69 | { 70 | "uid":"abcd" 71 | } 72 | ``` 73 | > `id`为用户身份唯一标识 74 | `return`: 75 | ```json 76 | { 77 | "data":"取消成功" 78 | } 79 | ``` 80 | 81 | 82 | 获取用户状态 `GET` 83 | `uri`:`/wechat_applet_api/order_food/user_status` 84 | `params`: 85 | ```json 86 | { 87 | "uid":"abcd" 88 | } 89 | ``` 90 | > `id`为用户身份唯一标识 91 | `return`: 92 | ```json 93 | { 94 | "data": { 95 | "scratchCardStatus": true, 96 | "orderFoodStatus": true, 97 | "name": "test_user123", 98 | "id": "123" 99 | } 100 | } 101 | ``` 102 | 103 | 获取用户订餐信息:`GET` 104 | `uri`:`/wechat_applet_api/order_food/user_order` 105 | 106 | `params`: 107 | ```json 108 | { 109 | "uid":"abcd" 110 | } 111 | ``` 112 | > `id`为用户身份唯一标识 113 | `return`: 114 | ```json 115 | { 116 | "data":{ 117 | "name": "test_user123", 118 | "orderList": [ 119 | { 120 | "price": 15, 121 | "name": "test_food_110", 122 | "difference": null, 123 | "id": 110 124 | }, 125 | { 126 | "price": 21, 127 | "name": "test_food_111", 128 | "difference": 1, 129 | "id": 111 130 | } 131 | ], 132 | "id": "123" 133 | } 134 | } 135 | ``` 136 | -------------------------------------------------------------------------------- /server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.topschool 5 | xm 6 | war 7 | 1.0-SNAPSHOT 8 | xm Maven Webapp 9 | http://maven.apache.org 10 | 11 | 12 | 4.3.14.RELEASE 13 | 3.0.9.RELEASE 14 | 6.0.6 15 | 1.1.6 16 | 3.4.5 17 | 1.3.1 18 | 4.12 19 | 3.1.0 20 | 1.2.44 21 | 1.1.8 22 | 23 | 24 | 25 | 26 | org.springframework 27 | spring-webmvc 28 | ${spring.version} 29 | 30 | 31 | org.thymeleaf 32 | thymeleaf-spring4 33 | ${spring-thyeleaf.version} 34 | 35 | 36 | 37 | org.springframework 38 | spring-jdbc 39 | ${spring.version} 40 | 41 | 42 | mysql 43 | mysql-connector-java 44 | ${mysql-jdbc.version} 45 | 46 | 47 | com.alibaba 48 | druid 49 | ${druid.version} 50 | 51 | 52 | org.mybatis 53 | mybatis-spring 54 | ${spring-mybatis.version} 55 | 56 | 57 | org.mybatis 58 | mybatis 59 | ${mybatis.version} 60 | 61 | 62 | 63 | com.alibaba 64 | fastjson 65 | ${fastjson.version} 66 | 67 | 68 | 69 | 70 | javax.servlet 71 | javax.servlet-api 72 | ${javax-servlet-api.version} 73 | provided 74 | 75 | 76 | 77 | 78 | com.dingup 79 | ts-core 80 | ${ts-core.version} 81 | 82 | 83 | 84 | 85 | org.bouncycastle 86 | bcprov-jdk15on 87 | 1.59 88 | 89 | 90 | 91 | commons-codec 92 | commons-codec 93 | 1.11 94 | 95 | 96 | 97 | org.springframework 98 | spring-test 99 | ${spring.version} 100 | 101 | 102 | junit 103 | junit 104 | ${junit.version} 105 | test 106 | 107 | 108 | 109 | xm 110 | 111 | 112 | org.apache.maven.plugins 113 | maven-compiler-plugin 114 | 115 | 1.8 116 | 1.8 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/configuration/RestApiControlAdvice.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.configuration; 2 | 3 | import com.topschool.xm.exception.FoodNotExistException; 4 | import com.topschool.xm.exception.ScratchCardException; 5 | import com.topschool.xm.exception.UserNameNotFoundException; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.util.Assert; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.bind.annotation.RestControllerAdvice; 11 | 12 | import javax.naming.NoPermissionException; 13 | 14 | @RestControllerAdvice 15 | public class RestApiControlAdvice { 16 | 17 | @ExceptionHandler(FoodNotExistException.class) 18 | public ResponseEntity handle(FoodNotExistException e) { 19 | return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); 20 | } 21 | 22 | @ExceptionHandler(NoPermissionException.class) 23 | public ResponseEntity handle(NoPermissionException e) { 24 | return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); 25 | } 26 | 27 | @ExceptionHandler(ScratchCardException.class) 28 | public ResponseEntity handle(ScratchCardException e) { 29 | return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); 30 | } 31 | 32 | @ExceptionHandler(IllegalArgumentException.class) 33 | public ResponseEntity handle(IllegalArgumentException e) { 34 | return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); 35 | } 36 | 37 | @ExceptionHandler(UserNameNotFoundException.class) 38 | public ResponseEntity handle(UserNameNotFoundException e){ 39 | return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/controller/admin/FoodManageController.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.controller.admin; 2 | 3 | 4 | import com.topschool.xm.exception.BrandNotFoundException; 5 | import com.topschool.xm.exception.FoodNotExistException; 6 | import com.topschool.xm.service.MenuItemService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | @RequestMapping("/admin/food_manage") 15 | public class FoodManageController { 16 | 17 | @Autowired 18 | private MenuItemService menuItemService; 19 | 20 | @PostMapping("/menu_item/update") 21 | public Object update(@RequestParam("id") Integer id, 22 | @RequestParam(value = "name", required = false) String name, 23 | @RequestParam(value = "price", required = false) float price) throws FoodNotExistException { 24 | menuItemService.updateItem(id, name, price, null); 25 | return null; 26 | } 27 | 28 | @PostMapping("/menu_item/new") 29 | public Object addMenuItem(@RequestParam("id") Integer brandId, 30 | @RequestParam("name") String name, 31 | @RequestParam("price") float price) throws BrandNotFoundException { 32 | menuItemService.addItem(name, price, null, brandId); 33 | return null; 34 | } 35 | 36 | @PostMapping("/menu_item/delete") 37 | public Object deleteMenuItem(@RequestParam("id") Integer itemId) throws FoodNotExistException { 38 | menuItemService.deleteItem(itemId); 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/controller/admin/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.controller.admin; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | @Controller 9 | @RequestMapping("/admin") 10 | public class IndexController { 11 | @GetMapping("") 12 | public String index(){ 13 | return "/admin/index"; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/controller/admin/MenuManageController.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.controller.admin; 2 | 3 | import com.topschool.xm.exception.BrandNotFoundException; 4 | import com.topschool.xm.service.MenuService; 5 | import com.topschool.xm.service.OrderFoodService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import java.io.IOException; 13 | 14 | 15 | @RestController 16 | @RequestMapping("/admin/brand_manage") 17 | public class MenuManageController { 18 | 19 | @Autowired 20 | private OrderFoodService orderFoodService; 21 | 22 | @Autowired 23 | private MenuService menuService; 24 | 25 | @PostMapping("/today_menu/select_brand") 26 | public ResponseEntity selectBrand(Integer id){ 27 | orderFoodService.initOrderFoodSystem(id); 28 | return new ResponseEntity<>("success", HttpStatus.OK); 29 | } 30 | 31 | @GetMapping("/brands") 32 | public Object restaurants(){ 33 | return menuService.getAllMenu(); 34 | } 35 | 36 | @GetMapping("/brand/{id}") 37 | public Object foodList(@PathVariable(value = "id") Integer brandId){ 38 | 39 | return menuService.getMenuItem(brandId); 40 | } 41 | 42 | @PostMapping("/brand/new") 43 | public Object addBrand(@RequestParam(value = "name")String name, 44 | @RequestParam(value = "logo", required = false) MultipartFile logo, 45 | @RequestParam(value = "description", required = false) String description) throws IOException { 46 | menuService.addMenu(name, logo, description); 47 | return null; 48 | } 49 | 50 | @PostMapping("/brand/update") 51 | public Object updateBrand(@RequestParam(value = "brandId") Integer brandId, 52 | @RequestParam(value = "name", required = false) String name, 53 | @RequestParam(value = "logo", required = false)MultipartFile logo, 54 | @RequestParam(value = "description", required = false)String description) throws IOException, BrandNotFoundException { 55 | menuService.updateMenu(brandId, name, logo, description); 56 | return null; 57 | } 58 | 59 | @PostMapping("/brand/delete") 60 | public Object deleteBrand(Integer id) throws BrandNotFoundException { 61 | menuService.deleteMenu(id); 62 | return null; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/controller/user/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.controller.user; 2 | 3 | import com.topschool.xm.exception.UserNameNotFoundException; 4 | import com.topschool.xm.service.PartnerService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestParam; 12 | 13 | import javax.naming.NoPermissionException; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpSession; 16 | 17 | @Controller 18 | @RequestMapping("/login") 19 | public class LoginController { 20 | 21 | @Autowired 22 | private PartnerService partnerService; 23 | 24 | @GetMapping("") 25 | public String loginPage() { 26 | return "/admin/login"; 27 | } 28 | 29 | @PostMapping("") 30 | public String login(@RequestParam int uid, @RequestParam String password, Model model, HttpServletRequest request) throws UserNameNotFoundException, NoPermissionException { 31 | String username = partnerService.getUsername(uid, password); 32 | if (username!=null) { 33 | HttpSession session = request.getSession(); 34 | session.setAttribute("username", username); 35 | return "redirect:/admin/"; 36 | } 37 | model.addAttribute("uid", uid); 38 | model.addAttribute("password", password); 39 | model.addAttribute("error", "用户名密码不匹配"); 40 | 41 | return "/admin/login"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/controller/user/PartnerController.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.controller.user; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.topschool.xm.service.PartnerService; 5 | import com.topschool.xm.util.HttpUtil; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.naming.NoPermissionException; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import java.util.UUID; 15 | 16 | @RestController 17 | @RequestMapping("/user") 18 | public class PartnerController { 19 | private static final String GET_OPEN_ID_URL_TEMPLATE = "https://api.weixin.qq.com/sns/jscode2session?" + 20 | "appid=%s&secret=%s&js_code=%s&grant_type=authorization_code"; 21 | private static final String APP_ID = "wx7c0418540db4d54f"; 22 | private static final String SECRET = "1d8dcd22cb939840d73e995094ce99d9"; 23 | private static final String INVITATION_CODE = "1234567890"; 24 | private static final String[] AREAS = {"北京", "上海", "南京", "无锡"}; 25 | private static final Map USER_ID_OPEN_ID_CACHE = new HashMap(); 26 | 27 | @Autowired 28 | private PartnerService partnerService; 29 | 30 | @PostMapping("/sign_up") 31 | public ResponseEntity signUp(@RequestParam String uid, 32 | @RequestParam String username, 33 | @RequestParam String invitationCode, 34 | @RequestParam Integer area) { 35 | String expectOpenId = (String) USER_ID_OPEN_ID_CACHE.get(uid); 36 | if (expectOpenId == null) { 37 | throw new IllegalArgumentException("未认证的uid无法注册"); 38 | } 39 | if (username.trim().length() < 2 || username.trim().length() > 5) { 40 | throw new IllegalArgumentException("姓名非法"); 41 | } 42 | if (!INVITATION_CODE.equals(invitationCode)) { 43 | throw new IllegalArgumentException("非法的邀请码"); 44 | } 45 | if (area < 0 || area > 3) { 46 | throw new IllegalArgumentException("非法的地址"); 47 | } 48 | Map userInfo = partnerService.register(uid, username, invitationCode, expectOpenId, area); 49 | USER_ID_OPEN_ID_CACHE.remove(uid); 50 | return new ResponseEntity<>(userInfo, HttpStatus.OK); 51 | } 52 | 53 | @PostMapping("/get_uid") 54 | public ResponseEntity getUid(String code) { 55 | JSONObject object = HttpUtil.getJson(String.format(GET_OPEN_ID_URL_TEMPLATE, APP_ID, SECRET, code.trim())); 56 | if (object.get("openid") == null) { 57 | throw new IllegalArgumentException("code无效"); 58 | } 59 | System.out.println(code); 60 | Map userInfo = partnerService.getUserInfoByOpenId((String) object.get("openid")); 61 | if (userInfo != null) { 62 | return new ResponseEntity<>(userInfo.get("uid"), HttpStatus.OK); 63 | } 64 | for (Object o : USER_ID_OPEN_ID_CACHE.keySet()) { 65 | if (object.get("openid").equals(USER_ID_OPEN_ID_CACHE.get(o))) { 66 | return new ResponseEntity<>(o, HttpStatus.OK); 67 | } 68 | } 69 | String uid = UUID.randomUUID().toString().replace("-", ""); 70 | USER_ID_OPEN_ID_CACHE.put(uid, object.get("openid")); 71 | return new ResponseEntity<>(uid, HttpStatus.OK); 72 | } 73 | 74 | @GetMapping("/user_info") 75 | public ResponseEntity getUserInfo(String userId) { 76 | return null; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/controller/wechatapplet/OrderFoodController.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.controller.wechatapplet; 2 | 3 | import com.topschool.xm.exception.FoodNotExistException; 4 | import com.topschool.xm.service.OrderFoodService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.GetMapping; 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 | 13 | import javax.naming.NoPermissionException; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | import static org.springframework.http.HttpStatus.OK; 18 | 19 | @RestController 20 | @RequestMapping("/wechat_applet_api/order_food") 21 | public class OrderFoodController { 22 | 23 | @Qualifier("defaultOrderFoodServiceImpl") 24 | @Autowired 25 | private OrderFoodService orderFoodService; 26 | 27 | @GetMapping("/food_list") 28 | public ResponseEntity getList(String uid){ 29 | Map map = orderFoodService.getFoodList(); 30 | return new ResponseEntity(map, OK); 31 | } 32 | 33 | @PostMapping("/booking") 34 | public ResponseEntity booking(String uid, Integer foodId) throws Exception, FoodNotExistException { 35 | String msg = orderFoodService.booking(uid, foodId); 36 | return new ResponseEntity(msg, OK); 37 | } 38 | 39 | @PostMapping("/foods_booking") 40 | public ResponseEntity foodsBooking(String uid, Integer[] foods) throws NoPermissionException, FoodNotExistException { 41 | for (Integer food : foods) { 42 | orderFoodService.booking(uid, food); 43 | } 44 | return new ResponseEntity(OK); 45 | } 46 | 47 | @PostMapping("/cancel") 48 | public ResponseEntity cancel(String uid){ 49 | String msg = orderFoodService.cancel(uid); 50 | return new ResponseEntity(msg, OK); 51 | } 52 | 53 | @GetMapping("/user_status") 54 | public ResponseEntity getUserStatus(String uid){ 55 | Map status = orderFoodService.getUserStatus(uid); 56 | return new ResponseEntity(status, OK); 57 | } 58 | 59 | @GetMapping("/user_order") 60 | public ResponseEntity getUserOrder(String uid) throws FoodNotExistException { 61 | Map map = orderFoodService.getUsersOrder(uid); 62 | return new ResponseEntity(map, OK); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/controller/wechatapplet/ScratchCardController.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.controller.wechatapplet; 2 | 3 | import com.topschool.xm.dto.ScratchResult; 4 | import com.topschool.xm.exception.ScratchCardException; 5 | import com.topschool.xm.service.ScratchCardService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Qualifier; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.Date; 14 | 15 | import static org.springframework.http.HttpStatus.OK; 16 | 17 | @RestController 18 | @RequestMapping("/wechat_applet_api/scratch-card") 19 | public class ScratchCardController { 20 | 21 | @Qualifier("defaultScratchCardServiceImpl") 22 | @Autowired 23 | private ScratchCardService scratchCardService; 24 | 25 | @GetMapping("") 26 | public ResponseEntity scratch(String uid, int isScratch) throws ScratchCardException { 27 | System.out.printf("id:%15s isScratch:%5s\n", uid, isScratch); 28 | scratchCardService.initCardPool(100); 29 | ScratchResult result = new ScratchResult(); 30 | result.setPartnerStatus(-1); 31 | result.setCurUserGroup(1); 32 | if (scratchCardService.getPartnerTodayStatus(uid)){ 33 | result.setPartnerStatus(1); 34 | } 35 | if (isScratch == 1) { 36 | result.setCurrentScratchResult(scratchCardService.scratch(uid.trim())); 37 | result.setPartnerStatus(0); 38 | } 39 | if (isScratch!=1 && isScratch!=-1){ 40 | throw new IllegalArgumentException("请求存在非法参数"); 41 | } 42 | result.setLastList(scratchCardService.getTodayLastList(0, 2)); 43 | result.setTopList(scratchCardService.getTodayTopList(0, 2)); 44 | result.setTodayList(scratchCardService.getTodayResult(0, 2)); 45 | result.setTotalTop(scratchCardService.getTotalTopResult(0, 3)); 46 | result.setTotalNum(scratchCardService.getTodayTotal(new Date())); 47 | return new ResponseEntity(result, OK); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/dao/PartnerMapper.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao; 2 | 3 | import com.topschool.xm.model.Partner; 4 | 5 | import java.util.List; 6 | 7 | public interface PartnerMapper { 8 | void insert(Partner partner); 9 | Partner getById(Integer id); 10 | Partner getByOpenId(String openId); 11 | Partner getByUid(String uid); 12 | List getAll(); 13 | // List getBy 14 | } 15 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/dao/orderfood/FoodMapper.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao.orderfood; 2 | 3 | import com.topschool.xm.model.orderfood.Food; 4 | 5 | import java.util.List; 6 | 7 | public interface FoodMapper { 8 | 9 | boolean insert(Food food); 10 | 11 | Food getById(Integer id); 12 | 13 | List getAll(); 14 | 15 | boolean deleteById(Integer id); 16 | 17 | boolean update(Food food); 18 | 19 | List getByRestaurantId(Integer id); 20 | } 21 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/dao/orderfood/OrderLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao.orderfood; 2 | 3 | import com.topschool.xm.model.orderfood.OrderLog; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.sql.Date; 7 | import java.util.List; 8 | 9 | public interface OrderLogMapper { 10 | boolean insert(OrderLog orderLog); 11 | boolean exist(OrderLog orderLog); 12 | List getByRestaurantId(Integer id); 13 | List getByDate(Date date); 14 | List getByUserId(String id); 15 | List getByFoodId(int id); 16 | boolean delete(@Param("uid")String uid, @Param("foodId")Integer foodId); 17 | List getTodayOrderByUserId(String id); 18 | } 19 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/dao/orderfood/RestaurantMapper.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao.orderfood; 2 | 3 | import com.topschool.xm.model.orderfood.Restaurant; 4 | 5 | import java.util.List; 6 | 7 | public interface RestaurantMapper { 8 | 9 | boolean insert(Restaurant restaurant); 10 | 11 | Restaurant getById(Integer id); 12 | 13 | List getAll(); 14 | 15 | boolean deleteById(Integer id); 16 | 17 | boolean update(Restaurant restaurant); 18 | } 19 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/dao/scratchcard/ScratchLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao.scratchcard; 2 | 3 | import com.topschool.xm.model.scratchcard.ScratchLog; 4 | import org.apache.ibatis.annotations.MapKey; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.sql.Date; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public interface ScratchLogMapper { 12 | 13 | Boolean insert(ScratchLog scratchLog); 14 | 15 | /** 16 | * wxId and scratchDate are not null 17 | * @param scratchLog 18 | * @return 19 | */ 20 | ScratchLog getOnesScratchResult(ScratchLog scratchLog); 21 | 22 | List getCurrentMouthScratchListByWxId(String id); 23 | 24 | List getTodayScratchResultList(); 25 | 26 | Integer getMouthCountByWxId(String id); 27 | 28 | @MapKey("id") 29 | List getCurrentMouthTop(Integer size); 30 | 31 | Boolean isExist(@Param("id")String id, @Param("scratchDate")Date scratchDate); 32 | } 33 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/dto/ScratchResult.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dto; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class ScratchResult implements Serializable{ 8 | 9 | private Integer totalNum; 10 | private Integer curUserGroup; 11 | private Integer partnerStatus; 12 | private Integer currentScratchResult; 13 | /** 14 | * size: 2 15 | * map key: 16 | * key1: id, key2: nickname, key3: money 17 | */ 18 | private List> topList; 19 | /** 20 | * size: 2 21 | * map key: 22 | * key1: id, key2: nickname, key3: money 23 | */ 24 | private List> lastList; 25 | /** 26 | * map key: 27 | * key1: id, key2: nickname, key3: money 28 | */ 29 | private List> todayList; 30 | /** 31 | * size: 3 32 | * map key: 33 | * key1: id, key2: nickname, key3: money 34 | */ 35 | private List totalTop; 36 | 37 | public Integer getCurUserGroup() { 38 | return curUserGroup; 39 | } 40 | 41 | public void setCurUserGroup(Integer curUserGroup) { 42 | this.curUserGroup = curUserGroup; 43 | } 44 | 45 | public Integer getTotalNum() { 46 | return totalNum; 47 | } 48 | 49 | public void setTotalNum(Integer totalNum) { 50 | this.totalNum = totalNum; 51 | } 52 | 53 | public Integer getPartnerStatus() { 54 | return partnerStatus; 55 | } 56 | 57 | public Integer getCurrentScratchResult() { 58 | return currentScratchResult; 59 | } 60 | 61 | public void setCurrentScratchResult(Integer currentScratchResult) { 62 | this.currentScratchResult = currentScratchResult; 63 | } 64 | 65 | public void setPartnerStatus(Integer partnerStatus) { 66 | this.partnerStatus = partnerStatus; 67 | } 68 | 69 | public List> getTopList() { 70 | return topList; 71 | } 72 | 73 | public void setTopList(List> topList) { 74 | this.topList = topList; 75 | } 76 | 77 | public List> getLastList() { 78 | return lastList; 79 | } 80 | 81 | public void setLastList(List> lastList) { 82 | this.lastList = lastList; 83 | } 84 | 85 | public List> getTodayList() { 86 | return todayList; 87 | } 88 | 89 | public void setTodayList(List> todayList) { 90 | this.todayList = todayList; 91 | } 92 | 93 | public List getTotalTop() { 94 | return totalTop; 95 | } 96 | 97 | public void setTotalTop(List totalTop) { 98 | this.totalTop = totalTop; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/exception/BrandNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.exception; 2 | 3 | public class BrandNotFoundException extends Throwable { 4 | public BrandNotFoundException() { 5 | } 6 | 7 | public BrandNotFoundException(String message) { 8 | super(message); 9 | } 10 | 11 | public BrandNotFoundException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/exception/FoodNotExistException.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.exception; 2 | 3 | public class FoodNotExistException extends Throwable { 4 | public FoodNotExistException() { 5 | super(); 6 | } 7 | 8 | public FoodNotExistException(String message) { 9 | super(message); 10 | } 11 | 12 | public FoodNotExistException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/exception/ScratchCardException.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.exception; 2 | 3 | public class ScratchCardException extends Throwable { 4 | public ScratchCardException() { 5 | super(); 6 | } 7 | 8 | public ScratchCardException(String message) { 9 | super(message); 10 | } 11 | 12 | public ScratchCardException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/exception/UserNameNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.exception; 2 | 3 | public class UserNameNotFoundException extends Throwable { 4 | public UserNameNotFoundException() { 5 | super(); 6 | } 7 | 8 | public UserNameNotFoundException(String message) { 9 | super(message); 10 | } 11 | 12 | public UserNameNotFoundException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/interceptor/AdminInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.interceptor; 2 | 3 | import org.springframework.web.servlet.ModelAndView; 4 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import javax.servlet.http.HttpSession; 9 | 10 | public class AdminInterceptor extends HandlerInterceptorAdapter { 11 | @Override 12 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 13 | HttpSession session = request.getSession(); 14 | String username = (String) session.getAttribute("username"); 15 | if (username==null){ 16 | response.sendRedirect("/login?"); 17 | return false; 18 | } 19 | return true; 20 | } 21 | 22 | @Override 23 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { 24 | super.postHandle(request, response, handler, modelAndView); 25 | } 26 | 27 | @Override 28 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { 29 | super.afterCompletion(request, response, handler, ex); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/interceptor/WxApiInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.interceptor; 2 | 3 | import com.topschool.xm.service.PartnerService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | @Configuration 12 | public class WxApiInterceptor extends HandlerInterceptorAdapter { 13 | 14 | @Autowired 15 | private PartnerService partnerService; 16 | 17 | @Override 18 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 19 | String uid = request.getParameter("uid"); 20 | if (!partnerService.uidExist(uid)){ 21 | throw new IllegalArgumentException("uid不存在"); 22 | } 23 | return true; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/model/Partner.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.model; 2 | 3 | public class Partner { 4 | private Integer id; 5 | private String uid; 6 | private String username; 7 | private String openId; 8 | private String password; 9 | private boolean isAdmin; 10 | private int area; 11 | private long createTime; 12 | 13 | public int getArea() { 14 | return area; 15 | } 16 | 17 | public void setArea(int area) { 18 | this.area = area; 19 | } 20 | 21 | public Integer getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Integer id) { 26 | this.id = id; 27 | } 28 | 29 | public String getUid() { 30 | return uid; 31 | } 32 | 33 | public void setUid(String uid) { 34 | this.uid = uid; 35 | } 36 | 37 | public String getOpenId() { 38 | return openId; 39 | } 40 | 41 | public void setOpenId(String openId) { 42 | this.openId = openId; 43 | } 44 | 45 | public long getCreateTime() { 46 | return createTime; 47 | } 48 | 49 | public void setCreateTime(long createTime) { 50 | this.createTime = createTime; 51 | } 52 | 53 | public String getUsername() { 54 | return username; 55 | } 56 | 57 | public void setUsername(String username) { 58 | this.username = username; 59 | } 60 | 61 | public String getPassword() { 62 | return password; 63 | } 64 | 65 | public void setPassword(String password) { 66 | this.password = password; 67 | } 68 | 69 | public boolean getIsAdmin() { 70 | return isAdmin; 71 | } 72 | 73 | public void setIsAdmin(boolean isAdmin) { 74 | this.isAdmin = isAdmin; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/model/orderfood/Food.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.model.orderfood; 2 | 3 | public class Food { 4 | 5 | private Integer id; 6 | private String name; 7 | private double price; 8 | private Integer restaurantId; 9 | private String logoUrl; 10 | 11 | public Integer getId() { 12 | return id; 13 | } 14 | 15 | public void setId(Integer id) { 16 | this.id = id; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public double getPrice() { 28 | return price; 29 | } 30 | 31 | public void setPrice(double price) { 32 | this.price = price; 33 | } 34 | 35 | public Integer getRestaurantId() { 36 | return restaurantId; 37 | } 38 | 39 | public void setRestaurantId(Integer restaurantId) { 40 | this.restaurantId = restaurantId; 41 | } 42 | 43 | public String getLogoUrl() { 44 | return logoUrl; 45 | } 46 | 47 | public void setLogoUrl(String logoUrl) { 48 | this.logoUrl = logoUrl; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/model/orderfood/OrderLog.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.model.orderfood; 2 | 3 | public class OrderLog { 4 | 5 | private Integer id; 6 | private String userId; 7 | private Integer foodId; 8 | private Long createTime; 9 | 10 | public Integer getId() { 11 | return id; 12 | } 13 | 14 | public void setId(Integer id) { 15 | this.id = id; 16 | } 17 | 18 | public String getUserId() { 19 | return userId; 20 | } 21 | 22 | public void setUserId(String userId) { 23 | this.userId = userId; 24 | } 25 | 26 | public Integer getFoodId() { 27 | return foodId; 28 | } 29 | 30 | public void setFoodId(Integer foodId) { 31 | this.foodId = foodId; 32 | } 33 | 34 | public Long getCreateTime() { 35 | return createTime; 36 | } 37 | 38 | public void setCreateTime(Long createTime) { 39 | this.createTime = createTime; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/model/orderfood/OrderPool.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.model.orderfood; 2 | 3 | import org.springframework.context.annotation.Scope; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.List; 7 | 8 | @Component 9 | @Scope("singleton") 10 | public class OrderPool { 11 | private List foodList; 12 | private boolean status; 13 | 14 | public List getFoodList() { 15 | return foodList; 16 | } 17 | 18 | public void setFoodList(List foodList) { 19 | this.foodList = foodList; 20 | } 21 | 22 | public boolean getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(boolean status) { 27 | this.status = status; 28 | } 29 | 30 | public boolean inFoodList(Integer foodId){ 31 | for (Food food : foodList) { 32 | if (food.getId().equals(foodId)) { 33 | return true; 34 | } 35 | } 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/model/orderfood/Restaurant.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.model.orderfood; 2 | 3 | public class Restaurant { 4 | private Integer id; 5 | private String name; 6 | private String logo; 7 | private String description; 8 | 9 | public Integer getId() { 10 | return id; 11 | } 12 | 13 | public void setId(Integer id) { 14 | this.id = id; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | 25 | public String getLogo() { 26 | return logo; 27 | } 28 | 29 | public void setLogo(String logo) { 30 | this.logo = logo; 31 | } 32 | 33 | public String getDescription() { 34 | return description; 35 | } 36 | 37 | public void setDescription(String description) { 38 | this.description = description; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/model/scratchcard/Card.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.model.scratchcard; 2 | 3 | import org.springframework.context.annotation.Scope; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | @Scope("request") 8 | public class Card { 9 | private String uid; 10 | private String nickname; 11 | private Integer price; 12 | private String imgUrl; 13 | 14 | public String getImgUrl() { 15 | return imgUrl; 16 | } 17 | 18 | public void setImgUrl(String imgUrl) { 19 | this.imgUrl = imgUrl; 20 | } 21 | 22 | public String getUid() { 23 | return uid; 24 | } 25 | 26 | public void setUid(String uid) { 27 | this.uid = uid; 28 | } 29 | 30 | public String getNickname() { 31 | return nickname; 32 | } 33 | 34 | public void setNickname(String nickname) { 35 | this.nickname = nickname; 36 | } 37 | 38 | public Integer getPrice() { 39 | return price; 40 | } 41 | 42 | public void setPrice(Integer price) { 43 | this.price = price; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/model/scratchcard/CardPool.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.model.scratchcard; 2 | 3 | import com.topschool.xm.util.RandomUtil; 4 | import org.springframework.context.annotation.Scope; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | @Component 12 | @Scope("singleton") 13 | public class CardPool { 14 | private Card[] top2; 15 | private List last2; 16 | private List todayList; 17 | private List pool; 18 | private List totalList; 19 | private int todayTotal; 20 | 21 | /** 22 | * init card pool 23 | * @param poolSize pool size 24 | */ 25 | public void init(int poolSize){ 26 | top2 = new Card[2]; 27 | last2 = new ArrayList(2); 28 | todayList = new ArrayList(poolSize); 29 | pool = new ArrayList(poolSize); 30 | pool.addAll(Arrays.asList(new Integer[]{8, 6, 0, 0, 1, 1, 2, 2})); 31 | for (int i = 0; i < poolSize - 8; i++) { 32 | pool.add(RandomUtil.generationRandom(3, 5)); 33 | } 34 | } 35 | 36 | public Integer popFromPool(){ 37 | return this.pool.remove(RandomUtil.generationRandom(0, this.pool.size())); 38 | } 39 | 40 | public List getPool() { 41 | return pool; 42 | } 43 | 44 | public void setPool(List pool) { 45 | this.pool = pool; 46 | } 47 | 48 | public Card[] getTop2() { 49 | return top2; 50 | } 51 | 52 | public void setTop2(Card[] top2) { 53 | this.top2 = top2; 54 | } 55 | 56 | public List getLast2() { 57 | return last2; 58 | } 59 | 60 | public void setLast2(List last2) { 61 | this.last2 = last2; 62 | } 63 | 64 | public List getTodayList() { 65 | return todayList; 66 | } 67 | 68 | public void setTodayList(List todayList) { 69 | this.todayList = todayList; 70 | } 71 | 72 | public List getTotalList() { 73 | return totalList; 74 | } 75 | 76 | public void setTotalList(List totalList) throws Exception { 77 | if (totalList.size()>3){ 78 | throw new Exception("total list max size is 3"); 79 | } 80 | this.totalList = totalList; 81 | } 82 | 83 | public int getTodayTotal() { 84 | return todayTotal; 85 | } 86 | 87 | public void setTodayTotal(int todayTotal) { 88 | this.todayTotal = todayTotal; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/model/scratchcard/ScratchLog.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.model.scratchcard; 2 | 3 | 4 | import java.sql.Date; 5 | 6 | public class ScratchLog { 7 | 8 | private Integer id; 9 | private String uid; 10 | private Integer result; 11 | private Date scratchDate; 12 | private Long createDate; 13 | 14 | public Integer getId() { 15 | return id; 16 | } 17 | 18 | public void setId(Integer id) { 19 | this.id = id; 20 | } 21 | 22 | public String getUid() { 23 | return uid; 24 | } 25 | 26 | public void setUid(String uid) { 27 | this.uid = uid; 28 | } 29 | 30 | public Integer getResult() { 31 | return result; 32 | } 33 | 34 | public void setResult(Integer result) { 35 | this.result = result; 36 | } 37 | 38 | public Date getScratchDate() { 39 | return scratchDate; 40 | } 41 | 42 | public void setScratchDate(Date scratchDate) { 43 | this.scratchDate = scratchDate; 44 | } 45 | 46 | public Long getCreateDate() { 47 | return createDate; 48 | } 49 | 50 | public void setCreateDate(Long createDate) { 51 | this.createDate = createDate; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/MenuItemService.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service; 2 | 3 | 4 | import com.topschool.xm.exception.BrandNotFoundException; 5 | import com.topschool.xm.exception.FoodNotExistException; 6 | 7 | public interface MenuItemService { 8 | void updateItem(Integer id, String name, float price, String logo) throws FoodNotExistException; 9 | 10 | void deleteItem(Integer foodId) throws FoodNotExistException; 11 | 12 | void addItem(String name, float price, String logo, Integer restaurantId) throws BrandNotFoundException; 13 | } 14 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/MenuService.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service; 2 | 3 | import com.topschool.xm.exception.BrandNotFoundException; 4 | import com.topschool.xm.model.orderfood.Food; 5 | import com.topschool.xm.model.orderfood.Restaurant; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public interface MenuService { 12 | List getAllMenu(); 13 | 14 | List getMenuItem(Integer id); 15 | 16 | 17 | void updateMenu(Integer id, String name, MultipartFile logo, String description) throws BrandNotFoundException, IOException; 18 | 19 | void deleteMenu(Integer restaurantId) throws BrandNotFoundException; 20 | 21 | void addMenu(String name, MultipartFile logo, String description) throws IOException; 22 | } 23 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/OrderFoodService.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service; 2 | 3 | import com.topschool.xm.exception.FoodNotExistException; 4 | 5 | import javax.naming.NoPermissionException; 6 | import java.util.Map; 7 | 8 | public interface OrderFoodService { 9 | 10 | /** 11 | * 获取今日菜单 12 | * 13 | * @return 菜单集合 14 | */ 15 | Map getFoodList(); 16 | 17 | /** 18 | * 用户订餐 19 | * 20 | * @param userId 用户id 21 | * @param foodId food id 22 | * @return 订餐结果 23 | * @throws NoPermissionException 无订餐资格 24 | * @throws FoodNotExistException 不存在food 25 | */ 26 | String booking(String userId, Integer foodId) throws NoPermissionException, FoodNotExistException; 27 | 28 | /** 29 | * 取消订餐,取消当日所有记录 30 | * 31 | * @param userId 用户id 32 | * @return 操作结果 33 | */ 34 | String cancel(String userId); 35 | 36 | /** 37 | * 获取用户状态,包括订餐状态和刮卡状态 38 | * 39 | * @param userId 用户id 40 | * @return 状态信息 41 | */ 42 | Map getUserStatus(String userId); 43 | 44 | /** 45 | * 获取用户今日订单 46 | * 47 | * @param userId 用户id 48 | * @return 今日订单信息 49 | */ 50 | Map getUsersOrder(String userId) throws FoodNotExistException; 51 | 52 | /** 53 | * 初始化今日菜单 54 | * 55 | * @param restaurantId 饭馆编号 56 | */ 57 | void initOrderFoodSystem(int restaurantId); 58 | 59 | /** 60 | * 提交今日订单 61 | * 62 | * @return 63 | * @throws Exception 64 | */ 65 | @Deprecated 66 | boolean submit() throws Exception; 67 | 68 | /** 69 | * 清除订单缓存 70 | * 71 | * @return 72 | */ 73 | boolean clean(); 74 | } 75 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/PartnerService.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service; 2 | 3 | import com.topschool.xm.exception.UserNameNotFoundException; 4 | 5 | import javax.naming.NoPermissionException; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | public interface PartnerService { 10 | 11 | Map register(String uid, String username, String invitationCode, String openId, int area); 12 | 13 | String getUsername(Integer uid, String password) throws UserNameNotFoundException, NoPermissionException; 14 | 15 | List getAllPartner(); 16 | 17 | void deletePartner(String uid); 18 | 19 | Map getUserInfoByOpenId(String openId); 20 | 21 | boolean uidExist(String uid); 22 | } 23 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/ScratchCardService.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service; 2 | 3 | import com.topschool.xm.exception.ScratchCardException; 4 | 5 | import java.util.Date; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | public interface ScratchCardService { 10 | 11 | /** 12 | * 初始化抽奖池 13 | * 14 | * @param size 奖池大小 15 | */ 16 | void initCardPool(Integer size); 17 | 18 | /** 19 | * 刮卡 20 | * 21 | * @param uid 用户id 22 | * @return 刮刀的结果 23 | * @throws Exception 24 | */ 25 | Integer scratch(String uid) throws ScratchCardException; 26 | 27 | /** 28 | * 获取今日用户状态 29 | * 30 | * @param uid 用户id 31 | * @return 32 | */ 33 | boolean getPartnerTodayStatus(String uid); 34 | 35 | /** 36 | * 获取今天所有人员刮卡记录(分页) 37 | * 38 | * @param page 页码 39 | * @param pageSize 每页大小 40 | * @return 集合 41 | */ 42 | List> getTodayResult(Integer page, Integer pageSize); 43 | 44 | /** 45 | * 获取今日最高的成员(分页) 46 | * 47 | * @param page 页码 48 | * @param pageSize 每页大小 49 | * @return 集合 50 | */ 51 | List> getTodayTopList(Integer page, Integer pageSize); 52 | 53 | /** 54 | * 获取今日最低的成员(分页) 55 | * 56 | * @param page 页码 57 | * @param pageSize 每页大小 58 | * @return 集合 59 | */ 60 | List> getTodayLastList(Integer page, Integer pageSize); 61 | 62 | /** 63 | * 获取当月总和最高的成员(分页) 64 | * 65 | * @param page 页码 66 | * @param pageSize 每页大小 67 | * @return 集合 68 | */ 69 | List getTotalTopResult(Integer page, Integer pageSize); 70 | 71 | /** 72 | * 获取用户刮卡概括信息,包括月总额,最高,最低,平均值 73 | * 74 | * @param id 用户id 75 | * @return 信息集 76 | */ 77 | Map getScratchSummary(String id); 78 | 79 | /** 80 | * 获取当天所有刮卡总额 81 | * 82 | * @param date 日期 83 | * @return 总额 84 | */ 85 | Integer getTodayTotal(Date date); 86 | 87 | } 88 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/impl/DefaultMenuAndItemServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service.impl; 2 | 3 | import com.dingup.util.GOssUtil; 4 | import com.topschool.xm.dao.orderfood.FoodMapper; 5 | import com.topschool.xm.dao.orderfood.RestaurantMapper; 6 | import com.topschool.xm.exception.BrandNotFoundException; 7 | import com.topschool.xm.exception.FoodNotExistException; 8 | import com.topschool.xm.model.orderfood.Food; 9 | import com.topschool.xm.model.orderfood.Restaurant; 10 | import com.topschool.xm.service.MenuItemService; 11 | import com.topschool.xm.service.MenuService; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.transaction.annotation.Transactional; 15 | import org.springframework.web.multipart.MultipartFile; 16 | 17 | import java.io.IOException; 18 | import java.util.List; 19 | 20 | @Service 21 | public class DefaultMenuAndItemServiceImpl implements MenuItemService, MenuService { 22 | 23 | private static final String FOLDER = "dinner/img"; 24 | private static final String BUCKET_NAME = "topschool-xiaomai"; 25 | 26 | @Autowired 27 | private FoodMapper foodMapper; 28 | 29 | @Autowired 30 | private RestaurantMapper restaurantMapper; 31 | 32 | @Override 33 | public List getMenuItem(Integer id) { 34 | return foodMapper.getByRestaurantId(id); 35 | } 36 | 37 | @Transactional(rollbackFor = Exception.class) 38 | @Override 39 | public void updateItem(Integer id, String name, float price, String logo) throws FoodNotExistException { 40 | Food food = foodMapper.getById(id); 41 | if (food==null) { 42 | throw new FoodNotExistException("id为%d的food不存在"); 43 | } 44 | food.setName(name); 45 | food.setPrice(price); 46 | food.setLogoUrl(logo); 47 | foodMapper.update(food); 48 | } 49 | 50 | @Transactional(rollbackFor = Exception.class) 51 | @Override 52 | public void deleteItem(Integer foodId) throws FoodNotExistException { 53 | Food food = foodMapper.getById(foodId); 54 | if (food==null) { 55 | throw new FoodNotExistException("id为%d的food不存在"); 56 | } 57 | foodMapper.deleteById(foodId); 58 | } 59 | 60 | @Transactional(rollbackFor = Exception.class) 61 | @Override 62 | public void addItem(String name, float price, String logo, Integer restaurantId) throws BrandNotFoundException { 63 | Restaurant restaurant = restaurantMapper.getById(restaurantId); 64 | if (restaurant==null) { 65 | throw new BrandNotFoundException(String.format("id为%d的品牌不存在", restaurantId)); 66 | } 67 | Food food = new Food(); 68 | food.setName(name); 69 | food.setPrice(price); 70 | food.setRestaurantId(restaurantId); 71 | foodMapper.insert(food); 72 | } 73 | 74 | @Override 75 | public List getAllMenu() { 76 | return restaurantMapper.getAll(); 77 | } 78 | 79 | @Transactional(rollbackFor = Exception.class) 80 | @Override 81 | public void updateMenu(Integer id, String name, MultipartFile logo, String description) throws BrandNotFoundException, IOException { 82 | Restaurant restaurant = restaurantMapper.getById(id); 83 | if (restaurant==null) { 84 | throw new BrandNotFoundException(String.format("id为%d的品牌不存在", id)); 85 | } 86 | GOssUtil.deleteObjectInOss(restaurant.getLogo()); 87 | String filename = String.valueOf(System.currentTimeMillis()); 88 | String url = GOssUtil.putObjectToOss(logo.getInputStream(), logo.getSize(), logo.getContentType(), FOLDER, filename, BUCKET_NAME); 89 | restaurant.setDescription(description); 90 | restaurant.setLogo(url); 91 | restaurant.setName(name); 92 | restaurantMapper.update(restaurant); 93 | } 94 | 95 | @Transactional(rollbackFor = Exception.class) 96 | @Override 97 | public void deleteMenu(Integer restaurantId) throws BrandNotFoundException { 98 | Restaurant restaurant = restaurantMapper.getById(restaurantId); 99 | if (restaurant==null) { 100 | throw new BrandNotFoundException(String.format("id为%d的品牌不存在", restaurantId)); 101 | } 102 | restaurantMapper.deleteById(restaurantId); 103 | GOssUtil.deleteObjectInOss(restaurant.getLogo()); 104 | } 105 | 106 | @Transactional(rollbackFor = Exception.class) 107 | @Override 108 | public void addMenu(String name, MultipartFile logo, String description) throws IOException { 109 | String filename = String.valueOf(System.currentTimeMillis()); 110 | String url = GOssUtil.putObjectToOss(logo.getInputStream(), logo.getSize(), logo.getContentType(), FOLDER, filename, BUCKET_NAME); 111 | Restaurant restaurant = new Restaurant(); 112 | restaurant.setName(name); 113 | restaurant.setLogo(url); 114 | restaurant.setDescription(description); 115 | restaurantMapper.insert(restaurant); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/impl/DefaultOrderFoodServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service.impl; 2 | 3 | import com.topschool.xm.dao.orderfood.FoodMapper; 4 | import com.topschool.xm.dao.orderfood.OrderLogMapper; 5 | import com.topschool.xm.dao.scratchcard.ScratchLogMapper; 6 | import com.topschool.xm.exception.FoodNotExistException; 7 | import com.topschool.xm.model.orderfood.Food; 8 | import com.topschool.xm.model.orderfood.OrderLog; 9 | import com.topschool.xm.model.orderfood.OrderPool; 10 | import com.topschool.xm.service.OrderFoodService; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | import org.springframework.transaction.annotation.Transactional; 14 | 15 | import javax.naming.NoPermissionException; 16 | import java.sql.Date; 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | @Transactional(rollbackFor = Exception.class) 23 | @Service 24 | public class DefaultOrderFoodServiceImpl implements OrderFoodService { 25 | 26 | @Autowired 27 | private OrderPool orderPool; 28 | 29 | @Autowired 30 | private OrderLogMapper orderLogMapper; 31 | 32 | @Autowired 33 | private FoodMapper foodMapper; 34 | 35 | @Autowired 36 | private ScratchLogMapper scratchLogMapper; 37 | 38 | public Map getFoodList() { 39 | Map result = new HashMap(); 40 | List foods = new ArrayList<>(); 41 | if (null == orderPool.getFoodList()) { 42 | result.put("systemStatus", false); 43 | result.put("foods", null); 44 | return result; 45 | } 46 | for (Food food : orderPool.getFoodList()) { 47 | foods.add(changeFoodInfoToMap(food)); 48 | } 49 | result.put("systemStatus", orderPool.getStatus()); 50 | result.put("foods", foods); 51 | return result; 52 | } 53 | 54 | public String booking(String userId, Integer foodId) throws NoPermissionException, FoodNotExistException { 55 | assert userId != null; 56 | assert foodId != null; 57 | Boolean flag = scratchLogMapper.isExist(userId, new Date(System.currentTimeMillis())); 58 | if (null == flag || !flag) { 59 | throw new NoPermissionException("今日未刮卡,不能点餐"); 60 | } 61 | if (!orderPool.inFoodList(foodId)) { 62 | throw new FoodNotExistException(String.format("id为%d的food不存在", foodId)); 63 | } 64 | OrderLog orderLog = new OrderLog(); 65 | orderLog.setFoodId(foodId); 66 | orderLog.setUserId(userId); 67 | orderLog.setCreateTime(System.currentTimeMillis()); 68 | orderLogMapper.insert(orderLog); 69 | return "订餐成功"; 70 | } 71 | 72 | public String cancel(String userId) { 73 | List orderLogs = orderLogMapper.getTodayOrderByUserId(userId); 74 | if (orderLogs == null || orderLogs.size() < 1) { 75 | return "还未订餐"; 76 | } 77 | for (OrderLog order : orderLogs) { 78 | orderLogMapper.delete(order.getUserId(), order.getFoodId()); 79 | } 80 | return "取消成功"; 81 | } 82 | 83 | public Map getUserStatus(String userId) { 84 | Map map = new HashMap(); 85 | map.put("id", userId); 86 | // map.put("name", ); 87 | map.put("scratchCardStatus", scratchLogMapper.isExist(userId, new Date(System.currentTimeMillis())) != null); 88 | map.put("orderFoodStatus", isExist(userId)); 89 | return map; 90 | } 91 | 92 | public Map getUsersOrder(String userId) throws FoodNotExistException { 93 | List orderLogs = orderLogMapper.getTodayOrderByUserId(userId); 94 | List orders = new ArrayList<>(); 95 | 96 | for (OrderLog order : orderLogs) { 97 | Food food = foodMapper.getById(order.getFoodId()); 98 | if (null == food) { 99 | throw new FoodNotExistException(String.format("id为%d的food不存在", order.getFoodId())); 100 | } 101 | orders.add(changeFoodInfoToMap(food)); 102 | } 103 | Map map = new HashMap(); 104 | map.put("id", userId); 105 | // map.put("name", "test_user"+userId); 106 | map.put("orderList", orders); 107 | return map; 108 | } 109 | 110 | @Override 111 | public void initOrderFoodSystem(int restaurantId) { 112 | List list = foodMapper.getByRestaurantId(restaurantId); 113 | orderPool.setFoodList(list); 114 | orderPool.setStatus(true); 115 | } 116 | 117 | @Override 118 | public boolean submit() throws Exception { 119 | 120 | return true; 121 | } 122 | 123 | @Override 124 | public boolean clean() { 125 | orderPool.setStatus(false); 126 | orderPool.setFoodList(null); 127 | // orderPool.setOrderList(null); 128 | return false; 129 | } 130 | 131 | private boolean isExist(String uid) { 132 | List orderLogs = orderLogMapper.getTodayOrderByUserId(uid); 133 | return null != orderLogs && orderLogs.size() > 0; 134 | } 135 | 136 | private Map changeFoodInfoToMap(Food food) { 137 | Map map = new HashMap(); 138 | map.put("id", food.getId()); 139 | map.put("name", food.getName()); 140 | map.put("price", food.getPrice()); 141 | map.put("difference", food.getPrice() > 20 ? food.getPrice() - 20 : 0); 142 | map.put("imageUrl", food.getLogoUrl()); 143 | return map; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/impl/DefaultPartnerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service.impl; 2 | 3 | import com.topschool.xm.dao.PartnerMapper; 4 | import com.topschool.xm.exception.UserNameNotFoundException; 5 | import com.topschool.xm.model.Partner; 6 | import com.topschool.xm.service.PartnerService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import javax.naming.NoPermissionException; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | @Service 16 | public class DefaultPartnerServiceImpl implements PartnerService { 17 | 18 | @Autowired 19 | private PartnerMapper partnerMapper; 20 | 21 | @Override 22 | public Map register(String uid, String username, String invitationCode, String openId, int area) { 23 | Map userInfo = new HashMap(); 24 | Partner partner = new Partner(); 25 | partner.setUid(uid); 26 | partner.setUsername(username); 27 | partner.setIsAdmin(false); 28 | partner.setOpenId(openId); 29 | partner.setCreateTime(System.currentTimeMillis()); 30 | partnerMapper.insert(partner); 31 | userInfo.put("username", username); 32 | userInfo.put("uid", uid); 33 | return userInfo; 34 | } 35 | 36 | @Override 37 | public String getUsername(Integer uid, String password) throws UserNameNotFoundException, NoPermissionException { 38 | Partner u = partnerMapper.getById(uid); 39 | if (null == u) { 40 | throw new UserNameNotFoundException("id不存在"); 41 | } 42 | if (!u.getIsAdmin()) { 43 | throw new NoPermissionException("普通用户无权登录管理系统"); 44 | } 45 | return u.getPassword().equals(password) ? u.getUsername() : null; 46 | } 47 | 48 | @Override 49 | public List getAllPartner() { 50 | return null; 51 | } 52 | 53 | @Override 54 | public void deletePartner(String uid) { 55 | 56 | } 57 | 58 | @Override 59 | public Map getUserInfoByOpenId(String openId) { 60 | Map userInfo = new HashMap(); 61 | Partner u = partnerMapper.getByOpenId(openId); 62 | if (null == u) { 63 | return null; 64 | } 65 | userInfo.put("uid", u.getUid()); 66 | userInfo.put("username", u.getUsername()); 67 | return userInfo; 68 | } 69 | 70 | @Override 71 | public boolean uidExist(String uid) { 72 | return partnerMapper.getByUid(uid) != null; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/service/impl/DefaultScratchCardServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service.impl; 2 | 3 | import com.topschool.xm.dao.PartnerMapper; 4 | import com.topschool.xm.dao.scratchcard.ScratchLogMapper; 5 | import com.topschool.xm.exception.ScratchCardException; 6 | import com.topschool.xm.model.Partner; 7 | import com.topschool.xm.model.scratchcard.Card; 8 | import com.topschool.xm.model.scratchcard.CardPool; 9 | import com.topschool.xm.model.scratchcard.ScratchLog; 10 | import com.topschool.xm.service.ScratchCardService; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | 14 | import java.util.*; 15 | 16 | @Service 17 | public class DefaultScratchCardServiceImpl implements ScratchCardService { 18 | 19 | private static final String IMAGE_URL_TEMPLATE = "http://ts-dingup-onlinetest.oss-cn-beijing.aliyuncs.com/img/shop/%d.jpg"; 20 | 21 | @Autowired 22 | private ScratchLogMapper scratchLogMapper; 23 | @Autowired 24 | private PartnerMapper partnerMapper; 25 | @Autowired 26 | private CardPool cardPool; 27 | 28 | public void initCardPool(Integer size) { 29 | if (cardPool.getPool() == null) { 30 | cardPool.init(size); 31 | } 32 | } 33 | 34 | public Integer scratch(String uid) throws ScratchCardException { 35 | if (getPartnerTodayStatus(uid)) { 36 | throw new ScratchCardException("today's log has exist"); 37 | } 38 | Integer result = cardPool.popFromPool(); 39 | // save into db 40 | ScratchLog scratchLog = new ScratchLog(); 41 | scratchLog.setUid(uid); 42 | scratchLog.setScratchDate(new java.sql.Date(System.currentTimeMillis())); 43 | scratchLog.setCreateDate(System.currentTimeMillis()); 44 | scratchLog.setResult(result); 45 | if (!scratchLogMapper.insert(scratchLog)) { 46 | throw new ScratchCardException("scratch fail"); 47 | } 48 | // push into toady's scratch log 49 | Card card = new Card(); 50 | Partner u = partnerMapper.getByUid(uid); 51 | card.setUid(uid); 52 | card.setNickname(u.getUsername()); 53 | card.setPrice(result); 54 | cardPool.getTodayList().add(card); 55 | if (result == 8) { 56 | cardPool.getTop2()[0] = card; 57 | } 58 | if (result == 6) { 59 | cardPool.getTop2()[1] = card; 60 | } 61 | if (result == 0) { 62 | cardPool.getLast2().add(card); 63 | } 64 | // sum 65 | cardPool.setTodayTotal(cardPool.getTodayTotal() + result); 66 | return result; 67 | } 68 | 69 | public boolean getPartnerTodayStatus(String uid) { 70 | ScratchLog param = new ScratchLog(); 71 | param.setUid(uid); 72 | param.setScratchDate(new java.sql.Date(System.currentTimeMillis())); 73 | 74 | return null != scratchLogMapper.getOnesScratchResult(param); 75 | } 76 | 77 | public List> getTodayResult(Integer page, Integer pageSize) { 78 | return changeList(cardPool.getTodayList()); 79 | } 80 | 81 | public List> getTodayTopList(Integer page, Integer pageSize) { 82 | return changeList(Arrays.asList(cardPool.getTop2())); 83 | } 84 | 85 | public List> getTodayLastList(Integer page, Integer pageSize) { 86 | return changeList(cardPool.getLast2()); 87 | } 88 | 89 | public List getTotalTopResult(Integer page, Integer pageSize) { 90 | return scratchLogMapper.getCurrentMouthTop(3); 91 | } 92 | 93 | public Map getScratchSummary(String id) { 94 | return null; 95 | } 96 | 97 | public Integer getTodayTotal(Date date) { 98 | return cardPool.getTodayTotal(); 99 | } 100 | 101 | private Map changeToMap(Card card) { 102 | Map map = new HashMap(); 103 | map.put("id", card.getUid()); 104 | map.put("nickname", card.getNickname()); 105 | map.put("money", card.getPrice()); 106 | map.put("imgUrl", String.format(IMAGE_URL_TEMPLATE, card.getPrice())); 107 | 108 | return map; 109 | } 110 | 111 | private List> changeList(List list) { 112 | List> result = new ArrayList>(list.size()); 113 | for (Card card : list) { 114 | if (card==null){ 115 | continue; 116 | } 117 | result.add(changeToMap(card)); 118 | } 119 | return result; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/task/ScratchCardTask.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.task; 2 | 3 | import org.springframework.scheduling.annotation.EnableScheduling; 4 | import org.springframework.scheduling.annotation.Scheduled; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @EnableScheduling 9 | public class ScratchCardTask { 10 | 11 | @Scheduled(cron = "0/5 * * * * ? ") 12 | public void initScratchCardPool(){ 13 | System.out.println("initScratchCardPool"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/util/AESUtil.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.util; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | import org.bouncycastle.jce.provider.BouncyCastleProvider; 5 | 6 | import javax.crypto.BadPaddingException; 7 | import javax.crypto.Cipher; 8 | import javax.crypto.IllegalBlockSizeException; 9 | import javax.crypto.NoSuchPaddingException; 10 | import javax.crypto.spec.IvParameterSpec; 11 | import javax.crypto.spec.SecretKeySpec; 12 | import java.io.UnsupportedEncodingException; 13 | import java.security.*; 14 | import java.security.spec.InvalidParameterSpecException; 15 | 16 | 17 | public class AESUtil { 18 | static { 19 | Security.addProvider(new BouncyCastleProvider()); 20 | } 21 | 22 | /** 23 | * AES解密 24 | * 25 | * @param data //密文,被加密的数据 26 | * @param key //秘钥 27 | * @param iv //偏移量 28 | * @param encodingFormat //解密后的结果需要进行的编码 29 | * @return 30 | */ 31 | public static String decrypt(String data, String key, String iv, String encodingFormat) { 32 | 33 | //被加密的数据 34 | byte[] dataByte = Base64.decodeBase64(data); 35 | //加密秘钥 36 | byte[] keyByte = Base64.decodeBase64(key); 37 | //偏移量 38 | byte[] ivByte = Base64.decodeBase64(iv); 39 | 40 | try { 41 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); 42 | Key spec = new SecretKeySpec(keyByte, "AES"); 43 | 44 | AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES"); 45 | parameters.init(new IvParameterSpec(ivByte)); 46 | 47 | cipher.init(Cipher.DECRYPT_MODE, spec, parameters); 48 | 49 | byte[] resultByte = cipher.doFinal(dataByte); 50 | if (null != resultByte && resultByte.length > 0) { 51 | return new String(resultByte, encodingFormat); 52 | } 53 | return null; 54 | } catch (NoSuchAlgorithmException | UnsupportedEncodingException | BadPaddingException | IllegalBlockSizeException | InvalidAlgorithmParameterException | InvalidKeyException | InvalidParameterSpecException | NoSuchPaddingException e) { 55 | e.printStackTrace(); 56 | } 57 | 58 | return null; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/util/HttpUtil.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.util; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | import java.net.HttpURLConnection; 10 | import java.net.URL; 11 | 12 | public class HttpUtil { 13 | public static JSONObject getJson(String url) { 14 | StringBuilder sb = new StringBuilder(); 15 | try { 16 | HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); 17 | // connection.connect(); 18 | BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); 19 | String line = null; 20 | while ((line = reader.readLine()) != null) { 21 | sb.append(line); 22 | } 23 | reader.close(); 24 | } catch (IOException e) { 25 | e.printStackTrace(); 26 | } 27 | return JSON.parseObject(sb.toString()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /server/src/main/java/com/topschool/xm/util/RandomUtil.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.util; 2 | 3 | import java.util.Collection; 4 | import java.util.Random; 5 | 6 | public class RandomUtil { 7 | 8 | public static int generationRandom(int min, int max) { 9 | Random random = new Random(); 10 | return Math.abs(random.nextInt() % (max + 1 - min)) + min; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /server/src/main/resources/configuration/application.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | classpath*:configuration/*.properties 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /server/src/main/resources/configuration/db.properties: -------------------------------------------------------------------------------- 1 | datasource.driverClass=com.mysql.jdbc.Driver 2 | datasource.url=jdbc:mysql://rm-2ze4tk0u850c64o60o.mysql.rds.aliyuncs.com:3306/ts_xiaomai?characterEncoding=UTF-8 3 | datasource.username=dbuser4test_dsxm 4 | datasource.password=dbuser4test_dsxm_20171014 5 | druid.filters=stat 6 | -------------------------------------------------------------------------------- /server/src/main/resources/configuration/mybatis-conf.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /server/src/main/resources/configuration/spring-mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | WriteNullListAsEmpty 17 | WriteMapNullValue 18 | WriteNullStringAsEmpty 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /server/src/main/resources/configuration/spring-mybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /server/src/main/resources/configuration/spring-task.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /server/src/main/resources/mapper/foodMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | insert into 18 | order_food 19 | (name, price, kind, img) 20 | values ( 21 | #{name}, #{price}, #{restaurantId},#{logoUrl} 22 | ) 23 | 24 | 25 | 26 | 27 | name=#{name}, 28 | 29 | 30 | price=#{price}, 31 | 32 | 33 | kind=#{restaurantId}, 34 | 35 | 36 | img=#{logoUrl}, 37 | 38 | 39 | 40 | 41 | DELETE FROM order_food WHERE id=#{id} 42 | 43 | 46 | 49 | 52 | -------------------------------------------------------------------------------- /server/src/main/resources/mapper/orderLogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | insert into order_log (user_id, food_id, create_time) values (#{userId},#{foodId},#{createTime}); 17 | 18 | 19 | DELETE FROM order_log WHERE user_id=#{uid} AND food_id=#{foodId} AND to_days(from_unixtime(create_time DIV 1000))=to_days(curdate()); 20 | 21 | 24 | 27 | 30 | 33 | 38 | 42 | -------------------------------------------------------------------------------- /server/src/main/resources/mapper/partnerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | insert into user_info (uid, username, password, open_id, area, is_admin, create_time) 20 | values 21 | (#{uid}, #{username}, #{password}, #{openId}, #{area}, #{isAdmin}, #{createTime}); 22 | 23 | 27 | 31 | 35 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /server/src/main/resources/mapper/restaurantMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | insert into restaurant (name, logo, description) values (#{name}, #{logo}, #{description}); 17 | 18 | 19 | 20 | 21 | name = #{name}, 22 | 23 | 24 | logo = #{logo}, 25 | 26 | 27 | description=#{description}, 28 | 29 | 30 | 31 | 32 | DELETE FROM restaurant WHERE id=#{id} 33 | 34 | 37 | 40 | -------------------------------------------------------------------------------- /server/src/main/resources/mapper/scratchLogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | insert into scratch_log (wx_id, result, scratch_date, create_time) 19 | values (#{uid},#{result},#{scratchDate},#{createDate}); 20 | 21 | 22 | 25 | 26 | 29 | 30 | 33 | 36 | 45 | 48 | -------------------------------------------------------------------------------- /server/src/main/webapp/WEB-INF/templates/admin/foodList.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /server/src/main/webapp/WEB-INF/templates/admin/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | Document 9 | 10 | 11 |

hello world

12 |

13 | 14 |
15 | 初始化订餐: 16 |
17 | 20 | 21 |
22 |
23 | 24 | -------------------------------------------------------------------------------- /server/src/main/webapp/WEB-INF/templates/admin/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | Document 9 | 10 | 11 |
12 | 13 | 14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /server/src/main/webapp/WEB-INF/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | Document 9 | 10 | 11 | 12 |

world

13 | 14 | -------------------------------------------------------------------------------- /server/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | Archetype Created Web Application 10 | 11 | 12 | dispatcher 13 | org.springframework.web.servlet.DispatcherServlet 14 | 15 | contextConfigLocation 16 | classpath*:configuration/application.xml 17 | 18 | 19 | 20 | dispatcher 21 | / 22 | 23 | 24 | 25 | druidStatView 26 | com.alibaba.druid.support.http.StatViewServlet 27 | 28 | exclusions 29 | *.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/* 30 | 31 | 32 | 33 | druidStatView 34 | /druid/* 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | public class BaseTest { 7 | private ApplicationContext context; 8 | 9 | public BaseTest(){ 10 | context = new ClassPathXmlApplicationContext("classpath:application.xml"); 11 | } 12 | 13 | public T getBean(String clazz){ 14 | return (T)this.context.getBean(clazz); 15 | } 16 | 17 | public T getBean(Class clazz){ 18 | return (T)this.context.getBean(clazz); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/dao/ScratchLogMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao; 2 | 3 | import com.topschool.xm.BaseTest; 4 | import com.topschool.xm.dao.scratchcard.ScratchLogMapper; 5 | import com.topschool.xm.model.scratchcard.ScratchLog; 6 | import org.junit.Test; 7 | 8 | import java.sql.Date; 9 | import java.util.Map; 10 | import java.util.Random; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | public class ScratchLogMapperTest extends BaseTest { 15 | 16 | private ScratchLogMapper scratchLogMapper = this.getBean(ScratchLogMapper.class); 17 | 18 | @Test 19 | public void insert() { 20 | Random random = new Random(); 21 | Date date = new Date(System.currentTimeMillis()); 22 | 23 | for (int i = 1; i < 4; i++) { 24 | for (int j = 1; j < 28; j++) { 25 | ScratchLog scratchLog = new ScratchLog(); 26 | for (int k = 0; k < 20; k++) { 27 | scratchLog.setUid("wx_test" + k); 28 | scratchLog.setResult(Math.abs(random.nextInt() % 10)); 29 | date.setMonth(i); 30 | date.setDate(j); 31 | scratchLog.setScratchDate(date); 32 | scratchLog.setCreateDate(System.currentTimeMillis()); 33 | assert scratchLogMapper.insert(scratchLog); 34 | } 35 | } 36 | } 37 | } 38 | 39 | @Test 40 | public void getOnesScratchResult() { 41 | ScratchLog scratchLog = new ScratchLog(); 42 | scratchLog.setUid("wx_test1"); 43 | scratchLog.setScratchDate(new java.sql.Date(System.currentTimeMillis())); 44 | assertNotNull(scratchLogMapper.getOnesScratchResult(scratchLog)); 45 | System.out.println(); 46 | } 47 | 48 | @Test 49 | public void getCurrentMouthScratchListByWxId() { 50 | 51 | assertNotNull(scratchLogMapper.getCurrentMouthScratchListByWxId("wx_test1")); 52 | } 53 | 54 | @Test 55 | public void getTodayScratchResultList() { 56 | assertNotNull(scratchLogMapper.getTodayScratchResultList()); 57 | } 58 | 59 | @Test 60 | public void getMouthCountByWxId() { 61 | assertNotNull(scratchLogMapper.getMouthCountByWxId("wx_test1")); 62 | } 63 | 64 | @Test 65 | public void getCurrentMouthTop() { 66 | for (Map map : scratchLogMapper.getCurrentMouthTop(3)) { 67 | System.out.println(map.get("id")); 68 | System.out.println(map.get("money")); 69 | System.out.println(map.get("username")); 70 | } 71 | } 72 | 73 | @Test 74 | public void randomTest() { 75 | System.out.println(new Date(System.currentTimeMillis()).toString()); 76 | } 77 | 78 | @Test 79 | public void isExist(){ 80 | Boolean flog = scratchLogMapper.isExist("2", new Date(System.currentTimeMillis())); 81 | System.out.printf(""); 82 | } 83 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/dao/orderfood/FoodMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao.orderfood; 2 | 3 | import com.topschool.xm.BaseTest; 4 | import com.topschool.xm.model.orderfood.Food; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | public class FoodMapperTest extends BaseTest{ 10 | 11 | private FoodMapper foodMapper = this.getBean(FoodMapper.class); 12 | 13 | @Test 14 | public void insert() { 15 | } 16 | 17 | @Test 18 | public void getById() { 19 | Food food = foodMapper.getById(12); 20 | System.out.println(); 21 | } 22 | 23 | @Test 24 | public void getAll() { 25 | } 26 | 27 | @Test 28 | public void deleteById() { 29 | } 30 | 31 | @Test 32 | public void update() { 33 | } 34 | 35 | @Test 36 | public void getByRestaurantId() { 37 | } 38 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/dao/orderfood/OrderLogMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao.orderfood; 2 | 3 | import com.topschool.xm.BaseTest; 4 | import com.topschool.xm.model.orderfood.OrderLog; 5 | import org.junit.Test; 6 | 7 | import java.sql.Date; 8 | import java.util.List; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | public class OrderLogMapperTest extends BaseTest { 13 | 14 | OrderLogMapper orderLogMapper = getBean(OrderLogMapper.class); 15 | 16 | @Test 17 | public void insert() { 18 | OrderLog orderLog = new OrderLog(); 19 | orderLog.setFoodId(1); 20 | orderLog.setUserId("abc"); 21 | orderLog.setCreateTime(System.currentTimeMillis()); 22 | assert orderLogMapper.insert(orderLog); 23 | } 24 | 25 | @Test 26 | public void exist() { 27 | OrderLog orderLog = new OrderLog(); 28 | orderLog.setUserId("abcd"); 29 | orderLog.setCreateTime(System.currentTimeMillis()); 30 | boolean flag = orderLogMapper.exist(orderLog); 31 | assert flag; 32 | } 33 | 34 | @Test 35 | public void getByRestaurantId() { 36 | assertNotNull(orderLogMapper.getByRestaurantId(2)); 37 | } 38 | 39 | @Test 40 | public void getByDate() { 41 | assertNotNull(orderLogMapper.getByDate(new Date(System.currentTimeMillis()))); 42 | } 43 | 44 | @Test 45 | public void getByUserId() { 46 | assertNotNull(orderLogMapper.getByUserId("abc")); 47 | } 48 | 49 | @Test 50 | public void getByFoodId() { 51 | assertNotNull(orderLogMapper.getByFoodId(1)); 52 | } 53 | 54 | @Test 55 | public void getTodayOrderByUserId(){ 56 | List orderLogs = orderLogMapper.getTodayOrderByUserId("2"); 57 | System.out.println(); 58 | } 59 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/dao/orderfood/RestaurantMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.dao.orderfood; 2 | 3 | import com.topschool.xm.BaseTest; 4 | import com.topschool.xm.model.orderfood.Restaurant; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | public class RestaurantMapperTest extends BaseTest { 10 | 11 | private RestaurantMapper restaurantMapper = getBean(RestaurantMapper.class); 12 | 13 | @Test 14 | public void insert() { 15 | Restaurant restaurant = new Restaurant(); 16 | restaurant.setName("A"); 17 | restaurant.setLogo("a.png"); 18 | restaurant.setDescription("very delicious"); 19 | assert restaurantMapper.insert(restaurant); 20 | } 21 | 22 | @Test 23 | public void getById() { 24 | Restaurant r = restaurantMapper.getById(1); 25 | assertNotNull(r); 26 | } 27 | 28 | @Test 29 | public void getAll() { 30 | assertNotNull(restaurantMapper.getAll()); 31 | } 32 | 33 | @Test 34 | public void deleteById() { 35 | assert restaurantMapper.deleteById(1); 36 | } 37 | 38 | @Test 39 | public void update() { 40 | Restaurant restaurant = new Restaurant(); 41 | restaurant.setId(2); 42 | restaurant.setName("A"); 43 | restaurant.setLogo("a.png"); 44 | restaurant.setDescription("good"); 45 | assert restaurantMapper.update(restaurant); 46 | } 47 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/service/impl/DefaultOrderFoodServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service.impl; 2 | 3 | import com.topschool.xm.BaseTest; 4 | import com.topschool.xm.model.orderfood.OrderPool; 5 | import com.topschool.xm.service.OrderFoodService; 6 | import org.junit.Test; 7 | 8 | public class DefaultOrderFoodServiceImplTest extends BaseTest { 9 | 10 | OrderFoodService orderFoodService = this.getBean(DefaultOrderFoodServiceImpl.class); 11 | OrderPool orderPool = this.getBean(OrderPool.class); 12 | 13 | @Test 14 | public void getFoodList() { 15 | } 16 | 17 | @Test 18 | public void booking() { 19 | } 20 | 21 | @Test 22 | public void cancel() { 23 | } 24 | 25 | @Test 26 | public void getUserStatus() { 27 | } 28 | 29 | @Test 30 | public void getUsersOrder() { 31 | } 32 | 33 | @Test 34 | public void initOrderFoodSystem() { 35 | orderFoodService.initOrderFoodSystem(1); 36 | System.out.println(); 37 | } 38 | 39 | @Test 40 | public void submit() { 41 | } 42 | 43 | @Test 44 | public void clean() { 45 | } 46 | 47 | @Test 48 | public void isExist() { 49 | } 50 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/service/impl/DefaultPartnerServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service.impl; 2 | 3 | import com.topschool.xm.BaseTest; 4 | import com.topschool.xm.service.PartnerService; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | public class DefaultPartnerServiceImplTest extends BaseTest { 10 | 11 | PartnerService partnerService = getBean(DefaultPartnerServiceImpl.class); 12 | 13 | @Test 14 | public void register() { 15 | partnerService.register("abcdefg", "张三", "xxxx", "xxxxxxx", 1); 16 | } 17 | 18 | @Test 19 | public void getAllPartner() { 20 | } 21 | 22 | @Test 23 | public void deletePartner() { 24 | } 25 | 26 | @Test 27 | public void isExist(){ 28 | assert partnerService.uidExist("abcdefg"); 29 | } 30 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/service/impl/DefaultScratchCardServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.service.impl; 2 | 3 | import com.topschool.xm.BaseTest; 4 | import com.topschool.xm.exception.ScratchCardException; 5 | import com.topschool.xm.model.scratchcard.CardPool; 6 | import com.topschool.xm.service.ScratchCardService; 7 | import org.junit.Test; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Qualifier; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | public class DefaultScratchCardServiceImplTest extends BaseTest { 14 | 15 | private ScratchCardService scratchCardService = this.getBean(DefaultScratchCardServiceImpl.class); 16 | 17 | private CardPool cardPool = this.getBean(CardPool.class); 18 | 19 | @Test 20 | public void initCardPool() { 21 | scratchCardService.initCardPool(100); 22 | assert cardPool.getPool().size()==100; 23 | } 24 | 25 | @Test 26 | public void scratch() throws ScratchCardException { 27 | cardPool.init(100); 28 | scratchCardService.scratch("hello-world"); 29 | System.out.println(); 30 | } 31 | 32 | @Test 33 | public void getPartnerTodayStatus() { 34 | assert scratchCardService.getPartnerTodayStatus("hello-world"); 35 | } 36 | 37 | @Test 38 | public void getTodayResult() { 39 | } 40 | 41 | @Test 42 | public void getTodayTopList() { 43 | } 44 | 45 | @Test 46 | public void getTodayLastList() { 47 | } 48 | 49 | @Test 50 | public void getTotalTopResult() { 51 | } 52 | 53 | @Test 54 | public void getScratchSummary() { 55 | } 56 | 57 | @Test 58 | public void getTodayTotal() { 59 | } 60 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/util/AESTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.util; 2 | 3 | import org.junit.Test; 4 | 5 | 6 | public class AESTest { 7 | @Test 8 | public void aesDecodeTest() throws Exception { 9 | String data = "lS7DgKOIfBcmvRrdouisAfgjmO3e1lZFGuSSxnV78aZCPdDiB+YQYoALK1PRq4GdnEcDogks1vG7TH4jE9fpXr/NXiy+lAPzctVnHSrQ17aBrNgXT0Te+gZviC3DGa0Gu5CVy0pxSRXLGiUgaCQ6TKTU3+LoZQ+GInYc5KSZqidtqageOLB838NxmS2tFq568ibtAm1NaBzp7XwWKY9+MDzitrm74qXfjgTHor04FHHJt5Y372xUFSeCLgUufE+F/lwPX/1ucYupNhggh+khZ8y3HNUefN43Kyb0cvXu7Ank48QZaihQL8YxyBA3hHIOa0Q8787tbMbvyRnUFmjLRKzgR2vZsu8zDOE2ivUX7zUZMcEV2A18WK3lZXzF4273VtI/Bd0nTK5dQ/KX432kHZaSSwhdS1ggUOaNKDa2QI9cXVzWpzcCHcB8HDRbvAgZrHEfbdq5qd91VJYyzqGLVO25S9DtdGT5Q+KR8R4up34MAw4+v4m+csnZ7dYyjbralOuHCNcrEo9KjjsKR5J96g=="; 10 | String sessionKey = "ykjQ+7B+5w+d49D0AEDrjA=="; 11 | String iv = "iL1DTnPx6OhosLn+uo9Aqg=="; 12 | String result = AESUtil.decrypt(data, sessionKey, iv, "utf-8"); 13 | System.out.println(result); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/util/HttpUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.util; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | public class HttpUtilTest { 8 | 9 | @Test 10 | public void getJson() { 11 | String url = "http://api.map.baidu.com/telematics/v3/weather?location=%E6%88%90%E9%83%BD&output=json&ak=rnm8udmHdWaHFWZTO2tuTiG8"; 12 | Object o = HttpUtil.getJson(url); 13 | System.out.println(o); 14 | } 15 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/util/RandomUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.util; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | public class RandomUtilTest { 8 | 9 | @Test 10 | public void generationRandom() { 11 | for (int i = 0; i < 10; i++) { 12 | System.out.println(RandomUtil.generationRandom(3, 5)); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /server/src/test/java/com/topschool/xm/util/TimeTest.java: -------------------------------------------------------------------------------- 1 | package com.topschool.xm.util; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Date; 6 | 7 | public class TimeTest { 8 | @Test 9 | public void test(){ 10 | System.out.println(new Date(1517905864928L)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /server/src/test/resources/application.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | classpath*:configuration/*.properties 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /server/src/test/resources/mybatis-conf.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /server/src/test/resources/spring-mybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /订餐打卡系统/app.js: -------------------------------------------------------------------------------- 1 | //app.js 2 | var m = 0 3 | App({ 4 | onLaunch: function () { 5 | // 展示本地存储能力 6 | var logs = wx.getStorageSync('logs') || [] 7 | logs.unshift(Date.now()) 8 | wx.setStorageSync('logs', logs) 9 | // wx.getUserInfo({ 10 | // success: function (res) { 11 | // console.log(res) 12 | // } 13 | // }) 14 | // 登录 15 | wx.login({ 16 | success: res => { 17 | var self = this; 18 | // console.log(res.code) 19 | // 发送 res.code 到后台换取 openId, sessionKey, unionId 20 | var name = wx.getStorageSync('uid') 21 | console.log(name+'asd') 22 | if (name == '' || name == null || wx.getStorageSync('uid') !=wx.getStorageSync('key')){ 23 | console.log('qwerty') 24 | wx.request({ 25 | url: 'http://192.168.3.27:8080/user/get_uid', 26 | data: { 27 | "code": res.code 28 | }, 29 | header: { 30 | 'Content-Type': 'application/x-www-form-urlencoded' 31 | }, 32 | method: 'POST', 33 | success: function (res_1) { 34 | console.log(res_1.data) 35 | var snc=wx.setStorageSync('uid', res_1.data) 36 | wx.redirectTo({ 37 | url: '../login/login', 38 | }) 39 | }, 40 | fail:function(err){ 41 | console.log(err) 42 | } 43 | }) 44 | }else{ 45 | 46 | wx.redirectTo({ 47 | url: '../homepage/homepage', 48 | }) 49 | } 50 | 51 | } 52 | }) 53 | // 获取用户信息 54 | wx.getSetting({ 55 | success: res => { 56 | if (res.authSetting['scope.userInfo']) { 57 | // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 58 | wx.getUserInfo({ 59 | success: res => { 60 | // 可以将 res 发送给后台解码出 unionId 61 | this.globalData.userInfo = res.userInfo 62 | // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 63 | // 所以此处加入 callback 以防止这种情况 64 | if (this.userInfoReadyCallback) { 65 | this.userInfoReadyCallback(res) 66 | } 67 | } 68 | }) 69 | } 70 | } 71 | }) 72 | }, 73 | globalData: { 74 | userInfo: null, 75 | } 76 | }) -------------------------------------------------------------------------------- /订餐打卡系统/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages": [ 3 | "pages/waiting/waiting", 4 | "pages/login/login", 5 | "pages/homepage/homepage", 6 | "pages/dinnerOrder/dinnerOrder", 7 | "pages/scratch_card/scratch_card", 8 | "pages/index/index", 9 | "pages/logs/logs" 10 | ], 11 | "window": { 12 | "backgroundTextStyle": "light", 13 | "navigationBarBackgroundColor": "#DD7042", 14 | "navigationBarTitleText": "顶上小卖部", 15 | "navigationBarTextStyle": "white" 16 | } 17 | } -------------------------------------------------------------------------------- /订餐打卡系统/app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | .container { 3 | height: 100%; 4 | display: flex; 5 | flex-direction: column; 6 | align-items: center; 7 | justify-content: space-between; 8 | padding: 200rpx 0; 9 | box-sizing: border-box; 10 | } 11 | -------------------------------------------------------------------------------- /订餐打卡系统/images/001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/001.jpg -------------------------------------------------------------------------------- /订餐打卡系统/images/001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/001.png -------------------------------------------------------------------------------- /订餐打卡系统/images/002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/002.jpg -------------------------------------------------------------------------------- /订餐打卡系统/images/002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/002.png -------------------------------------------------------------------------------- /订餐打卡系统/images/003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/003.png -------------------------------------------------------------------------------- /订餐打卡系统/images/004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/004.png -------------------------------------------------------------------------------- /订餐打卡系统/images/005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/005.png -------------------------------------------------------------------------------- /订餐打卡系统/images/006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/006.png -------------------------------------------------------------------------------- /订餐打卡系统/images/007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topschool/Xiaomai/65ddf7085cc2b6a471de80364482b0ceae2c6a4c/订餐打卡系统/images/007.png -------------------------------------------------------------------------------- /订餐打卡系统/pages/dinnerOrder/dinnerOrder.js: -------------------------------------------------------------------------------- 1 | var num = 0; 2 | const app = getApp(); 3 | // var userNummber ='abcdefg'; 4 | var userNummber=wx.getStorageSync('uid'); 5 | console.log(userNummber) 6 | var number = new Array(); 7 | var num_tap = 0; 8 | var str = new Array(); 9 | Page({ 10 | 11 | /** 12 | * 页面的初始数据 13 | */ 14 | data: { 15 | today: '', 16 | food: '', 17 | dinner_status: '', 18 | item_1: "circle", 19 | money: 0, 20 | orderFood_1: [], 21 | orderFood_2: '', 22 | shuliang: '', 23 | finished: '', 24 | check: "", 25 | length: '' 26 | }, 27 | toGet() { 28 | var self = this; 29 | wx.request({ 30 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/user_status', 31 | data: { 32 | uid: wx.getStorageSync('uid'), //1挂卡请求 33 | }, 34 | header: { 35 | 'Content-Type': 'application/x-www-form-urlencoded' 36 | }, 37 | method: 'GET', 38 | success: function (res) { 39 | console.log(res.data) 40 | if (res.data.orderFoodStatus == false) { 41 | self.setData({ 42 | dinner_status: 'order_begin', 43 | }) 44 | } else { 45 | self.setData({ 46 | dinner_status: 'order_finished', 47 | }) 48 | } 49 | }, 50 | fail: function (err) { 51 | 52 | } 53 | }) 54 | }, 55 | 56 | /** 57 | * 生命周期函数--监听页面加载 58 | */ 59 | onLoad: function (options) { 60 | 61 | }, 62 | 63 | /** 64 | * 生命周期函数--监听页面初次渲染完成 65 | */ 66 | onReady: function () { 67 | 68 | }, 69 | 70 | /** 71 | * 生命周期函数--监听页面显示 72 | */ 73 | onShow: function () { 74 | var self = this; 75 | self.checkDinnerStatus() 76 | // self.taphandle() 77 | // self.toGet() 78 | }, 79 | 80 | /** 81 | * 生命周期函数--监听页面隐藏 82 | */ 83 | onHide: function () { 84 | 85 | }, 86 | 87 | /** 88 | * 生命周期函数--监听页面卸载 89 | */ 90 | onUnload: function () { 91 | 92 | }, 93 | 94 | /** 95 | * 页面相关事件处理函数--监听用户下拉动作 96 | */ 97 | onPullDownRefresh: function () { 98 | 99 | }, 100 | 101 | /** 102 | * 页面上拉触底事件的处理函数 103 | */ 104 | onReachBottom: function () { 105 | 106 | }, 107 | 108 | /** 109 | * 用户点击右上角分享 110 | */ 111 | onShareAppMessage: function () { 112 | 113 | }, 114 | checkDinnerStatus: function () { 115 | var self = this; 116 | wx.request({ 117 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/user_status', 118 | data: { 119 | uid: wx.getStorageSync('uid'), 120 | }, 121 | header: { 122 | 'Content-Type': 'application/x-www-form-urlencoded' 123 | }, 124 | method: 'GET', 125 | success: function (res) { 126 | console.log(res.data.scratchCardStatus) 127 | if (res.data.scratchCardStatus == true) { 128 | wx.request({ 129 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/food_list', 130 | data: { 131 | uid: wx.getStorageSync('uid'), 132 | }, 133 | header: { 134 | 'Content-Type': 'application/x-www-form-urlencoded' 135 | }, 136 | method: 'GET', 137 | success: function (res_1) { 138 | console.log(res_1.data); 139 | console.log(res_1.data.systemStatus); 140 | if (res_1.data.systemStatus == true) { 141 | console.log(res_1.data) 142 | if (res.data.orderFoodStatus == false) { 143 | console.log(123) 144 | self.setData({ 145 | food: res_1, 146 | dinner_status: 'order_begin', 147 | }) 148 | } else { 149 | wx.request({ 150 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/user_order', 151 | data: { 152 | uid: wx.getStorageSync('uid'), 153 | }, 154 | header: { 155 | 'Content-Type': 'application/x-www-form-urlencoded' 156 | }, 157 | method: 'GET', 158 | success: function (res_3) { 159 | console.log(res_3.data) 160 | self.setData({ 161 | orderFood_2: res_3, 162 | dinner_status: 'order_finished', 163 | }) 164 | }, 165 | fail: function (err) { 166 | } 167 | }) 168 | } 169 | console.log(res_1) 170 | } else if (res_1.data.systemStatus == false) { 171 | self.setData({ 172 | // food: res_1, 173 | dinner_status: 'order_waiting' 174 | }) 175 | } 176 | 177 | }, 178 | fail: function (err) { 179 | } 180 | }) 181 | } else if (res.data.scratchCardStatus == null) { 182 | wx.request({ 183 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/food_list', 184 | data: { 185 | uid: wx.getStorageSync('uid'), 186 | }, 187 | header: { 188 | 'Content-Type': 'application/x-www-form-urlencoded' 189 | }, 190 | method: 'GET', 191 | success: function (res_2) { 192 | // console.log(res_2), 193 | self.setData({ 194 | // food: res_2, 195 | dinner_status: 'needscratchCard' 196 | }) 197 | }, 198 | fail: function (err) { 199 | } 200 | }) 201 | } 202 | }, 203 | fail: function (err) { 204 | } 205 | }) 206 | 207 | }, 208 | bindtaphandle: function (e) { 209 | var self = this;console.log 210 | wx.request({ 211 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/food_list', 212 | data: { 213 | uid: wx.getStorageSync('uid'), 214 | }, 215 | header: { 216 | 'Content-Type': 'application/x-www-form-urlencoded' 217 | }, 218 | method: 'GET', 219 | success: function (res_2) { 220 | if (e.detail.value == true) { 221 | console.log(e.currentTarget.dataset.index) 222 | number[num_tap] = res_2.data.foods[e.currentTarget.dataset.index].id; 223 | num_tap++; 224 | } else { 225 | for (var i = 0; i < number.length; i++) { 226 | if (number[i] == (res_2.data.foods[e.currentTarget.dataset.index].id)) { 227 | number.splice(i, 1); 228 | } 229 | } 230 | num_tap--; 231 | } 232 | } 233 | }) 234 | 235 | }, 236 | taphandle: function () { 237 | var self = this; 238 | var number_new=[]; 239 | for (var i = 0; i < number.length; i++) { 240 | if (typeof (number[i]) != 'undefined') { 241 | number_new.push(number[i]); 242 | } 243 | } 244 | console.log(number) 245 | wx.request({ 246 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/foods_booking', 247 | data: { 248 | uid: wx.getStorageSync('uid'), 249 | foods: number_new 250 | }, 251 | header: { 252 | 'Content-Type': 'application/x-www-form-urlencoded' 253 | }, 254 | method: 'POST', 255 | success: function (res_2) { 256 | console.log(111) 257 | wx.request({ 258 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/user_order', 259 | data: { 260 | uid: wx.getStorageSync('uid'), 261 | }, 262 | header: { 263 | 'Content-Type': 'application/x-www-form-urlencoded' 264 | }, 265 | method: 'GET', 266 | success: function (res_3) { 267 | console.log(res_3.data) 268 | self.setData({ 269 | orderFood_2: res_3, 270 | 271 | }) 272 | }, 273 | fail: function (err) { 274 | } 275 | }) 276 | }, 277 | fail: function (err) { 278 | } 279 | }) 280 | self.setData({ 281 | dinner_status: 'order_finished' 282 | }) 283 | }, 284 | tapCancleHandle: function () { 285 | var self = this; 286 | number.splice(0, number.length); 287 | console.log(number) 288 | wx.request({ 289 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/cancel', 290 | data: { 291 | uid: wx.getStorageSync('uid'), 292 | }, 293 | header: { 294 | 'Content-Type': 'application/x-www-form-urlencoded' 295 | }, 296 | method: 'POST', 297 | success: function (res) { 298 | wx.request({ 299 | url: 'http://192.168.3.27:8080/wechat_applet_api/order_food/food_list', 300 | data: { 301 | uid: wx.getStorageSync('uid'), 302 | }, 303 | header: { 304 | 'Content-Type': 'application/x-www-form-urlencoded' 305 | }, 306 | method: 'GET', 307 | success: function (res_2) { 308 | // console.log(res_2), 309 | self.setData({ 310 | food: res_2, 311 | }) 312 | }, 313 | fail: function (err) { 314 | } 315 | }) 316 | self.setData({ 317 | dinner_status: 'order_begin', 318 | }) 319 | }, 320 | fail: function (err) { 321 | } 322 | }) 323 | } 324 | }) -------------------------------------------------------------------------------- /订餐打卡系统/pages/dinnerOrder/dinnerOrder.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /订餐打卡系统/pages/dinnerOrder/dinnerOrder.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 | 25 | 26 | {{food.data.foods[index].id}} 27 | 28 | 29 | {{food.data.foods[index].name}} 30 | 31 | 32 | {{food.data.foods[index].price}} 33 | 34 | 35 | {{food.data.foods[index].difference}} 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 订餐还未开始 46 | 47 | 48 | 49 | 50 | 51 | 订餐已经结束 52 | 53 | 54 | 55 | 56 | 57 | 订餐完成 58 | 59 | 60 | {{orderFood_2.data.orderList[index].name}} 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 您还未刮卡 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/dinnerOrder/dinnerOrder.wxss: -------------------------------------------------------------------------------- 1 | page { 2 | height: 100%; 3 | } 4 | 5 | .root { 6 | height: 100%; 7 | width: 100%; 8 | background-color: #d05744; 9 | } 10 | 11 | .header { 12 | display: flex; 13 | } 14 | .color{ 15 | /* background-color: #a6c0e5; */ 16 | } 17 | 18 | .item { 19 | flex: 1; 20 | flex-direction: row; 21 | text-align: center; 22 | background-color: #a6c0e5; 23 | } 24 | .icon{ 25 | margin-left: 30%; 26 | } 27 | .description{ 28 | margin-left: 40%; 29 | } 30 | .header_item { 31 | display: flex; 32 | height: 5%; 33 | align-items: center; 34 | border-top: 1px solid #a6c0e5; 35 | border-bottom: 1px solid #a6c0e5; 36 | } 37 | .checkbox{ 38 | margin-left: 8.5%; 39 | } 40 | .item_1 { 41 | flex: 1; 42 | display: flex; 43 | /* border-right: 1px solid #a6c0e5; */ 44 | } 45 | .click{ 46 | width: 100%; 47 | } 48 | .item_0{ 49 | flex: 0.5; 50 | /* border-right: 1px solid #a6c0e5; */ 51 | /* border-left: 1px solid #a6c0e5; */ 52 | } 53 | .text_1 { 54 | margin-left: 23%; 55 | font-size: 18px; 56 | } 57 | 58 | .item_1 { 59 | flex: 1; 60 | /* border-right: 1px solid #a6c0e5; */ 61 | border-left: 1px solid #a6c0e5; 62 | } 63 | .item_2 { 64 | flex: 3; 65 | border-right: 1px solid #a6c0e5; 66 | border-left: 1px solid #a6c0e5; 67 | } 68 | 69 | .text_2 { 70 | margin-left: 10%; 71 | font-size: 18px; 72 | } 73 | 74 | .item_3 { 75 | flex: 1; 76 | border-right: 1px solid #a6c0e5; 77 | } 78 | 79 | .text_3 { 80 | margin-left: 23%; 81 | font-size: 18px; 82 | } 83 | 84 | .item_4 { 85 | flex: 1; 86 | /* border-right: 1px solid #a6c0e5; */ 87 | } 88 | 89 | .text_4 { 90 | margin-left: 23%; 91 | font-size: 18px; 92 | } 93 | 94 | .order_list { 95 | display: flex; 96 | height: 5%; 97 | align-items: center; 98 | border-bottom: 1px solid #a6c0e5; 99 | } 100 | .bottom{ 101 | margin-top: 5%; 102 | width: 80%; 103 | margin-left: 10%; 104 | } 105 | .huanghang{ 106 | display: flex; 107 | flex-direction: column; 108 | } 109 | .orderFood_1{ 110 | display: flex; 111 | flex-direction: column; 112 | } 113 | .button{ 114 | height: 100%; 115 | width: 100%; 116 | } 117 | 118 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/homepage/homepage.js: -------------------------------------------------------------------------------- 1 | // pages/homepage/homepage.js 2 | Page({ 3 | 4 | /** 5 | * 页面的初始数据 6 | */ 7 | data: { 8 | 9 | }, 10 | 11 | /** 12 | * 生命周期函数--监听页面加载 13 | */ 14 | onLoad: function (options) { 15 | 16 | }, 17 | 18 | /** 19 | * 生命周期函数--监听页面初次渲染完成 20 | */ 21 | onReady: function () { 22 | 23 | }, 24 | 25 | /** 26 | * 生命周期函数--监听页面显示 27 | */ 28 | onShow: function () { 29 | 30 | }, 31 | 32 | /** 33 | * 生命周期函数--监听页面隐藏 34 | */ 35 | onHide: function () { 36 | 37 | }, 38 | 39 | /** 40 | * 生命周期函数--监听页面卸载 41 | */ 42 | onUnload: function () { 43 | 44 | }, 45 | 46 | /** 47 | * 页面相关事件处理函数--监听用户下拉动作 48 | */ 49 | onPullDownRefresh: function () { 50 | 51 | }, 52 | 53 | /** 54 | * 页面上拉触底事件的处理函数 55 | */ 56 | onReachBottom: function () { 57 | 58 | }, 59 | taphandle:function(){ 60 | wx.navigateTo({ 61 | url: '../scratch_card/scratch_card', 62 | }) 63 | }, 64 | bindtaphandle:function(){ 65 | wx.navigateTo({ 66 | url: "../dinnerOrder/dinnerOrder", 67 | }) 68 | }, 69 | /** 70 | * 用户点击右上角分享 71 | */ 72 | onShareAppMessage: function () { 73 | 74 | } 75 | }) -------------------------------------------------------------------------------- /订餐打卡系统/pages/homepage/homepage.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /订餐打卡系统/pages/homepage/homepage.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 顶上小卖部 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/homepage/homepage.wxss: -------------------------------------------------------------------------------- 1 | /* pages/homepage/homepage.wxss */ 2 | page{ 3 | height: 100%; 4 | } 5 | 6 | .root{ 7 | height: 100%; 8 | width: 100%; 9 | background-color: #d05744; 10 | } 11 | .header{ 12 | height: 20%; 13 | width: 100%; 14 | } 15 | .header_text{ 16 | margin-top: 50%; 17 | margin-left: 36%; 18 | } 19 | .Interface_scratchCard{ 20 | height: 20%; 21 | width: 80%; 22 | margin-left: 10%; 23 | /* margin-top: 20%; */ 24 | } 25 | .Interface_dinnerOrder{ 26 | height: 20%; 27 | width: 80%; 28 | margin-left: 10%; 29 | 30 | } 31 | .button{ 32 | height: 40%; 33 | width: 100%; 34 | border: 1px solid white; 35 | 36 | } -------------------------------------------------------------------------------- /订餐打卡系统/pages/index/index.js: -------------------------------------------------------------------------------- 1 | //index.js 2 | //获取应用实例 3 | const app = getApp() 4 | const ctx = wx.createCanvasContext('guagua_card') 5 | Page({ 6 | data: { 7 | word:'', 8 | }, 9 | onLoad: function () { 10 | var self = this; 11 | wx.request({ 12 | url: 'http://192.168.3.5:8080/test/get-api', 13 | // data: { 14 | // data: , 15 | // }, 16 | header: { 17 | 'Content-Type': 'application/x-www-form-urlencoded' 18 | }, 19 | method: 'GET', 20 | success: function (res) { 21 | console.log(res) 22 | self.setData({ 23 | word:res.data 24 | }) 25 | }, 26 | fail:function(err){ 27 | console.log(err) 28 | } 29 | }) 30 | }, 31 | 32 | 33 | }) 34 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/index/index.wxss: -------------------------------------------------------------------------------- 1 | page{ 2 | height: 100%; 3 | } 4 | .root{ 5 | height: 100%; 6 | width: 100%; 7 | background-color:#D05744; 8 | } 9 | .header{ 10 | display: flex; 11 | position:relative; 12 | /* align-items: center; 13 | align-content: center; */ 14 | border-top: 1px solid black; 15 | /* border-bottom: 1px solid black; */ 16 | height: 40%; 17 | width: 100%; 18 | background-color: white; 19 | } 20 | .header_image{ 21 | height: 100%; 22 | width:100%; 23 | background-color: #D05744; 24 | } 25 | .scratch{ 26 | height: 23%; 27 | width: 90%; 28 | background-color: blue; 29 | margin-left: 5%; 30 | position: absolute; 31 | top:25%; 32 | } 33 | .scratch .guagua_card{ 34 | height: 100%; 35 | width: 100%; 36 | 37 | } -------------------------------------------------------------------------------- /订餐打卡系统/pages/login/login.js: -------------------------------------------------------------------------------- 1 | // pages/login/login.js 2 | const app = getApp() 3 | var uid; 4 | var city_number; 5 | // uid = getApp().globalData.uid; 6 | // console.log(getApp().globalData.uid) 7 | Page({ 8 | 9 | /** 10 | * 页面的初始数据 11 | */ 12 | data: { 13 | // casArray: ['北京', '上海', '南京', '无锡'], 14 | // casIndex1:0, 15 | inputname:'', 16 | inputinvite:"", 17 | inputcity:'' 18 | }, 19 | 20 | /** 21 | * 生命周期函数--监听页面加载 22 | */ 23 | onLoad: function (options) { 24 | 25 | }, 26 | 27 | /** 28 | * 生命周期函数--监听页面初次渲染完成 29 | */ 30 | onReady: function () { 31 | 32 | }, 33 | 34 | /** 35 | * 生命周期函数--监听页面显示 36 | */ 37 | onShow: function () { 38 | // console.log(uid) 39 | 40 | }, 41 | 42 | /** 43 | * 生命周期函数--监听页面隐藏 44 | */ 45 | onHide: function () { 46 | 47 | }, 48 | 49 | /** 50 | * 生命周期函数--监听页面卸载 51 | */ 52 | onUnload: function () { 53 | 54 | }, 55 | 56 | /** 57 | * 页面相关事件处理函数--监听用户下拉动作 58 | */ 59 | onPullDownRefresh: function () { 60 | 61 | }, 62 | 63 | /** 64 | * 页面上拉触底事件的处理函数 65 | */ 66 | onReachBottom: function () { 67 | 68 | }, 69 | 70 | /** 71 | * 用户点击右上角分享 72 | */ 73 | onShareAppMessage: function () { 74 | 75 | }, 76 | nameInput:function(e){ 77 | this.setData({ 78 | inputname:e.detail.value 79 | }) 80 | }, 81 | inviteInput:function(e){ 82 | this.setData({ 83 | inputinvite:e.detail.value 84 | }) 85 | }, 86 | cityInput:function(e){ 87 | this.setData({ 88 | inputcity:e.detail.value 89 | }) 90 | }, 91 | taphandle: function (e) { 92 | var self = this; 93 | var uidplus = wx.getStorageSync('uid') 94 | console.log(wx.getStorageSync('uid')) 95 | console.log(self.data.inputname) 96 | console.log(self.data.inputinvite) 97 | console.log(self.data.inputcity) 98 | if (self.data.inputcity=='北京'){ 99 | city_number=0 100 | } else if(self.data.inputcity == '上海'){ 101 | city_number = 1 102 | } else if(self.data.inputcity == '无锡'){ 103 | city_number = 2 104 | } else if(self.data.inputcity == '南京'){ 105 | city_number = 3 106 | } 107 | wx.request({ 108 | url: 'http://192.168.3.27:8080/user/sign_up', 109 | data: { 110 | uid: uidplus, 111 | username: self.data.inputname, 112 | invitationCode: self.data.inputinvite, 113 | area: city_number 114 | }, 115 | header: { 116 | 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' 117 | }, 118 | method: 'POST', 119 | success: function (res) { 120 | console.log(res) 121 | // wx.setStorageSync('uid', res.data.uid) 122 | if (wx.getStorageSync('uid') == res.data.uid){ 123 | wx.setStorageSync('key', res.data.uid) 124 | wx.redirectTo({ 125 | url: '../homepage/homepage', 126 | }) 127 | }else{ 128 | wx.showModal({ 129 | title: '错误', 130 | content: res.data, 131 | }) 132 | } 133 | 134 | }, 135 | fail:function(err){ 136 | console.log(err) 137 | } 138 | }) 139 | } 140 | }) -------------------------------------------------------------------------------- /订餐打卡系统/pages/login/login.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /订餐打卡系统/pages/login/login.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 真实姓名 6 | 7 | 8 | 9 | 邀请码 10 | 11 | 12 | 13 | 所在地 14 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/login/login.wxss: -------------------------------------------------------------------------------- 1 | /* pages/login/login.wxss */ 2 | page{ 3 | height: 100%; 4 | } 5 | .root{ 6 | height: 100%; 7 | width: 100%; 8 | background-color: #d05744; 9 | } 10 | .headerPicture{ 11 | width: 100%; 12 | height: 45%; 13 | } 14 | .name{ 15 | display: flex; 16 | flex-direction: row; 17 | margin-left: 15%; 18 | margin-top: 10%; 19 | margin-bottom: 10%; 20 | } 21 | .name_text{ 22 | color:white; 23 | } 24 | .name_input{ 25 | height: 5%; 26 | width: 50%; 27 | border: 1px solid white; 28 | margin-left: 5%; 29 | /* background-color: #FA9919; */ 30 | } 31 | .invite{ 32 | display: flex; 33 | flex-direction: row; 34 | margin-left: 15%; 35 | margin-top: 10%; 36 | margin-bottom: 10%; 37 | } 38 | .invite_text{ 39 | color:white; 40 | } 41 | .invite_input{ 42 | margin-left: 11%; 43 | height: 5%; 44 | width: 50%; 45 | border: 1px solid white; 46 | /* background-color: #FA9919; */ 47 | } 48 | .city{ 49 | display: flex; 50 | flex-direction: row; 51 | margin-left: 15%; 52 | margin-top: 10%; 53 | margin-bottom: 10%; 54 | } 55 | .city_text{ 56 | color:white; 57 | } 58 | .city_input{ 59 | margin-left: 11%; 60 | height: 5%; 61 | width: 50%; 62 | border: 1px solid white; 63 | /* background-color: #FA9919; */ 64 | } 65 | .button{ 66 | margin-left: 60%; 67 | } 68 | .button_text{ 69 | width: 50%; 70 | } -------------------------------------------------------------------------------- /订餐打卡系统/pages/logs/logs.js: -------------------------------------------------------------------------------- 1 | //logs.js 2 | const util = require('../../utils/util.js') 3 | 4 | Page({ 5 | data: { 6 | logs: [] 7 | }, 8 | onLoad: function () { 9 | this.setData({ 10 | logs: (wx.getStorageSync('logs') || []).map(log => { 11 | return util.formatTime(new Date(log)) 12 | }) 13 | }) 14 | } 15 | }) 16 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/logs/logs.json: -------------------------------------------------------------------------------- 1 | { 2 | "navigationBarTitleText": "查看启动日志" 3 | } -------------------------------------------------------------------------------- /订餐打卡系统/pages/logs/logs.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{index + 1}}. {{log}} 5 | 6 | 7 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/logs/logs.wxss: -------------------------------------------------------------------------------- 1 | .log-list { 2 | display: flex; 3 | flex-direction: column; 4 | padding: 40rpx; 5 | } 6 | .log-item { 7 | margin: 10rpx; 8 | } 9 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/scratch_card/scratch_card.js: -------------------------------------------------------------------------------- 1 | // pages/scratch_card/scratch_card.js 2 | const app = getApp() 3 | var uid = wx.getStorageSync('uid') 4 | console.log(uid) 5 | const ctx = wx.createCanvasContext('guagua_card') //加载画布 6 | var startX = 0; //保存X坐标轴变量 7 | var startY = 0;//保存X坐标轴变量 8 | var timer; 9 | var num = -1; 10 | Page({ 11 | data: { 12 | word: '', 13 | price: '', 14 | hidden: 'true', 15 | image_src_0: "http://ts-dingup-onlinetest.oss-cn-beijing.aliyuncs.com/img/shop/8-1.png", 16 | image_src_1: "http://ts-dingup-onlinetest.oss-cn-beijing.aliyuncs.com/img/shop/6-1.png", 17 | image_src_2: "http://ts-dingup-onlinetest.oss-cn-beijing.aliyuncs.com/img/shop/0-1.png", 18 | image_src_3: "http://ts-dingup-onlinetest.oss-cn-beijing.aliyuncs.com/img/shop/0-1.png", 19 | block_image_src: '../../images/001.ipg', 20 | name_0: '', 21 | name_4: '', 22 | name_1: '', 23 | name_3: '', 24 | toplist: '', 25 | timelist: true, 26 | }, 27 | onLoad: function (options) { 28 | 29 | }, 30 | toGet_Card() { //请求数据 31 | var self = this; 32 | console.log(uid + '-----------') 33 | wx.request({ 34 | url: 'http://192.168.3.27:8080/wechat_applet_api/scratch-card', 35 | data: { 36 | uid: wx.getStorageSync('uid'), 37 | isScratch: num //1挂卡请求 38 | }, 39 | header: { 40 | 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' 41 | }, 42 | method: 'GET', 43 | success: function (res) { 44 | console.log(1) 45 | if (res.data.partnerStatus == "0") { 46 | self.draw(); 47 | self.setData({ 48 | price: res 49 | }) 50 | if (res.data.topList != []) { 51 | if (res.data.topList.length == 2) { 52 | self.setData({ 53 | name_0: res.data.topList[0].nickname, 54 | name_1: res.data.topList[1].nickname, 55 | image_src_0: res.data.topList[0].imgUrl, 56 | image_src_1: res.data.topList[1].imgUrl 57 | }) 58 | } else if (res.data.topList.length == 1) { 59 | if (res.data.topList[0].money == 8) { 60 | self.setData({ 61 | name_0: res.data.topList[0].nickname, 62 | image_src_0: res.data.topList[0].imgUrl 63 | }) 64 | } else if (res.data.topList[0].money == 6) { 65 | self.setData({ 66 | name_1: res.data.topList[0].nickname, 67 | image_src_1: res.data.topList[0].imgUrl 68 | }) 69 | } 70 | } 71 | } 72 | if (res.data.lastList != []) { 73 | if (res.data.lastList.length == 2) { 74 | self.setData({ 75 | name_4: res.data.lastList[0].nickname, 76 | name_3: res.data.lastList[1].nickname, 77 | image_src_2: res.data.lastList[0].imgUrl, 78 | image_src_3: res.data.lastList[1].imgUrl 79 | }) 80 | } else if (res.data.lastList.length == 1) { 81 | self.setData({ 82 | name_4: res.data.lastList[0].nickname, 83 | image_src_2: res.data.lastList[0].imgUrl 84 | 85 | }) 86 | } 87 | } 88 | }; 89 | if (res.data.partnerStatus == "1") { 90 | self.setData({ 91 | price: res 92 | }) 93 | if (res.data.topList != []) { 94 | if (res.data.topList.length == 2) { 95 | self.setData({ 96 | name_0: res.data.topList[0].nickname, 97 | name_1: res.data.topList[1].nickname, 98 | image_src_0: res.data.topList[0].imgUrl, 99 | image_src_1: res.data.topList[1].imgUrl 100 | }) 101 | 102 | } else if (res.data.topList.length == 1) { 103 | if (res.data.topList[0].money == 8) { 104 | self.setData({ 105 | name_0: res.data.topList[0].nickname, 106 | image_src_0: res.data.topList[0].imgUrl 107 | }) 108 | 109 | } else if (res.data.topList[0].money == 6) { 110 | self.setData({ 111 | name_1: res.data.topList[0].nickname, 112 | image_src_1: res.data.topList[0].imgUrl 113 | 114 | }) 115 | } 116 | } 117 | } 118 | if (res.data.lastList != []) { 119 | if (res.data.lastList.length == 2) { 120 | self.setData({ 121 | name_4: res.data.lastList[0].nickname, 122 | name_3: res.data.lastList[1].nickname, 123 | image_src_2: res.data.lastList[0].imgUrl, 124 | image_src_3: res.data.lastList[1].imgUrl 125 | }) 126 | } else if (res.data.lastList.length == 1) { 127 | self.setData({ 128 | name_4: res.data.lastList[0].nickname, 129 | image_src_2: res.data.lastList[0].imgUrl 130 | 131 | }) 132 | } 133 | } 134 | } 135 | if (res.data.partnerStatus == "-1") { 136 | self.setData({ 137 | price: res 138 | }) 139 | self.draw(); 140 | if (res.data.topList != []) { 141 | if (res.data.topList.length == 2) { 142 | self.setData({ 143 | name_0: res.data.topList[0].nickname, 144 | name_1: res.data.topList[1].nickname, 145 | image_src_0: res.data.topList[0].imgUrl, 146 | image_src_1: res.data.topList[1].imgUrl 147 | }) 148 | 149 | } else if (res.data.topList.length == 1) { 150 | if (res.data.topList[0].money == 8) { 151 | self.setData({ 152 | name_0: res.data.topList[0].nickname, 153 | image_src_0: res.data.topList[0].imgUrl 154 | }) 155 | 156 | } else if (res.data.topList[0].money == 6) { 157 | self.setData({ 158 | name_1: res.data.topList[0].nickname, 159 | image_src_1: res.data.topList[0].imgUrl 160 | 161 | }) 162 | } 163 | } 164 | } 165 | if (res.data.lastList != []) { 166 | if (res.data.lastList.length == 2) { 167 | self.setData({ 168 | name_4: res.data.lastList[0].nickname, 169 | name_3: res.data.lastList[1].nickname, 170 | image_src_2: res.data.lastList[0].imgUrl, 171 | image_src_3: res.data.lastList[1].imgUrl 172 | }) 173 | } else if (res.data.lastList.length == 1) { 174 | self.setData({ 175 | name_4: res.data.lastList[0].nickname, 176 | image_src_2: res.data.lastList[0].imgUrl 177 | 178 | }) 179 | } 180 | } 181 | }; 182 | console.log(res.data) 183 | 184 | }, 185 | fail: function (err) { 186 | console.log(err) 187 | } 188 | }) 189 | }, 190 | 191 | touchStart: function (start) { 192 | var self = this; 193 | num = 1; 194 | timer = setTimeout(function () { 195 | self.toGet_Card() 196 | ctx.draw(); 197 | console.log("----Countdown----"); 198 | self.setData({ 199 | hidden: '' 200 | }) 201 | self.toGet_Card() 202 | num = -1; 203 | }, 3000); 204 | 205 | }, 206 | touchMove: function (start) { 207 | var start_X = start.changedTouches[0].x 208 | var start_Y = start.changedTouches[0].y 209 | ctx.save(); 210 | ctx.moveTo(this.startX, this.startY) 211 | ctx.clearRect(start_X, start_Y, 20, 20) 212 | ctx.restore() 213 | this.startX = start_X; 214 | this.startY = start_Y; 215 | wx.drawCanvas({ 216 | canvasId: 'guagua_card', 217 | reserve: true, 218 | actions: ctx.getActions() // 获取绘图动作数组 219 | }) 220 | }, 221 | // touchEnd: function (res) { 222 | // var self = this; 223 | // var ui = res.target; 224 | // console.log(ui) 225 | // }, 226 | taphandle1: function () { 227 | var self = this; 228 | self.setData({ 229 | toplist: 'true', 230 | timelist: '', 231 | }) 232 | }, 233 | taphandle2: function () { 234 | var self = this; 235 | self.setData({ 236 | timelist: 'true', 237 | toplist: '', 238 | }) 239 | }, 240 | /** 241 | * 生命周期函数--监听页面初次渲染完成 242 | */ 243 | onReady: function () { 244 | 245 | }, 246 | draw() { 247 | ctx.setFillStyle('#919FAE'), 248 | ctx.fillRect(0, 0, 500, 180), 249 | ctx.draw() 250 | console.log(111) 251 | }, 252 | /** 253 | * 生命周期函数--监听页面显示 254 | */ 255 | onShow: function () { 256 | var self = this; 257 | self.toGet_Card(); 258 | console.log(uid) 259 | }, 260 | 261 | /** 262 | * 生命周期函数--监听页面隐藏 263 | */ 264 | onHide: function () { 265 | 266 | }, 267 | 268 | /** 269 | * 生命周期函数--监听页面卸载 270 | */ 271 | onUnload: function () { 272 | 273 | }, 274 | 275 | /** 276 | * 页面相关事件处理函数--监听用户下拉动作 277 | */ 278 | onPullDownRefresh: function () { 279 | 280 | }, 281 | 282 | /** 283 | * 页面上拉触底事件的处理函数 284 | */ 285 | onReachBottom: function () { 286 | 287 | }, 288 | 289 | /** 290 | * 用户点击右上角分享 291 | */ 292 | onShareAppMessage: function () { 293 | 294 | } 295 | }) -------------------------------------------------------------------------------- /订餐打卡系统/pages/scratch_card/scratch_card.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } -------------------------------------------------------------------------------- /订餐打卡系统/pages/scratch_card/scratch_card.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 请等候…… 9 | 10 | 11 | 12 | 13 | 恭喜刮到{{price.data.currentScratchResult}} 14 | 15 | 16 | 17 | 感谢亲,今日已经筹集{{price.data.totalNum}} 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | {{name_0}} 26 | 27 | 28 | {{name_1}} 29 | 30 | 31 | {{name_4}} 32 | 33 | 34 | {{name_3}} 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 49 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/scratch_card/scratch_card.wxss: -------------------------------------------------------------------------------- 1 | page { 2 | height: 100%; 3 | background-color: #d05744; 4 | } 5 | 6 | .root { 7 | height: 100%; 8 | width: 100%; 9 | background-color: #d05744; 10 | } 11 | 12 | ::-webkit-scrollbar { 13 | height: 0; 14 | width: 0; 15 | color: transparent; 16 | } 17 | 18 | .header { 19 | display: flex; 20 | position: relative; 21 | /* align-items: center; 22 | align-content: center; */ 23 | /* border-top: 1px solid black; */ 24 | /* border-bottom: 1px solid black; */ 25 | height: 40%; 26 | width: 100%; 27 | background-color: white; 28 | } 29 | 30 | .header_image { 31 | height: 100%; 32 | width: 100%; 33 | background-color: #d05744; 34 | } 35 | 36 | .scratch { 37 | height: 23%; 38 | width: 90%; 39 | background-color: white; 40 | margin-left: 5%; 41 | position: absolute; 42 | top: 25%; 43 | } 44 | 45 | .scratch .guagua_card { 46 | height: 100%; 47 | width: 100%; 48 | } 49 | 50 | .guagua_card { 51 | display: flex; 52 | flex-direction: column; 53 | position: relative; 54 | } 55 | 56 | .scratch_text { 57 | position: absolute; 58 | top: 33%; 59 | color: #919fae; 60 | margin-left: 20%; 61 | } 62 | .resoult{ 63 | color: #d05744; 64 | font-size: 30px; 65 | } 66 | .class_erweima { 67 | margin-top: 14%; 68 | width: 100%; 69 | /* background-color: black; */ 70 | } 71 | 72 | .erweima { 73 | /* display: grid; */ 74 | height: 80px; 75 | width: 20%; 76 | margin-left: 36%; 77 | } 78 | 79 | .famous { 80 | width: 100%; 81 | height: 60%; 82 | /* margin-left: 5%; */ 83 | } 84 | 85 | .famous_image { 86 | height: 40%; 87 | width: 90%; 88 | margin-left: 5%; 89 | position: relative; 90 | } 91 | 92 | .top_Name { 93 | position: absolute; 94 | top: 60%; 95 | left: 70%; 96 | color: white; 97 | font-size: 30px; 98 | } 99 | 100 | .list { 101 | height: 80%; 102 | width: 90%; 103 | margin-top: 65%; 104 | margin-left: 5%; 105 | } 106 | 107 | .toplist { 108 | height: 10%; 109 | width: 100%; 110 | background-color: white; 111 | margin-top: 20%; 112 | display: flex; 113 | align-items: center; 114 | } 115 | 116 | .block_toplist1 { 117 | height: 10%; 118 | width: 100%; 119 | background-color: blue; 120 | } 121 | .block_toplist2 { 122 | height: 24%; 123 | width: 100%; 124 | background-color: blue; 125 | } 126 | .taptext{ 127 | margin-left: 73%; 128 | /* border: 1px solid black; */ 129 | background-color: #A7C0DC; 130 | color: white; 131 | font-size: 110%; 132 | } 133 | 134 | .item1 { 135 | height: 100%; 136 | width: 100%; 137 | display: flex; 138 | align-items: center; 139 | background-color: white; 140 | border-top: 1px solid #A7C0DC; 141 | position: relative; 142 | } 143 | .item2 { 144 | height: 100%; 145 | width: 100%; 146 | display: flex; 147 | align-items: center; 148 | background-color: white; 149 | border-top: 1px solid #A7C0DC; 150 | position: relative; 151 | } 152 | 153 | .block_image { 154 | height: 100%; 155 | width: 45%; 156 | position: absolute; 157 | left: 55%; 158 | /* margin-left: 50%; */ 159 | } 160 | .erweima_picture{ 161 | height: 20%; 162 | width: 30%; 163 | margin-left: 34%; 164 | margin-top: 20%; 165 | } 166 | .item_text1{ 167 | position: absolute; 168 | left: 10%; 169 | } 170 | .item_text2{ 171 | /* margin-left: 80%; */ 172 | position: absolute; 173 | left: 80%; 174 | } 175 | .zanzhu{ 176 | position: absolute; 177 | left: 10%; 178 | } 179 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/waiting/waiting.js: -------------------------------------------------------------------------------- 1 | // pages/waiting/waiting.js 2 | Page({ 3 | 4 | /** 5 | * 页面的初始数据 6 | */ 7 | data: { 8 | 9 | }, 10 | 11 | /** 12 | * 生命周期函数--监听页面加载 13 | */ 14 | onLoad: function (options) { 15 | 16 | }, 17 | 18 | /** 19 | * 生命周期函数--监听页面初次渲染完成 20 | */ 21 | onReady: function () { 22 | 23 | }, 24 | 25 | /** 26 | * 生命周期函数--监听页面显示 27 | */ 28 | onShow: function () { 29 | 30 | }, 31 | 32 | /** 33 | * 生命周期函数--监听页面隐藏 34 | */ 35 | onHide: function () { 36 | 37 | }, 38 | 39 | /** 40 | * 生命周期函数--监听页面卸载 41 | */ 42 | onUnload: function () { 43 | 44 | }, 45 | 46 | /** 47 | * 页面相关事件处理函数--监听用户下拉动作 48 | */ 49 | onPullDownRefresh: function () { 50 | 51 | }, 52 | 53 | /** 54 | * 页面上拉触底事件的处理函数 55 | */ 56 | onReachBottom: function () { 57 | 58 | }, 59 | 60 | /** 61 | * 用户点击右上角分享 62 | */ 63 | onShareAppMessage: function () { 64 | 65 | } 66 | }) -------------------------------------------------------------------------------- /订餐打卡系统/pages/waiting/waiting.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /订餐打卡系统/pages/waiting/waiting.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /订餐打卡系统/pages/waiting/waiting.wxss: -------------------------------------------------------------------------------- 1 | /* pages/waiting/waiting.wxss */ 2 | page{ 3 | height: 100%; 4 | } 5 | .root{ 6 | height: 100%; 7 | width: 100%; 8 | background-color: #DD7042; 9 | } -------------------------------------------------------------------------------- /订餐打卡系统/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "setting": { 4 | "urlCheck": false, 5 | "es6": true, 6 | "postcss": true, 7 | "minified": true, 8 | "newFeature": true 9 | }, 10 | "compileType": "miniprogram", 11 | "libVersion": "1.9.1", 12 | "appid": "wx7c0418540db4d54f", 13 | "projectname": "%E8%AE%A2%E9%A4%90%E6%89%93%E5%8D%A1%E7%B3%BB%E7%BB%9F", 14 | "condition": { 15 | "search": { 16 | "current": -1, 17 | "list": [] 18 | }, 19 | "conversation": { 20 | "current": -1, 21 | "list": [] 22 | }, 23 | "game": { 24 | "currentL": -1, 25 | "list": [] 26 | }, 27 | "miniprogram": { 28 | "current": -1, 29 | "list": [] 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /订餐打卡系统/utils/util.js: -------------------------------------------------------------------------------- 1 | const formatTime = date => { 2 | const year = date.getFullYear() 3 | const month = date.getMonth() + 1 4 | const day = date.getDate() 5 | const hour = date.getHours() 6 | const minute = date.getMinutes() 7 | const second = date.getSeconds() 8 | 9 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') 10 | } 11 | 12 | const formatNumber = n => { 13 | n = n.toString() 14 | return n[1] ? n : '0' + n 15 | } 16 | 17 | module.exports = { 18 | formatTime: formatTime 19 | } 20 | --------------------------------------------------------------------------------