123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package dispatch
- import (
- "errors"
- "fmt"
- "zhiyuan/pkg/db"
- "github.com/gin-gonic/gin"
- )
- type DispatchSiteProcess struct {
- ID int64 `json:"id" prop:"add:false"`
- TableId int64 `json:"table_id" label:"表" type:"int"`
- CollectId int64 `json:"collect_id" label:"汇总" type:"int"`
- Explain string `json:"explain" label:"说明" type:"string" search:"like"`
- Pictures string `json:"pictures" label:"图片" type:"string" search:"like"`
- Type int64 `json:"type" label:"类型" type:"int" prop:"add" default:"0"`
- Signature string `json:"signature" label:"签名" prop:"add" type:"string"`
- State int64 `json:"state" label:"状态" type:"int" prop:"add" default:"0"`
- CreatedId int64 `json:"created_id" label:"创建人员" type:"int" prop:"add:false" search:"="`
- CreatedName string `json:"created_name" prop:"add:false select:created.username"`
- CreatedPhone string `json:"created_phone" prop:"add:false select:created.phone"`
- CreatedHeadimgurl string `json:"created_headimgurl" prop:"add:false select:created.headimgurl"`
- 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 (DispatchSiteProcess) TableName() string {
- return "zy_dispatch_site_process"
- }
- func (model DispatchSiteProcess) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
- table_id, _ := db.ToInt64(data["table_id"])
- collect_id, _ := db.ToInt64(data["collect_id"])
- if table_id != 0 && collect_id != 0 {
- s.Where = append(s.Where, fmt.Sprintf("`%s`.`table_id` = %s OR `%s`.`collect_id` = %s", model.TableName(), s.Param(table_id), model.TableName(), s.Param(collect_id)))
- } else if table_id != 0 {
- s.Where = append(s.Where, fmt.Sprintf("`%s`.`table_id` = %s", model.TableName(), s.Param(table_id)))
- } else if collect_id != 0 {
- s.Where = append(s.Where, fmt.Sprintf("`%s`.`collect_id` = %s", model.TableName(), s.Param(collect_id)))
- }
- return true
- }
- func (DispatchSiteProcess) OnePrivilege(c *gin.Context, id int64) bool {
- return true
- }
- func (DispatchSiteProcess) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
- data["created_id"] = c.GetInt("adminID")
- typ, _ := db.ToInt64(data["type"])
- tableID, _ := db.ToInt64(data["table_id"])
- collectID, _ := db.ToInt64(data["collect_id"])
- state, _ := db.ToInt64(data["state"])
- if tableID != 0 {
- var model DispatchSiteTable
- db.GetModel(map[string]interface{}{
- "id": tableID,
- }, &model)
- if model.ID == 0 || model.State != typ {
- return errors.New("没有权限")
- }
- s := model.State + 1
- if state != 0 {
- s = -1
- }
- if s > 2 {
- return errors.New("没有权限")
- }
- err := db.UpdateModel(db.Type(model), tableID, map[string]interface{}{
- "state": s,
- })
- if err != nil {
- return errors.New("没有权限")
- }
- if s == -1 {
- tableid, err := db.InsertModel(db.Type(DispatchSiteTable{}), map[string]interface{}{
- "type_id": model.TypeId,
- "site_id": model.SiteId,
- "worker_id": model.WorkerId,
- "budget": model.Budget,
- "state": 0,
- })
- if err == nil {
- items, _ := db.GetModelMap(db.Type(DispatchTypeItem{}), map[string]interface{}{"type_id": model.TypeId}, nil)
- if items != nil {
- for _, v := range items {
- db.InsertModel(db.Type(DispatchSiteItem{}), map[string]interface{}{
- "table_id": tableid,
- "name": v["name"],
- "unit": v["unit"],
- "price": v["price"],
- "num": 0,
- })
- }
- }
- }
- }
- } else if collectID != 0 {
- var model DispatchSiteCollect
- db.GetModel(map[string]interface{}{
- "id": collectID,
- }, &model)
- if model.ID == 0 || model.State != typ {
- return errors.New("没有权限")
- }
- if state != 0 {
- return errors.New("没有权限")
- }
- s := model.State + 1
- err := db.UpdateModel(db.Type(model), collectID, map[string]interface{}{
- "state": s,
- })
- if err != nil {
- return errors.New("没有权限")
- }
- err = db.UpdateModels(db.Type(DispatchSiteTable{}), map[string]interface{}{
- "collect_id": collectID,
- }, map[string]interface{}{
- "state": s,
- })
- if err != nil {
- return errors.New("没有权限")
- }
- } else {
- return errors.New("没有权限")
- }
- return nil
- }
- func (DispatchSiteProcess) Page() bool {
- return false
- }
- func (model DispatchSiteProcess) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
- return []db.JoinModel{
- {
- Model: JoinAdmin{},
- As: "created",
- On: []string{"`created`.`id` = " + model.TableName() + ".`created_id`"},
- },
- }
- }
|