tm_order.go 17.1 KB
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
package tm

import (
	"context"
	"encoding/json"
	link "github.com/alibabacloud-go/linkedmall-20220531/v2/client"
	"github.com/alibabacloud-go/tea/tea"
	"github.com/gogf/gf/encoding/gjson"

)

type orderTm struct {
}

var Order = orderTm{}

type OrderAddress struct {
	AddressDetail string `json:"AddressDetail"`
	DivisionCode  string `json:"DivisionCode"`
	FullName      string `json:"FullName"`
	Mobile        string `json:"Mobile"`
	TownDivisionCode string `json:"TownDivisionCode"`
}
type RenderDistributionOrderReq struct {
	ItemInfoLists []*ItemInfo `json:"ItemInfoLists"`
	BuyerId string `json:"BuyerId"`
	Addr string `json:"Addr"`
}
type ItemInfo struct{
	DistributionMallId string `json:"DistributionMallId,omitempty" xml:"DistributionMallId,omitempty"`
	LmItemId           string `json:"LmItemId,omitempty" xml:"LmItemId,omitempty"`
	Quantity           int32  `json:"Quantity,omitempty" xml:"Quantity,omitempty"`
	SkuId              string `json:"SkuId,omitempty" xml:"SkuId,omitempty"`
}
type RenderDistributionOrderRes struct {
	Code    string `json:" Code"`
	Message string `json:"Message"`
	Model   struct {
		AddressInfos []struct {
			AddressDetail    string `json:"AddressDetail"`
			AddressId        int64  `json:"AddressId"`
			DivisionCode     string `json:"DivisionCode"`
			Receiver         string `json:"Receiver"`
			ReceiveRPhone    string `json:"Receive rPhone"`
			TownDivisionCode string `json:"TownDivisionCode"`
		} `json:"AddressInfos"`
		CanSell          bool `json:"CanSell"`
		RenderOrderInfos []struct {
			CanSell       bool `json:"CanSell"`
			DeliveryInfos []struct {
				DisplayName string `json:"DisplayName"`
				Id          string `json:"Id"`
				PostFee     int    `json:"PostFee"`
				ServiceType int    `json:"ServiceType"`
			} `json:"DeliveryInfos"`
			InvoiceInfo struct {
			} `json:"InvoiceInfo"`
			ItemInfos []struct {
				CanSell            bool   `json:"CanSell"`
				DistributionMallId string `json:"DistributionMallId"`
				Features           struct {
					DeliveryVersion string `json:"delivery_version"`
					ExTraPeriod     string `json:"ex traPeriod"`
					TaxInvoice      string `json:"tax_invoice"`
				} `json:"Features"`
				ItemId     string `json:"ItemId"`
				ItemName   string `json:"ItemName"`
				ItemPicUrl string `json:"ItemPicUrl"`
				Price      int    `json:"Price"`
				Quantity   int    `json:"Quantity"`
				SkuId      int64  `json:"SkuId"`
				SkuName    string `json:"SkuName"`
			} `json:"ItemInfos"`
		} `json:"RenderOrderInfos"`
		UnsellableRenderOrderInfos []struct {
			ItemInfos []struct {
				ItemPicUrl string `json:"ItemPicUrl"`
				Message    string `json:"Message"`
				Price      int    `json:"Price"`
				ItemName   string `json:"ItemName"`
				Quantity   int    `json:"Quantity"`
				Features   struct {
					DeliveryVersion string `json:"delivery_version"`
				} `json:"Features"`
				SkuId              int    `json:"SkuId"`
				ItemId             string `json:"ItemId"`
				DistributionMallId string `json:"DistributionMallId"`
				CanSell            bool   `json:"CanSell"`
			} `json:"ItemInfos"`
			CanSell bool `json:"CanSell"`
		} `json:"UnsellableRenderOrderInfos"`
	} `json:"Model"`
	RequestId string `json:"RequestId"`
	Success   bool   `json:"Success"`
}

