祖安之光
2025-08-07 ad5c4cc086a40708e66040574ff1d465b66304b6
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
63
64
65
66
67
68
69
70
// 云函数入口文件
const cloud = require('wx-server-sdk')
 
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
 
// 云函数入口函数
exports.main = async (event, context) => {
  // const wxContext = cloud.getWXContext()
  // return {
  //   event,
  //   openid: wxContext.OPENID,
  //   appid: wxContext.APPID,
  //   unionid: wxContext.UNIONID,
  // }
  let {userInfo,hazmatId} = event
  return cloud.database().collection("hazmatFlowList").aggregate()
    .lookup({
      from: "userList",
      localField: 'create_id',
      foreignField: 'id',
      as: 'user'
    })
    .unwind({
      path: "$user",
      preserveNullAndEmptyArrays: true
    })
    .lookup({
      from: "departmentList",
      localField: "user.depart_id",
      foreignField: "id",
      as: "user.department"
    })
    .unwind({
      path: "$user.department",
      preserveNullAndEmptyArrays: true
    })
    .lookup({
      from: "hazmatBasic",
      localField: 'basic_id',
      foreignField: 'id',
      as: 'hazmatBasic'
    })
    .unwind({
      path: "$hazmatBasic",
      preserveNullAndEmptyArrays: true
    })
    .lookup({
      from: "hazmatList",
      localField: 'hazmat_id',
      foreignField: 'id',
      as: 'codeTemp'
    })
    .addFields({
      code: { $arrayElemAt: ["$codeTemp.code", 0] }
    })
    .project({
      codeTemp: 0
    })
    .match({
      hazmat_id: hazmatId
    })
    .end({
      success: function (res) {
        return res;
      },
      fail(error) {
        return error;
      }
    })
}