فهرست منبع

销售管理、采购管理

yumeng 5 ماه پیش
والد
کامیت
febdb46b26

+ 417 - 2
ruixuan-live/src/main/java/com/ruixuan/isc/controller/KwaiXiaoDianReportController.java

@@ -6,14 +6,22 @@ import com.ruixuan.common.constant.HttpStatus;
 import com.ruixuan.common.core.page.TableDataInfo;
 import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.DateUtils;
+import com.ruixuan.data.utils.ExportExcelUtils;
 import com.ruixuan.isc.service.IKwaiXiaoDianReportService;
 import com.ruixuan.isc.service.IKwaixiaodianItemGetService;
 import com.ruixuan.system.service.ISysRoleService;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -52,7 +60,7 @@ public class KwaiXiaoDianReportController {
                 if (!Check.isNull(companyId)) {
                     requestMap.put("companyId", companyId);
                 }
-            } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
+            } else if ("industry_admin".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
                 companyId = kwaixiaodianItemGetService.getCompanyId(userId);
                 if (Check.isNull(companyId)) {
                     throw new Exception("此用户未查询到归属公司");
@@ -73,7 +81,7 @@ public class KwaiXiaoDianReportController {
                 }
                 List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
                 requestMap.put("itemIds", itemIds);
-            } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
+            } else if ("industry_courtship_manager".equals(roleId) ) { // 招商、采购经理角色查看部门下所有成员数据
                 List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
                 if (Check.isNull(courtshipPurchaseIds)) {
                     throw new Exception("此用户未查询到部门成员信息");
@@ -738,4 +746,411 @@ public class KwaiXiaoDianReportController {
         }
         return rspData;
     }
+
+
+    @GetMapping("/getSaleReport")
+    public TableDataInfo getSaleReport(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
+        TableDataInfo rspData = new TableDataInfo();
+        try {
+            if (Check.isNull(userId)) {
+                throw new Exception("请传入用户ID");
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            String roleId = sysRoleService.getRoleBYUserId(userId);
+            if ("admin".equals(roleId)) { // 管理员查看所有
+                if (!Check.isNull(companyId)) {
+                    requestMap.put("companyId", companyId);
+                }
+            } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
+                companyId = kwaixiaodianItemGetService.getCompanyId(userId);
+                if (Check.isNull(companyId)) {
+                    throw new Exception("此用户未查询到归属公司");
+                }
+                requestMap.put("companyId", companyId);
+            } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
+                requestMap.put("userId", userId);
+            }
+
+            Long start = DateUtils.strDateToInt(startDate);
+            Long end = DateUtils.strDateToInt(endDate);
+            requestMap.put("start", start);
+            requestMap.put("end", end);
+
+            startPage(pageNum, pageSize);
+            List<JSONObject> list = kwaiXiaoDianReportService.getSaleReport(requestMap);
+            rspData.setCode(HttpStatus.SUCCESS);
+            rspData.setMsg("查询成功");
+            rspData.setRows(list);
+            rspData.setTotal(new PageInfo(list).getTotal());
+        } catch (Exception e) {
+            e.printStackTrace();
+            rspData.setCode(HttpStatus.ERROR);
+            rspData.setMsg(e.getMessage());
+        }
+        return rspData;
+    }
+
+
+    @GetMapping("/exportSaleReport")
+    public void exportSaleReport(HttpServletRequest request, HttpServletResponse response, Long companyId, Long userId, String startDate, String endDate, String shopId, Long itemId, String itemTitle, Integer itemType) throws IOException, ParseException {
+
+        if (Check.isNull(userId)) {
+            return;
+        }
+        if (Check.isNull(startDate)) {
+            return;
+        }
+        if (Check.isNull(endDate)) {
+            return;
+        }
+
+        Map<String, Object> requestMap = new HashMap<>();
+        String roleId = sysRoleService.getRoleBYUserId(userId);
+        if ("admin".equals(roleId)) { // 管理员查看所有
+            if (!Check.isNull(companyId)) {
+                requestMap.put("companyId", companyId);
+            }
+        } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
+            companyId = kwaixiaodianItemGetService.getCompanyId(userId);
+            if (Check.isNull(companyId)) {
+                return;
+            }
+            requestMap.put("companyId", companyId);
+
+        } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
+            requestMap.put("userId", userId);
+        }
+
+        Long start = DateUtils.strDateToInt(startDate);
+        Long end = DateUtils.strDateToInt(endDate);
+        requestMap.put("start", start);
+        requestMap.put("end", end);
+        List<JSONObject> list = kwaiXiaoDianReportService.getSaleReport(requestMap);
+        List<List<Object>> exportList = new ArrayList<>();
+        if (!Check.isNull(list)) {
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject data = list.get(i);
+                List<Object> export = new ArrayList();
+                export.add(data.getString("userId"));
+                export.add(data.getString("userName"));
+                export.add(data.getString("itemCount"));
+                export.add(data.getString("orderNum"));
+                export.add(data.getString("totalFee"));
+                export.add(data.getString("costPrice"));
+
+                exportList.add(export);
+            }
+        }
+        String[] headers = {"销售ID", "销售", "商品数", "订单数", "收入", "成本"};
+        OutputStream os = response.getOutputStream();
+        ExportExcelUtils eeu = new ExportExcelUtils();
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        eeu.exportExcel(workbook, 0, "销售管理", headers, exportList);
+        this.setResponseHeader(response, "销售管理.xls");
+        try {
+            workbook.write(os);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        os.flush();
+        os.close();
+    }
+
+
+    @GetMapping("/getSaleDetail")
+    public TableDataInfo getSaleDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize) {
+        TableDataInfo rspData = new TableDataInfo();
+        try {
+            if (Check.isNull(userId)) {
+                throw new Exception("请传入用户ID");
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("userId", userId);
+
+            Long start = DateUtils.strDateToInt(startDate);
+            Long end = DateUtils.strDateToInt(endDate);
+            requestMap.put("start", start);
+            requestMap.put("end", end);
+
+
+            startPage(pageNum, pageSize);
+            List<JSONObject> list = kwaiXiaoDianReportService.getSaleDetail(requestMap);
+            rspData.setCode(HttpStatus.SUCCESS);
+            rspData.setMsg("查询成功");
+            rspData.setRows(list);
+            rspData.setTotal(new PageInfo(list).getTotal());
+        } catch (Exception e) {
+            e.printStackTrace();
+            rspData.setCode(HttpStatus.ERROR);
+            rspData.setMsg(e.getMessage());
+        }
+        return rspData;
+    }
+
+
+    @GetMapping("/exportSaleDetail")
+    public void exportSaleDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate) throws IOException, ParseException {
+
+        if (Check.isNull(userId)) {
+            return;
+        }
+        if (Check.isNull(startDate)) {
+            return;
+        }
+        if (Check.isNull(endDate)) {
+            return;
+        }
+
+        Map<String, Object> requestMap = new HashMap<>();
+        requestMap.put("userId", userId);
+
+        Long start = DateUtils.strDateToInt(startDate);
+        Long end = DateUtils.strDateToInt(endDate);
+        requestMap.put("start", start);
+        requestMap.put("end", end);
+
+
+        List<JSONObject> list = kwaiXiaoDianReportService.getSaleDetail(requestMap);
+
+        List<List<Object>> exportList = new ArrayList<>();
+        if (!Check.isNull(list)) {
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject data = list.get(i);
+                List<Object> export = new ArrayList();
+
+                export.add(data.getString("itemId"));
+                export.add(data.getString("itemTitle"));
+                export.add(data.getString("userId"));
+                export.add(data.getString("userName"));
+                export.add(data.getString("orderNum"));
+                export.add(data.getString("totalFee"));
+                export.add(data.getString("costPrice"));
+                exportList.add(export);
+            }
+        }
+        String[] headers = {"商品ID", "商品名称", "销售ID", "销售", "订单数", "收入", "成本"};
+        OutputStream os = response.getOutputStream();
+        ExportExcelUtils eeu = new ExportExcelUtils();
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        eeu.exportExcel(workbook, 0, "销售详情", headers, exportList);
+        this.setResponseHeader(response, "销售详情.xls");
+        try {
+            workbook.write(os);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        os.flush();
+        os.close();
+    }
+
+
+    @GetMapping("/getPurchaserReport")
+    public TableDataInfo getPurchaserReport(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
+        TableDataInfo rspData = new TableDataInfo();
+        try {
+            if (Check.isNull(userId)) {
+                throw new Exception("请传入用户ID");
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            String roleId = sysRoleService.getRoleBYUserId(userId);
+            if ("admin".equals(roleId)) { // 管理员查看所有
+                if (!Check.isNull(companyId)) {
+                    requestMap.put("companyId", companyId);
+                }
+            } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
+                companyId = kwaixiaodianItemGetService.getCompanyId(userId);
+                if (Check.isNull(companyId)) {
+                    throw new Exception("请传入公司ID");
+                }
+                requestMap.put("companyId", companyId);
+
+            } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
+                requestMap.put("userId", userId);
+            }
+
+            Long start = DateUtils.strDateToInt(startDate);
+            Long end = DateUtils.strDateToInt(endDate);
+            requestMap.put("start", start);
+            requestMap.put("end", end);
+
+            startPage(pageNum, pageSize);
+            List<JSONObject> list = kwaiXiaoDianReportService.getPurchaserReport(requestMap);
+            rspData.setCode(HttpStatus.SUCCESS);
+            rspData.setMsg("查询成功");
+            rspData.setRows(list);
+            rspData.setTotal(new PageInfo(list).getTotal());
+        } catch (Exception e) {
+            e.printStackTrace();
+            rspData.setCode(HttpStatus.ERROR);
+            rspData.setMsg(e.getMessage());
+        }
+        return rspData;
+    }
+
+
+    @GetMapping("/exportPurchaserReport")
+    public void exportPurchaserReport(HttpServletRequest request, HttpServletResponse response, Long companyId, Long userId, String startDate, String endDate, String shopId, Long itemId, String itemTitle, Integer itemType) throws IOException, ParseException {
+
+        if (Check.isNull(userId)) {
+            return;
+        }
+        if (Check.isNull(startDate)) {
+            return;
+        }
+        if (Check.isNull(endDate)) {
+            return;
+        }
+
+        Map<String, Object> requestMap = new HashMap<>();
+        String roleId = sysRoleService.getRoleBYUserId(userId);
+        if ("admin".equals(roleId)) { // 管理员查看所有
+            if (!Check.isNull(companyId)) {
+                requestMap.put("companyId", companyId);
+            }
+        } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
+            companyId = kwaixiaodianItemGetService.getCompanyId(userId);
+            if (Check.isNull(companyId)) {
+                return;
+            }
+            requestMap.put("companyId", companyId);
+        }
+
+        Long start = DateUtils.strDateToInt(startDate);
+        Long end = DateUtils.strDateToInt(endDate);
+        requestMap.put("start", start);
+        requestMap.put("end", end);
+
+
+        List<JSONObject> list = kwaiXiaoDianReportService.getPurchaserReport(requestMap);
+        List<List<Object>> exportList = new ArrayList<>();
+        if (!Check.isNull(list)) {
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject data = list.get(i);
+                List<Object> export = new ArrayList();
+                export.add(data.getString("userId"));
+                export.add(data.getString("userName"));
+                export.add(data.getString("orderNum"));
+                export.add(data.getString("totalFee"));
+                export.add(data.getString("costPrice"));
+                export.add(data.getString("purchaseCost"));
+
+                exportList.add(export);
+            }
+        }
+        String[] headers = {"采购ID", "采购", "订单数", "收入", "成本", "采购金额"};
+        OutputStream os = response.getOutputStream();
+        ExportExcelUtils eeu = new ExportExcelUtils();
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        eeu.exportExcel(workbook, 0, "采购管理", headers, exportList);
+        this.setResponseHeader(response, "采购管理.xls");
+        try {
+            workbook.write(os);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        os.flush();
+        os.close();
+    }
+
+
+    @GetMapping("/getPurchaseDetail")
+    public TableDataInfo getPurchaseDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize) {
+        TableDataInfo rspData = new TableDataInfo();
+        try {
+            if (Check.isNull(userId)) {
+                throw new Exception("请传入用户ID");
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("userId", userId);
+
+            Long start = DateUtils.strDateToInt(startDate);
+            Long end = DateUtils.strDateToInt(endDate);
+            requestMap.put("start", start);
+            requestMap.put("end", end);
+
+
+            startPage(pageNum, pageSize);
+            List<JSONObject> list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap);
+            rspData.setCode(HttpStatus.SUCCESS);
+            rspData.setMsg("查询成功");
+            rspData.setRows(list);
+            rspData.setTotal(new PageInfo(list).getTotal());
+        } catch (Exception e) {
+            e.printStackTrace();
+            rspData.setCode(HttpStatus.ERROR);
+            rspData.setMsg(e.getMessage());
+        }
+        return rspData;
+    }
+
+
+    @GetMapping("/exportPurchaseDetail")
+    public void exportPurchaseDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate) throws IOException, ParseException {
+
+        if (Check.isNull(userId)) {
+            return;
+        }
+        if (Check.isNull(startDate)) {
+            return;
+        }
+        if (Check.isNull(endDate)) {
+            return;
+        }
+
+        Map<String, Object> requestMap = new HashMap<>();
+        requestMap.put("userId", userId);
+
+        Long start = DateUtils.strDateToInt(startDate);
+        Long end = DateUtils.strDateToInt(endDate);
+        requestMap.put("start", start);
+        requestMap.put("end", end);
+
+
+        List<JSONObject> list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap);
+
+        List<List<Object>> exportList = new ArrayList<>();
+        if (!Check.isNull(list)) {
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject data = list.get(i);
+                List<Object> export = new ArrayList();
+                export.add(data.getString("itemId"));
+                export.add(data.getString("itemTitle"));
+                export.add(data.getString("userId"));
+                export.add(data.getString("userName"));
+                export.add(data.getString("orderNum"));
+                export.add(data.getString("totalFee"));
+                export.add(data.getString("costPrice"));
+                exportList.add(export);
+            }
+        }
+        String[] headers = {"商品ID", "商品名称", "销售ID", "销售", "订单数", "收入", "成本"};
+        OutputStream os = response.getOutputStream();
+        ExportExcelUtils eeu = new ExportExcelUtils();
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        eeu.exportExcel(workbook, 0, "采购详情", headers, exportList);
+        this.setResponseHeader(response, "采购详情.xls");
+        try {
+            workbook.write(os);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        os.flush();
+        os.close();
+    }
+
+    public void setResponseHeader(HttpServletResponse response, String fileName) {
+        try {
+            try {
+                fileName = new String(fileName.getBytes(), "ISO8859-1");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
 }

+ 8 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/KwaiXiaoDianReportMapper.java

@@ -31,4 +31,12 @@ public interface KwaiXiaoDianReportMapper {
     List<JSONObject> getCostDate(Map<String, Object> requestMap);
 
     List<JSONObject> getItemCostList(Map<String, Object> requestMap);
+
+    List<JSONObject> getSaleReport(Map<String, Object> requestMap);
+
+    List<JSONObject> getSaleDetail(Map<String, Object> requestMap);
+
+    List<JSONObject> getPurchaserReport(Map<String, Object> requestMap);
+
+    List<JSONObject> getPurchaseDetail(Map<String, Object> requestMap);
 }

+ 8 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/IKwaiXiaoDianReportService.java

@@ -27,4 +27,12 @@ public interface IKwaiXiaoDianReportService {
     List<JSONObject> getCostDate(Map<String, Object> requestMap);
 
     List<JSONObject> getItemCostList(Map<String, Object> requestMap);
+
+    List<JSONObject> getSaleReport(Map<String, Object> requestMap);
+
+    List<JSONObject> getSaleDetail(Map<String, Object> requestMap);
+
+    List<JSONObject> getPurchaserReport(Map<String, Object> requestMap);
+
+    List<JSONObject> getPurchaseDetail(Map<String, Object> requestMap);
 }

+ 20 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KwaiXiaoDianReportServiceImpl.java

@@ -104,4 +104,24 @@ public class KwaiXiaoDianReportServiceImpl implements IKwaiXiaoDianReportService
     public List<JSONObject> getItemCostList(Map<String, Object> requestMap) {
         return kwaiXiaoDianReportMapper.getItemCostList(requestMap);
     }
+
+    @Override
+    public List<JSONObject> getSaleReport(Map<String, Object> requestMap) {
+        return kwaiXiaoDianReportMapper.getSaleReport(requestMap);
+    }
+
+    @Override
+    public List<JSONObject> getSaleDetail(Map<String, Object> requestMap) {
+        return kwaiXiaoDianReportMapper.getSaleDetail(requestMap);
+    }
+
+    @Override
+    public List<JSONObject> getPurchaserReport(Map<String, Object> requestMap) {
+        return kwaiXiaoDianReportMapper.getPurchaserReport(requestMap);
+    }
+
+    @Override
+    public List<JSONObject> getPurchaseDetail(Map<String, Object> requestMap) {
+        return kwaiXiaoDianReportMapper.getPurchaseDetail(requestMap);
+    }
 }

+ 154 - 6
ruixuan-live/src/main/resources/mapper/isc/KwaiXiaoDianReportMapper.xml

@@ -873,16 +873,12 @@
         where t1.po_date &gt;= concat(date_format(#{start}, '%Y-%m-%d'), '00:00:01')
         and t1.po_date &lt;= concat(date_format(#{end}, '%Y-%m-%d'), '23:59:59')
         and t1.status in ('Confirmed', 'Finished')) t5
-
-
         join (select round(sum(t2.price * t2.qty), 2) as 'purchaseCost'
         from kwaixiaodian_jst_purchase t1
         left join kwaixiaodian_jst_purchase_items t2
         on t1.po_id = t2.po_id
-        where t1.po_date &gt;=str_to_date(concat(date_format( #{lastStart}, '%Y-%m-%d'), '00:00:01'), '%Y-%m-%d
-        %H:%i:%s')
-        and t1.po_date &lt;=str_to_date(concat(date_format( #{lastEnd}, '%Y-%m-%d'), '23:59:59'), '%Y-%m-%d
-        %H:%i:%s')
+        where t1.po_date &gt;=concat(date_format( #{lastStart}, '%Y-%m-%d'), '00:00:01')
+        and t1.po_date &lt;=concat(date_format( #{lastEnd}, '%Y-%m-%d'), '23:59:59')
         and t1.status in ('Confirmed', 'Finished')) t6
 
     </select>
@@ -947,4 +943,156 @@
         group by t.itemId
         order by count(t.oid) desc
     </select>
+    <select id="getSaleReport" resultType="com.alibaba.fastjson.JSONObject">
+        select t.userId as 'userId',
+        t.userName as 'userName',
+        count(distinct (t.itemId)) as 'itemCount',
+        count(t.oid) as 'orderNum',
+        round(
+        sum(t.totalFee) / 100, 2
+        ) as 'totalFee',
+        sum(tt.costPrice) as 'costPrice'
+        from (select t1.oid as 'oid',
+        t1.status as 'status',
+        t1.total_fee as 'totalFee',
+        t1.item_id as 'itemId',
+        t2.user_id as 'userId',
+        t2.user_name as 'userName'
+        from kwaixiaodian_order_cursor_list t1
+        left join kwaixiaodian_item_get t2
+        on t1.item_id = t2.item_id
+        where t1.send_time &gt;= #{start}
+        and t1.send_time &lt;= #{end}
+        <if test='companyId != null and companyId != ""'>
+            and t1.company_id = #{companyId}
+        </if>
+        <if test='userId != null and userId != ""'>
+            and t2.user_id = #{userId}
+        </if>
+        and t1.status in (40, 50, 70)
+        group by t1.oid) t
+        left join
+        (select oid, sum(cost_price) as 'costPrice'
+        from kwaixiaodian_cost_detail_end
+        where send_time &gt;= #{start}
+        and send_time &lt;= #{end}
+        group by oid) tt
+        on t.oid = tt.oid
+        group by t.userId
+        order by sum(t.totalFee) desc
+    </select>
+    <select id="getSaleDetail" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT CAST(t.itemId AS char) AS 'itemId', t.itemTitle,
+               t.itemPicUrl,
+               COUNT(t.oid) AS 'orderNum', round(
+            SUM(t.totalFee) / 100, 2
+            ) AS 'totalFee', SUM(tt.costPrice) AS 'costPrice', t.userId,
+               t.userName
+        FROM (SELECT t1.oid AS 'oid', t1.status AS 'status', t1.total_fee AS 'totalFee', t1.item_id AS 'itemId', t1.item_title AS 'itemTitle', t2.user_id AS 'userId', t2.user_name AS 'userName', t1.item_pic_url AS 'itemPicUrl'
+              FROM kwaixiaodian_order_cursor_list t1
+                       LEFT JOIN kwaixiaodian_item_get t2
+                                 ON t1.item_id = t2.item_id
+              WHERE t1.send_time &gt;= #{start}
+                AND t1.send_time &lt;= #{end}
+                AND t1.status IN (40, 50, 70)
+                AND t2.user_id = #{userId}
+              GROUP BY t1.oid) t
+                 LEFT JOIN
+             (SELECT oid, SUM(cost_price) AS 'costPrice'
+              FROM kwaixiaodian_cost_detail_end
+              WHERE send_time &gt;= #{start}
+                AND send_time &lt;= #{end}
+              GROUP BY oid) tt
+             ON t.oid = tt.oid
+        GROUP BY t.itemId
+        ORDER BY COUNT(t.oid) DESC
+    </select>
+    <select id="getPurchaserReport" resultType="com.alibaba.fastjson.JSONObject">
+        select *
+        from (select t.userId as 'userId',
+        t.userName as 'userName',
+        count(distinct (t.itemId)) as 'itemCount',
+        count(t.oid) as 'orderNum',
+        round(
+        sum(t.totalFee) / 100, 2
+        ) as 'totalFee',
+        sum(tt.costPrice) as 'costPrice'
+        from (select t1.oid as 'oid',
+        t1.status as 'status',
+        t1.total_fee as 'totalFee',
+        t1.item_id as 'itemId',
+        t2.courtship_purchase_id as 'userId',
+        t2.courtship_purchase_name as 'userName'
+        from kwaixiaodian_order_cursor_list t1
+        left join kwaixiaodian_item_get t2
+        on t1.item_id = t2.item_id
+        WHERE t1.send_time &gt;= #{start}
+        AND t1.send_time &lt;= #{end}
+        AND t1.status IN (40, 50, 70)
+        <if test='companyId != null and companyId != ""'>
+            and t1.company_id = #{companyId}
+        </if>
+        <if test='userId != null and userId != ""'>
+            and t2.courtship_purchase_id = #{userId}
+        </if>
+        group by t1.oid) t
+        left join
+        (select oid, sum(cost_price) as 'costPrice'
+        from kwaixiaodian_cost_detail_end
+        where send_time &gt;= #{start}
+        and send_time &lt;= #{end}
+        group by oid) tt
+        on t.oid = tt.oid
+        group by t.userId) t
+        left join (select t1.purchaser_name as 'purchaserName',
+        round(sum(t2.price * t2.in_qty), 2) as 'purchaseCost'
+        from kwaixiaodian_jst_purchase t1
+        left join kwaixiaodian_jst_purchase_items t2
+        on t1.po_id = t2.po_id
+        where t1.po_date &gt;= concat(date_format(#{start}, '%Y-%m-%d'), '00:00:01')
+        and t1.po_date &lt;=concat(date_format( #{end}, '%Y-%m-%d'), '23:59:59')
+        and t1.status in ('Confirmed', 'Finished')
+        group by t1.purchaser_name) tt on t.userName = tt.purchaserName
+        order by t.orderNum desc
+    </select>
+    <select id="getPurchaseDetail" resultType="com.alibaba.fastjson.JSONObject">
+        select t.userId as 'userId',
+        t.userName as 'userName',
+        count(t.oid) as 'orderNum',
+        round(
+        sum(t.totalFee) / 100, 2
+        ) as 'totalFee',
+        sum(tt.costPrice) as 'costPrice',
+        t.itemTitle,
+        t.itemPicUrl,
+        CAST(t.itemId AS char) AS 'itemId'
+        from (select t1.oid as 'oid',
+        t1.status as 'status',
+        t1.total_fee as 'totalFee',
+        t1.item_id as 'itemId',
+        t1.item_title as 'itemTitle',
+        t1.item_pic_url as 'itemPicUrl',
+        t2.courtship_purchase_id as 'userId',
+        t2.courtship_purchase_name as 'userName'
+        from kwaixiaodian_order_cursor_list t1
+        left join kwaixiaodian_item_get t2
+        on t1.item_id = t2.item_id
+        where t1.send_time &gt;= #{start}
+        and t1.send_time &lt;= #{end}
+        <if test='companyId != null and companyId != ""'>
+            and t1.company_id = #{companyId}
+        </if>
+        and t1.status in (40, 50, 70)
+        and t2.courtship_purchase_id = #{userId}
+        group by t1.oid) t
+        left join
+        (select oid, sum(cost_price) as 'costPrice'
+        from kwaixiaodian_cost_detail_end
+        where send_time &gt;= #{start}
+        and send_time &lt;= #{end}
+        group by oid) tt
+        on t.oid = tt.oid
+        group by t.itemId
+        order by count(t.oid) desc
+    </select>
 </mapper>