type OrderCreateReq struct {
	UserId       string
	ChannelOrder string
	Address      string
	ItemLists    []OrderGoodsItem
}
type OrderGoodsItem struct {
	LmItemId   string `json:"LmItemId"`
	Quantity string `json:"Quantity"`
	SkuId    string `json:"SkuId"`
	DistributionMallId string `json:"DistributionMallId"`

}
type OrderCreateRes struct {
	RequestId string `json:"RequestId"`
	Message   string `json:"Message"`
	Model     string `json:"Model"`
	Code      string `json:"Code"`
	Success   bool   `json:"Success"`
}
type OrderFilter struct {
	DistributionTradeId     string `json:"DistributionTradeId,omitempty"`
	OrderList    []string `json:"OrderList,omitempty"`
	LogisticsStatus string   `json:"LogisticsStatus,omitempty"`
	OrderStatus     string   `json:"OrderStatus,omitempty"`
}
type T struct {
	CreateDate          string `json:"createDate"`
	DistributionOrderId string `json:"distributionOrderId"`
	DistributorId       string `json:"distributorId"`
	LogisticsStatus     string `json:"logisticsStatus"`
	OrderAmount         string `json:"orderAmount"`
	OrderStatus         string `json:"orderStatus"`
	SubOrderList        []struct {
		ItemId    string `json:"itemId"`
		ItemPic   string `json:"itemPic"`
		ItemPrice []struct {
			FundAmountMoney string `json:"fundAmountMoney"`
		} `json:"itemPrice"`
		ItemTitle               string `json:"itemTitle"`
		Number                  string `json:"number"`
		SkuId                   string `json:"skuId"`
		SkuName                 string `json:"skuName"`
		OrderStatus             string `json:"orderStatus"`
		LogisticsStatus         string `json:"logisticsStatus"`
		SubDistributionOrderId  string `json:"subDistributionOrderId"`
		MainDistributionOrderId string `json:"mainDistributionOrderId"`
	} `json:"subOrderList"`
}
type OrderListRes struct {
	RequestId   string `json:"RequestId"`
	Message     string `json:"Message"`
	PageSize    int    `json:"PageSize"`
	PageNumber  int    `json:"PageNumber"`
	Code string `json:"Code"`
	Model []struct{
		CreateDate          string `json:"CreateDate"`
		DistributionOrderId string `json:"DistributionOrderId"`
		DistributorId       string `json:"DistributorId"`
		LogisticsStatus     string `json:"LogisticsStatus"`
		OrderAmount         string `json:"OrderAmount"`
		OrderStatus         string `json:"OrderStatus"`
		SubOrderList        []struct {
			ItemId    string `json:"ItemId"`
			ItemPic   string `json:"ItemPic"`
			ItemPrice []struct {
				FundAmountMoney string `json:"FundAmountMoney"`
			} `json:"ItemPrice"`
			ItemTitle               string `json:"ItemTitle"`
			Number                  string `json:"Number"`
			SkuId                   string `json:"SkuId"`
			SkuName                 string `json:"SkuName"`
			OrderStatus             string `json:"OrderStatus"`
			LogisticsStatus         string `json:"LogisticsStatus"`
			SubDistributionOrderId  string `json:"SubDistributionOrderId"`
			MainDistributionOrderId string `json:"MainDistributionOrderId"`
		} `json:"SubOrderList"`
	}
}

