后端
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.java1234.mapper.OrderMapper"><resultMap id="orderResult" type="com.java1234.entity.Order"><association property="wxUserInfo" column="userId" select="com.java1234.mapper.WxUserInfoMapper.findByOpenId"></association></resultMap><select id="list" parameterType="Map" resultMap="orderResult">select * from t_order<where><if test="orderNo!=null and orderNo!='' ">and orderNo like concat('%',#{orderNo},'%')</if></where>order by createDate desc<if test="start!=null and pageSize!=null ">limit #{start},#{pageSize}</if></select><select id="getTotal" parameterType="Map" resultType="Long">select count(*) from t_order<where><if test="orderNo!=null and orderNo!='' ">and orderNo like concat('%',#{orderNo},'%')</if></where></select></mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.java1234.mapper.WxUserInfoMapper"><resultMap id="wxUserInfoResult" type="com.java1234.entity.WxUserInfo"></resultMap><select id="findByOpenId" parameterType="String" resultMap="wxUserInfoResult">select * from t_wxuserinfo where openid=#{openid}</select></mapper>
package com.java1234.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java1234.entity.Order;import java.util.List;
import java.util.Map;/*** 订单Mapper接口* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2022-02-23 22:00*/
public interface OrderMapper extends BaseMapper<Order> {List<Order> list(Map<String,Object> map);Long getTotal(Map<String,Object> map);
}
package com.java1234.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java1234.entity.BigType;
import com.java1234.entity.WxUserInfo;/*** 微信用户Mapper接口* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2022-02-23 22:00*/
public interface WxUserInfoMapper extends BaseMapper<WxUserInfo> {public WxUserInfo findByOpenId(String openId);
}
package com.java1234.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.java1234.entity.Order;import java.util.List;
import java.util.Map;/*** 订单Service接口* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2022-02-23 22:01*/
public interface IOrderService extends IService<Order> {/*** 根据条件分页查询订单数据* @param map* @return*/List<Order> list(Map<String,Object> map);/*** 根据条件查询订单总记录数* @param map* @return*/Long getTotal(Map<String,Object> map);
}
package com.java1234.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java1234.entity.Order;
import com.java1234.mapper.OrderMapper;
import com.java1234.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;
import java.util.Map;/*** 订单Service实现类* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2022-02-23 22:02*/
@Service("orderService")
public class IOrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements IOrderService {@Autowiredprivate OrderMapper orderMapper;@Overridepublic List<Order> list(Map<String, Object> map) {return orderMapper.list(map);}@Overridepublic Long getTotal(Map<String, Object> map) {return orderMapper.getTotal(map);}
}
package com.java1234.controller.admin;import com.java1234.entity.Order;
import com.java1234.entity.PageBean;
import com.java1234.entity.R;
import com.java1234.service.IOrderService;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.List;
import java.util.Map;/*** 管理员-订单Controller控制器* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2022-05-21 21:07*/
@RestController
@RequestMapping("/admin/order")
public class AdminOrderController {@Autowiredprivate IOrderService orderService;/*** 根据条件分页查询* @param pageBean* @return*/@RequestMapping("/list")public R list(@RequestBody PageBean pageBean){System.out.println(pageBean);Map<String,Object> map=new HashMap<>();map.put("orderNo",pageBean.getQuery().trim());map.put("start",pageBean.getStart());map.put("pageSize",pageBean.getPageSize());List<Order> orderList=orderService.list(map);Long total=orderService.getTotal(map);Map<String,Object> resultMap=new HashMap<>();resultMap.put("orderList",orderList);resultMap.put("total",total);return R.ok(resultMap);}
}
前端
<template><el-card><el-row :gutter="20" class="header"><el-col :span="7"><el-input placeholder="请输入订单号..." v-model="queryForm.query" clearable></el-input></el-col><el-button type="primary" :icon="Search" @click="initOrderList">搜索</el-button></el-row><el-table :data="tableData" stripe style="width: 100%"><el-table-column prop="orderNo" label="订单号" width="250" fixed/><el-table-column prop="wxUserInfo" label="用户昵称" width="200" :formatter="wxUserInfoNickNameFormatter"/><el-table-column prop="totalPrice" label="订单总价" width="100" /><el-table-column prop="status" label="订单状态" width="100" :formatter="statusFormatter"/><el-table-column prop="createDate" label="订单创建日期" width="200" /><el-table-column prop="payDate" label="订单支付日期" width="200" /><el-table-column prop="consignee" label="收货人" width="80" /><el-table-column prop="telNumber" label="联系电话" width="150" /><el-table-column prop="address" label="收货地址" width="400" /><el-table-column prop="action" label="操作" width="300" fixed="right"><template v-slot="scope"><el-button type="success">详情</el-button><el-button type="primary">发货</el-button><el-button type="primary">退货</el-button><el-button type="danger" :icon="Delete"/></template></el-table-column></el-table><el-paginationv-model:currentPage="queryForm.pageNum"v-model:page-size="queryForm.pageSize":page-sizes="[10, 20, 30, 40,50]"layout="total, sizes, prev, pager, next, jumper":total="total"@size-change="handleSizeChange"@current-change="handleCurrentChange"/></el-card>
</template><script setup>
import { Search ,Delete } from '@element-plus/icons-vue'
import { ref } from 'vue'
import axios from "@/util/axios";const queryForm=ref({query:'',pageNum:1,pageSize:10
})const total=ref(0)const tableData = ref([])const initOrderList=async()=>{const res=await axios.post("admin/order/list",queryForm.value)tableData.value=res.data.orderList;total.value=res.data.total;
}initOrderList();const handleSizeChange=(pageSize)=>{queryForm.value.pageNum=1;queryForm.value.pageSize=pageSize;initOrderList();
}const handleCurrentChange=(pageNum)=>{queryForm.value.pageNum=pageNum;initOrderList();
}const wxUserInfoNickNameFormatter=(row)=>{return row.wxUserInfo.nickName;
}const statusFormatter=(row)=>{switch (row.status){case 1:return "待支付"case 2:return "待发货"case 3:return "退款/退货"}
}</script><style lang="scss" scoped>.header{padding-bottom: 16px;box-sizing: border-box;
}.el-pagination{padding-top: 15px;box-sizing: border-box;
}</style>