| | |
| | | if req.Number == "" { |
| | | return nil, errors.New("采购编号不能为空") |
| | | } |
| | | err := global.GVA_DB.Model(&purchase.Purchase{}).Where("number = ?", req.Number). |
| | | Updates(map[string]interface{}{"status": purchase.OrderStatusStored}).Error |
| | | m := make(map[string]interface{}) |
| | | m["status"] = purchase.OrderStatusStored |
| | | if req.Status > 0 { |
| | | m["status"] = req.Status |
| | | } |
| | | err := global.GVA_DB.Model(&purchase.Purchase{}).Where("number = ?", req.Number).Updates(m).Error |
| | | return new(UpdatePurchaseStatusResponse), err |
| | | } |
| | | |
| | |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | purchaseIds := make([]uint, 0) |
| | | for _, p := range ps { |
| | | purchaseIds = append(purchaseIds, p.ID) |
| | | } |
| | | if len(purchaseIds) == 0 { |
| | | return nil, errors.New("没有查到采购单") |
| | | } |
| | | pps := make([]*purchase.PurchaseProducts, 0) |
| | | err = global.GVA_DB.Model(&purchase.PurchaseProducts{}).Where("purchase_id in (?)", purchaseIds).Preload("Product").Find(&pps).Error |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | infos := make([]*PurchaseInfo, 0) |
| | | for _, p := range ps { |
| | | var info PurchaseInfo |
| | |
| | | info.SupplierName = p.Supplier.Name |
| | | info.Amount = p.Quantity.IntPart() |
| | | info.Status = int64(p.Status) |
| | | infos = append(infos, &info) |
| | | if p.Status == purchase.OrderStatusStored || p.Status == purchase.OrderStatusCompleted { |
| | | info.FinishAmount = info.Amount |
| | | } |
| | | for _, pp := range pps { |
| | | if int(p.ID) == pp.PurchaseId { |
| | | ni := info |
| | | ni.ProductId = pp.Product.Number |
| | | ni.ProductName = pp.Product.Name |
| | | ni.Specs = pp.Product.Specifications |
| | | ni.Unit = pp.Product.Unit |
| | | infos = append(infos, &ni) |
| | | } |
| | | } |
| | | } |
| | | resp := new(GetPurchaseInfoResponse) |
| | | resp.Infos = infos |