final_site.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. package final
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/gogf/gf/v2/util/gconv"
  6. "strings"
  7. "time"
  8. "zhiyuan/models"
  9. "zhiyuan/pkg/db"
  10. "zhiyuan/pkg/logger"
  11. "zhiyuan/pkg/utils"
  12. "zhiyuan/pkg/weixin/mp"
  13. "zhiyuan/services/admin"
  14. admin2 "zhiyuan/services/final/admin"
  15. "zhiyuan/services/user"
  16. "github.com/gin-gonic/gin"
  17. "github.com/gogf/gf/v2/os/gtime"
  18. )
  19. type FinalSite struct {
  20. ID int64 `json:"id" prop:"add:false"`
  21. PkgId int64 `json:"pkg_id" label:"套餐" type:"int" prop:"add:false edit:false" search:"multiple"`
  22. TypeId int64 `json:"type_id" label:"开工类型" type:"int" prop:"add:false edit:false" search:"multiple"`
  23. Username string `json:"username" label:"业主姓名" type:"string" prop:"add edit" search:"like"`
  24. Phone string `json:"phone" label:"手机号码" type:"string" prop:"add edit" search:"like"`
  25. AreaId int64 `json:"area_id" label:"区域" type:"int" prop:"add edit" search:"multiple"`
  26. CustomerId int64 `json:"customer_id" label:"客户" type:"int" prop:"edit:false" search:"="`
  27. OrderId int64 `json:"order_id" label:"合同" type:"int" prop:"edit:false" search:"="`
  28. Village string `json:"village" label:"小区名称" type:"string" prop:"edit" search:"like"`
  29. Address string `json:"address" label:"房屋地址" type:"string" prop:"edit" search:"like"`
  30. RoomNo string `json:"room_no" label:"楼栋房号" type:"string" prop:"edit" search:"like"`
  31. Areacode string `json:"areacode" label:"区划代码" type:"string" prop:"edit" search:"rightlike"`
  32. Name string `json:"name" label:"名称" type:"string" prop:"add:false select:concat(zy_final_site.village,'\\t',zy_final_site.address,'\\t',zy_final_site.room_no)" search:"like"`
  33. Room1 int64 `json:"room_1" label:"户型" type:"int" prop:"add:false edit:false" search:"="`
  34. Room2 int64 `json:"room_2" label:"户型" type:"int" prop:"add:false edit:false" search:"="`
  35. Room3 int64 `json:"room_3" label:"户型" type:"int" prop:"add:false edit:false" search:"="`
  36. Room4 int64 `json:"room_4" label:"户型" type:"int" prop:"add:false edit:false" search:"="`
  37. Room5 int64 `json:"room_5" label:"户型" type:"int" prop:"add:false edit:false" search:"="`
  38. Names string `json:"names" label:"名称" type:"string" prop:"add:false select:concat(zy_final_site.village,zy_final_site.address,zy_final_site.room_no)" search:"like"`
  39. Area float64 `json:"area" label:"面积" type:"float" prop:"add:false edit:false"`
  40. ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"add:false edit:false" search:"multiple"`
  41. ManagerId int64 `json:"manager_id" label:"项目经理" type:"int" prop:"edit" search:"multiple"`
  42. ProjectLeaderId int64 `json:"project_leader_id" label:"工程队长" type:"int" prop:"edit" search:"multiple"`
  43. DesignerId int64 `json:"designer_id" label:"设计师" type:"int" prop:"edit" search:"multiple"`
  44. StartTime int64 `json:"starttime" label:"开工日期" type:"int" prop:"add edit" search:"="`
  45. EndTime int64 `json:"endtime" label:"完工日期" type:"int" prop:""`
  46. CreatedId int64 `json:"created_id" label:"创建人员" type:"int" prop:"add:false" search:"="`
  47. ChangeState int64 `json:"change_state" label:"状态" type:"int" prop:"add:false edit" default:"0" search:"="`
  48. ChangeRemark string `json:"change_remark" label:"变更备注" type:"string" prop:"add:false edit"`
  49. Remark string `json:"remark" label:"备注" type:"string" prop:"add:false edit:false"`
  50. Activity string `json:"activity" label:"活动" type:"string" prop:"add:false edit:false"`
  51. Attachment string `json:"attachment" label:"附件" type:"string" prop:"add:false edit:false"`
  52. DeptId int64 `json:"dept_id" label:"归属部门" type:"int" prop:"add:false edit:false" search:"multiple"`
  53. SalesmanId int64 `json:"salesman_id" label:"业务员" type:"int" prop:"add:false edit:false" search:"multiple"`
  54. State int64 `json:"state" label:"状态" type:"int" prop:"add:false edit" default:"2"`
  55. ContactTime int64 `json:"contacttime" label:"接触时间" type:"int" prop:"edit" search:"="`
  56. StoreTime int64 `json:"storetime" label:"到店时间" type:"int" prop:"edit" search:"="`
  57. SignTime int64 `json:"signtime" label:"签订时间" type:"int" prop:"edit" search:"="`
  58. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  59. CreatedAt int64 `json:"created_at" prop:"add:false"`
  60. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  61. db.BaseModel
  62. }
  63. func (FinalSite) TableName() string {
  64. return "zy_final_site"
  65. }
  66. func (model FinalSite) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  67. s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` in %s and `%s`.`manager_id` != %s", model.TableName(), s.Param([]int64{1, 2}), model.TableName(), s.Param(0)))
  68. if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  69. adminID := s.Param(c.GetInt("adminID"))
  70. where := fmt.Sprintf("`%s`.`manager_id` = %s OR `%s`.`project_leader_id` = %s OR `%s`.`created_id` = %s", model.TableName(), adminID, model.TableName(), adminID, model.TableName(), adminID)
  71. if admin.CheckAuth([]string{"work:worksite:view"}, c.GetInt("adminID")) {
  72. where = fmt.Sprintf("%s OR FIND_IN_SET(`%s`.`shop_id`, %s)", where, model.TableName(), "0")
  73. }
  74. s.Where = append(s.Where, fmt.Sprintf("(%s)", where))
  75. }
  76. if search, ok := data["search"]; ok {
  77. search = s.Param(fmt.Sprintf("%%%s%%", search))
  78. s.Where = append(s.Where, fmt.Sprintf("`%s`.`username` LIKE %s OR `%s`.`phone` LIKE %s OR concat(`%s`.`village`,`%s`.`address`,`%s`.`room_no`) LIKE %s", model.TableName(), search, model.TableName(), search, model.TableName(), model.TableName(), model.TableName(), search))
  79. }
  80. if starttime1s, ok := data["starttime1"]; ok {
  81. if starttime1, ok := db.ToInt64(starttime1s); ok {
  82. s.Where = append(s.Where, fmt.Sprintf("`%s`.`starttime` >= %s", model.TableName(), s.Param(starttime1)))
  83. }
  84. }
  85. if starttime2s, ok := data["starttime2"]; ok {
  86. if starttime2, ok := db.ToInt64(starttime2s); ok {
  87. s.Where = append(s.Where, fmt.Sprintf("`%s`.`starttime` < %s", model.TableName(), s.Param(starttime2+60*60*24)))
  88. }
  89. }
  90. if endtime1s, ok := data["endtime1"]; ok {
  91. if endtime1, ok := db.ToInt64(endtime1s); ok {
  92. s.Where = append(s.Where, fmt.Sprintf("`%s`.`endtime` >= %s", model.TableName(), s.Param(endtime1)))
  93. }
  94. }
  95. if endtime2s, ok := data["endtime2"]; ok {
  96. if endtime2, ok := db.ToInt64(endtime2s); ok {
  97. s.Where = append(s.Where, fmt.Sprintf("`%s`.`endtime` < %s", model.TableName(), s.Param(endtime2+60*60*24)))
  98. }
  99. }
  100. return true
  101. }
  102. func (FinalSite) OnePrivilege(c *gin.Context, id int64) bool {
  103. return true
  104. }
  105. func (FinalSite) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  106. var model FinalSite
  107. db.GetModel(map[string]interface{}{
  108. "village": data["village"],
  109. "room_no": data["room_no"],
  110. "deleted_at": 0,
  111. }, &model)
  112. if model.ID != 0 {
  113. return errors.New("工地已存在")
  114. }
  115. user, err := user.GetOne(map[string]interface{}{"phone": data["phone"]}, nil, nil)
  116. if err != nil {
  117. return errors.New("获取用户信息失败")
  118. }
  119. if user == nil {
  120. return errors.New("用户未关注公众号")
  121. }
  122. data["created_id"] = c.GetInt("adminID")
  123. return nil
  124. }
  125. func (FinalSite) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
  126. //todo 添加工地
  127. //加载节假日
  128. holidays := admin2.LoadHolidays()
  129. fmt.Println("000000 holidays 00000000000", holidays)
  130. // 查询套餐表
  131. //field := " select * from zy_mat_pick "
  132. //db.GetMultiRaw(field, map[string]interface{}{
  133. // "pkg_id": post["pkg_id"],
  134. //}, map[string]interface{}{}, &checkList)
  135. checkList, err := db.GetModelMap(db.Type(models.WorkQualityAcceptItem{}), map[string]interface{}{"state": 1}, nil)
  136. if err != nil {
  137. errors.New("施工节点未找到")
  138. return
  139. }
  140. siteStart := gtime.New(utils.ToInt(post["starttime"])).Format("Y-m-d")
  141. fmt.Println("开始时间", siteStart)
  142. var siteCompletionTime string
  143. sql := "INSERT INTO zy_mat_pick_work(site_id,pick_id,`name`,pictures,photograph,room_type,`cycle`,example_at) VALUES "
  144. for _, item := range checkList {
  145. //fmt.Println(item)
  146. domain := "https://image.nczyzs.com/"
  147. result := strings.ReplaceAll(utils.ToStr(item["pictures"]), domain, "")
  148. sql += "("
  149. sql += utils.ToStr(id) + ","
  150. sql += utils.ToStr(item["id"]) + "," //accept_item_id
  151. sql += "'" + utils.ToStr(item["content"]) + "'," //施工名称
  152. sql += "'" + result + "'," //图片
  153. sql += "'" + utils.ToStr(item["photograph"]) + "'," //施工标准
  154. sql += utils.ToStr(item["quality_accept_id"]) + ","
  155. sql += utils.ToStr(item["days"]) + ","
  156. endDate, _ := admin2.CalculateEndDate(holidays, siteStart, gconv.Int(item["days"]))
  157. sql += "'" + endDate + "'"
  158. //_ = fmt.Sprintf("节点:%s ,工期:%d, 结束节点:%s", item["pick_name"], item["cycle"], endDate)
  159. //gt1 := gtime.New(post["starttime"]).Add(gconv.Duration(gconv.Int(pkg["cycle"]) * 86400))
  160. sql += "),"
  161. siteCompletionTime = endDate
  162. }
  163. //移除最后一个逗号
  164. if len(sql) > 0 {
  165. sql = sql[:len(sql)-1]
  166. }
  167. _, err = db.InsertRaw(sql, nil)
  168. fmt.Println("添加工地", sql)
  169. if err == nil {
  170. MatPickWork{}.AddAfter(c, id, data, data)
  171. }
  172. //更新工地的完工时间
  173. err = db.UpdateModels(db.Type(FinalSite{}), map[string]interface{}{
  174. "id": id,
  175. "deleted_at": 0,
  176. }, map[string]interface{}{
  177. "endtime": gtime.New(siteCompletionTime).Unix(), //回写完工日期
  178. })
  179. fmt.Println("最终完工时间", siteCompletionTime)
  180. //if err != nil {
  181. // app.ErrorMsg(c, err.Error(), nil)
  182. // return
  183. //}
  184. //var model FinalSite
  185. //db.GetModel(map[string]interface{}{
  186. // "id": id,
  187. // "deleted_at": 0,
  188. //}, &model)
  189. //
  190. //address := model.Address
  191. //if model.Village != " " {
  192. // address += " " + model.Village
  193. //}
  194. //if model.RoomNo != " " {
  195. // address += " " + model.RoomNo
  196. //}
  197. //switch model.ShopId {
  198. //case 9, 13, 14, 18:
  199. // SendSiteMessage(1003, id, address, "工地已创建,请及时下单")
  200. //case 10, 12, 15:
  201. // SendSiteMessage(1004, id, address, "工地已创建,请及时下单")
  202. //case 6, 16:
  203. // SendSiteMessage(1257, id, address, "工地已创建,请及时下单")
  204. //case 7, 17:
  205. // SendSiteMessage(1173, id, address, "工地已创建,请及时下单")
  206. //}
  207. }
  208. func (FinalSite) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  209. //开工的工地不允许修改套餐,检查工地表开工时间和当前时间做对比
  210. //site, err := db.GetOneModelMap(db.Type(FinalSite{}), map[string]interface{}{"id": post["id"]}, nil)
  211. //if err != nil {
  212. // return errors.New("工地未找到")
  213. //}
  214. //startTime, _ := db.ToInt64(site["starttime"])
  215. //curTime := time.Now().Unix()
  216. //
  217. //if data["pkg_id"] != site["pkg_id"] && curTime > startTime {
  218. // return errors.New("工地已开工,套餐无法变更")
  219. //}
  220. //删除原有工作,写入新工作
  221. //var MatPickWork MatPickWork
  222. //_, err = db.Delete(MatPickWork.TableName(), map[string]interface{}{"site_id": id})
  223. //
  224. //sql := "INSERT INTO zy_mat_pick_work(site_id,pkg_id,pick_id,room_type,manager_id) SELECT {{site_id}},pkg_id,id,room_type,{{manager_id}} FROM zy_mat_pick WHERE pkg_id={{pkg_id}}"
  225. //_, err = db.InsertRaw(sql, map[string]interface{}{"site_id": id, "pkg_id": post["pkg_id"], "manager_id": data["manager_id"]})
  226. //if err == nil {
  227. // MatPickWork.EditAfter(c, id, data, data)
  228. //}
  229. return nil
  230. }
  231. func (FinalSite) DelPrivilege(c *gin.Context, id int64) error {
  232. return nil
  233. }
  234. func (FinalSite) Page() bool {
  235. return false
  236. }
  237. func (FinalSite) Count() bool {
  238. return true
  239. }
  240. func (model FinalSite) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  241. return []db.JoinModel{}
  242. }
  243. func (model FinalSite) GroupBy() string {
  244. return fmt.Sprintf("`%s`.`id`", model.TableName())
  245. }
  246. type JoinAdmin struct {
  247. db.BaseModel
  248. }
  249. func (JoinAdmin) TableName() string {
  250. return "zy_admin"
  251. }
  252. type FinalSiteMobile struct {
  253. ManagerName string `json:"manager_name" type:"string" prop:"select:manager.username"`
  254. ManagerPhone string `json:"manager_phone" type:"string" prop:"select:manager.phone"`
  255. ManagerHeadImgUrl string `json:"manager_headimgurl" type:"string" prop:"select:manager.headimgurl"`
  256. DesignerName string `json:"designer_name" type:"string" prop:"select:designer.username"`
  257. DesignerPhone string `json:"designer_phone" type:"string" prop:"select:designer.phone"`
  258. DesignerHeadImgUrl string `json:"designer_headimgurl" type:"string" prop:"select:designer.headimgurl"`
  259. SalesmanName string `json:"salesman_name" type:"string" prop:"select:salesman.username"`
  260. SalesmanPhone string `json:"salesman_phone" type:"string" prop:"select:salesman.phone"`
  261. SalesmanHeadImgUrl string `json:"salesman_headimgurl" type:"string" prop:"select:salesman.headimgurl"`
  262. TableCount int64 `json:"table_count" type:"int" prop:"select:count(distinct(if(pickwork.deleted_at=0,pickwork.id,NULL)))"`
  263. Uncount int64 `json:"uncount" type:"int" prop:"select:count(distinct(IF((pickwork.deleted_at=0)AND(pickwork.item_status=0),pickwork.id,NULL)))"`
  264. HandleCount int64 `json:"handle_count" type:"int" prop:"select:count(distinct(IF((pickwork.deleted_at=0)AND(pickwork.item_status=2),pickwork.id,NULL)))"`
  265. FinishCount int64 `json:"finish_count" type:"int" prop:"select:count(distinct(IF((pickwork.deleted_at=0)AND(pickwork.item_status=1),pickwork.id,NULL)))"`
  266. //HandleCount int64 `json:"handle_count" type:"int" prop:"select:count(distinct(IF((pickwork.state>0)AND(finalsitetable.state<5),finalsitetable.id,NULL)))"`
  267. //FinishCount int64 `json:"finish_count" type:"int" prop:"select:count(distinct(IF(finalsitetable.state=5,finalsitetable.id,NULL)))"`
  268. //Count1 int64 `json:"count1" type:"int" prop:"select:count(distinct(IF(finalsitetable.state=1,finalsitetable.id,NULL)))"`
  269. //Count2 int64 `json:"count2" type:"int" prop:"select:count(distinct(IF(finalsitetable.state=2,finalsitetable.id,NULL)))"`
  270. //Count3 int64 `json:"count3" type:"int" prop:"select:count(distinct(IF(finalsitetable.state=3,finalsitetable.id,NULL)))"`
  271. //Count4 int64 `json:"count4" type:"int" prop:"select:count(distinct(IF(finalsitetable.state=4,finalsitetable.id,NULL)))"`
  272. SettleID int64 `json:"settle_id" type:"int" prop:"select:finalsettle.id"`
  273. SettleTotal float64 `json:"settle_total" type:"float" prop:"select:finalsettle.total"`
  274. SettleState int64 `json:"settle_state" type:"int" prop:"select:finalsettle.state"`
  275. SettleCreatedAt int64 `json:"settle_created_at" type:"int" prop:"select:finalsettle.created_at"`
  276. ShopName string `json:"shop_name" type:"string" prop:"select:shop.shop_name"`
  277. CollectInfo string `json:"collect_info" type:"string" prop:"select:shop.collect_info"`
  278. FinalSite
  279. }
  280. func (model FinalSiteMobile) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  281. if state, ok := data["state"]; ok {
  282. if n, ok := db.ToInt64(state); ok {
  283. switch n {
  284. case 1:
  285. s.Having = append(s.Having, "count(IF((pickwork.item_status=0)OR(pickwork.item_status=2)OR(pickwork.item_status=3),pickwork.id,NULL))")
  286. case 2:
  287. s.Having = append(s.Having, "count(IF((pickwork.item_status=0)OR(pickwork.item_status=2),pickwork.id,NULL)) = 0 ")
  288. case 3:
  289. //s.Having = append(s.Having, "count(IF(pickwork.item_status==1,pickwork.id,NULL)) = 0")
  290. case 4:
  291. //s.Having = append(s.Having, "count(IF(finalsitetable.state=1,finalsitetable.id,NULL)) != 0")
  292. case 5:
  293. //s.Having = append(s.Having, "count(IF(finalsitetable.state=2,finalsitetable.id,NULL)) != 0")
  294. case 6:
  295. //s.Having = append(s.Having, "count(IF(finalsitetable.state=3,finalsitetable.id,NULL)) != 0")
  296. case 7:
  297. //s.Having = append(s.Having, "count(IF(finalsitetable.state=4,finalsitetable.id,NULL)) != 0")
  298. }
  299. }
  300. }
  301. if admin.CheckAuth([]string{"work:worksite:view"}, c.GetInt("adminID")) {
  302. s.Where = append(s.Where, fmt.Sprintf("(`manager`.`audit_id` = %s OR `manager`.`audit_id` = %s)", s.Param(c.GetInt("adminID")), s.Param(0)))
  303. fmt.Println(":", c.GetInt("adminID"))
  304. fmt.Println("我有权限")
  305. }
  306. return model.FinalSite.ListPrivilege(c, data, s)
  307. }
  308. func (model FinalSiteMobile) ListAfter(c *gin.Context, data map[string]interface{}, list []map[string]interface{}) []map[string]interface{} {
  309. for n, item := range list {
  310. siteId := item["id"]
  311. params := make(map[string]interface{})
  312. params["site_id"] = siteId
  313. query := " SELECT w.room_type, a.name AS room_type_name,COUNT(w.id) AS total,SUM(CASE WHEN w.item_status = 1 THEN 1 ELSE 0 END) AS completed FROM zy_mat_pick_work w LEFT JOIN zy_work_quality_accept a ON w.room_type = a.id WHERE w.site_id = {{site_id}} AND w.deleted_at = 0 GROUP BY w.room_type, a.name ORDER BY w.room_type"
  314. params["adminID"] = c.GetInt("adminID")
  315. checkList, _ := db.QueryMap(query, params, nil)
  316. list[n]["static"] = checkList
  317. }
  318. return list
  319. }
  320. func (model FinalSiteMobile) GroupBy() string {
  321. return fmt.Sprintf("`%s`.`id`", model.TableName())
  322. }
  323. func (model FinalSiteMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  324. return append(model.FinalSite.LeftJoin(data, s),
  325. db.JoinModel{
  326. Model: JoinAdmin{},
  327. As: "manager",
  328. On: []string{"`manager`.`id` = " + model.TableName() + ".`manager_id`"},
  329. },
  330. db.JoinModel{
  331. Model: JoinAdmin{},
  332. As: "designer",
  333. On: []string{"`designer`.`id` = " + model.TableName() + ".`designer_id`"},
  334. },
  335. db.JoinModel{
  336. Model: JoinAdmin{},
  337. As: "salesman",
  338. On: []string{"`salesman`.`id` = " + model.TableName() + ".`salesman_id`"},
  339. },
  340. db.JoinModel{
  341. Model: JoinShop{},
  342. As: "shop",
  343. On: []string{"`shop`.`id` = " + model.TableName() + ".`shop_id`"},
  344. },
  345. db.JoinModel{
  346. Model: FinalMaterial{},
  347. As: "finalmaterial",
  348. On: []string{"`finalmaterial`.`site_id` = " + model.TableName() + ".`id` AND `finalmaterial`.`deleted_at` = 0"},
  349. },
  350. db.JoinModel{
  351. Model: MatPickWork{},
  352. As: "pickwork",
  353. On: []string{"`pickwork`.`site_id` = " + model.TableName() + ".`id`"},
  354. },
  355. db.JoinModel{
  356. Model: FinalSettle{},
  357. As: "finalsettle",
  358. On: []string{"`finalsettle`.`site_id` = " + model.TableName() + ".`id` AND `finalsettle`.`deleted_at` = 0"},
  359. })
  360. }
  361. type FinalSiteSupplier struct {
  362. ManagerName string `json:"manager_name" type:"string" prop:"select:manager.username"`
  363. ManagerPhone string `json:"manager_phone" type:"string" prop:"select:manager.phone"`
  364. ManagerHeadImgUrl string `json:"manager_headimgurl" type:"string" prop:"select:manager.headimgurl"`
  365. MaterialCount int64 `json:"count" type:"int" prop:"select:count(distinct(finalmaterial.id))"`
  366. Count2 int64 `json:"count2" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=2,finalmaterial.id,NULL)))"`
  367. Count3 int64 `json:"count3" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=3,finalmaterial.id,NULL)))"`
  368. Count4 int64 `json:"count4" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=4,finalmaterial.id,NULL)))"`
  369. Count5 int64 `json:"count5" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=5,finalmaterial.id,NULL)))"`
  370. Count6 int64 `json:"count6" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=6,finalmaterial.id,NULL)))"`
  371. Count7 int64 `json:"count7" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=7,finalmaterial.id,NULL)))"`
  372. Count8 int64 `json:"count8" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=8,finalmaterial.id,NULL)))"`
  373. Count9 int64 `json:"count9" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=9,finalmaterial.id,NULL)))"`
  374. Count10 int64 `json:"count10" type:"int" prop:"select:count(distinct(IF(finalmaterial.state=10,finalmaterial.id,NULL)))"`
  375. FinalSite
  376. }
  377. func (model FinalSiteSupplier) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  378. if state, ok := data["state"]; ok {
  379. if n, ok := db.ToInt64(state); ok {
  380. switch n {
  381. case 2:
  382. s.Having = append(s.Having, "count(IF(finalmaterial.state=2,finalmaterial.id,NULL)) != 0")
  383. case 3:
  384. s.Having = append(s.Having, "count(IF(finalmaterial.state=3,finalmaterial.id,NULL)) != 0")
  385. case 4:
  386. s.Having = append(s.Having, "count(IF(finalmaterial.state=4,finalmaterial.id,NULL)) != 0")
  387. case 5:
  388. s.Having = append(s.Having, "count(IF(finalmaterial.state=5,finalmaterial.id,NULL)) != 0")
  389. case 6:
  390. s.Having = append(s.Having, "count(IF(finalmaterial.state=6,finalmaterial.id,NULL)) != 0")
  391. case 7:
  392. s.Having = append(s.Having, "count(IF(finalmaterial.state=7,finalmaterial.id,NULL)) != 0")
  393. case 8:
  394. s.Having = append(s.Having, "count(IF(finalmaterial.state=8,finalmaterial.id,NULL)) != 0")
  395. case 9:
  396. s.Having = append(s.Having, "count(IF(finalmaterial.state=9,finalmaterial.id,NULL)) != 0")
  397. case 10:
  398. s.Having = append(s.Having, "count(IF(finalmaterial.state=10,finalmaterial.id,NULL)) != 0")
  399. }
  400. }
  401. }
  402. s.Where = append(s.Where, fmt.Sprintf("`finalmaterial`.`supplier_id` = %s", s.Param(c.GetInt("adminID"))))
  403. if search, ok := data["search"]; ok {
  404. search = s.Param(fmt.Sprintf("%%%s%%", search))
  405. s.Where = append(s.Where, fmt.Sprintf("`%s`.`username` LIKE %s OR `%s`.`phone` LIKE %s OR concat(`%s`.`village`,`%s`.`address`,`%s`.`room_no`) LIKE %s", model.TableName(), search, model.TableName(), search, model.TableName(), model.TableName(), model.TableName(), search))
  406. }
  407. return true
  408. }
  409. func (model FinalSiteSupplier) ListAfter(c *gin.Context, data map[string]interface{}, list []map[string]interface{}) []map[string]interface{} {
  410. ids := make([]int64, 0)
  411. idmap := make(map[int64]int)
  412. for i, v := range list {
  413. id, _ := db.ToInt64(v["id"])
  414. ids = append(ids, id)
  415. idmap[id] = i
  416. }
  417. datas, _ := db.GetModelMap(db.Type(FinalMaterialItemSupplier{}), map[string]interface{}{
  418. "finalmaterial.site_id in ": ids,
  419. "finalmaterial.supplier_id": c.GetInt("adminID"),
  420. fmt.Sprintf("`%s`.`deleted_at`", FinalMaterialItemSupplier{}.TableName()): 0,
  421. }, nil)
  422. for _, v := range datas {
  423. id, _ := db.ToInt64(v["site_id"])
  424. mid, _ := db.ToInt64(v["material_id"])
  425. if n, ok := idmap[id]; ok {
  426. materials := make([]map[string]interface{}, 0)
  427. if ms, ok := list[n]["materials"].([]map[string]interface{}); ok {
  428. materials = ms
  429. }
  430. findmaterial := false
  431. for i, m := range materials {
  432. materialid, _ := db.ToInt64(m["id"])
  433. if materialid == mid {
  434. findmaterial = true
  435. items := make([]map[string]interface{}, 0)
  436. if is, ok := m["items"].([]map[string]interface{}); ok {
  437. items = is
  438. }
  439. items = append(items, v)
  440. materials[i]["items"] = items
  441. break
  442. }
  443. }
  444. if !findmaterial {
  445. material := map[string]interface{}{
  446. "id": v["material_id"],
  447. "name": v["name"],
  448. "type": v["type"],
  449. "budget": v["budget"],
  450. "budget_type": v["budget_type"],
  451. "total": v["total"],
  452. "state": v["state"],
  453. "receipt_date": v["receipt_date"],
  454. "items": []map[string]interface{}{v},
  455. }
  456. materials = append(materials, material)
  457. }
  458. list[n]["materials"] = materials
  459. }
  460. }
  461. return list
  462. }
  463. func (model FinalSiteSupplier) GroupBy() string {
  464. return fmt.Sprintf("`%s`.`id`", model.TableName())
  465. }
  466. func (model FinalSiteSupplier) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  467. return []db.JoinModel{
  468. {
  469. Model: JoinAdmin{},
  470. As: "manager",
  471. On: []string{"`manager`.`id` = " + model.TableName() + ".`manager_id`"},
  472. },
  473. {
  474. Model: FinalMaterial{},
  475. As: "finalmaterial",
  476. On: []string{"`finalmaterial`.`site_id` = " + model.TableName() + ".`id` AND `finalmaterial`.`state` > 1 AND `finalmaterial`.`deleted_at` = 0"},
  477. },
  478. }
  479. }
  480. func SendSiteMessage(adminID int, siteId int64, address string, text string) error {
  481. logger.Sugar.Infof("SendSiteMessage, send: %v %v %v %v", adminID, siteId, address, text)
  482. client, err := mp.NewClient(1)
  483. if err != nil {
  484. return err
  485. }
  486. adminInfo, err := admin.GetInfoByID(adminID, nil, nil)
  487. if err != nil {
  488. return err
  489. }
  490. if adminInfo == nil || adminInfo.OpenId == "" {
  491. return nil
  492. }
  493. url := ""
  494. if siteId != 0 {
  495. url = "https://jz.nczyzs.com/final/#/detail/" + db.ToString(siteId)
  496. }
  497. ret, err := client.SendTemplateMessage(adminInfo.OpenId, "0tdzToVtXoCUrafmN-ub9J69HKKCfUWEsCan-WkuPKk", url, map[string]interface{}{
  498. "character_string1": map[string]interface{}{
  499. "value": db.ToString(siteId),
  500. },
  501. "thing2": map[string]interface{}{
  502. "value": utils.SubStr(address, 0, 20),
  503. },
  504. "thing5": map[string]interface{}{
  505. "value": utils.SubStr(text, 0, 20),
  506. },
  507. })
  508. logger.Sugar.Infof("SendSiteMessage, ret: %v %v", ret, err)
  509. return err
  510. }
  511. func SendSiteWorkMessage(adminID int, siteId int64, text string) error {
  512. return nil
  513. logger.Sugar.Infof("SendSiteWorkMessage, send: %v %v %v %v", adminID, siteId, text)
  514. client, err := mp.NewClient(1)
  515. if err != nil {
  516. return err
  517. }
  518. adminInfo, err := admin.GetInfoByID(adminID, nil, nil)
  519. if err != nil {
  520. return err
  521. }
  522. if adminInfo == nil || adminInfo.OpenId == "" {
  523. return nil
  524. }
  525. url := ""
  526. if siteId != 0 {
  527. url = "https://jz.nczyzs.com/final/#/detail/" + db.ToString(siteId)
  528. }
  529. ret, err := client.SendTemplateMessage(adminInfo.OpenId, "0tdzToVtXoCUrafmN-ub9J69HKKCfUWEsCan-WkuPKk", url, map[string]interface{}{
  530. "character_string1": map[string]interface{}{
  531. "value": db.ToString(siteId),
  532. },
  533. "thing5": map[string]interface{}{
  534. "value": utils.SubStr(text, 0, 20),
  535. },
  536. })
  537. logger.Sugar.Infof("SendSiteWorkMessage, ret: %v %v", ret, err)
  538. return err
  539. }
  540. type JoinWriteControl struct {
  541. db.BaseModel
  542. }
  543. func (JoinWriteControl) TableName() string {
  544. return "(select `id`,`site_id` from `zy_final_site_control` where `deleted_at` = 0 and `created_at` != `updated_at` group by `site_id`)"
  545. }
  546. type JoinPriceControl struct {
  547. db.BaseModel
  548. }
  549. func (JoinPriceControl) TableName() string {
  550. return "(select `id`,`site_id` from `zy_final_manager_price` where `deleted_at` = 0 group by `site_id`)"
  551. }
  552. type JoinApplyControl struct {
  553. db.BaseModel
  554. }
  555. func (JoinApplyControl) TableName() string {
  556. return "(select `id`, `site_id`, group_concat(concat(`name`, if(`settle_state` = 1,\"结算\", \"\"))) as `name`, count(`id`) as `manager_count` from (select `zy_final_site_control`.`id`, `zy_final_site_control`.`site_id`, `type`.`name` as `name`, IF((`zy_final_site_control`.`budget`!=0)and(count(distinct(IF(`table`.`state`<2,`table`.`id`,NULL)))=0)and(count(distinct(IF(`table`.`type`=1,`table`.`id`,NULL)))<`type`.`living_count`)and(count(distinct(IF(`table`.`type`=0,`table`.`id`,NULL)))=0)and((`type`.`living_settlement`=0)or(not(isnull(`livingpayment`.`id`)))),1,0) as `living_state`, IF((`zy_final_site_control`.`budget`!=0)and(count(distinct(IF(`table`.`state`<2,`table`.`id`,NULL)))=0)and((`type`.`settle_change`=0)or(`site`.`change_state`=1))and((`type`.`settlement`=0)or(not(isnull(`settlepayment`.`id`))))and(count(distinct(IF(`table`.`type`=0,`table`.`id`,NULL)))=0),1,0) as `settle_state`, count(`zy_final_site_control`.`id`) as `manager_count` from `zy_final_site_control` left join `zy_final_type` as `type` on `type`.`id` = `zy_final_site_control`.`type_id` left join `zy_final_site` as `site` on `site`.`id` = `zy_final_site_control`.`site_id` left join `zy_final_site_table` as `table` on `table`.`type_id` = `zy_final_site_control`.`type_id` and `table`.`site_id` = `zy_final_site_control`.`site_id` and `table`.`state` != -1 and `table`.`deleted_at` = 0 left join `zy_final_site_payment` as `livingpayment` on `livingpayment`.`type_id` = `type`.`living_settlement` and `livingpayment`.`site_id` = `zy_final_site_control`.`site_id` and `livingpayment`.`state` = 1 and `livingpayment`.`deleted_at` = 0 left join `zy_final_site_payment` as `settlepayment` on `settlepayment`.`type_id` = `type`.`settlement` and `settlepayment`.`site_id` = `zy_final_site_control`.`site_id` and `settlepayment`.`state` = 1 and `settlepayment`.`deleted_at` = 0 and `zy_final_site_control`.`deleted_at` = 0 group by `zy_final_site_control`.`id`) as `control` where `living_state` = 1 or `settle_state` = 1 group by `site_id`)"
  557. }
  558. type JoinStatistTable struct {
  559. db.BaseModel
  560. }
  561. func (JoinStatistTable) TableName() string {
  562. return "(select `zy_final_site_table`.`id`,`zy_final_site_table`.`site_id`, group_concat(concat(`type`.`name`, if(`zy_final_site_table`.`type` = 1,\"生活费\", \"结算\"))) as `name`, sum(if(`zy_final_site_table`.`state` = 0, 1, 0)) as `manager_count`, sum(if(`zy_final_site_table`.`state` = 1, 1, 0)) as `leader_count`, sum(if(`zy_final_site_table`.`state` = 2 or `zy_final_site_table`.`state` = 4, 1, 0)) as `finance_count`, sum(if(`zy_final_site_table`.`state` = 3, 1, 0)) as `shopowner_count`, sum(if(`zy_final_site_table`.`state` = 2, 1, 0)) as `incomplete_collect_count` from `zy_final_site_table` left join `zy_final_type` as `type` on `type`.`id` = `zy_final_site_table`.`type_id` where `zy_final_site_table`.`state` != 5 and `zy_final_site_table`.`state` != -1 and `zy_final_site_table`.`deleted_at` = 0 group by `zy_final_site_table`.`site_id`)"
  563. }
  564. type JoinStatistMaterial struct {
  565. db.BaseModel
  566. }
  567. func (JoinStatistMaterial) TableName() string {
  568. return "(select `zy_final_material`.`id`,`zy_final_material`.`site_id`, group_concat(`finalmatauxiliary`.`name`) as `name`, count(`zy_final_material`.`id`) as `manager_count` from `zy_final_material` left join `zy_final_mat_auxiliary` as `finalmatauxiliary` on `finalmatauxiliary`.`id` = `zy_final_material`.`type_id` where `zy_final_material`.`budget` != 0 and `zy_final_material`.`state` = 0 and `zy_final_material`.`deleted_at` = 0 group by `zy_final_material`.`site_id`)"
  569. }
  570. type JoinStatistOrder struct {
  571. db.BaseModel
  572. }
  573. func (JoinStatistOrder) TableName() string {
  574. return "(select `zy_final_material_order`.`id`,`zy_final_material_order`.`site_id`, group_concat(concat(`supplier`.`name`, \" \", `zy_final_material_order`.`order_no`)) as `name`, sum(if((`zy_final_material_order`.`state` in (9,0,2,5,11) and `zy_final_material_order`.`process_id` = 0) OR (`process`.`type` = 6 AND `process`.`check_at3` = 0), 1, 0)) as `supplier_count`, sum(if((`zy_final_material_order`.`state` in (8,1,3,4,6) and `zy_final_material_order`.`process_id` = 0) OR (`process`.`type` = 6 AND `process`.`check_at2` = 0) OR (`process`.`type` = 14 AND `process`.`check_at` = 0) OR (`process`.`type` = 7 AND `process`.`check_at2` = 0 AND `zy_final_material_order`.`created_id` = `finalsite`.`manager_id`), 1, 0)) as `manager_count`, sum(if(`zy_final_material_order`.`state` = 7 and `zy_final_material_order`.`process_id` = 0, 1, 0)) as `leader_count`, sum(if(`process`.`type` = 7 AND `process`.`check_at2` = 0 AND `zy_final_material_order`.`created_id` != `finalsite`.`manager_id`, 1, 0)) as `place_count`, sum(if((`process`.`type` = 7 AND `process`.`check_at` = 0) OR (`process`.`type` = 12 AND `process`.`check_at` = 0), 1, 0)) as `audit_count` from `zy_final_material_order` left join `zy_final_supplier` as `supplier` on `supplier`.`id` = `zy_final_material_order`.`supplier_id` left join `zy_final_material_order_process` as `process` on `process`.`id` = `zy_final_material_order`.`process_id` left join `zy_final_site` as `finalsite` on `finalsite`.`id` = `zy_final_material_order`.`site_id` where `zy_final_material_order`.`state` != 7 and `zy_final_material_order`.`state` != 11 and `zy_final_material_order`.`state` != 12 and `zy_final_material_order`.`state` != -1 and `zy_final_material_order`.`deleted_at` = 0 group by `zy_final_material_order`.`site_id`)"
  575. }
  576. type JoinStatistOrderAll struct {
  577. db.BaseModel
  578. }
  579. func (JoinStatistOrderAll) TableName() string {
  580. return "(select `zy_final_material_order`.`id`,`zy_final_material_order`.`site_id`, sum(if(`settle`.`state` = 2, 1, 0)) as `incomplete_collect_count`, sum(if(`zy_final_material_order`.`state` = 0, 1, 0)) as `state0_count`, sum(if(`zy_final_material_order`.`state` = 1, 1, 0)) as `state1_count`, sum(if(`zy_final_material_order`.`state` = 2, 1, 0)) as `state2_count`, sum(if(`zy_final_material_order`.`state` = 3, 1, 0)) as `state3_count`, sum(if(`zy_final_material_order`.`state` = 4, 1, 0)) as `state4_count`, sum(if(`zy_final_material_order`.`state` = 5, 1, 0)) as `state5_count`, sum(if(`zy_final_material_order`.`state` = 6, 1, 0)) as `state6_count`, sum(if(`zy_final_material_order`.`state` = 7, 1, 0)) as `state7_count`, sum(if(`zy_final_material_order`.`state` = 8, 1, 0)) as `state8_count`, sum(if(`zy_final_material_order`.`state` = 9, 1, 0)) as `state9_count`, sum(if(`zy_final_material_order`.`state` = 10, 1, 0)) as `state10_count`, sum(if(`zy_final_material_order`.`state` = 11, 1, 0)) as `state11_count`, sum(if(`zy_final_material_order`.`state` = 12, 1, 0)) as `state12_count` from `zy_final_material_order` left join `zy_final_material_settle` as `settle` on `settle`.`id` = `zy_final_material_order`.`settle_id` and `settle`.`deleted_at` = 0 where `zy_final_material_order`.`deleted_at` = 0 group by `zy_final_material_order`.`site_id`)"
  581. }
  582. type JoinStatistPayment struct {
  583. db.BaseModel
  584. }
  585. func (JoinStatistPayment) TableName() string {
  586. return "(select `zy_final_site_payment`.`id`,`zy_final_site_payment`.`site_id`, group_concat(`type`.`name`) as `name`, count(`zy_final_site_payment`.`id`) as `finance_count` from `zy_final_site_payment` left join `zy_final_payment_type` as `type` on `type`.`id` = `zy_final_site_payment`.`type_id` where `zy_final_site_payment`.`state` = 0 and `zy_final_site_payment`.`deleted_at` = 0 group by `zy_final_site_payment`.`site_id`)"
  587. }
  588. type JoinStatistSettle struct {
  589. db.BaseModel
  590. }
  591. func (JoinStatistSettle) TableName() string {
  592. return "(select `id`,`site_id`, `state`, `manager_price`, `worker_price`, `auxiliary_price`, `subsidy_price`, `total`, sum(if(`zy_final_settle`.`state` in (0,2), 1, 0)) as `manager_count`, sum(if(`zy_final_settle`.`state` = 1, 1, 0)) as `customer_count`, sum(if(`zy_final_settle`.`state` in (3,5), 1, 0)) as `finance_count`, sum(if(`zy_final_settle`.`state` = 4, 1, 0)) as `shopowner_count` from `zy_final_settle` where `state` != 0 and `deleted_at` = 0 group by `site_id`)"
  593. }
  594. type FinalSiteStatist struct {
  595. WriteControl int64 `json:"write_control" type:"int" prop:"select:if(isnull(price.id),1,0)" search:"="` //由原來的wirte改成price
  596. ApplyControl int64 `json:"apply_control" type:"int" prop:"select:if(isnull(apply.id),0,1)" search:"="`
  597. ApplyControlName string `json:"apply_control_name" type:"string" prop:"select:apply.name" search:"="`
  598. IncompleteTable int64 `json:"incomplete_table" type:"int" prop:"select:if(isnull(table.id),0,1)" search:"="`
  599. IncompleteTableName string `json:"incomplete_table_name" type:"string" prop:"select:table.name" search:"="`
  600. NoOrder int64 `json:"no_order" type:"int" prop:"select:if(isnull(material.id),0,1)" search:"="`
  601. NoOrderName string `json:"no_order_name" type:"string" prop:"select:material.name" search:"="`
  602. IncompleteOrder int64 `json:"incomplete_order" type:"int" prop:"select:if(isnull(order.id),0,1)" search:"="`
  603. IncompleteOrderName string `json:"incomplete_order_name" type:"string" prop:"select:order.name" search:"="`
  604. IncompletePayment int64 `json:"incomplete_payment" type:"int" prop:"select:if(isnull(payment.id),0,1)" search:"="`
  605. IncompletePaymentName string `json:"incomplete_payment_name" type:"string" prop:"select:payment.name" search:"="`
  606. IncompleteChange int64 `json:"incomplete_change" type:"int" prop:"select:if(zy_final_site.change_state=1,0,1)" search:"="`
  607. Total float64 `json:"total" label:"金额" type:"float" prop:"select:settle.total"`
  608. ManagerPrice float64 `json:"manager_price" label:"承包额" type:"float" prop:"select:settle.manager_price"`
  609. WorkerPrice float64 `json:"worker_price" label:"工人" type:"float" prop:"select:settle.worker_price"`
  610. AuxiliaryPrice float64 `json:"auxiliary_price" label:"辅材" type:"float" prop:"select:settle.auxiliary_price"`
  611. SubsidyPrice float64 `json:"subsidy_price" label:"补贴" type:"float" prop:"select:settle.subsidy_price"`
  612. SettleState int64 `json:"settle_state" label:"状态" type:"int" prop:"select:ifnull(settle.state,0)" search:"="`
  613. AreaName string `json:"area_name" type:"string" prop:"select:area.name" search:"="`
  614. ShopName string `json:"shop_name" type:"string" prop:"select:shop.shop_name"`
  615. DeptName string `json:"dept_name" prop:"select:dept.name"`
  616. ManagerName string `json:"manager_name" type:"string" prop:"select:manager.username"`
  617. ManagerPhone string `json:"manager_phone" type:"string" prop:"select:manager.phone"`
  618. ProjectLeaderName string `json:"project_leader_name" type:"string" prop:"select:project_leader.username"`
  619. ProjectLeaderPhone string `json:"project_leader_phone" type:"string" prop:"select:project_leader.phone"`
  620. DesignerName string `json:"designer_name" type:"string" prop:"select:designer.username"`
  621. DesignerPhone string `json:"designer_phone" type:"string" prop:"select:designer.phone"`
  622. SalesmanName string `json:"salesman_name" type:"string" prop:"select:salesman.username"`
  623. SalesmanPhone string `json:"salesman_phone" type:"string" prop:"select:salesman.phone"`
  624. PkgName string `json:"pkg_name" type:"string" prop:"select:pkg.name"`
  625. ManagerCount int64 `json:"manager_count" type:"int" prop:"select:if(isnull(apply.manager_count),0,apply.manager_count)+if(isnull(table.manager_count),0,table.manager_count)+if(isnull(material.manager_count),0,material.manager_count)+if(isnull(order.manager_count),0,order.manager_count)+if(isnull(material.manager_count),0,material.manager_count)+if(isnull(settle.manager_count),0,settle.manager_count)" search:"="`
  626. LeaderCount int64 `json:"leader_count" type:"int" prop:"select:if(isnull(table.leader_count),0,table.leader_count)+if(isnull(order.leader_count),0,order.leader_count)" search:"="`
  627. FinanceCount int64 `json:"finance_count" type:"int" prop:"select:if(isnull(table.finance_count),0,table.finance_count)+if(isnull(payment.finance_count),0,payment.finance_count)+if(isnull(settle.finance_count),0,settle.finance_count)" search:"="`
  628. AuditCount int64 `json:"audit_count" type:"int" prop:"select:if(isnull(order.audit_count),0,order.audit_count)+if(isnull(write.id),1,0)+if(zy_final_site.change_state=1,0,1)" search:"="`
  629. ShopownerCount int64 `json:"shopowner_count" type:"int" prop:"select:if(isnull(table.shopowner_count),0,table.shopowner_count)+if(isnull(settle.shopowner_count),0,settle.shopowner_count)" search:"="`
  630. CustomerCount int64 `json:"customer_count" type:"int" prop:"select:if(isnull(settle.customer_count),0,settle.customer_count)" search:"="`
  631. PlaceCount int64 `json:"place_count" type:"int" prop:"select:if(isnull(order.place_count),0,order.place_count)" search:"="`
  632. SupplierCount int64 `json:"supplier_count" type:"int" prop:"select:if(isnull(order.supplier_count),0,order.supplier_count)" search:"="`
  633. TableIncompleteCollectCount int64 `json:"table_incomplete_collect_count" type:"int" prop:"select:if(isnull(table.incomplete_collect_count),0,table.incomplete_collect_count)" search:"="`
  634. OrderIncompleteCollectCount int64 `json:"order_incomplete_collect_count" type:"int" prop:"select:if(isnull(orderall.incomplete_collect_count),0,orderall.incomplete_collect_count)" search:"="`
  635. OrderState0Count int64 `json:"order_state0_count" type:"int" prop:"select:if(isnull(orderall.state0_count),0,orderall.state0_count)" search:"="`
  636. OrderState1Count int64 `json:"order_state1_count" type:"int" prop:"select:if(isnull(orderall.state1_count),0,orderall.state1_count)" search:"="`
  637. OrderState2Count int64 `json:"order_state2_count" type:"int" prop:"select:if(isnull(orderall.state2_count),0,orderall.state2_count)" search:"="`
  638. OrderState3Count int64 `json:"order_state3_count" type:"int" prop:"select:if(isnull(orderall.state3_count),0,orderall.state3_count)" search:"="`
  639. OrderState4Count int64 `json:"order_state4_count" type:"int" prop:"select:if(isnull(orderall.state4_count),0,orderall.state4_count)" search:"="`
  640. OrderState5Count int64 `json:"order_state5_count" type:"int" prop:"select:if(isnull(orderall.state5_count),0,orderall.state5_count)" search:"="`
  641. OrderState6Count int64 `json:"order_state6_count" type:"int" prop:"select:if(isnull(orderall.state6_count),0,orderall.state6_count)" search:"="`
  642. OrderState7Count int64 `json:"order_state7_count" type:"int" prop:"select:if(isnull(orderall.state7_count),0,orderall.state7_count)" search:"="`
  643. OrderState8Count int64 `json:"order_state8_count" type:"int" prop:"select:if(isnull(orderall.state8_count),0,orderall.state8_count)" search:"="`
  644. OrderState9Count int64 `json:"order_state9_count" type:"int" prop:"select:if(isnull(orderall.state9_count),0,orderall.state9_count)" search:"="`
  645. OrderState10Count int64 `json:"order_state10_count" type:"int" prop:"select:if(isnull(orderall.state10_count),0,orderall.state10_count)" search:"="`
  646. OrderState11Count int64 `json:"order_state11_count" type:"int" prop:"select:if(isnull(orderall.state11_count),0,orderall.state11_count)" search:"="`
  647. OrderState12Count int64 `json:"order_state12_count" type:"int" prop:"select:if(isnull(orderall.state12_count),0,orderall.state12_count)" search:"="`
  648. FinalSite
  649. }
  650. func (model FinalSiteStatist) GroupBy() string {
  651. return ""
  652. }
  653. func (model FinalSiteStatist) ExportFields() []db.ExportField {
  654. return []db.ExportField{
  655. {
  656. Label: "ID",
  657. Name: "id",
  658. Width: 10,
  659. },
  660. {
  661. Label: "业主姓名",
  662. Name: "username",
  663. Width: 10,
  664. },
  665. {
  666. Label: "手机号码",
  667. Name: "phone",
  668. Width: 20,
  669. },
  670. {
  671. Label: "区域",
  672. Name: "area_name",
  673. Width: 10,
  674. },
  675. {
  676. Label: "工地",
  677. Name: "address",
  678. Width: 30,
  679. },
  680. {
  681. Label: "户型",
  682. Name: "room",
  683. Width: 30,
  684. },
  685. {
  686. Label: "门店",
  687. Name: "shop_name",
  688. Width: 15,
  689. },
  690. {
  691. Label: "部门",
  692. Name: "dept_name",
  693. Width: 15,
  694. },
  695. {
  696. Label: "设计师",
  697. Name: "designer_name",
  698. Width: 10,
  699. },
  700. {
  701. Label: "业务员",
  702. Name: "salesman_name",
  703. Width: 10,
  704. },
  705. {
  706. Label: "项目经理",
  707. Name: "manager_name",
  708. Width: 10,
  709. },
  710. {
  711. Label: "工程队长",
  712. Name: "project_leader_name",
  713. Width: 10,
  714. },
  715. {
  716. Label: "开工日期",
  717. Name: "starttime",
  718. Width: 20,
  719. },
  720. {
  721. Label: "完工日期",
  722. Name: "endtime",
  723. Width: 15,
  724. },
  725. {
  726. Label: "套餐",
  727. Name: "pkg_name",
  728. Width: 20,
  729. },
  730. {
  731. Label: "控额",
  732. Name: "write_control",
  733. Width: 10,
  734. },
  735. {
  736. Label: "工人申请",
  737. Name: "apply_control",
  738. Width: 10,
  739. },
  740. {
  741. Label: "工人项目",
  742. Name: "incomplete_table",
  743. Width: 10,
  744. },
  745. {
  746. Label: "辅材下单",
  747. Name: "no_order",
  748. Width: 10,
  749. },
  750. {
  751. Label: "材料订单",
  752. Name: "incomplete_order",
  753. Width: 10,
  754. },
  755. {
  756. Label: "结款",
  757. Name: "incomplete_payment",
  758. Width: 10,
  759. },
  760. {
  761. Label: "变更",
  762. Name: "incomplete_change",
  763. Width: 10,
  764. },
  765. {
  766. Label: "未申请工人项目",
  767. Name: "apply_control_name",
  768. Width: 20,
  769. },
  770. {
  771. Label: "未完成工人项目",
  772. Name: "incomplete_table_name",
  773. Width: 20,
  774. },
  775. {
  776. Label: "未下单辅材",
  777. Name: "no_order_name",
  778. Width: 20,
  779. },
  780. {
  781. Label: "未完成订单",
  782. Name: "incomplete_order_name",
  783. Width: 20,
  784. },
  785. {
  786. Label: "未完成结款",
  787. Name: "incomplete_payment_name",
  788. Width: 20,
  789. },
  790. {
  791. Label: "结算金额",
  792. Name: "settle_total",
  793. Width: 20,
  794. },
  795. {
  796. Label: "结算状态",
  797. Name: "settle_state",
  798. Width: 20,
  799. },
  800. {
  801. Label: "项目经理未完成",
  802. Name: "manager_count",
  803. Width: 20,
  804. },
  805. {
  806. Label: "工程队长未完成",
  807. Name: "leader_count",
  808. Width: 20,
  809. },
  810. {
  811. Label: "财务未完成",
  812. Name: "finance_count",
  813. Width: 20,
  814. },
  815. {
  816. Label: "成控未完成",
  817. Name: "audit_count",
  818. Width: 20,
  819. },
  820. {
  821. Label: "店长未完成",
  822. Name: "shopowner_count",
  823. Width: 20,
  824. },
  825. {
  826. Label: "客服未完成",
  827. Name: "customer_count",
  828. Width: 20,
  829. },
  830. {
  831. Label: "下单员未完成",
  832. Name: "place_count",
  833. Width: 20,
  834. },
  835. {
  836. Label: "材料商未完成",
  837. Name: "supplier_count",
  838. Width: 20,
  839. },
  840. {
  841. Label: "工人待汇总",
  842. Name: "table_incomplete_collect_count",
  843. Width: 20,
  844. },
  845. {
  846. Label: "材料待汇总",
  847. Name: "order_incomplete_collect_count",
  848. Width: 20,
  849. },
  850. {
  851. Label: "材料待备货",
  852. Name: "order_state0_count",
  853. Width: 20,
  854. },
  855. {
  856. Label: "材料已备货",
  857. Name: "order_state1_count",
  858. Width: 20,
  859. },
  860. {
  861. Label: "材料待配送",
  862. Name: "order_state2_count",
  863. Width: 20,
  864. },
  865. {
  866. Label: "材料待收货",
  867. Name: "order_state3_count",
  868. Width: 20,
  869. },
  870. {
  871. Label: "材料已收货",
  872. Name: "order_state4_count",
  873. Width: 20,
  874. },
  875. {
  876. Label: "材料待安装",
  877. Name: "order_state5_count",
  878. Width: 20,
  879. },
  880. {
  881. Label: "材料待验收",
  882. Name: "order_state6_count",
  883. Width: 20,
  884. },
  885. {
  886. Label: "材料已完成",
  887. Name: "order_state7_count",
  888. Width: 20,
  889. },
  890. {
  891. Label: "材料已下单",
  892. Name: "order_state8_count",
  893. Width: 20,
  894. },
  895. {
  896. Label: "材料待测量",
  897. Name: "order_state9_count",
  898. Width: 20,
  899. },
  900. {
  901. Label: "材料待审核",
  902. Name: "order_state10_count",
  903. Width: 20,
  904. },
  905. {
  906. Label: "材料待结算",
  907. Name: "order_state11_count",
  908. Width: 20,
  909. },
  910. {
  911. Label: "材料已结算",
  912. Name: "order_state12_count",
  913. Width: 20,
  914. },
  915. }
  916. }
  917. func (FinalSiteStatist) ExportValue(row map[string]interface{}, rowIndex int, field db.ExportField, data []map[string]interface{}) string {
  918. switch field.Name {
  919. case "address":
  920. worksite := /*db.ToString(v["address"]) + " " +*/ db.ToString(row["village"]) + "" + db.ToString(row["room_no"])
  921. if worksite == "" {
  922. worksite = db.ToString(row["address"])
  923. }
  924. if db.ToString(row["area"]) != "" {
  925. worksite += " " + db.ToString(row["area"]) + "㎡"
  926. }
  927. return worksite
  928. case "room":
  929. return db.ToString(row["room_1"]) + "室 " + db.ToString(row["room_2"]) + "厅 " + db.ToString(row["room_3"]) + "厨 " + db.ToString(row["room_4"]) + "卫 " + db.ToString(row["room_5"]) + "阳台"
  930. case "starttime":
  931. starttime, _ := db.ToInt64(row["starttime"])
  932. if starttime == 0 {
  933. return ""
  934. }
  935. t := time.Unix(starttime, 0).Local()
  936. return t.Format("2006-01-02 15:04")
  937. case "endtime":
  938. endtime, _ := db.ToInt64(row["endtime"])
  939. if endtime == 0 {
  940. return ""
  941. }
  942. t := time.Unix(endtime, 0).Local()
  943. return t.Format("2006-01-02")
  944. case "write_control":
  945. write_control, _ := db.ToInt64(row["write_control"])
  946. if write_control == 1 {
  947. return "未完成"
  948. }
  949. return "已完成"
  950. case "apply_control":
  951. apply_control, _ := db.ToInt64(row["apply_control"])
  952. if apply_control == 1 {
  953. return "未完成"
  954. }
  955. return "已完成"
  956. case "incomplete_table":
  957. incomplete_table, _ := db.ToInt64(row["incomplete_table"])
  958. if incomplete_table == 1 {
  959. return "未完成"
  960. }
  961. return "已完成"
  962. case "no_order":
  963. no_order, _ := db.ToInt64(row["no_order"])
  964. if no_order == 1 {
  965. return "未完成"
  966. }
  967. return "已完成"
  968. case "incomplete_order":
  969. incomplete_order, _ := db.ToInt64(row["incomplete_order"])
  970. if incomplete_order == 1 {
  971. return "未完成"
  972. }
  973. return "已完成"
  974. case "incomplete_payment":
  975. incomplete_payment, _ := db.ToInt64(row["incomplete_payment"])
  976. if incomplete_payment == 1 {
  977. return "未完成"
  978. }
  979. return "已完成"
  980. case "incomplete_change":
  981. incomplete_change, _ := db.ToInt64(row["incomplete_change"])
  982. if incomplete_change == 1 {
  983. return "未完成"
  984. }
  985. return "已完成"
  986. case "settle_total":
  987. settle_total := ""
  988. manager_price, _ := db.ToFloat64(row["manager_price"])
  989. if manager_price != 0 {
  990. settle_total += "承包额:" + db.ToString(manager_price) + "\n"
  991. }
  992. worker_price, _ := db.ToFloat64(row["worker_price"])
  993. if worker_price != 0 {
  994. settle_total += "工人:" + db.ToString(worker_price) + "\n"
  995. }
  996. auxiliary_price, _ := db.ToFloat64(row["auxiliary_price"])
  997. if auxiliary_price != 0 {
  998. settle_total += "辅材:" + db.ToString(auxiliary_price) + "\n"
  999. }
  1000. subsidy_price, _ := db.ToFloat64(row["subsidy_price"])
  1001. if subsidy_price != 0 {
  1002. settle_total += "补贴:" + db.ToString(subsidy_price) + "\n"
  1003. }
  1004. total, _ := db.ToFloat64(row["total"])
  1005. if total != 0 {
  1006. settle_total += "金额:" + db.ToString(total) + "\n"
  1007. }
  1008. return settle_total
  1009. case "settle_state":
  1010. settle_state, _ := db.ToInt64(row["settle_state"])
  1011. switch settle_state {
  1012. case 0:
  1013. return "未发起"
  1014. case 1:
  1015. return "客服回访"
  1016. case 2:
  1017. return "项目经理确认"
  1018. case 3:
  1019. return "财务审核"
  1020. case 4:
  1021. return "店长审核"
  1022. case 5:
  1023. return "财务付款"
  1024. case 6:
  1025. return "已完成"
  1026. }
  1027. return ""
  1028. }
  1029. return db.ToString(row[field.Name])
  1030. }
  1031. func (model FinalSiteStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  1032. return []db.JoinModel{
  1033. {
  1034. Model: FinalArea{},
  1035. As: "area",
  1036. On: []string{"`area`.`id` = " + model.TableName() + ".`area_id`"},
  1037. },
  1038. {
  1039. Model: JoinShop{},
  1040. As: "shop",
  1041. On: []string{"`shop`.`id` = " + model.TableName() + ".`shop_id`"},
  1042. },
  1043. {
  1044. Model: JoinDept{},
  1045. As: "dept",
  1046. On: []string{"`dept`.`id` = " + model.TableName() + ".`dept_id`"},
  1047. }, {
  1048. Model: JoinAdmin{},
  1049. As: "manager",
  1050. On: []string{"`manager`.`id` = " + model.TableName() + ".`manager_id`"},
  1051. }, {
  1052. Model: JoinAdmin{},
  1053. As: "project_leader",
  1054. On: []string{"`project_leader`.`id` = " + model.TableName() + ".`project_leader_id`"},
  1055. },
  1056. {
  1057. Model: JoinAdmin{},
  1058. As: "designer",
  1059. On: []string{"`designer`.`id` = " + model.TableName() + ".`designer_id`"},
  1060. },
  1061. {
  1062. Model: JoinAdmin{},
  1063. As: "salesman",
  1064. On: []string{"`salesman`.`id` = " + model.TableName() + ".`salesman_id`"},
  1065. },
  1066. {
  1067. Model: FinalPkg{},
  1068. As: "pkg",
  1069. On: []string{"`pkg`.`id` = " + model.TableName() + ".`pkg_id`"},
  1070. },
  1071. {
  1072. Model: JoinWriteControl{},
  1073. As: "write",
  1074. On: []string{"`write`.`site_id` = " + model.TableName() + ".`id`"},
  1075. },
  1076. {
  1077. Model: JoinPriceControl{},
  1078. As: "price",
  1079. On: []string{"`price`.`site_id` = " + model.TableName() + ".`id`"},
  1080. },
  1081. {
  1082. Model: JoinApplyControl{},
  1083. As: "apply",
  1084. On: []string{"`apply`.`site_id` = " + model.TableName() + ".`id`"},
  1085. },
  1086. {
  1087. Model: JoinStatistTable{},
  1088. As: "table",
  1089. On: []string{"`table`.`site_id` = " + model.TableName() + ".`id`"},
  1090. },
  1091. {
  1092. Model: JoinStatistMaterial{},
  1093. As: "material",
  1094. On: []string{"`material`.`site_id` = " + model.TableName() + ".`id`"},
  1095. },
  1096. {
  1097. Model: JoinStatistOrder{},
  1098. As: "order",
  1099. On: []string{"`order`.`site_id` = " + model.TableName() + ".`id`"},
  1100. },
  1101. {
  1102. Model: JoinStatistOrderAll{},
  1103. As: "orderall",
  1104. On: []string{"`orderall`.`site_id` = " + model.TableName() + ".`id`"},
  1105. },
  1106. {
  1107. Model: JoinStatistPayment{},
  1108. As: "payment",
  1109. On: []string{"`payment`.`site_id` = " + model.TableName() + ".`id`"},
  1110. },
  1111. {
  1112. Model: JoinStatistSettle{},
  1113. As: "settle",
  1114. On: []string{"`settle`.`site_id` = " + model.TableName() + ".`id`"},
  1115. },
  1116. }
  1117. }