You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
9.7 KiB

package goods
import (
"recook/configs"
"recook/internal/v2/lib/db"
"recook/internal/v2/model/gys/enterprise"
"recook/internal/v2/model/search_ali"
"strconv"
"github.com/golangkit/formatime"
"github.com/shopspring/decimal"
)
const (
RecookGoodsInfoThirdPartyTypeNone = 0 // 供应商提报
RecookGoodsInfoThirdPartyTypeBomao = 1 // 舶茂
RecookGoodsInfoThirdPartyTypeJingtong = 2 // 景彤
RecookGoodsInfoJCook = 3 //京库客
RecookGoodsInfoBomaoStatusOn = 1 // 舶茂上架
RecookGoodsInfoBomaoStatusOff = 0 // 舶茂下架
RecookGoodsInfoPublishStatusOn = 1 // 上架
RecookGoodsInfoPublishStatusOff = 0 // 下架
RecookGoodsInfoIsJoinTeamPerformanceTrue = 1
RecookGoodsInfoHasAuthTrue = 1 // 需要实名认证
RecookGoodsInfoHasAuthFalse = 0 // 不需要实名认证
RecookGoodsInfoIsImportFalse = 0 // 非进口商品
RecookGoodsInfoIsImportTrue = 1 // 进口商品
RecookGoodsInfoIsFermeFalse = 0 // 不包税
RecookGoodsInfoIsFermeTrue = 1 // 包税
RecookGoodsInfoStorehouseNone = 0 // 非进口商品,无仓库
RecookGoodsInfoStorehouseDomestic = 1 // 国内仓
RecookGoodsInfoStorehouseDirectMail = 2 // 海外直邮
RecookGoodsInfoStorehouseBonded = 3 // 保税仓
RecookGoodsInfoPublishStatusFalse = 0 // 下架
RecookGoodsInfoPublishStatusTrue = 1 // 上架
RecookGoodsInfoIsDelFalse = 0 // 未删除
RecookGoodsInfoIsDelTrue = 1 // 已删除
)
type RecookGoodsInfoModel struct {
db.BaseModel
Id uint `gorm:"column:id;primary_key" json:"id,omitempty"`
GoodsSkuModel []RecookGoodsSkuModel `gorm:"foreignKey:GoodsId;references:Id"`
BrandID uint `gorm:"column:brand_id" json:"brandId"`
Brand RecookGoodsBrandModel `gorm:"foreignKey:BrandID"`
VendorID uint `gorm:"vendor_id" json:"vendorId"`
Vendor enterprise.GysEnterpriseStateModel `gorm:"foreignKey:VendorID;references:UserId" json:"vendor"`
GoodsName string `gorm:"column:goods_name" json:"goodsName"`
Description string `gorm:"description default:''" json:"description"`
Material string `gorm:"material default:''" json:"material"`
FirstCategoryID uint `gorm:"column:first_category_id" json:"firstCategoryId,omitempty"`
FirstCategory RecookGoodsCategoryModel `gorm:"foreignKey:FirstCategoryID"`
SecondCategoryID uint `gorm:"column:second_category_id" json:"secondCategoryId,omitempty"`
SecondCategory RecookGoodsCategoryModel `gorm:"foreignKey:SecondCategoryID"`
PublishStatus uint `gorm:"column:publish_status" json:"publish_status"`
FreightID uint `gorm:"column:freight_id" json:"freightId,omitempty"`
Weight decimal.Decimal `gorm:"column:weight" json:"weight"`
Hash string `gorm:"column:hash" json:"-"`
IsJoinTeamPerformance uint `gorm:"column:is_join_team_performance" json:"isJoinTeamPerformance"` // 是否参与团队业绩计算
CreatedAt formatime.Second `gorm:"column:created_at" json:"-"`
UpdatedAt formatime.Second `gorm:"column:updated_at" json:"-"`
SalesVolume uint `gorm:"column:sales_volume" json:"-"`
BomaoStatus int `gorm:"column:bomao_status" json:"bomaoStatus"` //舶茂的发布状态
BomaoId int `gorm:"column:bomao_id" json:"bomaoId"` //舶茂的产品id
ThirdPartyId uint `gorm:"column:third_party_id" json:"thirdPartyId"` //第三方商品id
ThirdPartyType int `gorm:"column:third_party_type" json:"thirdPartyType"` //第三方类型 1=舶茂 2=景彤
HasAuth int `gorm:"column:has_auth" json:"hasAuth"` //是否需要实名购买
IsImport int `gorm:"column:is_import" json:"isImport"` //是否进口商品
Storehouse int `gorm:"column:storehouse" json:"storehouse"` //进口商品仓库
IsFerme int `gorm:"column:is_ferme" json:"isFerme"` //是否包税
IsDel int `gorm:"column:is_del" json:"isDel"` //是否删除
Country uint `json:"country"`
CountryModel RecookAbroadCountryModel `gorm:"foreignKey:Country"`
ReturnAddressID uint `json:"return_address_id"`
JCookPublishStatus uint `gorm:"column:jcook_publish_status"`
SalePublish uint `gorm:"column:sale_publish"`
MainPhoto RecookGoodsMainPhotoModel `gorm:"foreignKey:GoodsId"`
IsSale bool `json:"is_sale"`
SkuPath []RecookGoodsSkuModel `gorm:"foreignKey:GoodsId"`
SkuList []RecookGoodsSkuModel `gorm:"foreignKey:goods_id" json:"-"`
}
func (r *RecookGoodsInfoModel) Publish() {
isSale := 0
if r.IsSale {
isSale = 1
}
f := search_ali.F{
ID: r.Id,
GoodsName: r.GoodsName,
Cate2: r.SecondCategory.Name,
Cate2ID: r.SecondCategoryID,
PublishStatus: r.PublishStatus,
SalePublish: r.SalePublish,
Version: 1,
IsSale: isSale,
}
search_ali.PublishMessage(search_ali.CreateRes(search_ali.ADD, f))
}
// TableName sets the insert table name for this struct type
func (*RecookGoodsInfoModel) TableName() string {
return "recook_goods_info"
}
//获取全部id列表
func (r *RecookGoodsInfoModel) GetAllIdByGYS(gysId uint) (ids []RecookGoodsInfoModel) {
r.GetDb().Model(&RecookGoodsInfoModel{}).Where("vendor_id=?", gysId).Find(&ids)
return
}
// @Title 是否支持瑞币抵扣
func (r *RecookGoodsInfoModel) HasCoin(storehouse int) bool {
switch storehouse {
case RecookGoodsInfoStorehouseDirectMail:
// 海外直邮
return false
case RecookGoodsInfoStorehouseBonded:
// 保税仓
return false
}
return true
}
// @Title 是否支持余额支付
func (r *RecookGoodsInfoModel) HasBalance(storehouse int) bool {
switch storehouse {
case RecookGoodsInfoStorehouseDirectMail:
// 海外直邮
return false
case RecookGoodsInfoStorehouseBonded:
// 保税仓
return false
}
return true
}
// @Title 添加
func (r *RecookGoodsInfoModel) GetSource() string {
switch r.ThirdPartyId {
case 0:
return "供应商提报"
default:
return "接口获取"
}
}
func (r *RecookGoodsInfoModel) GetStatus() string {
switch r.PublishStatus {
case 0:
return "已下架"
default:
return "上架中"
}
}
// @Style 添加
func (r *RecookGoodsInfoModel) Create(data *RecookGoodsInfoModel) {
r.GetDb().Create(data)
}
// @Title 添加
func (r *RecookGoodsInfoModel) FindByThirdIdType(thirdPartyId uint, thirdPartyType int) (result RecookGoodsInfoModel) {
r.GetDb().First(&result, "third_party_id = ? and third_party_type = ?", thirdPartyId, thirdPartyType)
return
}
// @Title 添加
func (r *RecookGoodsInfoModel) UpdateByThirdIdType(thirdPartyId uint, thirdPartyType int, date map[string]interface{}) (result int64) {
return r.GetDb().Model(&RecookGoodsInfoModel{}).Where("third_party_id = ? and third_party_type = ?", thirdPartyId, thirdPartyType).Updates(date).RowsAffected
}
// @Title 添加
func (r *RecookGoodsInfoModel) UpdateById(goodsId uint, date map[string]interface{}) (result error) {
return r.GetDb().Model(&RecookGoodsInfoModel{}).Where("id = ?", goodsId).Updates(date).Error
}
// @Title 批量获取数据
func (r *RecookGoodsInfoModel) FindByGoodsIds(goodsIds []uint) (result []RecookGoodsInfoModel) {
r.GetDb().Model(&RecookGoodsInfoModel{}).Find(&result, "id in (?)", goodsIds)
return
}
// @Title 获取数据
func (r *RecookGoodsInfoModel) FindById(goodsId uint) (result RecookGoodsInfoModel) {
r.GetDb().Model(&RecookGoodsInfoModel{}).First(&result, "id = ?", goodsId)
return
}
// @Title 获取列表数量
func (r *RecookGoodsInfoModel) List(start, limit int, order string, query interface{}, args ...interface{}) (result []RecookGoodsInfoModel) {
r.GetDb().Model(&RecookGoodsInfoModel{}).Offset(start).Limit(limit).Where(query, args...).Order(order).Find(&result)
return
}
// @Title 获取列表数量
func (r *RecookGoodsInfoModel) ListCount(query interface{}, args ...interface{}) (count int) {
r.GetDb().Model(&RecookGoodsInfoModel{}).Where(query, args...).Count(&count)
return
}
// @Title 添加
func (r *RecookGoodsInfoModel) Update(date map[string]interface{}, query interface{}, queryArgs ...interface{}) (result error) {
return r.GetDb().Model(&RecookGoodsInfoModel{}).Where(query, queryArgs...).Updates(date).Error
}
// GetIID 获取i_id.
func (r *RecookGoodsInfoModel) GetIID() string {
return configs.ConfigJSTPrefix + "#" + strconv.Itoa(int(r.Id))
}
// GetShopIID 获取shop_i_id.
func (r *RecookGoodsInfoModel) GetShopIID() string {
return configs.ConfigJSTPrefix + "#" + strconv.Itoa(int(r.Id))
}
// FindByGoodsID 获取数据.
func (r *RecookGoodsInfoModel) FindByGoodsID(by uint) (result RecookGoodsInfoModel) {
r.GetDb().Model(&RecookGoodsInfoModel{}).First(&result, "id = ?", by)
return
}