package final import ( "errors" "fmt" "zhiyuan/pkg/db" "github.com/gin-gonic/gin" ) type FinalOrderPunish struct { ID int64 `json:"id" prop:"add:false"` OrderId int64 `json:"orderId" label:"订单ID" type:"int" prop:"add" search:"="` Amount float64 `json:"amount" label:"金额" type:"float" prop:"add edit" default:"0" search:"="` Explain string `json:"explain" label:"说明" type:"string" prop:"add edit" search:"like"` Pictures string `json:"pictures" label:"图片" type:"string" search:"like"` CreatedId int64 `json:"created_id" type:"int" prop:"add:false"` DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"` CreatedAt int64 `json:"created_at" prop:"add:false"` UpdatedAt int64 `json:"updated_at" prop:"add:false"` db.BaseModel } func (FinalOrderPunish) TableName() string { return "zy_final_order_punish" } func (FinalOrderPunish) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (FinalOrderPunish) OnePrivilege(c *gin.Context, id int64) bool { return true } func (FinalOrderPunish) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { amount, _ := db.ToFloat64(data["amount"]) if amount < 0 { return errors.New("扣款金额必须大于0") } data["created_id"] = c.GetInt("adminID") return nil } func (FinalOrderPunish) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (FinalOrderPunish) DelPrivilege(c *gin.Context, id int64) error { return nil } func (FinalOrderPunish) Page() bool { return false } func (FinalOrderPunish) Count() bool { return true } func (FinalOrderPunish) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{} } type FinalOrderPunishStatist struct { OrderNo string `json:"order_no" label:"订单号" type:"string" prop:"select:order.order_no"` SupplierId int64 `json:"supplier_id" label:"材料商ID" type:"int" prop:"select:order.supplier_id"` ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"select:finalsite.shop_id"` Punished float64 `json:"punished" label:"已罚金额" type:"float" prop:"select:ifnull(deduction.deduction_total,0)"` UnPunished float64 `json:"unpunished" label:"未罚金额" type:"float" prop:"add:false select:zy_final_order_punish.amount-ifnull(deduction.deduction_total,0)"` FinalOrderPunish } type FinalOrderPunishStatistJoinDeduction struct { db.BaseModel } func (FinalOrderPunishStatistJoinDeduction) TableName() string { return "(select `deduction`.`supplierId`, `deduction`.`punishId`, ifnull(sum(`deduction`.`amount`),0) as `deduction_total` from `zy_final_order_punish_deduction` as `deduction` left join `zy_final_material_settle` as `settle` on `settle`.`id` = `deduction`.`settleId` where `deduction`.`deleted_at` = 0 and `settle`.`state` != -1 group by `deduction`.`punishId`)" } func (model FinalOrderPunishStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return model.FinalOrderPunish.ListPrivilege(c, data, s) } func (model FinalOrderPunishStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return append(model.FinalOrderPunish.LeftJoin(data, s), db.JoinModel{ Model: FinalOrderPunishStatistJoinDeduction{}, As: "deduction", On: []string{ fmt.Sprintf("`deduction`.`punishId` = `%s`.`id`", model.TableName()), }, }, db.JoinModel{ Model: FinalMaterialOrder{}, As: "order", On: []string{ fmt.Sprintf("`order`.`id` = `%s`.`orderId`", model.TableName()), }, }, db.JoinModel{ Model: FinalSite{}, As: "finalsite", On: []string{"`finalsite`.`id` = `order`.`site_id`"}, }) }