cshenfu
2024-06-27 58aa6e282bb343503be3cb198948328ea3ed7b79
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
module.exports = {
    /**
     * 获取推荐课程分页
     * @url client/course/pub/recommend_course 前端调用的url参数地址
     * data 请求参数
     * @param {String} params1  参数1
     */
    main: async (event) => {
        let { data = {}, userInfo, util, filterResponse, originalParam } = event;
        let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
        let { uid, pageIndex, pageSize, type, category_id, is_rec, keyword } = data;
        let res = { code: 0, msg: "" };
        // 业务逻辑开始-----------------------------------------------------------
        let fieldJson = {}
        let dbName = "course";
        let whereJson = {
            is_rec: is_rec, // 推荐课程
            category_parent_id: category_id, // 分类ID
            title: new RegExp(keyword) // 搜索条件
        }
        // 根据类型传入条件,2传子
        if (type == 2) {
            whereJson = {
                is_rec: is_rec,
                category_id: category_id
            }
        }
 
        let foreignDB = []
        if (uid != null) {
            foreignDB = [{
                dbName: "user_goods",
                localKey: "_id",
                foreignKey: "goods_id",
                whereJson: { user_id: uid },
                as: "isBuy",
                limit: 1,
            }]
        }
        res = await vk.baseDao.selects({
            dbName: dbName, // 表名
            getMain: false, // 是否只返回rows数据
            pageIndex: pageIndex, // 当前第几页
            pageSize: pageSize, // 每页条数
            foreignDB,
            sortArr: [{ "name": "_add_time", "type": "desc" }],
            // 条件
            whereJson: whereJson
        });
 
        if (uid != null) {
            await vk.baseDao.updateById({
                dbName: "uni-id-users",
                id: uid,
                dataJson: { last_check_home: new Date().getTime() }
            });
        }
        // 业务逻辑结束-----------------------------------------------------------
        return res;
    }
}