333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { default as BaseController } from "../baseController";
import { Post } from "egg-shell-decorators";
import { PurchaseShelve } from "../../entity/inbound/purchase/purchaseShelve";
import * as sql from "mssql";
import { In } from "typeorm";
import { SysUserLog } from "../../entity/sys/core/sysUserLog";
 
/**
 * 收货 - 上架
 */
export default class ShelveController extends BaseController {
  //#region 强制上架完成 forceShelve
  @Post()
  public async forceShelve() {
    let { ctx } = this;
    let body = ctx.request.body;
    try {
      // if (!Array.isArray(body.shelve_Ids) || body.shelve_Ids.length) {
      //   this.info.msg = "数据不存在";
      //   this.info.result = false;
      //   ctx.body = this.info;
      //   return;
      // }
      if (!body.shelve_Ids) {
        this.info.msg = "数据不存在";
        this.info.result = false;
        ctx.body = this.info;
        return;
      }
 
      await this.dbWrite.update(
        PurchaseShelve,
        {
          shelve_Id: In(body.shelve_Ids)
        },
        {
          onShelveStatus: "上架完成"
        }
      );
      this.info.result = true;
      this.info.msg = "强制上架完成";
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
 
    ctx.body = this.info;
    return;
  }
  //#endregion
 
  //#region 取消上架 cancelShelve
  @Post()
  public async cancelShelve() {
    let { ctx } = this;
    let body = ctx.request.body;
 
    const connection: any = await this.dbWrite.connection;
    let request = new sql.Request(connection.driver.master);
    request.input("shelve_Ids", body.shelve_Ids);
    request.output("outMsg", sql.NVarChar(2000));
    let result = await request.execute("sp_Purchase_Shelve_Cancel");
    let outMsg = result.output.outMsg;
 
    if (outMsg) {
      this.info.msg = outMsg;
      this.info.result = false;
    } else {
      this.info.msg = "上架撤销成功";
      this.info.result = true;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 审核 singleConfirm
  @Post()
  public async singleConfirm() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
 
    if (!Array.isArray(body.idValues) || body.idValues.length) {
      this.info.msg = "数据不存在";
      this.info.result = false;
      ctx.body = this.info;
      return;
    }
 
    let outMsg = [];
    for (let idValue of body.idValues) {
      const connection: any = await this.dbWrite.connection;
      let request = new sql.Request(connection.driver.master);
      request.input("shelve_Id", idValue);
      request.input("user_Id", userInfo.user_Id);
      request.input("menu_Id", body.menu_Id);
      request.output("outMsg", sql.NVarChar(2000));
      let result = await request.execute("sp_Purchase_Shelve_Check");
      outMsg.push(result.output.outMsg);
    }
 
    if (outMsg) {
      this.info.msg = outMsg.join("<br/>");
      this.info.result = false;
    } else {
      this.info.msg = "确认上架成功";
      this.info.result = true;
    }
    ctx.body = this.info;
    //#endregion
  }
 
  //#region 入库指令 shelveOrder
  @Post()
  public async shelveOrder() {
    let { ctx } = this;
    let body = ctx.request.body;
    try {
      await this.dbWrite.update(
        PurchaseShelve,
        {
          shelve_Id: body.shelve_Id
        },
        {
          onShelveStatus: "待上架"
        }
      );
      this.info.result = true;
      this.info.msg = "入库操作完成";
    } catch (error) {
      this.info.result = false;
      this.info.msg = "错误:" + error.message;
    }
 
    ctx.body = this.info;
    return;
  }
  //#endregion
  //#region 删除身份证信息
  @Post()
  public async deleteShelveCode() {
    try {
      let userInfo = await this.userInfo;
      // 根据id删除
      await this.dbWrite.delete(PurchaseShelve, {
        shelve_Id: In(this.body.ids)
      });
      // 添加日志
      let userLog = new SysUserLog();
      userLog.operateType = "码盘上架查询";
      userLog.action = "删除单号:-" + this.body.shelveCode;
      userLog.iP = this.ctx.request.ip;
      userLog.userTrueName = userInfo.userTrueName;
 
      await this.setAccountInfo(userLog);
      await this.dbWrite.save(userLog);
 
      this.info.result = true;
      this.info.msg = "删除成功!";
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误消息:" + ex.message;
    }
    this.ctx.body = this.info;
  }
  //#endregion
}