1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399 |
- package aftersale
- import (
- "fmt"
- "strings"
- "time"
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/config"
- "zhiyuan/pkg/db"
- "zhiyuan/pkg/param"
- orderParam "zhiyuan/pkg/param/order"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/admin"
- "zhiyuan/services/aftersale"
- "zhiyuan/services/aftersale/order"
- "zhiyuan/services/form"
- "zhiyuan/services/material/brand"
- "zhiyuan/services/region"
- "zhiyuan/services/user"
- "github.com/gin-gonic/gin"
- "github.com/tealeg/xlsx/v3"
- )
- func OrderAdd(c *gin.Context) {
- var form form.OrderAdd
- if app.Bind(c, &form) != nil {
- return
- }
- form.Typ = 2
- id, err := order.Add(form)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{"id": id})
- }
- func OrderEventList(c *gin.Context) {
- page := app.HandlePageNum(c)
- params := make(map[string]interface{})
- where := map[string]string{
- "where": "o.deleted_at=0 AND e.event_type=1",
- "_order_by": "id desc",
- }
- if page.PageSize != 0 {
- where["_page_size"] = utils.ToStr(page.PageSize)
- where["_page_num"] = utils.ToStr(page.PageNum)
- }
- // state
- state := utils.ToInt(c.Query("state"))
- if state != 0 {
- where["where"] += " AND e.order_state={{state}}"
- params["state"] = state
- }
- // created_date
- createdDate := c.QueryArray("created_date[]")
- if createdDate != nil && len(createdDate) == 2 {
- where["where"] += " AND e.created_at BETWEEN {{created_at_min}} AND {{created_at_max}}"
- params["created_at_min"] = utils.DateParseUnix(createdDate[0], "Y-m-d")
- params["created_at_max"] = utils.DateParseUnix(createdDate[1], "Y-m-d") + 86399
- }
- // site_id
- if adminInfo := admin.GetAdminCache(c.GetInt("adminID")); adminInfo.SiteID > 0 {
- where["where"] += " AND (site_id={{site_id}} or site_id=0)"
- params["site_id"] = adminInfo.SiteID
- }
- total, err := order.GetCountJoinOrder(where["where"], params)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- type Auth struct {
- Revoke bool `json:"revoke"`
- Check bool `json:"check"`
- Allot bool `json:"allot"`
- ReAllot bool `json:"re_allot"`
- }
- type OrderList struct {
- ID int `json:"id"`
- OrderNo string `json:"order_no"`
- LinkName string `json:"link_name"`
- LinkPhone string `json:"link_phone"`
- Content string `json:"content"`
- State int `json:"state"`
- StateName string `json:"state_name"`
- StateColor string `json:"state_color"`
- Title string `json:"title"`
- InWarranty string `json:"in_warranty"`
- Auth Auth `json:"auth"`
- Leader int `json:"leader"`
- CreatedAt string `json:"created_at"`
- }
- orderList := make([]OrderList, 0)
- err = order.GetListJoinOrder(where, params, &orderList)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- orderStateList := utils.ParseSliceMap(orderParam.Params.State, "id")
- for k, v := range orderList {
- v.StateName = utils.ToStr(orderStateList[utils.ToStr(v.State)]["name"])
- v.StateColor = utils.ToStr(orderStateList[utils.ToStr(v.State)]["color"])
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm")
- v.Auth = Auth{
- Check: utils.IsContain(orderParam.Allow.Check, v.State),
- Revoke: utils.IsContain(orderParam.Allow.Revoke, v.State),
- ReAllot: utils.IsContain(orderParam.Allow.ReAllot, v.State),
- Allot: utils.IsContain(orderParam.Allow.Allot, v.State),
- }
- if v.InWarranty == "0" {
- v.InWarranty = "否"
- } else {
- v.InWarranty = "是"
- }
- orderList[k] = v
- }
- data := gin.H{
- "list": orderList,
- "total": total,
- "limit": page.PageSize,
- }
- app.Success(c, data)
- }
- func OrderList(c *gin.Context) {
- page := app.HandlePageNum(c)
- params := make(map[string]interface{})
- where := map[string]string{
- "where": "deleted_at=0",
- "_order_by": "id desc",
- }
- if page.PageSize != 0 {
- where["_page_size"] = utils.ToStr(page.PageSize)
- where["_page_num"] = utils.ToStr(page.PageNum)
- }
- // leader
- leaderID := utils.ToInt(c.Query("leader_id"))
- if leaderID > 0 {
- where["where"] += " AND leader={{leader_id}}"
- params["leader_id"] = leaderID
- }
- // state
- state := utils.ToInt(c.Query("state"))
- if state != 0 {
- where["where"] += " AND if(state=90,90,if(is_force=0,state,100))={{state}}"
- params["state"] = state
- }
- // is_force
- isForce := utils.ToInt(c.Query("is_force"))
- if isForce != 0 {
- if isForce == 2 {
- where["where"] += " AND is_force!=0"
- } else {
- where["where"] += " AND is_force={{isForce}}"
- params["isForce"] = isForce - 1
- }
- }
- // type
- typ := utils.ToInt(c.Query("type"))
- if typ != 0 {
- where["where"] += " AND type={{type}}"
- params["type"] = typ - 1
- }
- // address
- address := c.Query("address")
- if address != "" {
- where["where"] += " AND address LIKE {{address}}"
- params["address"] = "%" + address + "%"
- }
- // inWarranty
- inWarranty := utils.ToInt(c.Query("in_warranty"))
- if utils.IsContain([]int{0, 1}, inWarranty) {
- where["where"] += " AND in_warranty={{in_warranty}}"
- params["in_warranty"] = inWarranty
- }
- // user
- user := c.Query("user")
- if user != "" {
- where["where"] += " AND (link_name LIKE {{user}} OR link_phone LIKE {{user}})"
- params["user"] = "%" + user + "%"
- }
- // site_id
- if adminInfo := admin.GetAdminCache(c.GetInt("adminID")); adminInfo.SiteID > 0 {
- where["where"] += " AND (site_id={{site_id}} or site_id=0)"
- params["site_id"] = adminInfo.SiteID
- }
- // state
- finish_state := utils.ToInt(c.Query("finish_state"))
- if finish_state != 0 {
- switch finish_state {
- case 1:
- where["where"] += " AND (o.finish_state=1)"
- break
- case 2:
- where["where"] += " AND (o.finish_state=2)"
- break
- case 3:
- where["where"] += " AND (o.finish_state=1 AND UNIX_TIMESTAMP()<=o.end_time)"
- break
- case 4:
- where["where"] += " AND (o.finish_state=1 AND UNIX_TIMESTAMP()>o.end_time)"
- break
- case 5:
- where["_order_by"] = "o.incomplete_count desc"
- break
- }
- }
- createdDate := c.QueryArray("created_date[]")
- if createdDate != nil && len(createdDate) == 2 {
- where["where"] += " AND o.created_at BETWEEN {{created_at_min}} AND {{created_at_max}}"
- params["created_at_min"] = utils.DateParseUnix(createdDate[0], "Y-m-d")
- params["created_at_max"] = utils.DateParseUnix(createdDate[1], "Y-m-d") + 86399
- }
- total, err := order.GetCountWidthDetail(where["where"], params)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- type Auth struct {
- Revoke bool `json:"revoke"`
- Check bool `json:"check"`
- Allot bool `json:"allot"`
- ReAllot bool `json:"re_allot"`
- ForceComplete bool `json:"force_complete"`
- }
- // 回访信息
- type Visit struct {
- OrderID int `json:"order_id"`
- Content string `json:"content"`
- FinishedAt string `json:"finished_at"`
- }
- type OrderList struct {
- ID int `json:"id"`
- OrderNo string `json:"order_no"`
- LinkName string `json:"link_name"`
- LinkPhone string `json:"link_phone"`
- Content string `json:"content"`
- State int `json:"state"`
- CState int `json:"cstate"`
- StateName string `json:"state_name"`
- StateColor string `json:"state_color"`
- InWarranty int `json:"in_warranty"`
- Remarks string `json:"remarks"`
- WarrantyStart string `json:"warranty_start"`
- WarrantyEnd string `json:"warranty_end"`
- WarrantyPeriod string `json:"warranty_period"`
- VisitList []*Visit `json:"visit_list"`
- Address string `json:"address"`
- IsIssue int `json:"is_issue"`
- IsForce int `json:"is_force"`
- Type int `json:"type"`
- Leader int `json:"leader"`
- LeaderName string `json:"leader_name"`
- Auth Auth `json:"auth"`
- CreatedAt string `json:"created_at"`
- MaintenanceRemark string `json:"maintenance_remark"`
- StartTime string `json:"start_time"`
- EndTime string `json:"end_time"`
- FinishTime string `json:"finish_time"`
- IncompleteCount int `json:"incomplete_count"`
- FinishState int `json:"finish_state"`
- RepairTimeout int `json:"repair_timeout"`
- }
- orderList := make([]OrderList, 0)
- err = order.GetListWidthDetail(where, params, &orderList)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- orderIds := make([]int, 0)
- adminIds := make([]int, 0)
- for _, v := range orderList {
- orderIds = append(orderIds, v.ID)
- if v.Leader > 0 {
- adminIds = append(adminIds, v.Leader)
- }
- }
- adminMap := make(map[int]string, 0)
- if len(adminIds) > 0 {
- adminList, err := admin.GetAdmins(map[string]interface{}{"id in": adminIds}, []string{"id, username"}, app.Page{}, nil)
- if err == nil {
- for _, v := range adminList {
- adminMap[v.ID] = v.Username
- }
- }
- }
- visitList := make([]*Visit, 0)
- visitListMap := make(map[int][]*Visit, 0)
- if len(orderIds) > 0 {
- if _, err := order.GetVisits(map[string]interface{}{"order_id in": orderIds, "_orderby": "created_at desc", "deleted_at": 0, "state": 2}, nil, &visitList); err == nil {
- for _, v := range visitList {
- v.FinishedAt = utils.DateS(v.FinishedAt, "YYYY-MM-DD")
- visitListMap[v.OrderID] = append(visitListMap[v.OrderID], v)
- }
- }
- }
- orderStateList := utils.ParseSliceMap(orderParam.Params.State, "id")
- for k, v := range orderList {
- v.StateName = utils.ToStr(orderStateList[utils.ToStr(v.CState)]["name"])
- v.StateColor = utils.ToStr(orderStateList[utils.ToStr(v.CState)]["color"])
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm")
- v.StartTime = utils.DateS(v.StartTime, "YYYY-MM-DD HH:mm")
- v.EndTime = utils.DateS(v.EndTime, "YYYY-MM-DD HH:mm")
- v.FinishTime = utils.DateS(v.FinishTime, "YYYY-MM-DD HH:mm")
- v.Auth = Auth{
- Check: utils.IsContain(orderParam.Allow.Check, v.CState),
- Revoke: utils.IsContain(orderParam.Allow.Revoke, v.CState),
- Allot: utils.IsContain(orderParam.Allow.Allot, v.CState),
- ReAllot: utils.IsContain(orderParam.Allow.ReAllot, v.CState),
- ForceComplete: utils.IsContain(orderParam.Allow.ForceComplete, v.CState),
- }
- if visitListMap[v.ID] == nil {
- v.VisitList = make([]*Visit, 0)
- } else {
- v.VisitList = visitListMap[v.ID]
- }
- v.LeaderName = adminMap[v.Leader]
- if v.WarrantyStart != "0" {
- v.WarrantyPeriod = utils.DateS(v.WarrantyStart, "YYYY-MM-DD") + " 至 " + utils.DateS(v.WarrantyEnd, "YYYY-MM-DD")
- } else {
- v.WarrantyPeriod = ""
- }
- orderList[k] = v
- }
- data := gin.H{
- "list": orderList,
- "total": total,
- "limit": page.PageSize,
- }
- app.Success(c, data)
- }
- func OrderLists(c *gin.Context) {
- page := app.HandlePageNum(c)
- params := make(map[string]interface{})
- where := map[string]string{
- "where": "deleted_at=0",
- "_order_by": "id desc",
- }
- if page.PageSize != 0 {
- where["_page_size"] = utils.ToStr(page.PageSize)
- where["_page_num"] = utils.ToStr(page.PageNum)
- }
- // leader
- leaderID := utils.ToInt(c.Query("leader_id"))
- if leaderID > 0 {
- where["where"] += " AND leader={{leader_id}}"
- params["leader_id"] = leaderID
- }
- // state
- state := utils.ToInt(c.Query("state"))
- if state != 0 {
- where["where"] += " AND if(state=90,90,if(is_force=0,state,100))={{state}}"
- params["state"] = state
- }
- // is_force
- isForce := utils.ToInt(c.Query("is_force"))
- if isForce != 0 {
- if isForce == 2 {
- where["where"] += " AND is_force!=0"
- } else {
- where["where"] += " AND is_force={{isForce}}"
- params["isForce"] = isForce - 1
- }
- }
- // type
- typ := utils.ToInt(c.Query("type"))
- if typ != 0 {
- where["where"] += " AND type={{type}}"
- params["type"] = typ - 1
- }
- // address
- address := c.Query("address")
- if address != "" {
- where["where"] += " AND address LIKE {{address}}"
- params["address"] = "%" + address + "%"
- }
- // inWarranty
- inWarranty := utils.ToInt(c.Query("in_warranty"))
- if utils.IsContain([]int{0, 1}, inWarranty) {
- where["where"] += " AND in_warranty={{in_warranty}}"
- params["in_warranty"] = inWarranty
- }
- // user
- user := c.Query("user")
- if user != "" {
- where["where"] += " AND (link_name LIKE {{user}} OR link_phone LIKE {{user}})"
- params["user"] = "%" + user + "%"
- }
- createdDate := c.QueryArray("created_date[]")
- if createdDate != nil && len(createdDate) == 2 {
- where["where"] += " AND o.created_at BETWEEN {{created_at_min}} AND {{created_at_max}}"
- params["created_at_min"] = utils.DateParseUnix(createdDate[0], "Y-m-d")
- params["created_at_max"] = utils.DateParseUnix(createdDate[1], "Y-m-d") + 86399
- }
- total, err := order.GetCountWidthDetail(where["where"], params)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- type Auth struct {
- Revoke bool `json:"revoke"`
- Check bool `json:"check"`
- Allot bool `json:"allot"`
- ReAllot bool `json:"re_allot"`
- ForceComplete bool `json:"force_complete"`
- }
- // 回访信息
- type Visit struct {
- OrderID int `json:"order_id"`
- Content string `json:"content"`
- FinishedAt string `json:"finished_at"`
- }
- type Comment struct {
- ID int `json:"id"`
- OrderID int `json:"order_id"`
- UserID int `json:"user_id"`
- Star int `json:"star"`
- Content string `json:"content"`
- Tags string `json:"tags"`
- }
- type OrderList struct {
- ID int `json:"id"`
- OrderNo string `json:"order_no"`
- LinkName string `json:"link_name"`
- LinkPhone string `json:"link_phone"`
- Content string `json:"content"`
- State int `json:"state"`
- CState int `json:"cstate"`
- StateName string `json:"state_name"`
- StateColor string `json:"state_color"`
- InWarranty int `json:"in_warranty"`
- Remarks string `json:"remarks"`
- WarrantyStart string `json:"warranty_start"`
- WarrantyEnd string `json:"warranty_end"`
- WarrantyPeriod string `json:"warranty_period"`
- VisitList []*Visit `json:"visit_list"`
- Address string `json:"address"`
- IsIssue int `json:"is_issue"`
- IsForce int `json:"is_force"`
- Type int `json:"type"`
- Leader int `json:"leader"`
- LeaderName string `json:"leader_name"`
- Auth Auth `json:"auth"`
- CreatedAt string `json:"created_at"`
- Comment *Comment `json:"comment"`
- }
- orderList := make([]OrderList, 0)
- err = order.GetListWidthDetail(where, params, &orderList)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- orderIds := make([]int, 0)
- adminIds := make([]int, 0)
- for _, v := range orderList {
- orderIds = append(orderIds, v.ID)
- if v.Leader > 0 {
- adminIds = append(adminIds, v.Leader)
- }
- }
- adminMap := make(map[int]string, 0)
- if len(adminIds) > 0 {
- adminList, err := admin.GetAdmins(map[string]interface{}{"id in": adminIds}, []string{"id, username"}, app.Page{}, nil)
- if err == nil {
- for _, v := range adminList {
- adminMap[v.ID] = v.Username
- }
- }
- }
- visitList := make([]*Visit, 0)
- visitListMap := make(map[int][]*Visit, 0)
- if len(orderIds) > 0 {
- if _, err := order.GetVisits(map[string]interface{}{"order_id in": orderIds, "_orderby": "created_at desc", "deleted_at": 0, "state": 2}, nil, &visitList); err == nil {
- for _, v := range visitList {
- v.FinishedAt = utils.DateS(v.FinishedAt, "YYYY-MM-DD")
- visitListMap[v.OrderID] = append(visitListMap[v.OrderID], v)
- }
- }
- }
- commentList := make([]Comment, 0)
- commentListMap := make(map[int]Comment, 0)
- if len(orderIds) > 0 {
- if _, err := order.GetComment(map[string]interface{}{"order_id in": orderIds}, nil, &commentList); err == nil {
- for _, v := range commentList {
- commentListMap[v.OrderID] = v
- }
- }
- }
- orderStateList := utils.ParseSliceMap(orderParam.Params.State, "id")
- for k, v := range orderList {
- v.StateName = utils.ToStr(orderStateList[utils.ToStr(v.CState)]["name"])
- v.StateColor = utils.ToStr(orderStateList[utils.ToStr(v.CState)]["color"])
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm")
- v.Auth = Auth{
- Check: utils.IsContain(orderParam.Allow.Check, v.CState),
- Revoke: utils.IsContain(orderParam.Allow.Revoke, v.CState),
- Allot: utils.IsContain(orderParam.Allow.Allot, v.CState),
- ReAllot: utils.IsContain(orderParam.Allow.ReAllot, v.CState),
- ForceComplete: utils.IsContain(orderParam.Allow.ForceComplete, v.CState),
- }
- if visitListMap[v.ID] == nil {
- v.VisitList = make([]*Visit, 0)
- } else {
- v.VisitList = visitListMap[v.ID]
- }
- if comment, ok := commentListMap[v.ID]; ok {
- v.Comment = &comment
- }
- v.LeaderName = adminMap[v.Leader]
- if v.WarrantyStart != "0" {
- v.WarrantyPeriod = utils.DateS(v.WarrantyStart, "YYYY-MM-DD") + " 至 " + utils.DateS(v.WarrantyEnd, "YYYY-MM-DD")
- } else {
- v.WarrantyPeriod = ""
- }
- orderList[k] = v
- }
- data := gin.H{
- "list": orderList,
- "total": total,
- "limit": page.PageSize,
- }
- app.Success(c, data)
- }
- func OrderCheck(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.ErrorMsg(c, "无效的订单ID", nil)
- return
- }
- var form = form.OrderCheck{
- Servicer: c.GetInt("adminID"),
- }
- if err := order.Check(form, id); err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
- func OrderRemark(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.ErrorMsg(c, "无效的订单ID", nil)
- return
- }
- var form form.OrderRemark
- if app.Bind(c, &form) != nil {
- return
- }
- if err := order.Remark(form, id); err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
- func OrderAllot(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.ErrorMsg(c, "无效的订单ID", nil)
- return
- }
- var form form.OrderAllot
- if app.Bind(c, &form) != nil {
- return
- }
- form.Servicer = c.GetInt("adminID")
- if err := order.Allot(form, id); err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
- func OrderInfo(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "工单 id 有误")
- return
- }
- type OrderInfo struct {
- ID int `json:"id"`
- OrderNo string `json:"order_no"`
- MainType int `json:"main_type"`
- SubType int `json:"sub_type"`
- Type string `json:"type"`
- LinkName string `json:"link_name"`
- LinkPhone string `json:"link_phone"`
- Province int `json:"province"`
- City int `json:"city"`
- Region int `json:"region"`
- Address string `json:"address"`
- Content string `json:"content"`
- Pics string `json:"pics"`
- PicList []string `json:"pic_list"`
- State int `json:"state"`
- StateName string `json:"state_name"`
- RepairID int `json:"repair_id"`
- InWarranty int `json:"in_warranty"`
- StateColor string `json:"state_color"`
- CreatedAt string `json:"created_at"`
- ScheduleTime string `json:"schedule_time"`
- }
- var orderInfo OrderInfo
- err := order.GetOneWithDetail("o.id={{id}}", map[string]interface{}{"id": id}, &orderInfo)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- orderTypeMap := aftersale.GetTypeMapByCache()
- orderStatusList := utils.ParseSliceMap(orderParam.Params.State, "id")
- orderInfo.PicList = utils.ParseImgStr(orderInfo.Pics)
- orderInfo.Address = region.GetFullAddressByCodes(orderInfo.Province, orderInfo.City, orderInfo.Region, orderInfo.Address, "", nil)
- orderInfo.StateName = utils.ToStr(orderStatusList[utils.ToStr(orderInfo.State)]["name"])
- orderInfo.StateColor = utils.ToStr(orderStatusList[utils.ToStr(orderInfo.State)]["color"])
- orderInfo.CreatedAt = utils.DateS(orderInfo.CreatedAt, "YYYY-MM-DD")
- orderInfo.Type = orderTypeMap[orderInfo.MainType] + "/" + orderTypeMap[orderInfo.SubType]
- type OrderEvent struct {
- Title string `json:"title"`
- Content string `json:"content"`
- Pics string `json:"pics"`
- PicList []string `json:"pic_list"`
- CreatedAt string `json:"created_at"`
- }
- eventList := make([]*OrderEvent, 0)
- _, err = order.GetEventList(map[string]interface{}{"order_id": id, "_orderby": "created_at desc", "event_type": 1}, nil, &eventList)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- for k, v := range eventList {
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD hh:mm")
- v.PicList = utils.ParseImgStr(v.Pics)
- eventList[k] = v
- }
- // repair
- type Repair struct {
- ID int `json:"id"`
- WorkerName string `json:"worker_name"`
- WorkerPhone string `json:"worker_phone"`
- ScheduleTime string `json:"schedule_time"`
- FinishedAt string `json:"finished_at"`
- Content string `json:"content"`
- Duration float64 `json:"duration"`
- Pics string `json:"pics"`
- PicList []string `json:"pic_list"`
- State int `json:"state"`
- StateName string `json:"state_name"`
- CreatedAt string `json:"created_at"`
- AuditType int `json:"audit_type"`
- AuditState int `json:"audit_state"`
- AuditAt int `json:"audit_at"`
- }
- repairList := make([]*Repair, 0)
- if _, err = order.GetRepairList(map[string]interface{}{"order_id": id, "_orderby": "created_at desc"}, nil, &repairList); err != nil {
- app.Error(c, err.Error())
- return
- }
- repairStatusList := utils.ParseSliceMap(orderParam.Params.RepairState, "id")
- for _, v := range repairList {
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD hh:mm")
- v.ScheduleTime = utils.DateS(v.ScheduleTime, "YYYY-MM-DD hh:mm")
- v.FinishedAt = utils.DateS(v.FinishedAt, "YYYY-MM-DD hh:mm")
- v.PicList = utils.ParseImgStr(v.Pics)
- v.StateName = utils.ToStr(repairStatusList[utils.ToStr(v.State)]["name"])
- }
- // 回访信息
- type Visit struct {
- ID int `json:"id"`
- OrderID int `json:"order_id"`
- State int `json:"state"`
- StateName string `json:"state_name"`
- VisitTime string `json:"visit_time"`
- Content string `json:"content"`
- FinishedAt string `json:"finished_at"`
- }
- visitList := make([]*Visit, 0)
- if _, err := order.GetVisits(map[string]interface{}{"order_id": id, "state": 2, "_orderby": "created_at desc", "deleted_at": 0}, nil, &visitList); err != nil {
- app.Error(c, err.Error())
- }
- for _, v := range visitList {
- v.FinishedAt = utils.DateS(v.FinishedAt, "YYYY-MM-DD")
- }
- // 完结信息
- type Issue struct {
- ID int `json:"id"`
- Director int `json:"director"`
- DirectorName string `json:"director_name"`
- IssueID int `json:"issue_id"`
- IssueName string `json:"issue_name"`
- IssueDesc string `json:"issue_desc"`
- Brand int `json:"brand"`
- BrandName string `json:"brand_name"`
- CreatedAt string `json:"created_at"`
- }
- issueList := make([]*Issue, 0)
- if _, err := order.GetIssues(map[string]interface{}{"order_id": id, "_orderby": "created_at desc"}, nil, &issueList); err != nil {
- app.Error(c, err.Error())
- }
- issueMap := aftersale.GetIssueMapByCache()
- directorList := utils.ParseSliceMap(orderParam.Params.IssueDirector, "id")
- brandIds := make([]int, 0)
- for _, v := range issueList {
- brandIds = utils.AppendUniqueInt(brandIds, v.Brand)
- }
- brandMap := make(map[int]string)
- if len(brandIds) > 0 {
- if brandList, err := brand.GetList(map[string]interface{}{"id in": brandIds}, nil, app.Page{}, nil); err == nil {
- for _, v := range brandList {
- brandMap[v.ID] = v.BrandName
- }
- }
- }
- for _, v := range issueList {
- if issueName, ok := issueMap[v.IssueID]; ok {
- v.IssueName = issueName
- }
- v.DirectorName = utils.ToStr(directorList[utils.ToStr(v.Director)]["name"])
- if brandName, ok := brandMap[v.Brand]; ok {
- v.BrandName = brandName
- }
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD")
- }
- res := gin.H{
- "info": orderInfo,
- "event": eventList,
- "repair": repairList,
- "visit": visitList,
- "issue": issueList,
- }
- type Comment struct {
- ID int `json:"id"`
- OrderID int `json:"order_id"`
- UserID int `json:"user_id"`
- Star int `json:"star"`
- Content string `json:"content"`
- Tags string `json:"tags"`
- }
- var comment Comment
- if _, err := order.GetComment(map[string]interface{}{"order_id": id}, nil, &comment); err != nil {
- app.Error(c, err.Error())
- }
- if comment.ID != 0 {
- res["comment"] = comment
- }
- app.Success(c, res)
- }
- func OrderDel(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "工单 id 有误")
- return
- }
- err := order.Del(id)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
- func OrderAddIssue(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "工单 id 有误")
- return
- }
- var form form.OrderIssue
- if app.Bind(c, &form) != nil {
- return
- }
- err := order.Issue(form, id)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
- func OrderComplete(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "工单 id 有误")
- return
- }
- var form form.OrderComplete
- if app.Bind(c, &form) != nil {
- return
- }
- form.Servicer = c.GetInt("adminID")
- form.IsForce = utils.ToInt(c.Query("is_force"))
- //if isForce := utils.ToInt(c.Query("is_force")); isForce == 1 {
- // form.IsForce = 1
- //}
- err := order.Complete(form, id)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
- func OrderExport(c *gin.Context) {
- params := make(map[string]interface{})
- where := map[string]string{
- "where": "deleted_at=0",
- "_order_by": "id desc",
- }
- // leader
- leaderID := utils.ToInt(c.Query("leader_id"))
- if leaderID > 0 {
- where["where"] += " AND leader={{leader_id}}"
- params["leader_id"] = leaderID
- }
- // state
- state := utils.ToInt(c.Query("state"))
- if state != 0 {
- where["where"] += " AND if(state=90,90,if(is_force=0,state,100))={{state}}"
- params["state"] = state
- }
- // is_force
- isForce := utils.ToInt(c.Query("is_force"))
- if isForce != 0 {
- if isForce == 2 {
- where["where"] += " AND is_force!=0"
- } else {
- where["where"] += " AND is_force={{isForce}}"
- params["isForce"] = isForce - 1
- }
- }
- // type
- typ := utils.ToInt(c.Query("type"))
- if typ != 0 {
- where["where"] += " AND type={{type}}"
- params["type"] = typ - 1
- }
- // address
- address := c.Query("address")
- if address != "" {
- where["where"] += " AND address LIKE {{address}}"
- params["address"] = "%" + address + "%"
- }
- // inWarranty
- inWarranty := utils.ToInt(c.Query("in_warranty"))
- if utils.IsContain([]int{0, 1}, inWarranty) {
- where["where"] += " AND in_warranty={{in_warranty}}"
- params["in_warranty"] = inWarranty
- }
- // user
- user1 := c.Query("user")
- if user1 != "" {
- where["where"] += " AND (link_name LIKE {{user}} OR link_phone LIKE {{user}})"
- params["user"] = "%" + user1 + "%"
- }
- // state
- finish_state := utils.ToInt(c.Query("finish_state"))
- if finish_state != 0 {
- switch finish_state {
- case 1:
- where["where"] += " AND (o.finish_state=1)"
- break
- case 2:
- where["where"] += " AND (o.finish_state=2)"
- break
- case 3:
- where["where"] += " AND (o.finish_state=1 AND UNIX_TIMESTAMP()<=o.end_time)"
- break
- case 4:
- where["where"] += " AND (o.finish_state=1 AND UNIX_TIMESTAMP()>o.end_time)"
- break
- case 5:
- where["_order_by"] = "o.incomplete_count desc"
- break
- }
- }
- createdDate := c.QueryArray("created_date[]")
- if createdDate != nil && len(createdDate) == 2 {
- where["where"] += " AND o.created_at BETWEEN {{created_at_min}} AND {{created_at_max}}"
- params["created_at_min"] = utils.DateParseUnix(createdDate[0], "Y-m-d")
- params["created_at_max"] = utils.DateParseUnix(createdDate[1], "Y-m-d") + 86399
- }
- if adminInfo := admin.GetAdminCache(c.GetInt("adminID")); adminInfo.SiteID > 0 {
- where["where"] += " AND site_id = {{site_id}}"
- params["site_id"] = adminInfo.SiteID
- }
- type House struct {
- ID int `json:"id"`
- Address string `json:"address"`
- Designer int `json:"designer"`
- DesignerName string `json:"designer_name"`
- District int `json:"district"`
- DistrictName string `json:"district_name"`
- Supervisor int `json:"supervisor"`
- SupervisorName string `json:"supervisor_name"`
- ProjectManager int `json:"project_manager"`
- ProjectManagerName string `json:"project_manager_name"`
- ProjectLeader int `json:"project_leader"`
- ProjectLeaderName string `json:"project_leader_name"`
- ProjectStart string `json:"project_start"`
- ProjectEnd string `json:"project_end"`
- }
- type Visit struct {
- OrderID int `json:"order_id"`
- Content string `json:"content"`
- FinishedAt string `json:"finished_at"`
- }
- type Detail struct {
- OrderID int `json:"order_id"`
- Address string `json:"address"`
- Content string `json:"content"`
- }
- type Issue struct {
- OrderID int `json:"order_id"`
- IssueDesc string `json:"issue_desc"`
- Director int `json:"director"`
- }
- type Repair struct {
- OrderID int `json:"order_id"`
- WorkerName string `json:"worker_name"`
- }
- type Orders struct {
- ID int `json:"id"`
- CreatedAt string `json:"created_at"`
- LinkName string `json:"link_name"`
- LinkPhone string `json:"link_phone"`
- UserID int `json:"user_id"`
- InWarranty int `json:"in_warranty"`
- Leader int `json:"leader"`
- LeaderName string `json:"leader_name"`
- HouseID int `json:"house_id"`
- House *House `json:"house"`
- Repair *Repair `json:"repair"`
- Issue *Issue `json:"issue"`
- Detail *Detail `json:"detial"`
- Visit string `json:"visit"`
- }
- orderList := make([]*Orders, 0)
- err := order.GetLists(where, params, app.Page{}, &orderList)
- houseIds := make([]int, 0)
- orderIds := make([]int, 0)
- userIds := make([]int, 0)
- adminIds := make([]int, 0)
- for _, v := range orderList {
- houseIds = append(houseIds, v.HouseID)
- orderIds = append(orderIds, v.ID)
- userIds = append(userIds, v.UserID)
- adminIds = append(adminIds, v.Leader)
- }
- houseMap := make(map[int]*House, 0)
- if len(houseIds) > 0 {
- houseList := make([]*House, 0)
- user.GetHouseList(map[string]interface{}{"id in": houseIds}, nil, app.Page{}, &houseList)
- for _, v := range houseList {
- adminIds = append(adminIds, v.Designer, v.Supervisor, v.ProjectManager, v.ProjectLeader)
- houseMap[v.ID] = v
- }
- }
- userMap := make(map[int]string, 0)
- if len(userIds) > 0 {
- userList, _ := user.GetList(map[string]interface{}{"id in": userIds}, nil, app.Page{}, nil)
- for _, v := range userList {
- userMap[v.ID] = v.Name
- }
- }
- type AdminInfo struct {
- Username string `json:"username"`
- State int `json:"state"`
- }
- adminMap := make(map[int]AdminInfo, 0)
- if len(adminIds) > 0 {
- adminList, _ := admin.GetAdmins(map[string]interface{}{"id in": adminIds}, nil, app.Page{}, nil)
- for _, v := range adminList {
- adminMap[v.ID] = AdminInfo{Username: v.Username, State: v.State}
- }
- }
- districtMap := make(map[int]string)
- for _, v := range param.Params.District {
- districtMap[v.ID] = v.Name
- }
- for k, v := range houseMap {
- if v.District > 0 {
- v.DistrictName = districtMap[v.District]
- }
- if v.Designer > 0 {
- v.DesignerName = adminMap[v.Designer].Username
- }
- if v.Supervisor > 0 {
- v.SupervisorName = adminMap[v.Supervisor].Username
- }
- if v.ProjectLeader > 0 {
- v.ProjectLeaderName = adminMap[v.ProjectLeader].Username
- }
- if v.ProjectManager > 0 {
- v.ProjectManagerName = adminMap[v.ProjectManager].Username
- }
- if v.Supervisor > 0 {
- if adminMap[v.Supervisor].State == -1 {
- v.SupervisorName = "离职项目经理"
- } else {
- v.SupervisorName = adminMap[v.Supervisor].Username
- }
- }
- houseMap[k] = v
- }
- detialMap := make(map[int]*Detail, 0)
- if len(orderIds) > 0 {
- detailList := make([]*Detail, 0)
- order.GetDetailList(map[string]interface{}{"order_id in": orderIds}, nil, app.Page{}, &detailList)
- for _, v := range detailList {
- detialMap[v.OrderID] = v
- }
- }
- issueMap := make(map[int]*Issue, 0)
- if len(orderIds) > 0 {
- issueList := make([]*Issue, 0)
- order.GetIssues(map[string]interface{}{"order_id in": orderIds}, nil, &issueList)
- for _, v := range issueList {
- issueMap[v.OrderID] = v
- }
- }
- issueDirectorMap := orderParam.GetIssueDirectorMap()
- visitList := make([]*Visit, 0)
- visitListMap := make(map[int][]string, 0)
- if len(orderIds) > 0 {
- if _, err := order.GetVisits(map[string]interface{}{"order_id in": orderIds, "_orderby": "created_at desc", "deleted_at": 0, "state": 2}, nil, &visitList); err == nil {
- for _, v := range visitList {
- visitListMap[v.OrderID] = append(visitListMap[v.OrderID], v.Content)
- }
- }
- }
- for _, v := range orderList {
- if v.Leader > 0 {
- v.LeaderName = adminMap[v.Leader].Username
- }
- if visitListMap[v.ID] != nil {
- v.Visit = strings.Join(visitListMap[v.ID], "\n")
- }
- v.House = houseMap[v.HouseID]
- }
- wb := xlsx.NewFile()
- filename := "售后维修表-" + db.ToString(time.Now().Unix()) + ".xlsx"
- fullPath := config.Cfg.App.ExportPath + filename
- styleBold := utils.GetCommonStyle(utils.StyleCfg{IsBold: true, FontSize: 10})
- styleCommon := utils.GetCommonStyle(utils.StyleCfg{FontSize: 9})
- sh, err := wb.AddSheet("Sheet1")
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- var row *xlsx.Row
- height := float64(30)
- row = utils.AddRow(sh, utils.Row{Height: height})
- utils.AddCell(row, utils.Cell{Value: "售后维修交接表", HMerge: 22, Style: styleBold})
- sh = utils.SetColWidth(sh, []float64{5, 5, 10, 10, 10, 10, 20, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 30, 15, 15, 15, 10, 10})
- row = utils.AddRow(sh, utils.Row{Height: height})
- utils.AddCell(row, utils.Cell{Value: "序号", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "级别", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "工地性质", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "开工日期", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "竣工", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "报修时间", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "工地名称", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "业主姓名", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "联系电话", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "设计师", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "区域", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "售后报修人", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "工程主管", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "队长", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "项目经理", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "指派项目经理", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "是否过保修", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "责任人", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "报修内容", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "反馈结果", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "客服回访情况", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "解决结果", Style: styleBold})
- utils.AddCell(row, utils.Cell{Value: "报销情况", Style: styleBold})
- for k, v := range orderList {
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY/MM/DD")
- if v.House.ProjectStart == "0" {
- v.House.ProjectStart = ""
- } else {
- v.House.ProjectStart = utils.DateS(v.House.ProjectStart, "YYYY/MM/DD")
- }
- if v.House.ProjectEnd == "0" {
- v.House.ProjectEnd = ""
- } else {
- v.House.ProjectEnd = utils.DateS(v.House.ProjectEnd, "YYYY/MM/DD")
- }
- row = utils.AddRow(sh, utils.Row{Height: height})
- utils.AddCell(row, utils.Cell{Value: utils.ToStr(k + 1), Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: "一级", Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: "全包", Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.House.ProjectStart, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.House.ProjectEnd, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.CreatedAt, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.House.Address, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.LinkName, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.LinkPhone, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.House.DesignerName, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.House.DistrictName, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: userMap[v.UserID], Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.House.ProjectManagerName, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.House.ProjectLeaderName, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.House.SupervisorName, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.LeaderName, Style: styleCommon})
- inWarranty := "是"
- if v.InWarranty > 0 {
- inWarranty = "否"
- }
- utils.AddCell(row, utils.Cell{Value: inWarranty, Style: styleCommon})
- issueDirectorName := ""
- issueDesc := ""
- if issue, ok := issueMap[v.ID]; ok {
- issueDirectorName = issueDirectorMap[issue.Director]
- issueDesc = issue.IssueDesc
- }
- utils.AddCell(row, utils.Cell{Value: issueDirectorName, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: detialMap[v.ID].Content, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: issueDesc, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: v.Visit, Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
- utils.AddCell(row, utils.Cell{Value: "", Style: styleCommon})
- }
- if err := wb.Save(fullPath); err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{"path": "export/" + filename, "filename": filename})
- }
- func OrderVisitStatist(c *gin.Context) {
- page := app.HandlePageNums(c)
- var s db.Select
- s.TableName = "`zy_as_order_visit`"
- s.Select = map[string]string{
- "date": "`zy_as_order_visit`.`visit_time`",
- "total": "COUNT(1)",
- "finished_visit": "COUNT(`zy_as_order_visit`.`state` = 2 OR NULL)",
- "ufinished_visit": "COUNT(`zy_as_order_visit`.`state` = 1 OR NULL)",
- "overtime_visit": "COUNT(`zy_as_order_visit`.`finished_at` > `zy_as_order_visit`.`visit_time` OR NULL)",
- }
- s.GroupBy = "`zy_as_order_visit`.`visit_time`"
- s.OrderBy = "`zy_as_order_visit`.`visit_time` DESC"
- if page.PageSize != 0 {
- s.Limit = int64(page.PageSize)
- s.Offset = int64(page.PageSize * (page.PageNum - 1))
- }
- date := utils.ToInt(c.Query("date"))
- if date != 0 {
- s.Where = append(s.Where, fmt.Sprintf("`zy_as_order_visit`.`visit_time` = %s", s.Param(date)))
- }
- startdate := utils.ToInt(c.Query("startdate"))
- if startdate != 0 {
- s.Where = append(s.Where, fmt.Sprintf("`zy_as_order_visit`.`visit_time` >= %s", s.Param(startdate)))
- }
- enddate := utils.ToInt(c.Query("enddate"))
- if enddate != 0 {
- s.Where = append(s.Where, fmt.Sprintf("`zy_as_order_visit`.`visit_time` <= %s", s.Param(enddate)))
- }
- s.Where = append(s.Where, fmt.Sprintf("`zy_as_order_visit`.`deleted_at` = %s", s.Param(0)))
- query, params := s.Query()
- list, err := db.QueryMap(query, params, nil)
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- if list == nil {
- list = make([]map[string]interface{}, 0)
- }
- count, err := db.GetCount(s, nil)
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, gin.H{
- "list": list,
- "count": count,
- })
- }
- func RepairCheckList(c *gin.Context) {
- page := app.HandlePageNum(c)
- where := map[string]string{
- "where": " o.deleted_at=0 and r.audit_type != 0",
- "_group_by": "r.id",
- "_order_by": "r.id desc",
- }
- param := make(map[string]interface{})
- if page.PageSize != 0 {
- where["_page_size"] = utils.ToStr(page.PageSize)
- where["_page_num"] = utils.ToStr(page.PageNum)
- }
- auditState := utils.ToInt(c.Query("audit_state"))
- if auditState > 0 {
- where["where"] = where["where"] + " AND r.audit_state = {{auditState}}"
- param["auditState"] = auditState - 1
- }
- auditType := utils.ToInt(c.Query("audit_type"))
- if auditType > 0 {
- where["where"] = where["where"] + " AND r.audit_type = {{auditType}}"
- param["auditType"] = auditType
- }
- keyword := c.Query("keyword")
- if keyword != "" {
- where["where"] = where["where"] + " AND (o.link_name like {{keyword}} or o.link_phone like {{keyword}})"
- param["keyword"] = "%" + keyword + "%"
- }
- // leader
- leaderID := utils.ToInt(c.Query("leader_id"))
- if leaderID > 0 {
- where["where"] += " AND leader={{leader_id}}"
- param["leader_id"] = leaderID
- }
- // address
- address := c.Query("address")
- if address != "" {
- where["where"] += " AND address LIKE {{address}}"
- param["address"] = "%" + address + "%"
- }
- createdDate := c.QueryArray("created_date[]")
- if createdDate != nil && len(createdDate) == 2 {
- where["where"] += " AND o.created_at BETWEEN {{created_at_min}} AND {{created_at_max}}"
- param["created_at_min"] = utils.DateParseUnix(createdDate[0], "Y-m-d")
- param["created_at_max"] = utils.DateParseUnix(createdDate[1], "Y-m-d") + 86399
- }
- total, err := order.GetCountWidthOrder(where["where"], param)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- type Admin struct {
- ID int `json:"id"`
- UserName string `json:"username"`
- Phone string `json:"phone"`
- }
- type RepairList struct {
- ID int `json:"id"`
- OrderId int `json:"order_id"`
- WorkerName string `json:"worker_name"`
- WorkerPhone string `json:"worker_phone"`
- ScheduleTime string `json:"schedule_time"`
- FinishedAt string `json:"finished_at"`
- Content string `json:"content"`
- Duration float64 `json:"duration"`
- Pics string `json:"pics"`
- PicList []string `json:"pic_list"`
- State int `json:"state"`
- StateName string `json:"state_name"`
- CreatedAt string `json:"created_at"`
- AuditType int `json:"audit_type"`
- AuditState int `json:"audit_state"`
- AuditAt string `json:"audit_at"`
- OrderNo string `json:"order_no"`
- MainType int `json:"main_type"`
- SubType int `json:"sub_type"`
- Type string `json:"type"`
- LinkName string `json:"link_name"`
- LinkPhone string `json:"link_phone"`
- Address string `json:"address"`
- DetailContent string `json:"detail_content"`
- DetailPics string `json:"detail_pics"`
- OrderCreatedAt string `json:"order_created_at"`
- Leader int `json:"leader"`
- LeaderInfo *Admin `json:"leader_info"`
- WarrantyStart string `json:"warranty_start"`
- WarrantyEnd string `json:"warranty_end"`
- WarrantyPeriod string `json:"warranty_period"`
- IsForce int `json:"is_force"`
- EndTime string `json:"end_time"`
- }
- repairList := make([]RepairList, 0)
- err = order.GetListWidthOrder(where, param, page, &repairList)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- adminIds := make([]int, 0)
- for _, v := range repairList {
- if v.Leader > 0 {
- adminIds = append(adminIds, v.Leader)
- }
- }
- orderTypeMap := aftersale.GetTypeMapByCache()
- adminMap := make(map[int]*Admin, 0)
- if len(adminIds) > 0 {
- adminList := make([]*Admin, 0)
- if _, err := admin.GetAdmins(map[string]interface{}{"id in": adminIds}, []string{"id, username, phone"}, app.Page{}, &adminList); err == nil {
- for _, v := range adminList {
- adminMap[v.ID] = v
- }
- }
- }
- repairStatusList := utils.ParseSliceMap(orderParam.Params.RepairState, "id")
- for k, v := range repairList {
- v.PicList = utils.ParseImgStr(v.Pics)
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD")
- v.Type = orderTypeMap[v.MainType] + "/" + orderTypeMap[v.SubType]
- if v.Leader > 0 && adminMap[v.Leader] != nil {
- v.LeaderInfo = adminMap[v.Leader]
- } else {
- v.LeaderInfo = &Admin{}
- }
- if v.WarrantyStart != "0" {
- v.WarrantyPeriod = utils.DateS(v.WarrantyStart, "YYYY-MM-DD") + " 至 " + utils.DateS(v.WarrantyEnd, "YYYY-MM-DD")
- } else {
- v.WarrantyPeriod = "保修期外"
- }
- v.ScheduleTime = utils.DateS(v.ScheduleTime, "YYYY-MM-DD")
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD")
- v.OrderCreatedAt = utils.DateS(v.OrderCreatedAt, "YYYY-MM-DD")
- v.EndTime = utils.DateS(v.EndTime, "YYYY-MM-DD HH:mm")
- v.FinishedAt = utils.DateS(v.FinishedAt, "YYYY-MM-DD HH:mm")
- v.AuditAt = utils.DateS(v.AuditAt, "YYYY-MM-DD HH:mm")
- v.StateName = utils.ToStr(repairStatusList[utils.ToStr(v.State)]["name"])
- repairList[k] = v
- }
- data := gin.H{
- "list": repairList,
- "total": total,
- "limit": page.PageSize,
- }
- app.Success(c, data)
- }
- func RepairCheck(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "工单 id 有误")
- return
- }
- var form form.RepairCheck
- if app.Bind(c, &form) != nil {
- return
- }
- err := order.RepairCheck(id, form.State, c.GetInt("adminID"), form.Remark)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
|