diff --git a/internal/api/mobile/order/submit.go b/internal/api/mobile/order/submit.go index cf035b1..34870f8 100755 --- a/internal/api/mobile/order/submit.go +++ b/internal/api/mobile/order/submit.go @@ -431,6 +431,69 @@ func ShaMaOrderSubmit(tx *gorm.DB, ip string, data map[uint][]order_preview.Good return resp, nil } +func SupplyOrderSubmit(tx *gorm.DB, ip string, data map[uint][]order_preview.GoodsDetail, vendor uint, previewOrderAddr order_preview.Addr, fData map[uint]decimal.Decimal, channelOrderID string) (jcook.OrderSubmitResp, error) { + client := jcook.GetClient() + t := make([]jcook.LogisticsInfo, 0) + orderFee := decimal.Zero + for _, j := range data[vendor] { + var sku goods.Sku + if err := tx.First(&sku, "id = ?", j.SkuID).Error; err != nil { + return jcook.OrderSubmitResp{}, err + } + cid, _ := strconv.Atoi(sku.ThirdPartySkuId) + t = append(t, jcook.LogisticsInfo{ + SkuID: uint(cid), + Quantity: j.Quantity, + SkuPrice: sku.PurchasePrice, + }) + amount := sku.PurchasePrice.Mul(decimal.NewFromInt(int64(j.Quantity))) + orderFee = orderFee.Add(amount) + } + addr := previewOrderAddr.Province + previewOrderAddr.City + previewOrderAddr.District + previewOrderAddr.Address + req1 := jcook.OrderSubmitReq{ + Address: addr, + SkuList: t, + OrderFee: orderFee, + Receiver: jcook.OrderReceiver{ + Name: previewOrderAddr.ReceiverName, + Mobile: previewOrderAddr.Mobile, + }, + FreightFee: fData[vendor], + UserIp: ip, + ChannelOrderID: channelOrderID, + } + var resp jcook.OrderSubmitResp + if err := client.Exec(req1, &resp); err != nil { + if err.Error() == "商品价格不匹配" { + go func() { + rq := jcook.SkuPriceReq{} + for _, info := range t { + rq.SkuIDSet = append(rq.SkuIDSet, info.SkuID) + } + var res []jcook.SkuPriceResp + if err := client.Exec(rq, &res); err != nil { + return + } + if len(res) == 0 { + return + } + for _, t := range res { + var sku goods2.RecookGoodsSkuModel + if err := mysql.Db.Table(sku.TableName()).Where("third_party_sku_id = ? and third_party_type=3", t.SkuID).Updates(map[string]interface{}{ + "purchase_price": t.SupplyPrice, + }).Error; err != nil { + log.Println(err.Error()) + return + } + } + }() + return jcook.OrderSubmitResp{}, errors.New("价格变动,请重新下单") + } + return jcook.OrderSubmitResp{}, err + } + return resp, nil +} + func GetVirtualID() uint { id, _ := snow.GetOrderWorker().NextID() return uint(id) diff --git a/internal/cron/task.go b/internal/cron/task.go index a391cf1..fa6fc17 100644 --- a/internal/cron/task.go +++ b/internal/cron/task.go @@ -60,9 +60,9 @@ func Task(c *cron.Cron) { if configs.IsProductionEnv() { go TaskMq() - // 启动供应链任务 - SupplyTask.run() } + // 启动供应链任务 + SupplyTask.run() if configs.IsProductionEnv() { //go ShaMaMq()