package dispatch import ( "errors" "fmt" "zhiyuan/pkg/db" "github.com/gin-gonic/gin" "github.com/xuri/excelize/v2" ) type DispatchSiteTable struct { ID int64 `json:"id" prop:"add:false"` TypeId int64 `json:"type_id" label:"类型" type:"int" prop:"add edit" search:"="` SiteId int64 `json:"site_id" label:"工地" type:"int" prop:"add edit" search:"="` CollectId int64 `json:"collect_id" label:"汇总ID" type:"int" prop:"add:false" search:"="` WorkerId int64 `json:"worker_id" label:"工人" type:"int" prop:"add:false" search:"="` Budget float64 `json:"budget" label:"预算" type:"float" prop:"edit" default:"0"` Image string `json:"image" label:"图片" type:"string" prop:"edit" default:""` State int64 `json:"state" label:"状态" type:"int" prop:"add:false" default:"0" search:"="` Tip int64 `json:"tip" label:"标记" type:"int" prop:"add:false edit" default:"0"` WorkerName string `json:"worker_name" label:"工人姓名" prop:"add:false select:worker.name"` WorkerPhone string `json:"worker_phone" label:"工人电话" prop:"add:false select:worker.phone"` BankName string `json:"bank_name" label:"开户行" prop:"add:false select:worker.bank_name"` BankCardNo string `json:"bank_card_no" label:"银行卡号" prop:"add:false select:worker.bank_card_no"` 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 (DispatchSiteTable) TableName() string { return "zy_dispatch_site_table" } func (model DispatchSiteTable) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (DispatchSiteTable) OnePrivilege(c *gin.Context, id int64) bool { return true } func (DispatchSiteTable) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { typ, _ := db.ToInt64(data["type_id"]) site_id, _ := db.ToInt64(data["site_id"]) table, _ := db.GetModelMap(db.Type(DispatchSiteTable{}), map[string]interface{}{"type_id": typ, "site_id": site_id, "deleted_at": 0}, nil) if table != nil { return errors.New("没有权限") } return nil } func (DispatchSiteTable) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) { typ, _ := db.ToInt64(data["type_id"]) items, _ := db.GetModelMap(db.Type(DispatchTypeItem{}), map[string]interface{}{"type_id": typ}, nil) if items == nil { return } for _, v := range items { db.InsertModel(db.Type(DispatchSiteItem{}), map[string]interface{}{ "table_id": id, "name": v["name"], "unit": v["unit"], "price": v["price"], "num": 0, }) } } func (DispatchSiteTable) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (DispatchSiteTable) DelPrivilege(c *gin.Context, id int64) error { return nil } func (DispatchSiteTable) Page() bool { return false } func (DispatchSiteTable) Count() bool { return true } type JoinWorker struct { db.BaseModel } func (JoinWorker) TableName() string { return "zy_worker" } func (model DispatchSiteTable) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{{ Model: JoinWorker{}, As: "worker", On: []string{"`worker`.`id` = " + model.TableName() + ".`worker_id`"}, }} } type DispatchSiteTableMobile struct { Username string `json:"username" label:"业主姓名" prop:"select:dispatchsite.username" search:"like"` Phone string `json:"phone" label:"手机号码" prop:"select:dispatchsite.phone" search:"like"` Village string `json:"village" label:"小区名称" prop:"select:dispatchsite.village" search:"like"` Address string `json:"address" label:"房屋地址" prop:"select:dispatchsite.address" search:"like"` RoomNo string `json:"room_no" label:"楼栋房号" prop:"select:dispatchsite.room_no" search:"like"` Area string `json:"area" label:"面积" prop:"select:dispatchsite.area"` ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"select:dispatchsite.shop_id" search:"="` ShopName int64 `json:"shop_name" label:"门店" prop:"select:shop.shop_name"` Name string `json:"name" label:"类别名称" prop:"select:dispatchtype.name"` WorkTypeId int64 `json:"work_type_id" label:"工种" prop:"select:dispatchtype.work_type_id"` WorkTypeName string `json:"work_type_name" label:"工种名称" prop:"select:worktype.name"` WorkIdcode string `json:"work_idcode" label:"工人身份证号码" prop:"select:worker.idcode"` Total float64 `json:"total" label:"合计" prop:"select:ROUND(sum(dispatchsiteitem.price*num))"` Remark string `json:"remark" label:"备注" prop:"select:GROUP_CONCAT(dispatchsiteitem.remark)"` DispatchSiteTable } func (model DispatchSiteTableMobile) GroupBy() string { return fmt.Sprintf("`%s`.`id`", model.TableName()) } type JoinWorkType struct { db.BaseModel } func (JoinWorkType) TableName() string { return "zy_work_type" } func (model DispatchSiteTableMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return append(model.DispatchSiteTable.LeftJoin(data, s), db.JoinModel{ Model: DispatchType{}, As: "dispatchtype", On: []string{"`dispatchtype`.`id` = " + model.TableName() + ".`type_id`"}, }, db.JoinModel{ Model: JoinWorkType{}, As: "worktype", On: []string{"`worktype`.`id` = `dispatchtype`.`work_type_id`"}, }, db.JoinModel{ Model: DispatchSiteItem{}, As: "dispatchsiteitem", On: []string{"`dispatchsiteitem`.`table_id` = " + model.TableName() + ".`id`"}, }, db.JoinModel{ Model: DispatchSite{}, As: "dispatchsite", On: []string{"`dispatchsite`.`id` = " + model.TableName() + ".`site_id`"}, }, db.JoinModel{ Model: JoinShop{}, As: "shop", On: []string{"`shop`.`id` = `dispatchsite`.`shop_id`"}, }) } func (DispatchSiteTableMobile) Export(model db.Model, data []map[string]interface{}, file *excelize.File) [][]string { rows := make([][]string, 0) states := []string{"未提交", "工程队长审核", "预审审核", "店长审核", "财务审核", "已完成"} header := []string{"ID", "门店", "工地", "类型", "工人姓名", "开户行", "银行卡号", "金额", "身份证号码", "备注", "状态"} rows = append(rows, header) for _, v := range data { worksite := /*db.ToString(v["address"]) + " " +*/ db.ToString(v["village"]) + "" + db.ToString(v["room_no"]) /*if db.ToString(v["area"]) != "" { worksite += " " + db.ToString(v["area"]) }*/ worker := "" if worker_id, ok := db.ToInt64(v["worker_id"]); ok && worker_id != 0 { worker = db.ToString(v["worker_name"]) /*+ " " + db.ToString(v["worker_phone"])*/ } state := int64(0) if t, ok := db.ToInt64(v["state"]); ok { state = t } row := []string{ db.ToString(v["id"]), db.ToString(v["shop_name"]), worksite, db.ToString(v["name"]), worker, db.ToString(v["bank_name"]), db.ToString(v["bank_card_no"]), db.ToString(v["total"]), db.ToString(v["work_idcode"]), db.ToString(v["remark"]), states[state], } rows = append(rows, row) } return rows } type DispatchSiteTableCollect struct { ManagerName string `json:"manager_name" prop:"select:manager.username"` ManagerPhone string `json:"manager_phone" prop:"select:manager.phone"` ProjectLeaderName string `json:"projectleader_name" prop:"select:projectleader.username"` ProjectLeaderPhone string `json:"projectleader_phone" prop:"select:projectleader.phone"` DispatchSiteTableMobile } func (model DispatchSiteTableCollect) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { if shopId, _ := db.ToInt64(data["shop_id"]); shopId == 0 { s.Where = append(s.Where, "(1!=1)") } return true } func (DispatchSiteTableCollect) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (DispatchSiteTableCollect) DelPrivilege(c *gin.Context, id int64) error { return errors.New("没有权限") } func (model DispatchSiteTableCollect) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return append(model.DispatchSiteTableMobile.LeftJoin(data, s), db.JoinModel{ Model: JoinAdmin{}, As: "manager", On: []string{"`manager`.`id` = `dispatchsite`.`manager_id`"}, }, db.JoinModel{ Model: JoinAdmin{}, As: "projectleader", On: []string{"`projectleader`.`id` = `dispatchsite`.`project_leader_id`"}, }, ) }