type OrderListReq struct {
	DistributorId       string `json:"DistributorId"`
	FilterOption        struct{
		DistributionTradeId string `json:"DistributionTradeId"`
		OrderList       []string `json:"OrderList"`
	}   `json:"FilterOption"`
	PageNumber       int32 `json:"PageNumber"`
	PageSize int32 `json:"PageSize"`
	LogisticsStatus string `json:"LogisticsStatus"`
	OrderStatus     string `json:"OrderStatus"`

}
type FilterOption struct {

}
type OrderInfoReq struct {
	MainDistributionOrderId       string `json:"MainDistributionOrderId"`
	UserId          string `json:"UserId"`
	LmOrderId       string `json:"LmOrderId"`
	LogisticsStatus string `json:"LogisticsStatus"`
	OrderStatus     string `json:"OrderStatus"`
}
type OrderInfoRes struct {
	RequestId   string `json:"RequestId"`
	Message     string `json:"Message"`
	Code string `json:"Code"`
	Model struct{
		CreateDate          string `json:"CreateDate"`
		DistributionOrderId string `json:"DistributionOrderId"`
		DistributorId       string `json:"DistributorId"`
		LogisticsStatus     string `json:"LogisticsStatus"`
		OrderAmount         string `json:"OrderAmount"`
		OrderStatus         string `json:"OrderStatus"`
		SubOrderList        []struct {
			ItemId    string `json:"ItemId"`
			ItemPic   string `json:"ItemPic"`
			ItemPrice []struct {
				FundAmountMoney string `json:"FundAmountMoney"`
			} `json:"ItemPrice"`
			ItemTitle               string `json:"ItemTitle"`
			Number                  string `json:"Number"`
			SkuId                   string `json:"SkuId"`
			SkuName                 string `json:"SkuName"`
			OrderStatus             string `json:"OrderStatus"`
			LogisticsStatus         string `json:"LogisticsStatus"`
			SubDistributionOrderId  string `json:"SubDistributionOrderId"`
			MainDistributionOrderId string `json:"MainDistributionOrderId"`
		} `json:"SubOrderList"`
	} `json:"Model"`
}
type OrderStatusReq struct {
	DistributionTradeId string `json:"DistributionTradeId"`
}
type OrderStatusRes struct {
	RequestId   string `json:"RequestId"`
	Message     string `json:"Message"`
	Code string `json:"Code"`
	Model string `json:"Model"`
	//1:分销单创建中
	//
	//10:采购中
	//
	//20:采购成功,待发货
	//
	//21:采购成功,部分发货
	//
	//22:采购成功,全部发货
	//
	//30:部分采购成功,待发货
	//
	//31:部分采购成功,部分发货
	//
	//32:部分采购成功,全部发货
	//
	//80:交易失败
	//
	//81:采购失败
	//
	//99:交易成功
}
type AddrInfoReq struct {
	DivisionCode          string `json:"DivisionCode"`
}
type AddrInfoRes struct {
	RequestId   string `json:"RequestId"`
	Message     string `json:"Message"`
	Code string `json:"Code"`
	Model struct{
	DivisionList []AddrInfo `json:"DivisionList"`
	} `json:"Model"`
}
type AddrInfo struct {
	ParentId      int    `json:"ParentId"`
	DivisionLevel int    `json:"DivisionLevel"`
	DivisionName  string `json:"DivisionName"`
	Pinyin        string `json:"Pinyin"`
	DivisionCode  int    `json:"DivisionCode"`
}
//Before 验证订单商品
func (s *orderTm) Before(ctx context.Context,itemInfo *RenderDistributionOrderReq) (res *RenderDistributionOrderRes, err error) {
	client,err :=initClient()
	if err!=nil{
		return
	}
	if client==nil{
		return
	}
	if itemInfo==nil{
		return
	}
	var itemInfoLists []*link.RenderDistributionOrderRequestItemInfoLists
	err =gjson.New(itemInfo.ItemInfoLists).Scan(&itemInfoLists)
	result ,err :=client.RenderDistributionOrder(&link.RenderDistributionOrderRequest{
		BuyerId: tea.String(itemInfo.BuyerId),
		DistributorId:      tea.String(server.DistributorId),
		ItemInfoLists:          itemInfoLists,
		TenantId:           tea.String(server.TenantId),
		DeliveryAddress: tea.String(itemInfo.Addr),
      	DistributionSupplierId: tea.String(server.DistributionSupplierId),
	})

	if result==nil{
		return
	}

	log(ctx,gjson.New(itemInfo).MustToJsonString(),result.Body,err)

	a,_ :=json.Marshal(result.Body)
	if err = json.Unmarshal([]byte(a), &res); err != nil {
		return
	}

	return
}

