schangxiang@126.com
2025-09-09 3d8966ba2c81e7e0365c8b123e861d18ee4f94f5
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
import BaseController from "../baseController";
import { Post } from "egg-shell-decorators";
import * as sql from "mssql";
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
import { SaleOrderList } from "../../entity/outbound/sale/saleOrderList";
import { SaleReturn } from "../../entity/outbound/service/saleReturn";
import { In } from "typeorm";
/**
 * 身份证处理
 */
export default class ReturnController extends BaseController {
  //#region getByCode
  /// <summary>
  /// 根据销售退货单Code获取销售退货单信息
  /// </summary>
  /// <param name="ReturnCode">销售退货单号</param>
  /// <returns>销售退货实体</returns>
  @Post()
  public async getByCode() {
    let orderCode = this.body.orderCode;
    let where: any = {};
    let userInfo = await this.userInfo;
    if (!userInfo) {
      this.info.result = false;
      this.info.data = null;
      this.info.msg = "获取失败。";
      this.ctx.body = this.info;
    }
    where.orderCode = orderCode;
    where.userProduct_Id = userInfo.userProduct_Id;
    let model = await this.dbRead.findOne(SaleOrder, where);
    if (!model) {
      this.info.result = false;
      this.info.data = null;
      this.info.msg = "获取失败。";
      this.ctx.body = this.info;
    } else {
      let detailList = await this.dbRead.find(SaleOrderList, {
        order_Id: model.order_Id
      });
      model.saleOrderList = detailList;
      this.info.result = true;
      this.info.data = model;
      this.ctx.body = this.info;
    }
  }
  //#endregion
 
  //#region  审核
  /// <summary>
  /// 预到货单-审核
  /// </summary>
  /// <param name="reqinfo"></param>
  /// <returns></returns>
  @Post()
  public async singleAuditing() {
    let return_Ids = this.body.return_Ids;
    let userInfo = await this.ctx.helper.userInfo();
    try {
      await this.dbWrite.update(
        SaleReturn,
        {
          return_Id: In(return_Ids)
        },
        {
          statusID: 2,
          auditor: userInfo.userTrueName,
          auditing: 2,
          auditDate: new Date(),
          statusText: "审核成功"
        }
      );
 
      this.info.result = true;
      this.info.msg = "审核成功";
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    this.ctx.body = this.info;
  }
  //#endregion
  //#region 转到预到货单
  @Post()
  public async toPurchase() {
    let userInfo = await this.ctx.helper.userInfo();
    try {
      const connection: any = await this.dbWrite.connection;
      let request = new sql.Request(connection.driver.master);
      request.input("return_Id", this.body.return_Id);
      request.input("user_Id", userInfo.user_Id);
      request.input("userTrueName", userInfo.userTrueName);
      request.input("userProduct_Id", userInfo.userProduct_Id);
      request.output("outMsg", sql.NVarChar(2000));
      let result = await request.execute("sp_Sale_Return_ToPurchaseOrder");
      let outMsg = result.output.outMsg;
      if (outMsg) {
        this.info.msg = outMsg;
        this.info.result = false;
        this.ctx.body = this.info;
      } else {
        this.info.msg = "转到预到货成功";
        this.info.result = true;
        this.ctx.body = this.info;
      }
    } catch (error) {
      this.info.msg = error.message;
      this.info.result = false;
      this.ctx.body = this.info;
    }
  }
 
  //#endregion
}