package budget import ( "fmt" "zhiyuan/models/final" "zhiyuan/pkg/db" "zhiyuan/services/admin" "zhiyuan/services/user" "github.com/gin-gonic/gin" ) type Customer struct { ID int64 `json:"id" prop:"add:false"` Username string `json:"username" label:"业主姓名" type:"string" prop:"add edit" search:"like"` Phone string `json:"phone" label:"业主姓名" type:"string" prop:"add edit" search:"like"` Village string `json:"village" label:"小区名称" type:"string" prop:"edit" search:"like"` Address string `json:"address" label:"房屋地址" type:"string" prop:"edit" search:"like"` RoomNo string `json:"room_no" label:"楼栋房号" type:"string" prop:"edit" search:"like"` ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"add edit" search:"="` OrderId int64 `json:"order_id" label:"门店" type:"int" prop:"add:false" search:"="` SiteId int64 `json:"site_id" label:"门店" type:"int" prop:"add:false" search:"="` Contract string `json:"contract" label:"合同复制件" type:"string" search:"like"` Pdf string `json:"pdf" label:"pdf施工图" type:"string" search:"like"` Receipt string `json:"receipt" label:"一期款收据照片或定金开工店长确认单" type:"string" search:"like"` State int64 `json:"state" label:"状态" type:"int" prop:"add:false"` CreatedId int64 `json:"created_id" type:"int" prop:"add:false" search:"="` 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 (Customer) TableName() string { return "zy_budget_customer" } func (model Customer) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { if !admin.IsSuperAdmin(c.GetInt("adminID")) { adminID := s.Param(c.GetInt("adminID")) where := fmt.Sprintf("`%s`.`created_id` = %s", model.TableName(), adminID) s.Where = append(s.Where, fmt.Sprintf("(%s)", where)) } return true } func (Customer) OnePrivilege(c *gin.Context, id int64) bool { return true } func (Customer) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { data["created_id"] = c.GetInt("adminID") return nil } func (Customer) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) { db.InsertModel(db.Type(BudgetCustomerProcess{}), map[string]interface{}{ "customer_id": id, "type": 0, "created_id": c.GetInt("adminID"), }) } func (Customer) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (Customer) DelPrivilege(c *gin.Context, id int64) error { return nil } func (model Customer) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{} } func (Customer) Page() bool { return true } func (Customer) Count() bool { return true } type CustomerMobile struct { Customer Layout string `json:"layout" label:"内容" type:"string" prop:"select:order.layout"` Area string `json:"area" label:"内容" type:"string" prop:"select:order.area"` } func (model CustomerMobile) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { s.Where = append(s.Where, fmt.Sprintf("`%s`.`order_id` != 0", model.TableName())) s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` > 1", model.TableName())) if !admin.IsSuperAdmin(c.GetInt("adminID")) { info, _ := admin.GetInfoByID(c.GetInt("adminID"), nil, nil) if info == nil { return false } where := fmt.Sprintf("FIND_IN_SET(`%s`.`shop_id`, %s)", model.TableName(), s.Param(info.ShopIds)) s.Where = append(s.Where, fmt.Sprintf("(%s)", where)) } return true } func (model CustomerMobile) GroupBy() string { return fmt.Sprintf("`%s`.`id`", model.TableName()) } func (model CustomerMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return append(model.Customer.LeftJoin(data, s), db.JoinModel{ Model: Order{}, As: "order", On: []string{"`order`.`id` = " + model.TableName() + ".`order_id`"}, }) } type CustomerUser struct { Customer Layout string `json:"layout" label:"内容" type:"string" prop:"select:order.layout"` Area string `json:"area" label:"内容" type:"string" prop:"select:order.area"` DesignerName string `json:"designer_name" type:"string" prop:"select:designer.username"` } func (model CustomerUser) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` > 0", model.TableName())) type UserInfo struct { ID int `json:"id"` Phone string `json:"phone"` } var userInfo UserInfo _, err := user.GetInfoByID(c.GetInt("userID"), nil, &userInfo) if err != nil { return false } s.Where = append(s.Where, fmt.Sprintf("`%s`.`phone` = %s", model.TableName(), s.Param(userInfo.Phone))) return true } func (model CustomerUser) GroupBy() string { return fmt.Sprintf("`%s`.`id`", model.TableName()) } func (model CustomerUser) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return append(model.Customer.LeftJoin(data, s), db.JoinModel{ Model: Order{}, As: "order", On: []string{"`order`.`id` = " + model.TableName() + ".`order_id`"}, }, db.JoinModel{ Model: final.JoinAdmin{}, As: "designer", On: []string{"`designer`.`id` = " + model.TableName() + ".`created_id`"}, }) }