package manage import ( "recook/internal/define" "recook/internal/model/order" "recook/internal/model/user" "recook/internal/v2/lib/db" "recook/internal/v2/model/gys/enterprise" "recook/internal/v2/model/recook/after" "recook/internal/v2/model/recook/goods" "strconv" "github.com/golangkit/formatime" "github.com/shopspring/decimal" ) const ( RecookOrderGoodsDetailPayStatusNone = 0 // 未支付 RecookOrderGoodsDetailPayStatusSuc = 1 // 支付成功 RecookOrderGoodsDetailExpressStatusNone = 0 // 未发货 RecookOrderGoodsDetailExpressStatusTrue = 1 // 已发货 RecookOrderGoodsDetailExpressStatusConfirm = 2 // 已确认收获 RecookOrderGoodsDetailIsClosedFalse = 0 // 未关闭 RecookOrderGoodsDetailIsClosedTrue = 1 // 已关闭 RecookOrderGoodsDetailShippingMethodExpress = 0 // 快递 RecookOrderGoodsDetailShippingMethodSelfRaising = 1 // 自提 RecookOrderGoodsDetailAssTypeNone = 0 // 无售后 RecookOrderGoodsDetailAssTypeRefund = 1 // 退款 RecookOrderGoodsDetailAssTypeRejected = 2 // 退货退款 RecookOrderGoodsDetailAssTypeCompensate = 3 // 订单补偿 RecookOrderGoodsDetailRefundStatusNone = 0 // 无退款 RecookOrderGoodsDetailRefundStatusIng = 1 // 退款中 RecookOrderGoodsDetailRefundStatusSuc = 2 // 退货成功 ExpressTime = 172800 // 超时未发货时间 ) type RecookOrderGoodsDetailModel struct { db.BaseModel Id uint `gorm:"column:id;primary_key" json:"goodsDetailId"` OrderId uint `gorm:"column:order_id;" json:"orderId"` UserCoinHistory user.RecookUserCoinHistory `gorm:"ForeignKey:OrderId;References:OrderId"` OrderInfo RecookOrderInfoModel `gorm:"foreignKey:OrderId"` ExpressInfo RecookOrderGoodsExpressModel `gorm:"ForeignKey:OrderGoodsId"` After after.RecookAfterSalesGoodsModel `gorm:"ForeignKey:OrderId;References:OrderId"` AncestorId uint `gorm:"column:ancestor_id" json:"-"` ParentId uint `gorm:"column:parent_id" json:"parentId"` SharerId uint `gorm:"column:sharer_id" json:"sharerId"` LiveId uint `gorm:"column:live_id" json:"liveId"` UserId uint `gorm:"column:user_id" json:"userId"` VendorId uint `gorm:"column:vendor_id" json:"vendorId"` // 供应商Id: 0表示自营 EnterpriseState enterprise.GysEnterpriseStateModel `gorm:"ForeignKey:VendorId;References:UserId"` //供应商关联source表 VendorName string `gorm:"column:vendor_name" json:"vendorName"` BrandId uint `gorm:"column:brand_id" json:"brandId"` // 品牌 BrandName string `gorm:"column:brand_name" json:"brandName"` // 品牌名称 CategoryName string `gorm:"column:category_name" json:"cateName"` GoodsId uint `gorm:"column:goods_id" json:"goodsId"` // 商品Id GoodsName string `gorm:"column:goods_name" json:"goodsName"` // 商品名快照 IsJoinTeamPerformance uint `gorm:"column:is_join_team_performance" json:"-"` // 是否参与团队业绩计算 Hash string `gorm:"column:hash" json:"-"` // 商品哈希值如果商品信息更新了 SkuId uint `gorm:"column:sku_id" json:"skuId"` // 商品sku_id Sku goods.RecookGoodsSkuModel `gorm:"foreignKey:SkuId"` SkuName string `gorm:"column:sku_name" json:"skuName"` // SKU名字组合起来 SkuCode string `gorm:"column:sku_code" json:"skuCode"` // 条形码或者编码 MainPhotoURL string `gorm:"column:main_photo_url" json:"mainPhotoUrl"` // 主图快照 先读sku 没有则读取主图 Quantity uint `gorm:"column:quantity" json:"quantity"` // 商品数量 FreightId uint `gorm:"column:freight_id" json:"-"` // 运费模板 Weight decimal.Decimal `gorm:"column:weight" json:"-"` // 重量 PromotionGoodsId uint `gorm:"column:promotion_goods_id" json:"-"` PromotionSkuId uint `gorm:"column:promotion_sku_id" json:"-"` // PromotionName string `gorm:"column:promotion_name" json:"promotionName"` // 活动名称 PromotionStartTime formatime.Second `gorm:"column:promotion_start_time" json:"-"` PromotionEndTime formatime.Second `gorm:"column:promotion_end_time" json:"-"` UnitPrice decimal.Decimal `gorm:"column:unit_price" json:"unitPrice"` // 单价 PurchasePrice decimal.Decimal `gorm:"column:purchase_price" json:"purchasePrice"` // 采购价 TotalCommission decimal.Decimal `gorm:"column:total_commission" json:"totalCommission"` // 提成总额 BrandCouponAmount decimal.Decimal `gorm:"column:brand_coupon_amount" json:"brandCouponAmount"` // 品牌优惠券抵扣金额 UniverseCouponAmount decimal.Decimal `gorm:"column:universe_coupon_amount" json:"universeBrandCouponAmount"` // 购物券抵扣金额 CoinAmount decimal.Decimal `gorm:"column:coin_amount" json:"coinAmount"` // 瑞币抵扣金额 GoodsAmount decimal.Decimal `gorm:"column:goods_amount" json:"goodsAmount"` // 商品总金额 单价x数量,不含其他费用减除 ExpressFee decimal.Decimal `gorm:"column:express_fee" json:"expressFee"` // 快递费 ActualAmount decimal.Decimal `gorm:"column:actual_amount" json:"actualAmount"` // 实际支付的金额 StoreId uint `gorm:"column:store_id" json:"-"` // 门店id BuyerMessage string `gorm:"column:buyer_message" json:"buyerMessage"` // 买家留言 StoreMessage string `gorm:"column:store_message" json:"storeMessage"` // 商家留言 OrderTime formatime.Second `gorm:"column:order_time" json:"orderTime"` PayStatus uint `gorm:"column:pay_status" json:"payStatus"` CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"` // 创建时间 ExpressStatus uint `gorm:"column:express_status" json:"expressStatus"` ExpressTime formatime.Second `gorm:"column:express_time" json:"expressTime"` ExpressCompName string `gorm:"column:express_comp_name" json:"expressCompName"` ExpressCompCode string `gorm:"column:express_comp_code" json:"expressCompCode"` ExpressNo string `gorm:"column:express_no" json:"expressNo"` AssType uint `gorm:"column:ass_type" json:"assType"` RefundStatus uint `gorm:"column:refund_status" json:"refundStatus"` Status uint `gorm:"column:status" json:"status"` ShippingMethod int `gorm:"shipping_method" json:"shippingMethod"` IsClosed int `gorm:"is_closed" json:"isClosed"` RStatus string `gorm:"-" json:"rStatus"` DetailInfo string `json:"detailInfo"` Bill int `gorm:"bill" json:"bill"` //是否开发票0代表未开1处理中2已成功3失败 Fpqqlsh string `gorm:"fpqqlsh" json:"fpqqlsh"` //流水号 IsExport int `gorm:"is_export" json:"isExport"` //舶茂的是否导出 BomaoNo string `gorm:"bomao_no" json:"bomaoNo"` //舶茂的订单编号 EvaluatedId int `gorm:"evaluated_id" json:"evaluatedId"` //评价id ReportMsg string `gorm:"report_msg" json:"reportMsg"` Report int `gorm:"report" json:"report"` IsImport int `gorm:"column:is_import" json:"isImport"` //是否进口商品 Storehouse int `gorm:"column:storehouse" json:"storehouse"` //进口商品仓库 IsFerme int `gorm:"column:is_ferme" json:"isFerme"` //是否包税 DeliveryTimeOut int `gorm:"column:delivery_time_out" json:"delivery_time_out"` //发货超时 OrderFiling uint `gorm:"column:order_filing" json:"order_filing"` //订单掩饰报备 ActivityStatus uint `gorm:"column:activity_status" json:"activity_status"` ActivityId uint `gorm:"column:activity_id" json:"activity_id"` //活动id MakeUpStatus uint `json:"make_up_status"` ExtraPrice decimal.Decimal `json:"-"` } // TableName sets the insert table name for this struct type func (r *RecookOrderGoodsDetailModel) TableName() string { return "recook_order_goods_detail" } func (r *RecookOrderGoodsDetailModel) GetSelfProfit(level int) decimal.Decimal { base := r.GetBase() switch level { case 0: return decimal.Zero case 1: self := base.Mul(order.Self.GetProfit()).Round(2) brand := base.Mul(order.Brand.GetProfit()).Round(2) return self.Add(brand) case 2: // 店铺买 self := base.Mul(order.Self.GetProfit()).Round(2) brand := base.Mul(order.Brand.GetProfit()).Round(2) shop := base.Mul(order.Shop.GetProfit()).Round(2) return self.Add(brand).Add(shop) case 10: // 子公司 100%自购 return base.Mul(order.All.GetProfit()) default: return decimal.Zero } } func (r *RecookOrderGoodsDetailModel) GetBase() decimal.Decimal { cost := r.PurchasePrice.Mul(decimal.NewFromFloat(1.03)) if !r.ExtraPrice.IsZero() { cost = r.PurchasePrice.Add(r.ExtraPrice) } base := r.UnitPrice.Sub(cost).Mul(decimal.NewFromFloat32(define.Coefficient)) return base.Round(2) } // @Style 添加 func (r *RecookOrderGoodsDetailModel) Create(data *RecookOrderGoodsDetailModel) { r.GetDb().Create(data) } // @Style 获取列表数量 func (r *RecookOrderGoodsDetailModel) List(start, limit int, order string, query interface{}, args ...interface{}) (result []RecookOrderGoodsDetailModel) { r.GetDb().Model(&RecookOrderGoodsDetailModel{}).Offset(start).Limit(limit).Where(query, args...).Order(order).Find(&result) return } // @Style 获取列表数量 func (r *RecookOrderGoodsDetailModel) ListCount(query interface{}, args ...interface{}) (count int) { r.GetDb().Model(&RecookOrderGoodsDetailModel{}).Where(query, args...).Count(&count) return } // @Style 编辑 func (r *RecookOrderGoodsDetailModel) UpdateById(orderGoodsId, userId uint, date *RecookOrderGoodsDetailModel) error { return r.GetDb().Model(&RecookOrderGoodsDetailModel{}).Where("id = ? and vendor_id = ?", orderGoodsId, userId).Update(date).Error } // @Style 编辑 func (r *RecookOrderGoodsDetailModel) FindById(orderGoodsId uint) (result RecookOrderGoodsDetailModel) { r.GetDb().Model(&RecookOrderGoodsDetailModel{}).Where("id = ?", orderGoodsId).First(&result) return } // @Style 根据orderId获取数据 func (r *RecookOrderGoodsDetailModel) FindByOrderId(orderId uint) (result []RecookOrderGoodsDetailModel) { r.GetDb().Model(&RecookOrderGoodsDetailModel{}).Where("order_id = ?", orderId).Preload("After").Find(&result) return } // @Style 根据orderIds获取数据 func (r *RecookOrderGoodsDetailModel) FindByOrderIds(orderIds []uint) (result []RecookOrderGoodsDetailModel) { r.GetDb().Model(&RecookOrderGoodsDetailModel{}).Where("order_id in (?)", orderIds).Find(&result) return } // @Style 获取售后类型 func (r *RecookOrderGoodsDetailModel) GetAssName() string { switch r.AssType { case RecookOrderGoodsDetailAssTypeNone: return "正常" case RecookOrderGoodsDetailAssTypeRefund: return "未发货退款" case RecookOrderGoodsDetailAssTypeRejected: return "退货退款" case RecookOrderGoodsDetailAssTypeCompensate: return "订单补偿" } return "" } // @Style 获取退款名称 func (r *RecookOrderGoodsDetailModel) GetRefundName() string { switch r.RefundStatus { case RecookOrderGoodsDetailRefundStatusNone: return "无退款" case RecookOrderGoodsDetailRefundStatusIng: return "退款中" case RecookOrderGoodsDetailRefundStatusSuc: return "退货成功" } return "" } // GetSoID 获取线上订单号. func (r *RecookOrderGoodsDetailModel) GetSoID() string { return strconv.Itoa(int(r.Id)) } //获取已发货的订单信息 func (r *RecookOrderGoodsDetailModel) GetOrderByGysId(vendorId uint) (rest []RecookOrderGoodsDetailModel) { r.GetDb().Model(&RecookOrderGoodsExpressModel{}).Where("vendor_id= ? and express_status=1 and shipping_method=0", vendorId).Find(&rest) return } //set express_status=1,where order_id=? func (r *RecookOrderGoodsDetailModel) UpdateExpressStatus(orderId uint64) { r.GetDb().Model(&RecookOrderGoodsDetailModel{}).Where("order_id= ?", orderId).Update("express_status", 1) } func (r *RecookOrderGoodsDetailModel) FindByIdAndOrderId(orderGoodsId uint, orderId uint) (result RecookOrderGoodsDetailModel) { r.GetDb().Model(&RecookOrderGoodsDetailModel{}).Where("id = ? and order_id= ?", orderGoodsId, orderId).First(&result) return } // 判断商品是否销售完成 func (r *RecookOrderGoodsDetailModel) IsFinished() bool { // 成功 if r.AssType == 0 && r.ExpressStatus == 1 { return true } return false }