package models

import (
	"eta_gn/eta_api/global"
	"time"
)

type UserSellerRelation struct {
	RelationId int64     `gorm:"column:relation_id;primaryKey;type:bigint" orm:"column(relation_id);pk" gorm:"primaryKey"  description:"关系ID"`
	UserId     int       `gorm:"column:user_id;type:int" orm:"column(user_id)" description:"用户ID"`
	CompanyId  int       `gorm:"column:company_id;type:int" orm:"column(company_id)" description:"企业用户ID"`
	SellerId   int       `gorm:"column:seller_id;type:int" orm:"column(seller_id)" description:"销售ID"`
	Seller     string    `gorm:"column:seller;type:varchar(255)" orm:"column(seller)" description:"销售员名称"`
	ProductId  int       `gorm:"column:product_id;type:int" orm:"column(product_id)" description:"产品ID"`
	Mobile     string    `gorm:"column:mobile;type:varchar(255)" orm:"column(mobile)" description:"手机号"`
	Email      string    `gorm:"column:email;type:varchar(255)" orm:"column(email)" description:"邮箱"`
	ModifyTime time.Time `gorm:"column:modify_time;type:datetime" orm:"column(modify_time)" description:"修改时间"`
	CreateTime time.Time `gorm:"column:create_time;type:datetime" orm:"column(create_time)" description:"创建时间"`
}

// DeleteUserSellerRelationByProductId 根据产品id删除销售员与员工的关系
func DeleteUserSellerRelationByProductId(userId, productId int) (err error) {
	//o := orm.NewOrmUsingDB("weekly")
	sql := ` DELETE FROM user_seller_relation WHERE user_id=? and product_id = ?`
	//_, err = o.Raw(sql, userId, productId).Exec()
	err = global.DmSQL["weekly"].Exec(sql, userId, productId).Error
	return
}