feat: Add callback and exchange features, refactor care plan task generation logic, and update wiki ordering to prioritize hot items.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package plant
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/system"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ExchangeItem 兑换商品
|
||||
type ExchangeItem struct {
|
||||
global.BaseModel
|
||||
Name string `json:"name" gorm:"size:100;not null;column:name"` // 商品名称
|
||||
Description string `json:"description" gorm:"type:text;column:description"` // 商品描述
|
||||
ImageId string `json:"imageId" gorm:"size:50;column:image_id"` // 商品图片ID
|
||||
Type string `json:"type" gorm:"size:20;not null;default:PHYSICAL;column:type"` // 商品类型: PHYSICAL/VIRTUAL/COUPON
|
||||
CostSunlight int64 `json:"costSunlight" gorm:"not null;default:0;column:cost_sunlight"` // 消耗阳光值
|
||||
Stock int `json:"stock" gorm:"not null;default:-1;column:stock"` // 库存 -1无限
|
||||
LimitPerUser int `json:"limitPerUser" gorm:"not null;default:0;column:limit_per_user"` // 每人限兑次数 0不限
|
||||
Status int `json:"status" gorm:"not null;default:1;column:status"` // 1上架 2下架
|
||||
Sort int `json:"sort" gorm:"not null;default:0;column:sort"` // 排序
|
||||
StartTime *time.Time `json:"startTime" gorm:"column:start_time"` // 上架时间
|
||||
EndTime *time.Time `json:"endTime" gorm:"column:end_time"` // 下架时间
|
||||
Image *system.Oss `json:"image" gorm:"foreignKey:ImageId"` // 商品图片关联
|
||||
}
|
||||
|
||||
func (ExchangeItem) TableName() string {
|
||||
return "sundynix_exchange_item"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package plant
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ExchangeOrder 兑换订单
|
||||
type ExchangeOrder struct {
|
||||
global.BaseModel
|
||||
UserId string `json:"userId" gorm:"index;size:50;not null;column:user_id"` // 用户ID
|
||||
ItemId string `json:"itemId" gorm:"index;size:50;not null;column:item_id"` // 商品ID
|
||||
ItemName string `json:"itemName" gorm:"size:100;column:item_name"` // 商品名称(冗余快照)
|
||||
CostSunlight int64 `json:"costSunlight" gorm:"not null;default:0;column:cost_sunlight"` // 消耗阳光值
|
||||
Quantity int `json:"quantity" gorm:"not null;default:1;column:quantity"` // 数量
|
||||
Status int `json:"status" gorm:"not null;default:1;column:status"` // 1待处理 2处理中 3已发货 4已完成 5已取消
|
||||
ItemType string `json:"itemType" gorm:"size:20;column:item_type"` // 商品类型快照
|
||||
RecipientName string `json:"recipientName" gorm:"size:50;column:recipient_name"` // 收货人姓名
|
||||
Phone string `json:"phone" gorm:"size:20;column:phone"` // 联系电话
|
||||
Address string `json:"address" gorm:"size:255;column:address"` // 收货地址
|
||||
TrackingNo string `json:"trackingNo" gorm:"size:100;column:tracking_no"` // 快递单号
|
||||
Remark string `json:"remark" gorm:"size:255;column:remark"` // 备注
|
||||
CompletedAt *time.Time `json:"completedAt" gorm:"column:completed_at"` // 完成时间
|
||||
Item *ExchangeItem `json:"item" gorm:"foreignKey:ItemId"` // 商品关联
|
||||
}
|
||||
|
||||
func (ExchangeOrder) TableName() string {
|
||||
return "sundynix_exchange_order"
|
||||
}
|
||||
|
||||
// 订单状态常量
|
||||
const (
|
||||
OrderStatusPending = 1 // 待处理
|
||||
OrderStatusProcessing = 2 // 处理中
|
||||
OrderStatusShipped = 3 // 已发货
|
||||
OrderStatusCompleted = 4 // 已完成
|
||||
OrderStatusCancelled = 5 // 已取消
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
package plant
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
)
|
||||
|
||||
// MediaCheckResult 媒体安全检测结果
|
||||
// 对应微信 media_check_async 接口的返回结果
|
||||
type MediaCheckResult struct {
|
||||
global.BaseModel
|
||||
TraceId string `json:"traceId" gorm:"column:trace_id;size:100;uniqueIndex;comment:微信返回的唯一任务id"`
|
||||
PostId string `json:"postId" gorm:"column:post_id;size:50;index;comment:关联的帖子id"`
|
||||
OssId string `json:"ossId" gorm:"column:oss_id;size:50;comment:关联的oss文件id"`
|
||||
UserId string `json:"userId" gorm:"column:user_id;size:50;comment:提交检测的用户id"`
|
||||
Status int `json:"status" gorm:"column:status;default:0;comment:检测状态 0:检测中 1:通过 2:违规"`
|
||||
Type int `json:"type" gorm:"column:type;comment:媒体类型 1:音频 2:图片"`
|
||||
ErrMsg string `json:"errMsg" gorm:"column:err_msg;size:255;comment:错误信息"`
|
||||
}
|
||||
|
||||
func (MediaCheckResult) TableName() string {
|
||||
return "sundynix_media_check_result"
|
||||
}
|
||||
@@ -2,9 +2,6 @@ package plant
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/utils/timer"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CarePlan 养护计划
|
||||
@@ -19,28 +16,28 @@ type CarePlan struct {
|
||||
}
|
||||
|
||||
// AfterUpdate 钩子函数 修改计划后重新生成任务
|
||||
func (p *CarePlan) AfterUpdate(tx *gorm.DB) error {
|
||||
//1.删除旧任务
|
||||
err := tx.Where("plan_id = ?", p.Id).Unscoped().Delete(&CareTask{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//2.创建新任务
|
||||
today := timer.GetZeroTime()
|
||||
dueDate := today.AddDate(0, 0, p.Period)
|
||||
task := CareTask{
|
||||
UserId: p.UserId,
|
||||
PlantId: p.Id,
|
||||
PlanId: p.Id,
|
||||
Name: p.Name,
|
||||
Icon: p.Icon,
|
||||
DueDate: dueDate,
|
||||
Status: 1,
|
||||
}
|
||||
err = tx.Create(&task).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
// func (p *CarePlan) AfterUpdate(tx *gorm.DB) error {
|
||||
// //1.删除旧任务
|
||||
// err := tx.Where("plan_id = ?", p.Id).Unscoped().Delete(&CareTask{}).Error
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// //2.创建新任务
|
||||
// today := timer.GetZeroTime()
|
||||
// dueDate := today.AddDate(0, 0, p.Period)
|
||||
// task := CareTask{
|
||||
// UserId: p.UserId,
|
||||
// PlantId: p.Id,
|
||||
// PlanId: p.Id,
|
||||
// Name: p.Name,
|
||||
// Icon: p.Icon,
|
||||
// DueDate: dueDate,
|
||||
// Status: 1,
|
||||
// }
|
||||
// err = tx.Create(&task).Error
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package request
|
||||
|
||||
import common "sundynix-go/model/commom/request"
|
||||
|
||||
// ExchangeItemCreateReq 创建兑换商品请求
|
||||
type ExchangeItemCreateReq struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
ImageId string `json:"imageId"`
|
||||
Type string `json:"type" binding:"required"` // PHYSICAL / VIRTUAL / COUPON
|
||||
CostSunlight int64 `json:"costSunlight" binding:"required,min=1"`
|
||||
Stock int `json:"stock"` // -1 无限
|
||||
LimitPerUser int `json:"limitPerUser"` // 0 不限
|
||||
Sort int `json:"sort"`
|
||||
StartTime string `json:"startTime"` // 可选
|
||||
EndTime string `json:"endTime"` // 可选
|
||||
}
|
||||
|
||||
// ExchangeItemUpdateReq 更新兑换商品请求
|
||||
type ExchangeItemUpdateReq struct {
|
||||
Id string `json:"id" binding:"required"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
ImageId string `json:"imageId"`
|
||||
Type string `json:"type"`
|
||||
CostSunlight int64 `json:"costSunlight"`
|
||||
Stock int `json:"stock"`
|
||||
LimitPerUser int `json:"limitPerUser"`
|
||||
Status int `json:"status"` // 1上架 2下架
|
||||
Sort int `json:"sort"`
|
||||
StartTime string `json:"startTime"`
|
||||
EndTime string `json:"endTime"`
|
||||
}
|
||||
|
||||
// ExchangeItemListReq 商品列表查询请求
|
||||
type ExchangeItemListReq struct {
|
||||
common.PageInfo
|
||||
Type string `json:"type" form:"type"` // 按类型筛选
|
||||
Status int `json:"status" form:"status"` // 按状态筛选
|
||||
}
|
||||
|
||||
// ExchangeReq 用户兑换请求
|
||||
type ExchangeReq struct {
|
||||
ItemId string `json:"itemId" binding:"required"`
|
||||
Quantity int `json:"quantity"` // 默认1
|
||||
RecipientName string `json:"recipientName"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
}
|
||||
|
||||
// ExchangeOrderListReq 订单列表查询请求
|
||||
type ExchangeOrderListReq struct {
|
||||
common.PageInfo
|
||||
Status int `json:"status" form:"status"` // 按状态筛选
|
||||
UserId string `json:"userId" form:"userId"` // 管理端按用户筛选
|
||||
}
|
||||
|
||||
// ExchangeOrderUpdateReq 更新订单状态请求 (管理端)
|
||||
type ExchangeOrderUpdateReq struct {
|
||||
Id string `json:"id" binding:"required"`
|
||||
Status int `json:"status" binding:"required"` // 目标状态
|
||||
TrackingNo string `json:"trackingNo"` // 快递单号(发货时)
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
+3
-3
@@ -12,13 +12,13 @@ type Wiki struct {
|
||||
Name string `json:"name" form:"name" gorm:"column:name;size:50;comment:名称"`
|
||||
LatinName string `json:"latinName" form:"latinName" gorm:"size:100;column:latin_name;comment:拉丁名"`
|
||||
Aliases string `json:"aliases" form:"aliases" gorm:"size:100;column:aliases;comment:别名(逗号分隔)"`
|
||||
DistributionArea string `json:"distributionArea" form:"distributionArea" gorm:"size:100;column:distribution_area;comment:分布区域"` //分布区域
|
||||
DistributionArea string `json:"distributionArea" form:"distributionArea" gorm:"type:text;;column:distribution_area;comment:分布区域"` //分布区域
|
||||
//科学分类
|
||||
Genus string `json:"genus" form:"genus" gorm:"size:20;column:genus;comment:科属"` // 属
|
||||
Difficulty int `json:"difficulty" form:"difficulty" gorm:"column:difficulty;comment:种植难度"` //种植难度 1-5级
|
||||
//形态特征
|
||||
LifeCycle string `json:"lifeCycle" form:"lifeCycle" gorm:"size:20;column:life_cycle;comment:生命周期"` // 生命周期 一年生 二年生 多年生等
|
||||
GrowthHabit string `json:"growthHabit" form:"growthHabit" gorm:"size:200;column:growth_habit;comment:成长习性"` // 生长习性
|
||||
LifeCycle string `json:"lifeCycle" form:"lifeCycle" gorm:"type:text;column:life_cycle;comment:生命周期"` // 生命周期 一年生 二年生 多年生等
|
||||
GrowthHabit string `json:"growthHabit" form:"growthHabit" gorm:"type:text;column:growth_habit;comment:成长习性"` // 生长习性
|
||||
ReproductionMethod string `json:"reproductionMethod" form:"reproductionMethod" gorm:"size:200;column:reproduction_method;comment:繁殖方法"` //繁殖方法
|
||||
PestsDiseases string `json:"pestsDiseases" form:"pestsDiseases" gorm:"size:200;column:pests_diseases;comment:病虫害"`
|
||||
//光照
|
||||
|
||||
Reference in New Issue
Block a user