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
import { default as BaseController } from "../../baseController";
import { Post } from "egg-shell-decorators";
import { AppProductApply } from "../../../entity/crm/app/appProductApply";
import { BaseProductInfo } from "../../../entity/basicInfo/base/baseProductInfo";
import { In } from "typeorm";
export default class AppProductApplyController extends BaseController {
  //#region 保存物料
  /**
   * 保存物料
   */
  @Post()
  public async save() {
    let { ctx } = this;
    let body = ctx.request.body;
    try {
      if (!body.productName) {
        this.info.result = false;
        this.info.msg = "物料名称不能为空!";
        ctx.body = this.info;
        return;
      }
      if (!body.productModel) {
        this.info.result = false;
        this.info.msg = "物料条码不能为空!";
        ctx.body = this.info;
        return;
      }
      // 保存数据
      body.images = JSON.stringify(body.images);
      body.auditDate = new Date();
      body.auditing = 0;
 
      if (!body.productApply_Id) {
        // 新建时,获取编码
        let code = await this.ctx.service.common.getCodeRegular(1791);
        body.productCode = code;
      }
      // 设置账套数据
      await this.setAccountInfo(body);
      await this.dbWrite.save(AppProductApply, body);
 
      this.info.result = true;
      this.info.data = body;
      this.info.msg = "物料申请保存成功";
 
      ctx.body = this.info;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "物料申请保存失败" + error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region ProductAuditing
  /**
   * 物料审核
   */
  @Post()
  public async productAuditing() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo();
 
    try {
      if (!body.IDs) {
        this.info.result = false;
        this.info.msg = "至少选择一条物料";
        return;
      }
      let IDs = body.IDs.split(",");
 
      await this.dbWrite.update(
        AppProductApply,
        {
          userProduct_Id: userInfo.userProduct_Id,
          productApply_Id: In(IDs)
        },
        {
          auditor: userInfo.userTrueName,
          auditing: 2,
          auditDate: new Date()
        }
      );
 
      let datatable = await this.dbRead.find(AppProductApply, {
        // userProduct_Id: userInfo.userProduct_Id,
        productApply_Id: In(IDs)
      });
 
      for (let item of datatable) {
        let prodctInfo = new BaseProductInfo();
        prodctInfo.productCode = item.productCode;
        prodctInfo.brandName = item.brandName;
        prodctInfo.productModel = item.productModel;
        prodctInfo.consignor_Id = item.consignor_Id;
        prodctInfo.consignorCode = item.consignorCode;
        prodctInfo.consignorName = item.consignorName;
        prodctInfo.productName = item.productName;
        prodctInfo.type_Id = item.typeid;
        prodctInfo.typeName = item.typeName;
        prodctInfo.smallUnit = item.smallUnit;
        prodctInfo.originPlace = item.originPlace;
        await this.setAccountInfo(prodctInfo);
        await this.dbWrite.save(prodctInfo);
      }
 
      this.info.result = true;
      this.info.msg = "审核成功";
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    ctx.body = this.info;
  }
  //#endregion
}