animeic 1 år sedan
förälder
incheckning
40fc09edf4
5 ändrade filer med 78 tillägg och 6 borttagningar
  1. 11 1
      boxcost/api/plan.go
  2. 45 2
      boxcost/api/print.go
  3. 11 1
      boxcost/api/supplier.go
  4. 10 1
      boxcost/api/utils.go
  5. 1 1
      boxcost/db/model/user.go

+ 11 - 1
boxcost/api/plan.go

@@ -50,7 +50,7 @@ func ProductPlan(r *GinRouter) {
 	r.GET("/plan/cost/download", DownLoadPlanCost)
 
 	// 单据批量分配给供应商
-	r.GET("/plan/alloc/batch", PlanAllocBatch)
+	r.GETJWT("/plan/alloc/batch", PlanAllocBatch)
 
 }
 
@@ -58,6 +58,16 @@ func ProductPlan(r *GinRouter) {
 // id 为计划id
 // /plan/alloc/batch?id=xxx
 func PlanAllocBatch(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	// ?验证当前账户是否可发送订单
+	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
+	user, err1 := getUserById(apictx, userId)
+	if err1 != nil {
+		return nil, errors.New("用户错误")
+	}
+	if !isSender(user.Roles) {
+		return nil, errors.New("没有发送权限")
+	}
+
 	_planId := c.Query("id")
 	planId, err := primitive.ObjectIDFromHex(_planId)
 	if err != nil {

+ 45 - 2
boxcost/api/print.go

@@ -1,10 +1,10 @@
 package api
 
 import (
-	"box-cost/db/model"
 	"box-cost/db/repo"
 
 	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 // func UpdateIsAckStatus(c *gin.Context, apictx *ApiSession) (interface{}, error) {
@@ -73,9 +73,52 @@ func Printr(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	// bill.Remark = ""
 	// fmt.Println(bill)
 	// !数据库报错,不能识别remark == ""
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, "6440dc82afe88127dda4a5ef", &model.ProductBill{Remark: ""})
+	// !无效
+	// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, "6440dc82afe88127dda4a5ef", &model.ProductBill{Remark: ""})
+	// !有效
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, "6440dc82afe88127dda4a5ef", bson.M{"remark": ""})
 
 }
 
 // ? 测试供应商备注
 // {{boxcost}}/bill/produce/download?id=6444d14db2a7c8eae4240579
+
+// {
+//     "_id": ObjectId("6440dc82afe88127dda4a5ef"),
+//     "packId": ObjectId("643f9bdd75db8728bf88c0da"),
+//     "planId": ObjectId("643fae2175db8728bf88c0e7"),
+//     "supplierId": ObjectId("63f3167b1031634bc6eeb8be"),
+//     "userId": ObjectId("63e208dc7452ab74932b9e37"),
+//     "userName": "郑茜",
+//     "type": "成品采购",
+//     "status": "complete",
+//     "reviewed": NumberInt("1"),
+//     "createTime": ISODate("2023-04-20T06:32:34.18Z"),
+//     "updateTime": ISODate("2023-04-24T06:05:42.177Z"),
+//     "supplier": "029-温州意彩织带有限公司",
+//     "sendTo": "新都军屯镇食品大道158号稻香村--联系电话巫元萍13808077671",
+//     "productName": "稻香拾味定制款手提盒(5000套)--墨绿色罗纹丝带",
+//     "products": [
+//         {
+//             "id": "16819724424006440d278afe88127dda4a5e6",
+//             "name": "墨绿色罗纹丝带",
+//             "norm": "2cm*45cm",
+//             "orderCount": NumberInt("5100"),
+//             "orderPrice": 0.09,
+//             "remark": "2023粽子礼盒稻香拾味定制款彩盒手提绳",
+//             "deliveryTime": ISODate("2023-04-24T06:35:08.000Z"),
+//             "confirmCount": NumberInt("5100"),
+//             "unit": "元/对"
+//         }
+//     ],
+//     "serialNumber": "CPCG-000022",
+//     "remark": "2023粽子礼盒稻香拾味定制款彩盒手提绳",
+//     "isAck": false,
+//     "signUsers": [
+//         ObjectId("63e209a87452ab74932b9e38")
+//     ],
+//     "isSend": true,
+//     "sendTime": ISODate("2023-04-20T06:47:00.685Z"),
+//     "supplierRemark": " ",
+//     "completeTime": ISODate("2023-04-24T06:05:42.176Z")
+// }

+ 11 - 1
boxcost/api/supplier.go

@@ -44,7 +44,7 @@ func Supplier(r *GinRouter) {
 	r.POSTJWT("/supplier/bill/ack", SupplierBillAck)
 
 	// 单据分配给供应商
-	r.GET("/supplier/bill/alloc", SupplierBillAlloc)
+	r.GETJWT("/supplier/bill/alloc", SupplierBillAlloc)
 
 }
 
@@ -140,6 +140,16 @@ func genSupplierSmsTemp(billId primitive.ObjectID, billType string, apictx *ApiS
 // id为订单id
 // /supplier/bill/alloc?id=xxx&type=purchase
 func SupplierBillAlloc(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	// ?验证当前账户是否可发送订单
+	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
+	user, err1 := getUserById(apictx, userId)
+	if err1 != nil {
+		return nil, errors.New("用户错误")
+	}
+	if !isSender(user.Roles) {
+		return nil, errors.New("没有发送权限")
+	}
+
 	billId, _ := primitive.ObjectIDFromHex(c.Query("id"))
 	if billId.IsZero() {
 		return nil, errors.New("订单id不正确")

+ 10 - 1
boxcost/api/utils.go

@@ -137,7 +137,6 @@ func excelToPdf(formBody *bytes.Buffer, pdfHost string) (*http.Response, error)
 }
 
 func isManager(roles []string) bool {
-
 	if len(roles) > 0 {
 		for _, role := range roles {
 			if role == "manager" {
@@ -147,6 +146,16 @@ func isManager(roles []string) bool {
 	}
 	return false
 }
+func isSender(roles []string) bool {
+	if len(roles) > 0 {
+		for _, role := range roles {
+			if role == "sender" {
+				return true
+			}
+		}
+	}
+	return false
+}
 func getUserById(apictx *ApiSession, id primitive.ObjectID) (*model.UserSmaple, error) {
 	user := &model.UserSmaple{}
 	_, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{

+ 1 - 1
boxcost/db/model/user.go

@@ -14,7 +14,7 @@ type UserSmaple struct {
 	Avatar     string             `bson:"avatar,omitempty" json:"avatar"`
 	LoginName  string             `bson:"loginName,omitempty" json:"loginName"`
 	City       string             `bson:"city,omitempty" json:"city"`
-	Roles      []string           `bson:"roles,omitempty" json:"roles"`
+	Roles      []string           `bson:"roles,omitempty" json:"roles"` // manager管理员(可审核) supplier供应商 sender可发送短信
 	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
 	UpdateTime time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
 }