final_site.go 52 KB

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