final_site.go 51 KB

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