//订单列表
func (s *orderTm) List(ctx context.Context,item *OrderListReq) (res *OrderListRes, err error) {
	client,err :=initClient()
	if err!=nil{
		return
	}
	if client==nil{
		return
	}

	result ,err :=client.QueryOrderList4Distribution(&link.QueryOrderList4DistributionRequest{
		DistributorId: tea.String(server.DistributorId),
		FilterOption:  tea.String(gjson.New(item.FilterOption).MustToJsonString()),
		PageNumber:    tea.Int32(item.PageNumber),
		PageSize:      tea.Int32(item.PageSize),
		TenantId:      tea.String(server.TenantId),
	})


	if result==nil{
		return
	}
	log(ctx,gjson.New(item).MustToJsonString(),result.Body,err)

	a,_ :=json.Marshal(result.Body)
	if err = json.Unmarshal([]byte(a), &res); err != nil {
		panic(err)
	}
	return
}
//创建订单
func (s *orderTm) Create(ctx context.Context,item *OrderCreateReq) (res *OrderCreateRes, err error) {
	client,err :=initClient()
	if err!=nil{
		return
	}
	if client==nil{
		return
	}
	if item==nil{
		return
	}
	var itemInfoLists []*link.ApplyCreateDistributionOrderRequestItemInfoLists
	err =gjson.New(item.ItemLists).Scan(&itemInfoLists)

	result ,err :=client.ApplyCreateDistributionOrder(&link.ApplyCreateDistributionOrderRequest{
		DistributorId: tea.String(server.DistributorId),
		TenantId:      tea.String(server.TenantId),
		DistributionSupplierId:      tea.String(server.DistributionSupplierId),
		BuyerId:      tea.String(item.UserId),
		ItemInfoLists:      itemInfoLists,
		DeliveryAddress:      tea.String(item.Address),
	})

	if result==nil{
		return
	}
	log(ctx,gjson.New(item).MustToJsonString(),result.Body,err)

	err =gjson.New(result.Body).Scan(&res)

	return
}
//订单详情
func (s *orderTm) Detail(ctx context.Context,item *OrderInfoReq) (res *OrderInfoRes, err error) {
	client,err :=initClient()
	if err!=nil{
		return
	}
	if client==nil{
		return
	}
	result ,err :=client.QueryOrderDetail4Distribution(&link.QueryOrderDetail4DistributionRequest{
		DistributorId: tea.String(server.DistributorId),
		MainDistributionOrderId: tea.String(item.MainDistributionOrderId),
		TenantId:      tea.String(server.TenantId),
	})

	if result==nil{
		return
	}
	log(ctx,gjson.New(item).MustToJsonString(),result.Body,err)

	a,_ :=json.Marshal(result.Body)
	if err = json.Unmarshal([]byte(a), &res); err != nil {
		panic(err)
	}

	return
}
//订单交易状态
func (s *orderTm) Status(ctx context.Context,item *OrderStatusReq) (res *OrderStatusRes, err error) {
	client,err :=initClient()
	if err!=nil{
		return
	}
	if client==nil{
		return
	}
	result ,err :=client.QueryDistributionTradeStatus(&link.QueryDistributionTradeStatusRequest{
		DistributorId: tea.String(server.DistributorId),
		DistributionTradeId: tea.String(item.DistributionTradeId),
		TenantId:      tea.String(server.TenantId),
		DistributionSupplierId: tea.String(server.DistributionSupplierId),
	})

	if result==nil{
		return
	}
	log(ctx,gjson.New(item).MustToJsonString(),result.Body,err)

	a,_ :=json.Marshal(result.Body)
	if err = json.Unmarshal([]byte(a), &res); err != nil {
		panic(err)
	}


	return
}
//地址
func (s *orderTm) AddrInfo(ctx context.Context,itemInfo *AddrInfoReq) (res *AddrInfoRes, err error) {
	client,err :=initClient()
	if err!=nil{
		return
	}
	if client==nil{
		return
	}

	result ,err :=client.QueryChildDivisionCodeById(&link.QueryChildDivisionCodeByIdRequest{
		DistributorId:      tea.String(server.DistributorId),
		DivisionCode:         tea.String(itemInfo.DivisionCode),
		TenantId:           tea.String(server.TenantId),
	})

	if result==nil{
		return
	}
	log(ctx,gjson.New(itemInfo).MustToJsonString(),result.Body,err)

	a,_ :=json.Marshal(result.Body)
	if err = json.Unmarshal([]byte(a), &res); err != nil {
		panic(err)
	}

	return
}
//订单详情
//func (s *orderTm) Detail(ctx context.Context,req OrderInfoReq) (res OrderInfoRes,err error) {
//
//	method := "QueryOrderDetail4Distribution"
//
//
//	request := map[string]string{
//		"DistributorId" : server.DistributorId,
//		"MainDistributionOrderId" :req.MainDistributionOrderId,
//	}
//
//	result, err := post(ctx, method, request)
//	g.Dump(result,"resuelet--------")
//	//_ = json.Unmarshal([]byte(result), &res)
//	return
//}
//Before 验证订单商品 todo 该接口正确通过,由于订单部分接口不通过天猫技术不支持对接,后续有时间再自己写
//func (s *orderTm) RenderDistributionOrder(ctx context.Context, addr OrderAddress, itemInfo *RenderDistributionOrderReq) (res *RenderDistributionOrderRes, err error) {
//	method := "RenderDistributionOrder"
//	fmt.Println(1)
//	request := g.MapStrStr{
//		//"ItemInfoLists" :gjson.New(itemInfo.ItemInfoLists).MustToJsonString(),
//		//		"ItemInfoLists":fmt.Sprintf(`{
//		// "lmItemId" : "10027642-706637605402",
//		// "distributionMallId":"9e7b3e4ba5e24dd49b89498f09d05cf1",
//		// "skuId" : "46059969",
//		// "quantity": 1
//		//}`),
//		"DeliveryAddress":        gjson.New(addr).MustToJsonString(),
//		"BuyerId":                itemInfo.BuyerId,
//		"TenantId":               server.TenantId,
//		"DistributorId":          server.DistributorId,
//		"DistributionSupplierId": server.DistributionSupplierId,
//	}
//	g.Dump("request=====", request)
//
//	result, err := post(ctx, method, request)
//	err = gjson.New(result).Scan(&res)
//	return
//}
//Create 下单接口
//func (s *orderTm) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
//	method := "ApplyCreateDistributionOrder"
//	g.Dump("req.ItemLists=====",req.ItemLists)
//	request := convert("ItemInfoLists", gconv.Maps(req.ItemLists))
//	request["DeliveryAddress"] = gjson.New(req.Address).MustToJsonString()
//	request["TenantId"] = server.TenantId
//	request["DistributorId"] = server.DistributorId
//	request["BuyerId"] = req.UserId
//	request["DistributionSupplierId"] = server.DistributionSupplierId
//	request["DistributionOutTradeId"] = req.ChannelOrder
//	result, err := post(ctx, method, request)
//	err =gjson.New(result).Scan(&res)
//	return
//}



