eta_business.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package system
  2. /*
  3. const (
  4. EtaBusinessSigningStatusFirst = iota + 1
  5. EtaBusinessSigningStatusContinue
  6. EtaBusinessSigningStatusTerminate
  7. EtaBusinessSigningStatusWait
  8. )
  9. type EtaBusiness struct {
  10. EtaBusinessId int `orm:"column(eta_business_id);pk"`
  11. BusinessName string `description:"商家名称"`
  12. BusinessCode string `description:"商家编码"`
  13. CodeEncrypt string `description:"商家编码加密"`
  14. CreditCode string `description:"社会统一信用码"`
  15. RegionType string `description:"所属区域:国内;海外"`
  16. Province string `description:"省份"`
  17. City string `description:"城市"`
  18. Address string `description:"商家地址"`
  19. CreateTime time.Time `description:"创建时间"`
  20. ModifyTime time.Time `description:"更新时间"`
  21. }
  22. func (m *EtaBusiness) TableName() string {
  23. return "eta_business"
  24. }
  25. func (m *EtaBusiness) PrimaryId() string {
  26. return EtaBusinessColumns.EtaBusinessId
  27. }
  28. var EtaBusinessColumns = struct {
  29. EtaBusinessId string
  30. BusinessName string
  31. BusinessCode string
  32. CreditCode string
  33. RegionType string
  34. Province string
  35. City string
  36. Address string
  37. CreateTime string
  38. ModifyTime string
  39. }{
  40. EtaBusinessId: "eta_business_id",
  41. BusinessName: "business_name",
  42. BusinessCode: "business_code",
  43. CreditCode: "credit_code",
  44. RegionType: "region_type",
  45. Province: "province",
  46. City: "city",
  47. Address: "address",
  48. CreateTime: "create_time",
  49. ModifyTime: "modify_time",
  50. }
  51. func (m *EtaBusiness) Create() (err error) {
  52. o := orm.NewOrm()
  53. id, err := o.Insert(m)
  54. if err != nil {
  55. return
  56. }
  57. m.EtaBusinessId = int(id)
  58. return
  59. }
  60. func (m *EtaBusiness) CreateMulti(items []*EtaBusiness) (err error) {
  61. if len(items) == 0 {
  62. return
  63. }
  64. o := orm.NewOrm()
  65. _, err = o.InsertMulti(len(items), items)
  66. return
  67. }
  68. func (m *EtaBusiness) Update(cols []string) (err error) {
  69. o := orm.NewOrm()
  70. _, err = o.Update(m, cols...)
  71. return
  72. }
  73. func (m *EtaBusiness) Del() (err error) {
  74. o := orm.NewOrm()
  75. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  76. _, err = o.Raw(sql, m.EtaBusinessId).Exec()
  77. return
  78. }
  79. func (m *EtaBusiness) GetItemById(id int) (item *EtaBusiness, err error) {
  80. o := orm.NewOrm()
  81. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  82. err = o.Raw(sql, id).QueryRow(&item)
  83. return
  84. }
  85. func (m *EtaBusiness) GetItemByCondition(condition string, pars []interface{}) (item *EtaBusiness, err error) {
  86. o := orm.NewOrm()
  87. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  88. err = o.Raw(sql, pars).QueryRow(&item)
  89. return
  90. }
  91. func (m *EtaBusiness) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  92. o := orm.NewOrm()
  93. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  94. err = o.Raw(sql, pars).QueryRow(&count)
  95. return
  96. }
  97. func (m *EtaBusiness) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EtaBusiness, err error) {
  98. o := orm.NewOrm()
  99. fields := strings.Join(fieldArr, ",")
  100. if len(fieldArr) == 0 {
  101. fields = `*`
  102. }
  103. order := `ORDER BY create_time DESC`
  104. if orderRule != "" {
  105. order = ` ORDER BY ` + orderRule
  106. }
  107. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  108. _, err = o.Raw(sql, pars).QueryRows(&items)
  109. return
  110. }
  111. func (m *EtaBusiness) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaBusiness, err error) {
  112. o := orm.NewOrm()
  113. fields := strings.Join(fieldArr, ",")
  114. if len(fieldArr) == 0 {
  115. fields = `*`
  116. }
  117. order := `ORDER BY create_time DESC`
  118. if orderRule != "" {
  119. order = ` ORDER BY ` + orderRule
  120. }
  121. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  122. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  123. return
  124. }
  125. // EtaBusinessAddReq 新增商家请求体
  126. type EtaBusinessAddReq struct {
  127. BusinessName string `description:"商家名称"`
  128. CreditCode string `description:"社会统一信用码"`
  129. RegionType string `description:"所属区域:国内;海外"`
  130. Province string `description:"省份"`
  131. City string `description:"城市"`
  132. SellerId int `description:"销售ID"`
  133. SellerName string `description:"销售名称"`
  134. Leader string `description:"决策人"`
  135. IndustryId int `description:"行业ID"`
  136. IndustryName string `description:"行业名称"`
  137. CapitalScale string `description:"资金规模"`
  138. ResearchTeamSize string `description:"研究团队规模"`
  139. UserMax int `description:"用户上限"`
  140. SigningTime string `description:"签约时间"`
  141. ExpiredTime string `description:"到期时间"`
  142. IsCheck bool `description:"是否只做校验而不实际新增(业务操作上基础信息和签约时间分成两个步骤了)"`
  143. }
  144. // EtaBusinessEditReq 编辑商家请求体
  145. type EtaBusinessEditReq struct {
  146. EtaBusinessId int `description:"商家ID"`
  147. Province string `description:"省份"`
  148. City string `description:"城市"`
  149. Leader string `description:"决策人"`
  150. IndustryId int `description:"行业ID"`
  151. IndustryName string `description:"行业名称"`
  152. CapitalScale string `description:"资金规模"`
  153. ResearchTeamSize string `description:"研究团队规模"`
  154. UserMax int `description:"用户上限"`
  155. }
  156. // EtaBusinessSigningReq 商家签约请求体
  157. type EtaBusinessSigningReq struct {
  158. EtaBusinessId int `description:"商家ID"`
  159. SigningTime string `description:"当前合约的签约时间"`
  160. ExpiredTime string `description:"当前合约的到期时间"`
  161. }
  162. // EtaBusinessEnableReq 禁启用商家请求体
  163. type EtaBusinessEnableReq struct {
  164. EtaBusinessId int `description:"商家ID"`
  165. }
  166. // EtaBusinessMoveSellerReq 移动商家销售请求体
  167. type EtaBusinessMoveSellerReq struct {
  168. EtaBusinessId int `description:"商家ID"`
  169. SellerId int `description:"销售ID"`
  170. SellerName string `description:"销售名称"`
  171. }
  172. // CreateEtaBusinessCode 生成ETA商家编码
  173. func CreateEtaBusinessCode() (code string, err error) {
  174. var num int
  175. o := orm.NewOrm()
  176. sql := `SELECT COUNT(1) AS num FROM eta_business WHERE create_time >= ? `
  177. err = o.Raw(sql, time.Now().Format(utils.FormatDate)).QueryRow(&num)
  178. if err != nil {
  179. return
  180. }
  181. code = "E" + time.Now().Format("20060102") + fmt.Sprintf("%02d", num)
  182. return
  183. }
  184. // EtaBusinessListResp 商家分页列表响应体
  185. type EtaBusinessListResp struct {
  186. List []*EtaBusinessItem `description:"商家列表数据"`
  187. Paging *paging.PagingItem `description:"分页数据"`
  188. }
  189. // EtaBusinessItem ETA商家信息
  190. type EtaBusinessItem struct {
  191. EtaBusinessId int
  192. BusinessName string `description:"商家名称"`
  193. BusinessCode string `description:"商家编码"`
  194. CreditCode string `description:"社会统一信用码"`
  195. RegionType string `description:"所属区域:国内;海外"`
  196. Province string `description:"省份"`
  197. City string `description:"城市"`
  198. Address string `description:"商家地址"`
  199. SellerId int `description:"销售ID"`
  200. SellerName string `description:"销售名称"`
  201. Leader string `description:"决策人"`
  202. IndustryId int `description:"行业ID"`
  203. IndustryName string `description:"行业名称"`
  204. CapitalScale string `description:"资金规模"`
  205. ResearchTeamSize string `description:"研究团队规模"`
  206. UserMax int `description:"用户上限"`
  207. SigningStatus int `description:"签约状态:1-首次签约;2-续约中;3-已终止"`
  208. Enable int `description:"状态:0-禁用;1-启用"`
  209. ContractId int `description:"当前合约ID"`
  210. SigningTime string `description:"当前合约的签约时间"`
  211. ExpiredTime string `description:"当前合约的到期时间"`
  212. CreateTime string `description:"创建时间"`
  213. ModifyTime string `description:"更新时间"`
  214. }
  215. */