基于微信的宠物交易商城设计与开发
摘要:随着互联网的进一步发展,传统手机移动端应用软件所存在的问题逐渐出现在技术关注领域,原生的安卓应用软件在安装卸载过程中影响了用户的体验,一种为提高用户体验而产生的轻量级内嵌式WEB程序日益受到开发人员的关注。自微信小程序被提出以来,越来越多的互联网企业竞相研发独立小程序应用,在未来具有广阔前景。
本文基于当前流行的微信小程序应用开发技术,结合宠物交易商城的用户需求,面向小型店铺开发一套易于复用、可配置、低代码开发的微信小程序宠物交易商城系统。该系统通过目前主流Java后端开发框架SpringBoot与主流数据源配置框架MyBatis以及通用MySQL数据库搭建后台服务器项目,使用Vue前端设计框架和Element-ui界面元素实现小程序管理员系统界面,并根据微信小程序官方提供的设计文档制作了原生的宠物交易商城小程序。该小程序能够满足当前小型店铺的商业服务需求,实现了分模块动态配置,易于二次开发,便于快速搭建成型系统,具备一定经济效应。
关键词:宠物交易商城,小程序,动态配置,SpringBoot,Vue
【527】基于java springboot宠物交易商城微信小程序源码和论文
Design and Development of Online Mall Based on WeChat
Abstract: With the further development of the Internet, the problems existing in the traditional mobile terminal application software developed in the field of technological focus, the native android applications affect the user experience in the process of unloading installation, to improve the user experience and produce a lightweight embedded WEB application by developers, more and more attention. Since WeChat small program was put forward, more and more Internet enterprises compete to develop independent small program applications, which will have broad prospects in the future.
Based on the current popular WeChat small program application development technology, combined with the user needs of online shopping mall, for small shops to develop a set of easy reuse, configurable, low code development of WeChat small program online shopping mall system. The system uses the current mainstream Java backend development framework SpringBoot, the mainstream data source configuration framework Mybatis and the general MySQL database to build the backend server project, and uses the Vue front-end design framework and Element-UI interface elements to realize the small program administrator system interface. And according to the WeChat small program official design documents produced the original online mall small program. The small program can meet the current commercial service needs of small shops, realize the dynamic configuration of modules, easy to secondary development, easy to quickly build a molding system, with a certain economic effect.
Keywords: online mall, mini program, dynamic allocation, SpringBoot, Vue
package com.ndky.shop_back.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ndky.shop_back.dao.GoodDao;
import com.ndky.shop_back.entity.Good;
import com.ndky.shop_back.entity.QueryInfo;
import com.ndky.shop_back.service.GoodService;
import com.ndky.shop_back.util.Consts;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
@RestController
public class GoodController {
@Autowired
GoodService goodService;
@RequestMapping("/allGood")
public String getGoodList(QueryInfo queryInfo) {
// 获取最大列表数和当前编号
int number = goodService.getGoodCounts("%" + queryInfo.getQuery() + "%");
int pageState = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
List<Good> good = goodService.getAllGood("%" + queryInfo.getQuery() + "%", pageState, queryInfo.getPageSize());
HashMap<String, Object> res = new HashMap<>();
res.put("number", number);
res.put("data", good);
String res_string = JSON.toJSONString(res);
return res_string;
}
@RequestMapping("/goodState")
public String updateGoodState(@RequestParam("good_id") Integer good_id,
@RequestParam("good_state") Boolean good_state) {
int i = goodService.updateState(good_id, good_state);
return i > 0 ? "success" : "error";
}
@RequestMapping("/addGood")
public String addGood(@RequestBody Good good) {
int i = goodService.addGood(good);
return i > 0 ? "success" : "error";
}
@RequestMapping("/deleteGood")
public String deleteGood(int good_id) {
int i = goodService.deleteGood(good_id);
return i > 0 ? "success" : "error";
}
@RequestMapping("/getUpdateGood")
public String getUpdateGood(int good_id) {
Good good=goodService.getUpdateGood(good_id);
String string = JSON.toJSONString(good);//注意这里也可以直接返回对象,springboot会把对象直接转换成字符串
return string;
}
@RequestMapping("/editGood")
public String editUser(@RequestBody Good good) {
int i = goodService.editGood(good);
return i > 0 ? "success" : "error";
}
//查询所有商品,返回到微信小程序
@RequestMapping("/selectAllGood")
public String selectAllGood(){
List<Good> list=goodService.selectAllGood();
String string = JSON.toJSONString(list);//注意这里也可以直接返回对象,springboot会把对象直接转换成字符串
return string;
}
//按照class_name查询商品,填充商品分类右边栏目
@RequestMapping("/selectGoodByClass")
public String selectGoodByClass(@Param("class_name") String class_name){
List<Good> list=goodService.selectGoodByClass(class_name);
String string = JSON.toJSONString(list);
return string;
}
@RequestMapping("/selectGoodById")
public String selectGoodById(@Param("good_id") Integer good_id){
Good good=goodService.selectGoodById(good_id);
String string = JSON.toJSONString(good);
return string;
}
@RequestMapping("/searchGood")
public String searchGood(@Param("query") String query){
List<Good> list=goodService.searchGood(query);
String string = JSON.toJSONString(list);
return string;
}
@RequestMapping("/setGoodStar")
public String setGoodStar(@Param("good_id") Integer good_id,@Param("good_star")Integer good_star){
int i = goodService.setGoodStar(good_id, good_star);
return i > 0 ? "success" : "error";
}
@RequestMapping("/getGoodByStar")
public String getGoodByStar(QueryInfo queryInfo){
// 获取最大列表数和当前编号
int number = goodService.getGoodCounts("%" + queryInfo.getQuery() + "%");
int pageState = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
List<Good> good = goodService.getGoodByStar("%" + queryInfo.getQuery() + "%", pageState, queryInfo.getPageSize());
HashMap<String, Object> res = new HashMap<>();
res.put("number", number);
res.put("data", good);
String res_string = JSON.toJSONString(res);
return res_string;
}
@RequestMapping("/getStarByGoodId")
public Integer getStarByGoodId(@Param("good_id") Integer good_id){
return goodService.getStarByGoodId(good_id);
}
//更新商品图片
@RequestMapping("/updateGoodImage")
public Object updateGoodImage(@RequestParam("file") MultipartFile avatorFile, @RequestParam("good_id")int id){
JSONObject jsonObject = new JSONObject();
if(avatorFile.isEmpty()){
jsonObject.put(Consts.CODE,0);
jsonObject.put(Consts.MSG,"文件上传失败");
return jsonObject;
}
//文件名=当前时间到毫秒+原来的文件名
String fileName = System.currentTimeMillis()+avatorFile.getOriginalFilename();
//文件路径
String filePath = System.getProperty("user.dir")+System.getProperty("file.separator")+"img"
+System.getProperty("file.separator")+"goodImage";
//如果文件路径不存在,新增该路径
File file1 = new File(filePath);
if(!file1.exists()){
file1.mkdir();
}
//实际的文件地址
File dest = new File(filePath+System.getProperty("file.separator")+fileName);
//存储到数据库里的相对文件地址
String storeAvatorPath = Consts.URL+"/img/goodImage/"+fileName;
try {
avatorFile.transferTo(dest);
Good good=new Good();
good.setGood_id(id);
good.setGood_image(storeAvatorPath);
int flag = goodService.editGood(good);
if(flag>0){
jsonObject.put(Consts.CODE,1);
jsonObject.put(Consts.MSG,"上传成功");
jsonObject.put("pic",storeAvatorPath);
return jsonObject;
}
jsonObject.put(Consts.CODE,0);
jsonObject.put(Consts.MSG,"上传失败");
return jsonObject;
} catch (IOException e) {
jsonObject.put(Consts.CODE,0);
jsonObject.put(Consts.MSG,"上传失败"+e.getMessage());
}finally {
return jsonObject;
}
}
}
package com.ndky.shop_back.controller;
import com.alibaba.fastjson.JSON;
import com.ndky.shop_back.entity.QueryInfo;
import com.ndky.shop_back.entity.User;
import com.ndky.shop_back.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
@RestController
public class UserController {
@Autowired
UserService userService;
@RequestMapping("/allUser")
public String getUserList(QueryInfo queryInfo) {
// 获取最大列表数和当前编号
int number = userService.getUserCounts("%" + queryInfo.getQuery() + "%");
int pageState = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
List<User> users = userService.getAllUser("%" + queryInfo.getQuery() + "%", pageState, queryInfo.getPageSize());
HashMap<String, Object> res = new HashMap<>();
res.put("number", number);
res.put("data", users);
String res_string = JSON.toJSONString(res);
return res_string;
}
@RequestMapping("/userState")
public String updateUserState(@RequestParam("user_id") Integer user_id,
@RequestParam("user_state") Boolean user_state) {
int i = userService.updateState(user_id, user_state);
return i > 0 ? "success" : "error";
}
@RequestMapping("/addUser")
public String addUser(@RequestBody User user) {
int i = userService.addUser(user);
return i > 0 ? "success" : "error";
}
@RequestMapping("/deleteUser")
public String deleteUser(int user_id) {
int i = userService.deleteUser(user_id);
return i > 0 ? "success" : "error";
}
@RequestMapping("/getUpdate")
public String getUpdateUser(int user_id) {
User user = userService.getUpdateUser(user_id);
String string = JSON.toJSONString(user);//注意这里也可以直接返回对象,springboot会把对象直接转换成字符串
return string;
}
@RequestMapping("/editUser")
public String editUser(@RequestBody User user) {
int i = userService.editUser(user);
return i > 0 ? "success" : "error";
}
//检查是否已经注册该用户
@RequestMapping("/checkUser")
public String checkUser(@RequestBody User user0){
User user=userService.checkUser(user0.getUser_name());
if(user!=null){
return "error";
}
return "success";
}
//检查用户手机号是否已注册
@RequestMapping("/checkPhone")
public String checkPhone(@RequestBody User user0){
User user=userService.checkPhone(user0.getUser_phone());
if(user!=null){
return "error";
}
return "success";
}
//小程序端
@RequestMapping("/wxRegister")
public String wxRegister(@Param("user_name") String user_name,@Param("user_password") String user_password,@Param("user_phone") String user_phone){
int i = userService.wxRegister(user_name, user_password, user_phone);
return i > 0 ? "success" : "error";
}
//小程序验证用户名、手机号是否被注册
@RequestMapping("/wxCheckUser")
public String wxCheckUser(@Param("user_name") String user_name){
User user=userService.checkUser(user_name);
if(user!=null){
return "error";
}
return "success";
}
@RequestMapping("/wxCheckPhone")
public String wxCheckPhone(@Param("user_phone") String user_phone){
User user=userService.checkPhone(user_phone);
if(user!=null){
return "error";
}
return "success";
}
//充值或者消费 更新用户余额
@RequestMapping("/wxAddMoney")
public String wxAddMoney(@Param("user_name")String user_name,@Param("user_phone")String user_phone,@Param("user_money")String user_money){
int i=userService.wxAddMoney(user_name, user_phone, user_money);
return i>0? "success":"error";
}
@RequestMapping("/rePassword")
public String rePassword(@Param("user_id")Integer user_id,@Param("new_password")String new_password){
int i=userService.rePassword(user_id, new_password);
return i>0? "success":"error";
}
}