//
//type OrderListReq struct {
//	UserId          string
//	ChannelOrder    string
//	LmOrderId       string
//	LogisticsStatus string
//	OrderStatus     string
//}
//


//List 列表
//func (s *orderTm) QueryOrderList4Distribution(ctx context.Context,req OrderListReq) (res OrderListRes,err error) {
//	method := "QueryOrderList4Distribution"
//
//	var filterOption = OrderFilter{
//		LogisticsStatus: "1",
//		OrderStatus:     req.OrderStatus,
//	}
//	//if req.LmOrderId != "" {
//	//	filterOption.LmOrderList = garray.NewStrArray().Append(req.LmOrderId).Slice()
//	//}
//	//if req.ChannelOrder != "" {
//	//	filterOption.ChannelOrder = garray.NewStrArray().Append(req.ChannelOrder).Slice()
//	//
//	//}
//
//	request := map[string]string{
//		"FilterOption":     gjson.New(filterOption).MustToJsonString(),
//		"PageNumber":       "1",
//		"PageSize":         "20",
//		"DistributorId" : server.DistributorId,
//		"TenantId" :server.TenantId,
//
//	}
//
//	result, err := post(ctx, method, request)
//	g.Dump(result,"resuelet--------")
//	//_ = json.Unmarshal([]byte(result), &res)
//	return
//}

//type OrderCancelReq struct {
//	UserId    string
//	LmOrderId string
//}
//