面包店
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

há 8 meses
há 6 meses
há 8 meses
há 8 meses
há 6 meses
há 8 meses
há 8 meses
há 6 meses
há 8 meses
há 6 meses
há 8 meses
há 6 meses
há 8 meses
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package hdl
  2. import (
  3. "applet/app/admin/enum"
  4. "applet/app/admin/lib/validate"
  5. "applet/app/admin/md"
  6. "applet/app/admin/svc"
  7. "applet/app/db"
  8. "applet/app/db/model"
  9. "applet/app/e"
  10. "github.com/gin-gonic/gin"
  11. "time"
  12. )
  13. func EnterpriseList(c *gin.Context) {
  14. var req md.EnterpriseListReq
  15. err := c.ShouldBindJSON(&req)
  16. if err != nil {
  17. err = validate.HandleValidateErr(err)
  18. err1 := err.(e.E)
  19. e.OutErr(c, err1.Code, err1.Error())
  20. return
  21. }
  22. enterpriseDb := db.EnterpriseDb{}
  23. enterpriseDb.Set()
  24. engine := enterpriseDb.Db.Desc("enterprise.id").Limit(req.Limit, (req.Page-1)*req.Limit)
  25. if req.Name != "" {
  26. engine.And("enterprise.name like ?", "%"+req.Name+"%")
  27. }
  28. if req.InsideName != "" {
  29. engine.And("enterprise.inside_name like ?", "%"+req.InsideName+"%")
  30. }
  31. if req.Memo != "" {
  32. engine.And("enterprise.memo like ?", "%"+req.Memo+"%")
  33. }
  34. if req.LeadPhone != "" {
  35. engine.And("company.lead_phone like ?", "%"+req.LeadPhone+"%")
  36. }
  37. if req.LeadName != "" {
  38. engine.And("company.lead_name like ?", "%"+req.LeadName+"%")
  39. }
  40. var list []db.EnterpriseWithCompany
  41. count, err := engine.Join("LEFT", "company", "enterprise.company_id = company.id").
  42. FindAndCount(&list)
  43. if err != nil {
  44. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  45. return
  46. }
  47. var result []md.EnterpriseListResp
  48. for _, v := range list {
  49. result = append(result, md.EnterpriseListResp{
  50. Id: v.Enterprise.Id,
  51. State: v.Enterprise.State,
  52. Name: v.Enterprise.Name,
  53. InsideName: v.Enterprise.InsideName,
  54. Memo: v.Enterprise.Memo,
  55. CompanyName: v.Company.Name,
  56. CompanyId: v.Company.Id,
  57. LeadName: v.Company.LeadName,
  58. LeadPhone: v.Company.LeadPhone,
  59. CreateAt: v.Enterprise.CreateAt,
  60. UpdateAt: v.Enterprise.UpdateAt,
  61. })
  62. }
  63. e.OutSuc(c, map[string]interface{}{
  64. "list": result,
  65. "total": count,
  66. "state": []map[string]interface{}{
  67. {
  68. "name": enum.EnterpriseState(enum.EnterpriseStateForNormal).String(),
  69. "value": enum.EnterpriseStateForNormal,
  70. },
  71. {
  72. "name": enum.EnterpriseState(enum.EnterpriseStateForFreeze).String(),
  73. "value": enum.EnterpriseStateForFreeze,
  74. },
  75. },
  76. }, nil)
  77. return
  78. }
  79. func EnterpriseUpdateState(c *gin.Context) {
  80. var req md.EnterpriseUpdateStateReq
  81. err := c.ShouldBindJSON(&req)
  82. if err != nil {
  83. err = validate.HandleValidateErr(err)
  84. err1 := err.(e.E)
  85. e.OutErr(c, err1.Code, err1.Error())
  86. return
  87. }
  88. enterpriseDb := db.EnterpriseDb{}
  89. enterpriseDb.Set()
  90. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  91. if err != nil {
  92. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  93. return
  94. }
  95. if enterprise == nil {
  96. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  97. return
  98. }
  99. now := time.Now()
  100. enterprise.State = req.State
  101. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  102. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  103. if err != nil {
  104. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  105. return
  106. }
  107. e.OutSuc(c, "success", nil)
  108. return
  109. }
  110. func EnterpriseDelete(c *gin.Context) {
  111. var req md.EnterpriseDeleteReq
  112. err := c.ShouldBindJSON(&req)
  113. if err != nil {
  114. err = validate.HandleValidateErr(err)
  115. err1 := err.(e.E)
  116. e.OutErr(c, err1.Code, err1.Error())
  117. return
  118. }
  119. err = svc.EnterpriseDelete(req.EnterpriseIds)
  120. if err != nil {
  121. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  122. return
  123. }
  124. e.OutSuc(c, "success", nil)
  125. return
  126. }
  127. func EnterpriseAdd(c *gin.Context) {
  128. var req md.EnterpriseAddReq
  129. err := c.ShouldBindJSON(&req)
  130. if err != nil {
  131. err = validate.HandleValidateErr(err)
  132. err1 := err.(e.E)
  133. e.OutErr(c, err1.Code, err1.Error())
  134. return
  135. }
  136. enterpriseDb := db.EnterpriseDb{}
  137. enterpriseDb.Set()
  138. now := time.Now()
  139. enterprise := model.Enterprise{
  140. Name: req.Name,
  141. InsideName: req.InsideName,
  142. CompanyId: req.CompanyId,
  143. State: enum.EnterpriseStateForNormal,
  144. Memo: req.Memo,
  145. CreateAt: now.Format("2006-01-02 15:04:05"),
  146. UpdateAt: now.Format("2006-01-02 15:04:05"),
  147. }
  148. _, err = enterpriseDb.EnterpriseInsert(&enterprise)
  149. if err != nil {
  150. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  151. return
  152. }
  153. e.OutSuc(c, "success", nil)
  154. return
  155. }
  156. func EnterpriseUpdate(c *gin.Context) {
  157. var req md.EnterpriseUpdateReq
  158. err := c.ShouldBindJSON(&req)
  159. if err != nil {
  160. err = validate.HandleValidateErr(err)
  161. err1 := err.(e.E)
  162. e.OutErr(c, err1.Code, err1.Error())
  163. return
  164. }
  165. enterpriseDb := db.EnterpriseDb{}
  166. enterpriseDb.Set()
  167. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  168. if err != nil {
  169. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  170. return
  171. }
  172. if enterprise == nil {
  173. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  174. return
  175. }
  176. now := time.Now()
  177. enterprise.Name = req.Name
  178. enterprise.InsideName = req.InsideName
  179. enterprise.Memo = req.Memo
  180. enterprise.CompanyId = req.CompanyId
  181. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  182. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "update_at", "inside_name")
  183. if err != nil {
  184. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  185. return
  186. }
  187. e.OutSuc(c, "success", nil)
  188. return
  189. }