dispatch_site_table.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package dispatch
  2. import (
  3. "errors"
  4. "fmt"
  5. "zhiyuan/pkg/db"
  6. "github.com/gin-gonic/gin"
  7. "github.com/xuri/excelize/v2"
  8. )
  9. type DispatchSiteTable struct {
  10. ID int64 `json:"id" prop:"add:false"`
  11. TypeId int64 `json:"type_id" label:"类型" type:"int" prop:"add edit" search:"="`
  12. SiteId int64 `json:"site_id" label:"工地" type:"int" prop:"add edit" search:"="`
  13. CollectId int64 `json:"collect_id" label:"汇总ID" type:"int" prop:"add:false" search:"="`
  14. WorkerId int64 `json:"worker_id" label:"工人" type:"int" prop:"add:false" search:"="`
  15. Budget float64 `json:"budget" label:"预算" type:"float" prop:"edit" default:"0"`
  16. Image string `json:"image" label:"图片" type:"string" prop:"edit" default:""`
  17. State int64 `json:"state" label:"状态" type:"int" prop:"add:false" default:"0" search:"="`
  18. Tip int64 `json:"tip" label:"标记" type:"int" prop:"add:false edit" default:"0"`
  19. WorkerName string `json:"worker_name" label:"工人姓名" prop:"add:false select:worker.name"`
  20. WorkerPhone string `json:"worker_phone" label:"工人电话" prop:"add:false select:worker.phone"`
  21. BankName string `json:"bank_name" label:"开户行" prop:"add:false select:worker.bank_name"`
  22. BankCardNo string `json:"bank_card_no" label:"银行卡号" prop:"add:false select:worker.bank_card_no"`
  23. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  24. CreatedAt int64 `json:"created_at" prop:"add:false"`
  25. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  26. db.BaseModel
  27. }
  28. func (DispatchSiteTable) TableName() string {
  29. return "zy_dispatch_site_table"
  30. }
  31. func (model DispatchSiteTable) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  32. return true
  33. }
  34. func (DispatchSiteTable) OnePrivilege(c *gin.Context, id int64) bool {
  35. return true
  36. }
  37. func (DispatchSiteTable) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  38. typ, _ := db.ToInt64(data["type_id"])
  39. site_id, _ := db.ToInt64(data["site_id"])
  40. table, _ := db.GetModelMap(db.Type(DispatchSiteTable{}), map[string]interface{}{"type_id": typ, "site_id": site_id, "deleted_at": 0}, nil)
  41. if table != nil {
  42. return errors.New("没有权限")
  43. }
  44. return nil
  45. }
  46. func (DispatchSiteTable) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
  47. typ, _ := db.ToInt64(data["type_id"])
  48. items, _ := db.GetModelMap(db.Type(DispatchTypeItem{}), map[string]interface{}{"type_id": typ}, nil)
  49. if items == nil {
  50. return
  51. }
  52. for _, v := range items {
  53. db.InsertModel(db.Type(DispatchSiteItem{}), map[string]interface{}{
  54. "table_id": id,
  55. "name": v["name"],
  56. "unit": v["unit"],
  57. "price": v["price"],
  58. "num": 0,
  59. })
  60. }
  61. }
  62. func (DispatchSiteTable) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  63. return nil
  64. }
  65. func (DispatchSiteTable) DelPrivilege(c *gin.Context, id int64) error {
  66. return nil
  67. }
  68. func (DispatchSiteTable) Page() bool {
  69. return false
  70. }
  71. func (DispatchSiteTable) Count() bool {
  72. return true
  73. }
  74. type JoinWorker struct {
  75. db.BaseModel
  76. }
  77. func (JoinWorker) TableName() string {
  78. return "zy_worker"
  79. }
  80. func (model DispatchSiteTable) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  81. return []db.JoinModel{{
  82. Model: JoinWorker{},
  83. As: "worker",
  84. On: []string{"`worker`.`id` = " + model.TableName() + ".`worker_id`"},
  85. }}
  86. }
  87. type DispatchSiteTableMobile struct {
  88. Username string `json:"username" label:"业主姓名" prop:"select:dispatchsite.username" search:"like"`
  89. Phone string `json:"phone" label:"手机号码" prop:"select:dispatchsite.phone" search:"like"`
  90. Village string `json:"village" label:"小区名称" prop:"select:dispatchsite.village" search:"like"`
  91. Address string `json:"address" label:"房屋地址" prop:"select:dispatchsite.address" search:"like"`
  92. RoomNo string `json:"room_no" label:"楼栋房号" prop:"select:dispatchsite.room_no" search:"like"`
  93. Area string `json:"area" label:"面积" prop:"select:dispatchsite.area"`
  94. ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"select:dispatchsite.shop_id" search:"="`
  95. ShopName int64 `json:"shop_name" label:"门店" prop:"select:shop.shop_name"`
  96. Name string `json:"name" label:"类别名称" prop:"select:dispatchtype.name"`
  97. WorkTypeId int64 `json:"work_type_id" label:"工种" prop:"select:dispatchtype.work_type_id"`
  98. WorkTypeName string `json:"work_type_name" label:"工种名称" prop:"select:worktype.name"`
  99. WorkIdcode string `json:"work_idcode" label:"工人身份证号码" prop:"select:worker.idcode"`
  100. Total float64 `json:"total" label:"合计" prop:"select:ROUND(sum(dispatchsiteitem.price*num))"`
  101. Remark string `json:"remark" label:"备注" prop:"select:GROUP_CONCAT(dispatchsiteitem.remark)"`
  102. DispatchSiteTable
  103. }
  104. func (model DispatchSiteTableMobile) GroupBy() string {
  105. return fmt.Sprintf("`%s`.`id`", model.TableName())
  106. }
  107. type JoinWorkType struct {
  108. db.BaseModel
  109. }
  110. func (JoinWorkType) TableName() string {
  111. return "zy_work_type"
  112. }
  113. func (model DispatchSiteTableMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  114. return append(model.DispatchSiteTable.LeftJoin(data, s), db.JoinModel{
  115. Model: DispatchType{},
  116. As: "dispatchtype",
  117. On: []string{"`dispatchtype`.`id` = " + model.TableName() + ".`type_id`"},
  118. }, db.JoinModel{
  119. Model: JoinWorkType{},
  120. As: "worktype",
  121. On: []string{"`worktype`.`id` = `dispatchtype`.`work_type_id`"},
  122. },
  123. db.JoinModel{
  124. Model: DispatchSiteItem{},
  125. As: "dispatchsiteitem",
  126. On: []string{"`dispatchsiteitem`.`table_id` = " + model.TableName() + ".`id`"},
  127. }, db.JoinModel{
  128. Model: DispatchSite{},
  129. As: "dispatchsite",
  130. On: []string{"`dispatchsite`.`id` = " + model.TableName() + ".`site_id`"},
  131. }, db.JoinModel{
  132. Model: JoinShop{},
  133. As: "shop",
  134. On: []string{"`shop`.`id` = `dispatchsite`.`shop_id`"},
  135. })
  136. }
  137. func (DispatchSiteTableMobile) Export(model db.Model, data []map[string]interface{}, file *excelize.File) [][]string {
  138. rows := make([][]string, 0)
  139. states := []string{"未提交", "工程队长审核", "预审审核", "店长审核", "财务审核", "已完成"}
  140. header := []string{"ID", "门店", "工地", "类型", "工人姓名", "开户行", "银行卡号", "金额", "身份证号码", "备注", "状态"}
  141. rows = append(rows, header)
  142. for _, v := range data {
  143. worksite := /*db.ToString(v["address"]) + " " +*/ db.ToString(v["village"]) + "" + db.ToString(v["room_no"])
  144. /*if db.ToString(v["area"]) != "" {
  145. worksite += " " + db.ToString(v["area"])
  146. }*/
  147. worker := ""
  148. if worker_id, ok := db.ToInt64(v["worker_id"]); ok && worker_id != 0 {
  149. worker = db.ToString(v["worker_name"]) /*+ " " + db.ToString(v["worker_phone"])*/
  150. }
  151. state := int64(0)
  152. if t, ok := db.ToInt64(v["state"]); ok {
  153. state = t
  154. }
  155. row := []string{
  156. db.ToString(v["id"]),
  157. db.ToString(v["shop_name"]),
  158. worksite,
  159. db.ToString(v["name"]),
  160. worker,
  161. db.ToString(v["bank_name"]),
  162. db.ToString(v["bank_card_no"]),
  163. db.ToString(v["total"]),
  164. db.ToString(v["work_idcode"]),
  165. db.ToString(v["remark"]),
  166. states[state],
  167. }
  168. rows = append(rows, row)
  169. }
  170. return rows
  171. }
  172. type DispatchSiteTableCollect struct {
  173. ManagerName string `json:"manager_name" prop:"select:manager.username"`
  174. ManagerPhone string `json:"manager_phone" prop:"select:manager.phone"`
  175. ProjectLeaderName string `json:"projectleader_name" prop:"select:projectleader.username"`
  176. ProjectLeaderPhone string `json:"projectleader_phone" prop:"select:projectleader.phone"`
  177. DispatchSiteTableMobile
  178. }
  179. func (model DispatchSiteTableCollect) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  180. if shopId, _ := db.ToInt64(data["shop_id"]); shopId == 0 {
  181. s.Where = append(s.Where, "(1!=1)")
  182. }
  183. return true
  184. }
  185. func (DispatchSiteTableCollect) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  186. return nil
  187. }
  188. func (DispatchSiteTableCollect) DelPrivilege(c *gin.Context, id int64) error {
  189. return errors.New("没有权限")
  190. }
  191. func (model DispatchSiteTableCollect) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  192. return append(model.DispatchSiteTableMobile.LeftJoin(data, s),
  193. db.JoinModel{
  194. Model: JoinAdmin{},
  195. As: "manager",
  196. On: []string{"`manager`.`id` = `dispatchsite`.`manager_id`"},
  197. },
  198. db.JoinModel{
  199. Model: JoinAdmin{},
  200. As: "projectleader",
  201. On: []string{"`projectleader`.`id` = `dispatchsite`.`project_leader_id`"},
  202. },
  203. )
  204. }