Bläddra i källkod

添加了供应商相关的接口

mainqaq 3 år sedan
förälder
incheckning
0dc9e93669
3 ändrade filer med 109 tillägg och 20 borttagningar
  1. 62 1
      controllers/supply_order_api_contorller.go
  2. 10 9
      models/supply.models.go
  3. 37 10
      service/supply_service.go

+ 62 - 1
controllers/supply_order_api_contorller.go Visa fil

@@ -19,7 +19,12 @@ type SupplyOrderApiController struct {
19 19
 }
20 20
 
21 21
 func SupplyOrderApiRegistRouters() {
22
-
22
+	//删除单条联系人
23
+	beego.Router("/api/supply/delcontactone", &SupplyOrderApiController{}, "get:DelContactOne")
24
+	//获取单条供应商记录
25
+	beego.Router("/api/supply/getsupplyone", &SupplyOrderApiController{}, "get:GetSupplyOne")
26
+	//获取供应商类别
27
+	beego.Router("/api/supply/getsupplytype", &SupplyOrderApiController{}, "get:GetSupplyType")
23 28
 	//删除供应商及联系人
24 29
 	beego.Router("/api/supply/delsupply", &SupplyOrderApiController{}, "post:DelSupply")
25 30
 	//获取供应商编码
@@ -62,6 +67,38 @@ func SupplyOrderApiRegistRouters() {
62 67
 	beego.Router("/api/supply/getgoodordercountlist", &SupplyOrderApiController{}, "Get:GetGoodOrderCountList")
63 68
 }
64 69
 
70
+//获取单条供应商记录
71
+func (this *SupplyOrderApiController) GetSupplyOne() {
72
+	id, _ := this.GetInt64("id")
73
+	if id == 0 {
74
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
75
+		return
76
+	}
77
+	supply, contact, err := service.GetSupplyOne(id)
78
+	if err != nil {
79
+		utils.ErrorLog(err.Error())
80
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
81
+		return
82
+	}
83
+	this.ServeSuccessJSON(map[string]interface{}{
84
+		"supply":  supply,
85
+		"contact": contact,
86
+	})
87
+	return
88
+}
89
+
90
+//获取供应商类别
91
+func (this *SupplyOrderApiController) GetSupplyType() {
92
+	orgId := this.GetAdminUserInfo().CurrentOrgId
93
+	costClassify := "供应商类别"
94
+	drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
95
+	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
96
+	this.ServeSuccessJSON(map[string]interface{}{
97
+		"list": drugTypeList,
98
+	})
99
+	return
100
+}
101
+
65 102
 //删除供应商及联系人
66 103
 func (this *SupplyOrderApiController) DelSupply() {
67 104
 	//拿到供应商的id
@@ -85,6 +122,25 @@ func (this *SupplyOrderApiController) DelSupply() {
85 122
 	return
86 123
 }
87 124
 
125
+//删除单条联系人记录
126
+func (this *SupplyOrderApiController) DelContactOne() {
127
+	id, _ := this.GetInt64("id")
128
+	if id == 0 {
129
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人id不能为空")
130
+		return
131
+	}
132
+	err := service.DelContactOne(id)
133
+	if err != nil {
134
+		utils.ErrorLog(err.Error())
135
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
136
+		return
137
+	}
138
+	this.ServeSuccessJSON(map[string]interface{}{
139
+		"list": "删除成功",
140
+	})
141
+	return
142
+}
143
+
88 144
 //获取供应商编码
89 145
 func (this *SupplyOrderApiController) GetSupplyCode() {
90 146
 	supply, err := service.GetSuppliyCode()
@@ -135,6 +191,11 @@ func (this *SupplyOrderApiController) SaveSupply() {
135 191
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
136 192
 		return
137 193
 	}
194
+	//判断供应商编号是否有重复的
195
+	codebool, _ := service.FindSupplierCode(supplierCode)
196
+	if codebool {
197
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
198
+	}
138 199
 	supplierType, _ := this.GetInt64("suppliertype") //供应商类别
139 200
 	vatRate, _ := this.GetFloat("vatrate")           //增值税税率
140 201
 	number := this.GetString("number")               //纳税人识别号

+ 10 - 9
models/supply.models.go Visa fil

@@ -2,15 +2,16 @@ package models
2 2
 
3 3
 //供应商联系人
4 4
 type SpSupplierContacts struct {
5
-	ID        int64  `gorm:"column:id" json:"id" from:"id"`
6
-	Name      string `gorm:"column:name" json:"name" from:"name"`
7
-	Phone     string `gorm:"column:phone" json:"phone" from:"phone"`
8
-	Address   string `gorm:"column:address" json:"address" from:"address"`
9
-	IsFirst   int64  `gorm:"column:is_first" json:"is_first" from:"is_first"`
10
-	UserOrgId int64  `gorm:"column:user_org_id" json:"user_org_id" from:"user_org_id"`
11
-	Status    int64  `gorm:"column:status" json:"status" from:"status"`
12
-	Ctime     int64  `gorm:"column:ctime" json:"ctime" from:"ctime"`
13
-	Mtime     int64  `gorm:"column:mtime" json:"mtime" from:"mtime"`
5
+	ID           int64  `gorm:"column:id" json:"id" from:"id"`
6
+	Name         string `gorm:"column:name" json:"name" from:"name"`
7
+	Phone        string `gorm:"column:phone" json:"phone" from:"phone"`
8
+	Address      string `gorm:"column:address" json:"address" from:"address"`
9
+	IsFirst      int64  `gorm:"column:is_first" json:"is_first" from:"is_first"`
10
+	SupplierCode string `gorm:"column:supplier_code" json:"supplier_code" from:"supplier_code"`
11
+	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" from:"user_org_id"`
12
+	Status       int64  `gorm:"column:status" json:"status" from:"status"`
13
+	Ctime        int64  `gorm:"column:ctime" json:"ctime" from:"ctime"`
14
+	Mtime        int64  `gorm:"column:mtime" json:"mtime" from:"mtime"`
14 15
 }
15 16
 
16 17
 func (SpSupplierContacts) TableName() string {

+ 37 - 10
service/supply_service.go Visa fil

@@ -7,6 +7,20 @@ import (
7 7
 	"time"
8 8
 )
9 9
 
10
+//删除单条联系人记录
11
+func DelContactOne(id int64) error {
12
+	err := XTWriteDB().Model(&models.SpSupplierContacts{}).Where("id = ?", id).Update("status", 0).Error
13
+	return err
14
+}
15
+
16
+//获取单条供应商记录
17
+func GetSupplyOne(id int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
18
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
19
+	code := supply.SupplierCode
20
+	err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).Find(&contact).Error
21
+	return supply, contact, err
22
+}
23
+
10 24
 //删除供应商及联系人
11 25
 func DelSupply(supply models.SpSupplierName) error {
12 26
 	err := XTWriteDB().Model(&supply).Update("status", 0).Error
@@ -31,14 +45,15 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
31 45
 		isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64)
32 46
 
33 47
 		spcontacts := models.SpSupplierContacts{
34
-			Name:      name,
35
-			Phone:     phone,
36
-			Address:   address,
37
-			IsFirst:   isfirst,
38
-			UserOrgId: orgId,
39
-			Status:    1,
40
-			Ctime:     time.Now().Unix(),
41
-			Mtime:     0,
48
+			Name:         name,
49
+			Phone:        phone,
50
+			Address:      address,
51
+			IsFirst:      isfirst,
52
+			SupplierCode: supplierCode,
53
+			UserOrgId:    orgId,
54
+			Status:       1,
55
+			Ctime:        time.Now().Unix(),
56
+			Mtime:        0,
42 57
 		}
43 58
 		err = SaveContacts(spcontacts, tx)
44 59
 		if isfirst == 1 {
@@ -82,7 +97,7 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
82 97
 //获取供应商编码
83 98
 func GetSuppliyCode() (spcode []*models.SpSupplierName, err error) {
84 99
 
85
-	err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' ").Order("supplier_code desc").First(&spcode).Error
100
+	err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 ").Order("supplier_code desc").First(&spcode).Error
86 101
 	return spcode, err
87 102
 }
88 103
 
@@ -98,6 +113,18 @@ func FindSupplierName(supplierName string) (sbool bool, err error) {
98 113
 	return sbool, err
99 114
 }
100 115
 
116
+//查询供应商的编号是否有重复
117
+func FindSupplierCode(supplierCode string) (codebool bool, err error) {
118
+	var total int
119
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierCode).Count(&total).Error
120
+	if total != 0 {
121
+		codebool = true
122
+	} else {
123
+		codebool = false
124
+	}
125
+	return codebool, err
126
+}
127
+
101 128
 //保存一条供应商数据
102 129
 func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
103 130
 	err := tx.Create(&supply).Error
@@ -106,7 +133,7 @@ func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
106 133
 
107 134
 //获取联系人的id
108 135
 func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) {
109
-	err = tx.Model(&models.SpSupplierContacts{}).Select("id").Order("id desc").First(&spconid).Error
136
+	err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("and status = 1").Order("id desc").First(&spconid).Error
110 137
 	return
111 138
 }
112 139