|
|
@@ -0,0 +1,875 @@
|
|
|
+package order_controller
|
|
|
+
|
|
|
+import (
|
|
|
+ // "fmt"
|
|
|
+ "strconv"
|
|
|
+ // "time"
|
|
|
+ // "d"
|
|
|
+ "github.com/astaxie/beego"
|
|
|
+ // "github.com/astaxie/beego/context"
|
|
|
+ "fohow.com/apps"
|
|
|
+ // "fohow.com/apps/controllers/user_controller"
|
|
|
+ // "fohow.com/apps/models/activity_model"
|
|
|
+ "fohow.com/apps/models/order_model"
|
|
|
+ "fohow.com/apps/models/product_model"
|
|
|
+ // "fohow.com/apps/models/user_model"
|
|
|
+ // "fohow.com/apps/models/vas_model"
|
|
|
+ // "fohow.com/libs/wx_mp"
|
|
|
+ "encoding/csv"
|
|
|
+ "fmt"
|
|
|
+ "fohow.com/apps/helpers"
|
|
|
+ "fohow.com/apps/models/cow_order_model"
|
|
|
+ "fohow.com/apps/models/merchant_model"
|
|
|
+ "fohow.com/apps/models/subject_model"
|
|
|
+ "fohow.com/apps/models/user_model"
|
|
|
+ "fohow.com/libs/tool"
|
|
|
+ "strings"
|
|
|
+ "sync"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var updateExpressLock sync.Mutex
|
|
|
+
|
|
|
+//下单
|
|
|
+func (self *OrderController) Create() {
|
|
|
+ _pid := self.Ctx.Input.Param(":id")
|
|
|
+ pId, _ := strconv.ParseInt(_pid, 10, 64)
|
|
|
+ _count := self.Ctx.Input.Param(":count")
|
|
|
+ count, _ := strconv.ParseInt(_count, 10, 64)
|
|
|
+ if count <= 0 {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+ product := product_model.GetProductById(pId, false)
|
|
|
+ if product == nil {
|
|
|
+ self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
+ }
|
|
|
+ uId := self.GetCurrentUserId()
|
|
|
+ wxUId := self.GetCurrentWxUserId()
|
|
|
+ //user := self.GetCurrentUser(true)
|
|
|
+ //黑名单用户返回账户异常
|
|
|
+ //if user.IsBlackUser == 1 {
|
|
|
+ // self.ReturnError(403, apps.AccountError, "", nil)
|
|
|
+ //}
|
|
|
+ //加入限购逻辑
|
|
|
+ if product.PurchaseLimitCount > 0 {
|
|
|
+ if product.PurchaseLimitCount < count {
|
|
|
+ self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("该商品限购%d件", product.PurchaseLimitCount)}, "", nil)
|
|
|
+ } else {
|
|
|
+ purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(pId, wxUId)
|
|
|
+ //历史已经买够到限购数量了
|
|
|
+ if product.PurchaseLimitCount <= purchaseTotalCount {
|
|
|
+ self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("该商品限购%d件", product.PurchaseLimitCount)}, "", nil)
|
|
|
+ }
|
|
|
+ //历史没买够数量,但是历史总数+想购买的数量 超过限购数量
|
|
|
+ if product.PurchaseLimitCount < (purchaseTotalCount + count) {
|
|
|
+ canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
|
|
|
+ self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("您还可以购买%d件", canBuyCount)}, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断剩余数量
|
|
|
+ leftCount := int64(0)
|
|
|
+ product.SoldCount = order_model.GetSoldCountByPId(product.Id, false)
|
|
|
+ leftCount = product.Count - product.SoldCount
|
|
|
+ if count > leftCount {
|
|
|
+ self.ReturnError(403, apps.ProductStockNotEnough, "", nil)
|
|
|
+ }
|
|
|
+ //商品销售专题---start
|
|
|
+ isJoinSubjectPrize := false //商品是否参与专题的抽奖, 考虑开奖时间
|
|
|
+ productSaleSubjectId := int64(0) //专题的id
|
|
|
+ sId, _ := self.GetInt64("sid", 0)
|
|
|
+ if sId > 0 {
|
|
|
+ subject := subject_model.GetProductSaleSubjectById(sId, false)
|
|
|
+ if subject != nil {
|
|
|
+ productIds := subject.ProductIds
|
|
|
+ productIdArray := strings.Split(productIds, ",")
|
|
|
+ for _, productIdItem := range productIdArray {
|
|
|
+ productId, err := strconv.ParseInt(productIdItem, 10, 64)
|
|
|
+ if err == nil && productId == pId {
|
|
|
+ productSaleSubjectId = subject.Id
|
|
|
+ if subject.IsPrizeAct && subject.OpenPrizeTime.Unix() > time.Now().Unix() {
|
|
|
+ isJoinSubjectPrize = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ subjects := subject_model.GetPrizeActProductSaleSubjectsByProductId(pId, false)
|
|
|
+ if len(subjects) > 0 {
|
|
|
+ for _, item := range subjects {
|
|
|
+ productIds := item.ProductIds
|
|
|
+ productIdArray := strings.Split(productIds, ",")
|
|
|
+ for _, productIdItem := range productIdArray {
|
|
|
+ productId, err := strconv.ParseInt(productIdItem, 10, 64)
|
|
|
+ if err == nil && productId == pId {
|
|
|
+ productSaleSubjectId = item.Id
|
|
|
+ if item.IsPrizeAct && item.OpenPrizeTime.Unix() > time.Now().Unix() {
|
|
|
+ isJoinSubjectPrize = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //商品销售专题---end
|
|
|
+
|
|
|
+ //秒杀逻辑: 判断是否处于秒杀时间段内
|
|
|
+ if product.SeckilShowPrice > 0 {
|
|
|
+ now := time.Now()
|
|
|
+ if now.Unix() < product.SeckillStart.Unix() {
|
|
|
+ self.ReturnError(403, apps.SeckillNotStart, "", nil)
|
|
|
+ } else if now.Unix() > product.SeckillEnd.Unix() {
|
|
|
+ self.ReturnError(403, apps.SeckillIsEnd, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //限新逻辑: 微信支付完成购买过商品的用户
|
|
|
+ if product.IsOnlyNew {
|
|
|
+ paiedOrder := order_model.GetPaiedOrderByWxUIdAndPayWayLimitOne(wxUId, order_model.PAY_WAY_WEIXIN, false)
|
|
|
+ if paiedOrder != nil {
|
|
|
+ self.ReturnError(403, apps.OnlyNew, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ totalPrice := product.RoboBalancePrice * count
|
|
|
+ //小兔微信,测试微信支付
|
|
|
+ if wxUId == 42452 {
|
|
|
+ totalPrice = 1
|
|
|
+ }
|
|
|
+ freight := order_model.FREIGHT
|
|
|
+ if totalPrice >= order_model.FREIGHT_LIMIT {
|
|
|
+ freight = int64(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ order := new(order_model.Order).CreateNew(wxUId, uId,
|
|
|
+ totalPrice, freight, order_model.SOURCE_XCX)
|
|
|
+ if order != nil {
|
|
|
+ if productSaleSubjectId > 0 {
|
|
|
+ order.IsJoinSubjectPrize = isJoinSubjectPrize
|
|
|
+ order.ProductSaleSubjectId = productSaleSubjectId
|
|
|
+ }
|
|
|
+ order.Save()
|
|
|
+ //创建订单明细
|
|
|
+ go new(order_model.OrderDetail).Create(order.OrderId, order.Id, product.Id, product.Price, product.RoboBalancePrice, product.Name,
|
|
|
+ count)
|
|
|
+ }
|
|
|
+
|
|
|
+ type Order struct {
|
|
|
+ OrderId string `json:"order_id"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &Order{OrderId: order.OrderId}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+func (self *OrderController) GetExpressNo() {
|
|
|
+
|
|
|
+ oId := self.Ctx.Input.Param(":order_id")
|
|
|
+ o := order_model.GetOrderById(oId)
|
|
|
+
|
|
|
+ type Ret struct {
|
|
|
+ ExpressNo string `json:"express_no"`
|
|
|
+ ExpressCompany string `json:"express_company"`
|
|
|
+ }
|
|
|
+
|
|
|
+ var expressNo, expressCompany string
|
|
|
+ if o != nil {
|
|
|
+ expressNo = o.ExpressOrderNo
|
|
|
+ expressCompany = o.ExpressCompany
|
|
|
+ }
|
|
|
+
|
|
|
+ self.Data["json"] = &Ret{ExpressNo: expressNo, ExpressCompany: expressCompany}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+//购物车下单
|
|
|
+func (self *OrderController) MultipleCreate() {
|
|
|
+ uId := self.GetCurrentUserId()
|
|
|
+ wxUId := self.GetCurrentWxUserId()
|
|
|
+
|
|
|
+ ids := self.GetString("ids")
|
|
|
+ nums := self.GetString("nums")
|
|
|
+
|
|
|
+ if len(nums) <= 0 || len(ids) <= 0 {
|
|
|
+ self.ReturnError(403, apps.NoCart, "", nil)
|
|
|
+ }
|
|
|
+ totalPrice := int64(0)
|
|
|
+ c_arr := strings.Split(ids, ",")
|
|
|
+ beego.BeeLogger.Warn("c_arr(%s)", c_arr)
|
|
|
+ c_nums := strings.Split(nums, ",")
|
|
|
+ beego.BeeLogger.Warn("c_nums(%s)", c_nums)
|
|
|
+ for key, s_item := range c_arr {
|
|
|
+ cId, _ := strconv.ParseInt(s_item, 10, 64)
|
|
|
+ cNums := int64(1)
|
|
|
+ cNums, _ = strconv.ParseInt(c_nums[key], 10, 64)
|
|
|
+ cartItem := order_model.GetCartById(cId)
|
|
|
+ if cartItem == nil {
|
|
|
+ self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
+ }
|
|
|
+ if cartItem.WxUserId != wxUId {
|
|
|
+ self.ReturnError(403, apps.AccountError, "", nil)
|
|
|
+ }
|
|
|
+ product := product_model.GetProductById(cartItem.ProductId, false)
|
|
|
+ if product == nil {
|
|
|
+ self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
+ }
|
|
|
+ //加入限购逻辑
|
|
|
+ if product.PurchaseLimitCount > 0 {
|
|
|
+ if product.PurchaseLimitCount < cNums {
|
|
|
+ self.ReturnError(403, []string{apps.OverLimitCount[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
+ } else {
|
|
|
+ purchaseTotalCount := order_model.GetOrderCountByPIdAndWxUId(cartItem.ProductId, wxUId)
|
|
|
+ //历史已经买够到限购数量了
|
|
|
+ if product.PurchaseLimitCount <= purchaseTotalCount {
|
|
|
+ self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s商品限购%d件", product.Name, product.PurchaseLimitCount)}, "", nil)
|
|
|
+ }
|
|
|
+ //历史没买够数量,但是历史总数+想购买的数量 超过限购数量
|
|
|
+ if product.PurchaseLimitCount < (purchaseTotalCount + cNums) {
|
|
|
+ canBuyCount := product.PurchaseLimitCount - purchaseTotalCount
|
|
|
+ self.ReturnError(403, []string{apps.PurchasedReachLimit[0], fmt.Sprintf("%s您还可以购买%d件", product.Name, canBuyCount)}, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //普通下单--判断剩余数量
|
|
|
+ product.SoldCount = order_model.GetSoldCountByPId(product.Id, false)
|
|
|
+ leftCount := product.Count - product.SoldCount
|
|
|
+ if cNums > leftCount {
|
|
|
+ self.ReturnError(403, []string{apps.ProductStockNotEnough[0], fmt.Sprintf("%s商品库存不足", product.Name)}, "", nil)
|
|
|
+ }
|
|
|
+ //限新逻辑: 微信支付完成购买过商品的用户
|
|
|
+ if product.IsOnlyNew {
|
|
|
+ paiedOrder := order_model.GetPaiedOrderByWxUIdAndPayWayLimitOne(wxUId, order_model.PAY_WAY_WEIXIN, false)
|
|
|
+ if paiedOrder != nil {
|
|
|
+ self.ReturnError(403, []string{apps.OnlyNew[0], fmt.Sprintf("%s仅限新人购买", product.Name)}, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ totalPrice += product.Price * cNums
|
|
|
+ //小兔微信,测试微信支付
|
|
|
+ if wxUId == 12 {
|
|
|
+ //totalPrice = 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ freight := order_model.FREIGHT
|
|
|
+ if totalPrice >= order_model.FREIGHT_LIMIT {
|
|
|
+ freight = int64(0)
|
|
|
+ }
|
|
|
+ order := new(order_model.Order).CreateNew(wxUId, uId,
|
|
|
+ totalPrice, freight, order_model.SOURCE_XCX)
|
|
|
+ if order != nil {
|
|
|
+ order.Save()
|
|
|
+ //创建订单明细
|
|
|
+ for key, s_item := range c_arr {
|
|
|
+ cId, _ := strconv.ParseInt(s_item, 10, 64)
|
|
|
+ cNums := int64(1)
|
|
|
+ cNums, _ = strconv.ParseInt(c_nums[key], 10, 64)
|
|
|
+ cartItem := order_model.GetCartById(cId)
|
|
|
+ if cartItem == nil {
|
|
|
+ self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
+ }
|
|
|
+ if cartItem.WxUserId != wxUId {
|
|
|
+ self.ReturnError(403, apps.AccountError, "", nil)
|
|
|
+ }
|
|
|
+ product := product_model.GetProductById(cartItem.ProductId, false)
|
|
|
+ if product == nil {
|
|
|
+ self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
+ }
|
|
|
+ new(order_model.OrderDetail).Create(order.OrderId, order.Id, cartItem.ProductId, product.Price, product.RoboBalancePrice, product.Name,
|
|
|
+ cNums)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ go ClearCart(order.UserId, order.OrderId)
|
|
|
+ type Order struct {
|
|
|
+ OrderId string `json:"order_id"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &Order{OrderId: order.OrderId}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+func ClearCart(userId int64, orderId string) {
|
|
|
+ orderDetails := order_model.GetAllDetailsOrderId(orderId)
|
|
|
+ for _, item := range orderDetails {
|
|
|
+ cartItem := order_model.GetCartByUidAndPid(userId, item.ProductId)
|
|
|
+ if cartItem != nil {
|
|
|
+ cartItem.Delete()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//获取用户订单详情
|
|
|
+func (self *OrderController) Detail() {
|
|
|
+
|
|
|
+ cache, _ := self.GetBool("cache", false)
|
|
|
+ oId := self.Ctx.Input.Param(":order_id")
|
|
|
+ o := order_model.GetOrderById(oId)
|
|
|
+ if o == nil {
|
|
|
+ beego.BeeLogger.Error("order not exist id=[%s]", oId)
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ }
|
|
|
+ orderList := order_model.GetAllDetailsOrderId(o.OrderId)
|
|
|
+ for _, item := range orderList {
|
|
|
+ product := product_model.GetProductById(item.ProductId, cache)
|
|
|
+ if product == nil {
|
|
|
+ self.ReturnError(403, apps.ProductNotExist, "", nil)
|
|
|
+ }
|
|
|
+ product.OrderCount = item.Count
|
|
|
+ o.Count += item.Count
|
|
|
+ if product.SeckilShowPrice > 0 {
|
|
|
+ now := time.Now()
|
|
|
+ product.SeckillStartAt = product.SeckillStart.Unix()
|
|
|
+ product.SeckillEndAt = product.SeckillEnd.Unix()
|
|
|
+ if product.SeckillStart.Unix() > now.Unix() {
|
|
|
+ product.SeckillState = product_model.SECKILL_PREPARING_STATE
|
|
|
+ product.SeckillStateCn = product_model.SECKILL_PREPARING_STATE_CN
|
|
|
+ } else if product.SeckillStart.Unix() <= now.Unix() && now.Unix() < product.SeckillEnd.Unix() {
|
|
|
+ product.IsUnderSeckill = true
|
|
|
+ product.SeckillState = product_model.SECKILL_UNDER_STATE
|
|
|
+ product.SeckillStateCn = product_model.SECKILL_UNDER_STATE_CN
|
|
|
+ } else {
|
|
|
+ product.SeckillState = product_model.SECKILL_END_STATE
|
|
|
+ product.SeckillStateCn = product_model.SECKILL_END_STATE_CN
|
|
|
+ }
|
|
|
+ }
|
|
|
+ o.ProductList = append(o.ProductList, product)
|
|
|
+ }
|
|
|
+ wxUser := self.GetCurrentWxUser(cache)
|
|
|
+ if wxUser == nil {
|
|
|
+ self.ReturnError(403, apps.UserNotExist, "", nil)
|
|
|
+ } else {
|
|
|
+ if wxUser.Id != o.WxUserId {
|
|
|
+ beego.BeeLogger.Error("order not owner id=[%s]", oId)
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ }
|
|
|
+ wxUser.Head = user_model.GetFullImgUrl(wxUser.Head)
|
|
|
+ }
|
|
|
+
|
|
|
+ o.StatusCn = order_model.STATUS_CN_TEXT[o.Status]
|
|
|
+ o.CTime = o.CreatedAt.Unix()
|
|
|
+ o.DTime = o.DispatchTime.Unix()
|
|
|
+ if o.DTime < 0 {
|
|
|
+ o.DTime = 0
|
|
|
+ }
|
|
|
+ o.WxUser = wxUser
|
|
|
+ self.Data["json"] = o
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+//获取用户订单列表
|
|
|
+func (self *OrderController) List() {
|
|
|
+
|
|
|
+ status := self.GetString("status")
|
|
|
+ page, _ := self.GetInt("page")
|
|
|
+ perPage, _ := self.GetInt("per_page")
|
|
|
+ if page <= 0 {
|
|
|
+ page = 1
|
|
|
+ }
|
|
|
+ if perPage <= 0 || perPage > 100 {
|
|
|
+ perPage = 20
|
|
|
+ }
|
|
|
+ cache, _ := self.GetBool("cache", false)
|
|
|
+ //uId := self.GetCurrentUserId()
|
|
|
+ wxUId := self.GetCurrentWxUserId()
|
|
|
+ orders := order_model.GetUserOrders(wxUId, status, page, perPage)
|
|
|
+ count := order_model.GetUserOrdersCount(wxUId, status)
|
|
|
+
|
|
|
+ for _, item := range orders {
|
|
|
+ orderList := order_model.GetAllDetailsOrderId(item.OrderId)
|
|
|
+ for _, orderItem := range orderList {
|
|
|
+ product := product_model.GetProductById(orderItem.ProductId, cache)
|
|
|
+ item.Product = product
|
|
|
+ if product == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ item.Count += orderItem.Count
|
|
|
+ product.OrderCount = orderItem.Count
|
|
|
+ if product.SeckilShowPrice > 0 {
|
|
|
+ now := time.Now()
|
|
|
+ product.SeckillStartAt = product.SeckillStart.Unix()
|
|
|
+ product.SeckillEndAt = product.SeckillEnd.Unix()
|
|
|
+ if product.SeckillStart.Unix() > now.Unix() {
|
|
|
+ product.SeckillState = product_model.SECKILL_PREPARING_STATE
|
|
|
+ product.SeckillStateCn = product_model.SECKILL_PREPARING_STATE_CN
|
|
|
+ } else if product.SeckillStart.Unix() <= now.Unix() && now.Unix() < product.SeckillEnd.Unix() {
|
|
|
+ product.IsUnderSeckill = true
|
|
|
+ product.SeckillState = product_model.SECKILL_UNDER_STATE
|
|
|
+ product.SeckillStateCn = product_model.SECKILL_UNDER_STATE_CN
|
|
|
+ } else {
|
|
|
+ product.SeckillState = product_model.SECKILL_END_STATE
|
|
|
+ product.SeckillStateCn = product_model.SECKILL_END_STATE_CN
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.ProductList = append(item.ProductList, product)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ type Ret struct {
|
|
|
+ List []*order_model.Order `json:"list"`
|
|
|
+ ListCount int64 `json:"list_count"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &Ret{ListCount: count, List: orders}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+//用户更改订单状态
|
|
|
+func (self *OrderController) Operate() {
|
|
|
+ oId := self.Ctx.Input.Param(":order_id")
|
|
|
+ o := order_model.GetOrderById(oId)
|
|
|
+ if o == nil {
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ }
|
|
|
+ //uId := self.GetCurrentUserId()
|
|
|
+ //if uId != o.UserId {
|
|
|
+ // self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ //}
|
|
|
+ wxUId := self.GetCurrentWxUserId()
|
|
|
+ if wxUId != o.WxUserId {
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ }
|
|
|
+ operate := self.GetString(":operate")
|
|
|
+ if operate != order_model.OPERATE_CONFIRM && operate != order_model.OPERATE_CANCEL {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+ if operate == order_model.OPERATE_CONFIRM && o.Status == order_model.STATUS_DISPATCH {
|
|
|
+ o.Status = order_model.STATUS_COMPLETE
|
|
|
+ o.ReceiveTime = time.Now()
|
|
|
+ } else if operate == order_model.OPERATE_CANCEL && o.Status == order_model.STATUS_UNPAY {
|
|
|
+ o.Status = order_model.STATUS_CLOSED
|
|
|
+ }
|
|
|
+
|
|
|
+ if !o.Save() {
|
|
|
+ beego.BeeLogger.Error("wx_user[%d] complete order[%s] fail", wxUId, oId)
|
|
|
+ }
|
|
|
+ //已确认收货的订单、发放代销金给卖方
|
|
|
+ //if o.Status == order_model.STATUS_COMPLETE && o.OrderType == order_model.ORDER_TYPE_SALE {
|
|
|
+ //helpers.SendBalanceWhileSaleOrderCompleteHandler(o)
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if o.Status == order_model.STATUS_COMPLETE{
|
|
|
+ // helpers.HandleProductBenefitIntoCashBalance(o)
|
|
|
+ //}
|
|
|
+
|
|
|
+ type apiRet struct {
|
|
|
+ Status string `json:"status"`
|
|
|
+ StatusCnText string `json:"status_cn_text"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &apiRet{
|
|
|
+ Status: o.Status,
|
|
|
+ StatusCnText: order_model.STATUS_CN_TEXT[o.Status]}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// //确认收货后续动作
|
|
|
+// func afterTakeDelivery(order *order_model.Order) {
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+// 获取商家的订单列表
|
|
|
+func (self *OrderController) MerchantList() {
|
|
|
+
|
|
|
+ merchantId, _ := self.GetInt64("merchant_id", 0)
|
|
|
+ _queryPaiedStart := self.GetString("query_paied_start")
|
|
|
+ _queryPaiedEnd := self.GetString("query_paied_end")
|
|
|
+ _queryReceiveStart := self.GetString("query_receive_start")
|
|
|
+ _queryReceiveEnd := self.GetString("query_receive_end")
|
|
|
+ status := self.GetString("status")
|
|
|
+ page, _ := self.GetInt("page")
|
|
|
+ perPage, _ := self.GetInt("per_page")
|
|
|
+ contact := self.GetString("contact")
|
|
|
+ tel := self.GetString("tel")
|
|
|
+ orderType := self.GetString("order_type")
|
|
|
+ orderId := self.GetString("order_id")
|
|
|
+ province := self.GetString("province")
|
|
|
+ city := self.GetString("city")
|
|
|
+ district := self.GetString("district")
|
|
|
+
|
|
|
+ queryPaiedStart, queryPaiedEnd := int64(0), int64(0)
|
|
|
+ queryReceiveStart, queryReceiveEnd := int64(0), int64(0)
|
|
|
+ if strings.TrimSpace(_queryPaiedStart) != "" {
|
|
|
+ paiedStart, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", _queryPaiedStart), time.Local)
|
|
|
+ if err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "查询日期错误"}, "", nil)
|
|
|
+ }
|
|
|
+ queryPaiedStart = paiedStart.Unix()
|
|
|
+ }
|
|
|
+ if strings.TrimSpace(_queryPaiedEnd) != "" {
|
|
|
+ paiedEnd, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", _queryPaiedEnd), time.Local)
|
|
|
+ if err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "查询日期错误"}, "", nil)
|
|
|
+ }
|
|
|
+ queryPaiedEnd = paiedEnd.Unix()
|
|
|
+ }
|
|
|
+
|
|
|
+ if strings.TrimSpace(_queryReceiveStart) != "" {
|
|
|
+ receiveStart, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", _queryReceiveStart), time.Local)
|
|
|
+ if err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "查询日期错误"}, "", nil)
|
|
|
+ }
|
|
|
+ queryReceiveStart = receiveStart.Unix()
|
|
|
+ }
|
|
|
+ if strings.TrimSpace(_queryReceiveEnd) != "" {
|
|
|
+ receiveEnd, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", _queryReceiveEnd), time.Local)
|
|
|
+ if err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "查询日期错误"}, "", nil)
|
|
|
+ }
|
|
|
+ queryReceiveEnd = receiveEnd.Unix()
|
|
|
+ }
|
|
|
+
|
|
|
+ if status != "" && order_model.STATUS_CN_TEXT[status] == "" {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "状态错误"}, "", nil)
|
|
|
+ }
|
|
|
+ if orderType != "" {
|
|
|
+ _orderType, err := strconv.ParseInt(orderType, 10, 64)
|
|
|
+ if order_model.ORDER_TYPE_CN_TEXT[_orderType] == "" || err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "类型出错"}, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if page <= 0 {
|
|
|
+ page = 1
|
|
|
+ }
|
|
|
+ if perPage <= 0 || perPage > 100 {
|
|
|
+ perPage = 10
|
|
|
+ }
|
|
|
+ cache, _ := self.GetBool("cache", false)
|
|
|
+ uId := self.GetCurrentUserId()
|
|
|
+
|
|
|
+ var orders []*order_model.MerchantOrder
|
|
|
+ count := int64(0)
|
|
|
+ merchantUser := merchant_model.GetMerchantUserRelationByUserId(uId, cache)
|
|
|
+ if merchantUser != nil {
|
|
|
+ if merchantUser.MerchantId != merchantId {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ orders = order_model.GetMerchantOrders(merchantId, queryPaiedStart, queryPaiedEnd, queryReceiveStart, queryReceiveEnd, status,
|
|
|
+ contact, strings.TrimSpace(merchantUser.ManageProductIds),
|
|
|
+ tel, orderType, orderId, province, city, district, page, perPage)
|
|
|
+ count = order_model.GetMerchantOrdersCount(merchantId, queryPaiedStart, queryPaiedEnd, queryReceiveStart, queryReceiveEnd, status,
|
|
|
+ contact, strings.TrimSpace(merchantUser.ManageProductIds),
|
|
|
+ tel, orderType, orderId, province, city, district)
|
|
|
+
|
|
|
+ for _, item := range orders {
|
|
|
+ product := product_model.GetProductById(item.ProductId, cache)
|
|
|
+ wxUser := user_model.GetWxUserById(item.WxUserId, cache)
|
|
|
+ if wxUser != nil {
|
|
|
+ wxUser.Head = user_model.GetFullImgUrl(wxUser.Head)
|
|
|
+ }
|
|
|
+
|
|
|
+ item.Product = product
|
|
|
+ item.WxUser = wxUser
|
|
|
+ item.OrderTypeCn = order_model.ORDER_TYPE_CN_TEXT[item.OrderType]
|
|
|
+ item.CTime = item.CreatedAt.Unix()
|
|
|
+ item.DTime = item.DispatchTime.Unix()
|
|
|
+ item.RTime = item.ReceiveTime.Unix()
|
|
|
+ }
|
|
|
+ type Ret struct {
|
|
|
+ List []*order_model.MerchantOrder `json:"list"`
|
|
|
+ ListCount int64 `json:"list_count"`
|
|
|
+ }
|
|
|
+
|
|
|
+ if orders == nil {
|
|
|
+ orders = make([]*order_model.MerchantOrder, 0, 0)
|
|
|
+ }
|
|
|
+ self.Data["json"] = &Ret{ListCount: count, List: orders}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// 商家处理中订单数量提示
|
|
|
+func (self *OrderController) MerchantListCount() {
|
|
|
+ merchantId, _ := self.GetInt64("merchant_id", 0)
|
|
|
+
|
|
|
+ uId := self.GetCurrentUserId()
|
|
|
+
|
|
|
+ count := int64(0)
|
|
|
+ merchantUser := merchant_model.GetMerchantUserRelationByUserId(uId, true)
|
|
|
+ if merchantUser != nil {
|
|
|
+ if merchantUser.MerchantId != merchantId {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+ count = order_model.GetMerchantOrdersCount(merchantId, 0, 0, 0, 0, order_model.STATUS_PROCESSING, "",
|
|
|
+ strings.TrimSpace(merchantUser.ManageProductIds), "", "", "", "", "", "")
|
|
|
+
|
|
|
+ type Ret struct {
|
|
|
+ ListCount int64 `json:"list_count"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &Ret{ListCount: count}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// 商家更新物流信息
|
|
|
+// status只接收""或者dispatch两个值
|
|
|
+// 只能处理待发货、待收货的订单物流信息
|
|
|
+// 当status是""、订单状态是已发货:表示更改物流,当status是dispatch、订单状态是处理中表示添加物流信息
|
|
|
+// 不允许status为dispatch、同时订单状态是已发货。避免多个管理员重复发货。
|
|
|
+func (self *OrderController) UpdateExpress() {
|
|
|
+ oId := self.Ctx.Input.Param(":order_id")
|
|
|
+ expressCompany := self.GetString("express_company")
|
|
|
+ expressOrderNo := self.GetString("express_order_no")
|
|
|
+ status := self.GetString("status", "")
|
|
|
+
|
|
|
+ defer updateExpressLock.Unlock()
|
|
|
+ updateExpressLock.Lock()
|
|
|
+
|
|
|
+ o := order_model.GetOrderById(oId)
|
|
|
+ if o == nil {
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ uId := self.GetCurrentUserId()
|
|
|
+ merchantUser := merchant_model.GetMerchantUserRelationByUserId(uId, true)
|
|
|
+ if merchantUser == nil {
|
|
|
+ // 不是商户
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ //只能处理待发货、待收货的订单物流信息。
|
|
|
+ if o.Status != order_model.STATUS_PROCESSING && o.Status != order_model.STATUS_DISPATCH {
|
|
|
+ self.ReturnError(403, apps.OrderStatusNotSuit, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ //避免重复发货
|
|
|
+ if o.Status == order_model.STATUS_DISPATCH && status == order_model.STATUS_DISPATCH {
|
|
|
+ self.ReturnError(403, apps.OrderAlreadyDispatch, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验状态参数,是否合法。
|
|
|
+ if status != "" && status != order_model.STATUS_DISPATCH {
|
|
|
+ // 只支持发货操作
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ } else if status == order_model.STATUS_DISPATCH {
|
|
|
+
|
|
|
+ o.Status = order_model.STATUS_DISPATCH
|
|
|
+ o.DispatchTime = time.Now()
|
|
|
+ } else {
|
|
|
+
|
|
|
+ o.Status = o.Status
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验订单所属商户
|
|
|
+ product := product_model.GetProductById(o.ProductId, true)
|
|
|
+ if product == nil {
|
|
|
+ self.ReturnError(403, apps.ProductNotExist, "", nil)
|
|
|
+ }
|
|
|
+ if product.MerchantId != merchantUser.MerchantId {
|
|
|
+ self.ReturnError(403, apps.OrderNotBelongToCurrentUser, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ //该商家管理员是否负责管理该商品?
|
|
|
+ isManageTheProduct, _ := tool.Contain(fmt.Sprintf("%d", product.Id), strings.Split(merchantUser.ManageProductIds, ","))
|
|
|
+ if merchantUser.ManageProductIds != "0" && !isManageTheProduct {
|
|
|
+ self.ReturnError(403, apps.CurrentMerIsNotManageTheProduct, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ o.ExpressCompany = expressCompany
|
|
|
+ o.ExpressOrderNo = expressOrderNo
|
|
|
+
|
|
|
+ if !o.Save() {
|
|
|
+ beego.BeeLogger.Error("user[%d] complete order[%s] fail", uId, oId)
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送物流信息
|
|
|
+ if status == order_model.STATUS_DISPATCH { //发送发货通知
|
|
|
+
|
|
|
+ buyerWxUser := user_model.GetWxUserById(o.WxUserId, true)
|
|
|
+ if buyerWxUser != nil {
|
|
|
+ helpers.ProductLogisticsChangedNotify(*buyerWxUser, o.DispatchTime, product.Name, o.OrderId, o.ExpressCompany, o.ExpressOrderNo,
|
|
|
+ "您兑换的商品已经发货,请注意查收。", "pages/start/start?url=packageUser/pages/user/order/order&id="+o.OrderId)
|
|
|
+ }
|
|
|
+
|
|
|
+ } else { //发送物流修改信息
|
|
|
+
|
|
|
+ buyerWxUser := user_model.GetWxUserById(o.WxUserId, true)
|
|
|
+ if buyerWxUser != nil {
|
|
|
+ helpers.ProductLogisticsChangedNotify(*buyerWxUser, o.DispatchTime, product.Name, o.OrderId, o.ExpressCompany, o.ExpressOrderNo,
|
|
|
+ "您兑换的商品物流信息有改动,请注意查收。", "pages/start/start?url=packageUser/pages/user/order/order&id="+o.OrderId)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //同步牛就对了订单发货信息
|
|
|
+ if o.OrderType == order_model.ORDER_COW_BUY || o.OrderType == order_model.ORDER_COW_CHANGE {
|
|
|
+ cowOrder := cow_order_model.GetCowOrderByCowOrderId(o.OrderId)
|
|
|
+ if cowOrder != nil {
|
|
|
+ cowOrder.LogisNo = o.ExpressOrderNo
|
|
|
+ cowOrder.LogisComp = o.ExpressCompany
|
|
|
+ cowOrder.ConFlag = int64(1)
|
|
|
+ cowOrder.ConDate = time.Now().Unix()
|
|
|
+ cowOrder.Save()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ type apiRet struct {
|
|
|
+ Status string `json:"status"`
|
|
|
+ StatusCnText string `json:"status_cn_text"`
|
|
|
+ }
|
|
|
+ self.Data["json"] = &apiRet{
|
|
|
+ Status: o.Status,
|
|
|
+ StatusCnText: order_model.STATUS_CN_TEXT[o.Status]}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// 商家获取订单详情
|
|
|
+func (self *OrderController) MerchantOrderDetail() {
|
|
|
+
|
|
|
+ oId := self.Ctx.Input.Param(":order_id")
|
|
|
+ o := order_model.GetMerchantOrderById(oId)
|
|
|
+ cache, _ := self.GetBool("cache", false)
|
|
|
+ if o == nil {
|
|
|
+ beego.BeeLogger.Error("order not exist id=[%s]", oId)
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ }
|
|
|
+ user := self.GetCurrentUser(cache)
|
|
|
+
|
|
|
+ product := product_model.GetProductById(o.ProductId, cache)
|
|
|
+ if product == nil {
|
|
|
+ self.ReturnError(403, apps.ProductNotExist, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ merchantUser := merchant_model.GetMerchantUserRelationByUserId(user.Id, cache)
|
|
|
+ if merchantUser == nil {
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ } else {
|
|
|
+ if product.MerchantId != merchantUser.MerchantId {
|
|
|
+ beego.BeeLogger.Error("order not merchant_owner id=[%s]", oId)
|
|
|
+ self.ReturnError(404, apps.OrderNotExist, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wxUser := user_model.GetWxUserByUserId(o.UserId, cache)
|
|
|
+ if wxUser == nil {
|
|
|
+ self.ReturnError(403, apps.UserNotExist, "", nil)
|
|
|
+ } else {
|
|
|
+ wxUser.Head = user_model.GetFullImgUrl(wxUser.Head)
|
|
|
+ }
|
|
|
+
|
|
|
+ o.StatusCn = order_model.STATUS_CN_TEXT[o.Status]
|
|
|
+ o.CTime = o.CreatedAt.Unix()
|
|
|
+ o.DTime = o.DispatchTime.Unix()
|
|
|
+ if o.DTime < 0 {
|
|
|
+ o.DTime = 0
|
|
|
+ }
|
|
|
+ o.Product = product
|
|
|
+ o.WxUser = wxUser
|
|
|
+ o.ExCompanyArray = strings.Split(o.ExpressCompany, "/")
|
|
|
+ o.ExOrderNoArray = strings.Split(o.ExpressOrderNo, "/")
|
|
|
+ self.Data["json"] = o
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+func (self *OrderController) ExportMerchantOrders() {
|
|
|
+ merchantId, _ := self.GetInt64("merchant_id", 0)
|
|
|
+ _queryPaiedStart := self.GetString("query_paied_start")
|
|
|
+ _queryPaiedEnd := self.GetString("query_paied_end")
|
|
|
+ _queryReceiveStart := self.GetString("query_receive_start")
|
|
|
+ _queryReceiveEnd := self.GetString("query_receive_end")
|
|
|
+ status := self.GetString("status")
|
|
|
+ contact := self.GetString("contact")
|
|
|
+ tel := self.GetString("tel")
|
|
|
+ orderType := self.GetString("order_type")
|
|
|
+ orderId := self.GetString("order_id")
|
|
|
+ province := self.GetString("province")
|
|
|
+ city := self.GetString("city")
|
|
|
+ district := self.GetString("district")
|
|
|
+ cache, _ := self.GetBool("cache", false)
|
|
|
+
|
|
|
+ queryPaiedStart, queryPaiedEnd := int64(0), int64(0)
|
|
|
+ queryReceiveStart, queryReceiveEnd := int64(0), int64(0)
|
|
|
+ if strings.TrimSpace(_queryPaiedStart) != "" {
|
|
|
+ paiedStart, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", _queryPaiedStart), time.Local)
|
|
|
+ if err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "查询日期错误"}, "", nil)
|
|
|
+ }
|
|
|
+ queryPaiedStart = paiedStart.Unix()
|
|
|
+ }
|
|
|
+ if strings.TrimSpace(_queryPaiedEnd) != "" {
|
|
|
+ paiedEnd, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", _queryPaiedEnd), time.Local)
|
|
|
+ if err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "查询日期错误"}, "", nil)
|
|
|
+ }
|
|
|
+ queryPaiedEnd = paiedEnd.Unix()
|
|
|
+ }
|
|
|
+ if strings.TrimSpace(_queryReceiveStart) != "" {
|
|
|
+ receiveStart, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", _queryReceiveStart), time.Local)
|
|
|
+ if err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "查询日期错误"}, "", nil)
|
|
|
+ }
|
|
|
+ queryReceiveStart = receiveStart.Unix()
|
|
|
+ }
|
|
|
+ if strings.TrimSpace(_queryReceiveEnd) != "" {
|
|
|
+ receiveEnd, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", _queryReceiveEnd), time.Local)
|
|
|
+ if err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "查询日期错误"}, "", nil)
|
|
|
+ }
|
|
|
+ queryReceiveEnd = receiveEnd.Unix()
|
|
|
+ }
|
|
|
+
|
|
|
+ if status != "" && order_model.STATUS_CN_TEXT[status] == "" {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "状态错误"}, "", nil)
|
|
|
+ }
|
|
|
+ if orderType != "" {
|
|
|
+ _orderType, err := strconv.ParseInt(orderType, 10, 64)
|
|
|
+ if order_model.ORDER_TYPE_CN_TEXT[_orderType] == "" || err != nil {
|
|
|
+ self.ReturnError(403, []string{"paramsError", "类型出错"}, "", nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ uId := self.GetCurrentUserId()
|
|
|
+
|
|
|
+ var orders []*order_model.MerchantOrder
|
|
|
+ merchantUser := merchant_model.GetMerchantUserRelationByUserId(uId, cache)
|
|
|
+ if merchantUser != nil {
|
|
|
+ if merchantUser.MerchantId != merchantId {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.ReturnError(403, apps.ParamsError, "", nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ orders = order_model.GetMerchantOrders(merchantId, queryPaiedStart, queryPaiedEnd, queryReceiveStart, queryReceiveEnd, status,
|
|
|
+ contact, strings.TrimSpace(merchantUser.ManageProductIds),
|
|
|
+ tel, orderType, orderId, province, city, district, 0, 0)
|
|
|
+
|
|
|
+ fileName := fmt.Sprintf("[%d-%s].csv", merchantUser.UserId, time.Now().Format("2006年01月02日15时04分"))
|
|
|
+ self.Ctx.Output.Header("Content-Type", "text/csv")
|
|
|
+ self.Ctx.Output.Header("Content-Disposition", "attachment; filename="+fileName)
|
|
|
+ writer := csv.NewWriter(self.Controller.Ctx.ResponseWriter)
|
|
|
+ writer.Write([]string{"订单号", "微信昵称", "交易时间", "发货时间", "收货时间",
|
|
|
+ "商品", "类型", "单价/商家获得(元)", "总额/商家获得(元)",
|
|
|
+ "收件号码", "收件人", "收件地址", "物流信息"})
|
|
|
+ for _, order := range orders {
|
|
|
+ orderId := order.OrderId
|
|
|
+ var wxNickname, productName string
|
|
|
+ wxUser := user_model.GetWxUserById(order.WxUserId, true)
|
|
|
+ if wxUser != nil {
|
|
|
+ wxNickname = wxUser.Nickname
|
|
|
+ }
|
|
|
+
|
|
|
+ var paiedAtFormat, dispatchTimeFormat, receiveTimeFormat string
|
|
|
+ if order.PaiedAt > 0 {
|
|
|
+ paiedAtFormat = time.Unix(order.PaiedAt, 0).Format("2006-01-02 15:04")
|
|
|
+ }
|
|
|
+ if order.DispatchTime.Unix() > 0 {
|
|
|
+ dispatchTimeFormat = order.DispatchTime.Format("2006-01-02 15:04")
|
|
|
+ }
|
|
|
+ if order.ReceiveTime.Unix() > 0 {
|
|
|
+ receiveTimeFormat = order.ReceiveTime.Format("2006-01-02 15:04")
|
|
|
+ }
|
|
|
+
|
|
|
+ product := product_model.GetProductById(order.ProductId, true)
|
|
|
+ if product != nil {
|
|
|
+ productName = product.Name
|
|
|
+ }
|
|
|
+ orderTypeCn := order_model.ORDER_TYPE_CN_TEXT[order.OrderType]
|
|
|
+ unitGet := fmt.Sprintf("%0.2f(%0.2f)", float64(order.UnitPrice)/100.0, float64(order.BuyPrice/order.Count)/100.0)
|
|
|
+ totalGet := fmt.Sprintf("%0.2f(%0.2f)", float64(order.UnitPrice*order.Count)/100.0, float64(order.BuyPrice)/100.0)
|
|
|
+ tel := order.Tel
|
|
|
+ contact := order.Contact
|
|
|
+ address := order.Address
|
|
|
+ logistics := fmt.Sprintf("物流公司:%s;物流号:%s", order.ExpressCompany, order.ExpressOrderNo)
|
|
|
+
|
|
|
+ writer.Write([]string{orderId, wxNickname, paiedAtFormat, dispatchTimeFormat, receiveTimeFormat,
|
|
|
+ productName, orderTypeCn, unitGet, totalGet, tel, contact, address, logistics})
|
|
|
+ }
|
|
|
+ writer.Flush()
|
|
|
+ return
|
|
|
+}
|