eta_trial_approval.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package eta_trial
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type EtaTrialApproval struct {
  8. ApprovalId int `orm:"column(approval_id);pk" description:"eta审批id"`
  9. UserName string `description:"客户名称"`
  10. CompanyName string `description:"客户公司姓名"`
  11. Position string `description:"职位"`
  12. Mobile string `description:"手机号"`
  13. SellerId int `description:"销售id"`
  14. Seller string `description:"销售员名称"`
  15. CreateTime time.Time
  16. ModifyTime time.Time
  17. ApprovalContent string `description:"待审内容"`
  18. ApplyMethod int `description:"申请类型:1:申请账号 2:申请启用"`
  19. ApplyReasons string `description:"申请理由"`
  20. ApprovalRemark string `description:"审批描述"`
  21. ApprovalStatus string `description:"审批状态 '待审批','已审批','驳回','已撤回'"`
  22. }
  23. func GetETATrialApprovalByMobile(mobile string) (item *EtaTrialApproval, err error) {
  24. sql := `SELECT * FROM eta_trial_approval WHERE mobile = ? ORDER BY create_time DESC LIMIT 1`
  25. o := orm.NewOrm()
  26. err = o.Raw(sql, mobile).QueryRow(&item)
  27. return
  28. }
  29. // AddETATrialApproval 新增审批
  30. func AddETATrialApproval(item *EtaTrialApproval) (lastId int64, err error) {
  31. o := orm.NewOrm()
  32. lastId, err = o.Insert(item)
  33. return
  34. }
  35. type ETATrialListResp struct {
  36. BannedList []*ETATrialAddRespItem
  37. RepeatList []*ETATrialAddRespItem
  38. SuccessList []*ETATrialAddRespItem
  39. InternalList []*ETATrialAddRespItem
  40. }
  41. type ETATrialAddRespItem struct {
  42. UserName string `description:"客户名称"`
  43. CompanyName string `description:"客户公司姓名"`
  44. Position string `description:"职位"`
  45. Mobile string `description:"手机号"`
  46. Seller string `description:"销售"`
  47. }
  48. type ETAAddEnableReq struct {
  49. UserName string `description:"客户名称"`
  50. CompanyName string `description:"客户公司姓名"`
  51. Position string `description:"职位"`
  52. Mobile string `description:"手机号"`
  53. ApplyReasons string `description:"申请理由"`
  54. }
  55. type ETATrialApplyRevokeReq struct {
  56. Mobile string `description:"客户手机号"`
  57. }
  58. // 消息撤回
  59. func RevokeApproval(mobile string) (err error) {
  60. o := orm.NewOrm()
  61. sql := `UPDATE eta_trial_approval SET approval_status=4,modify_time=NOW()
  62. WHERE mobile=? AND approval_status=1 `
  63. _, err = o.Raw(sql, mobile).Exec()
  64. return
  65. }
  66. func DelApproval(approvalId int) (err error) {
  67. o := orm.NewOrm()
  68. sql := `DELETE FROM eta_trial_approval WHERE approval_id = ? `
  69. _, err = o.Raw(sql, approvalId).Exec()
  70. return
  71. }
  72. func RejectApproval(approvalId int, reason string) (err error) {
  73. o := orm.NewOrm()
  74. sql := `UPDATE eta_trial_approval SET approval_status=3,modify_time=NOW(), approval_remark = ?
  75. WHERE approval_id=? `
  76. _, err = o.Raw(sql, reason, approvalId).Exec()
  77. return
  78. }
  79. func ApprovalTrial(approvalId int) (err error) {
  80. o := orm.NewOrm()
  81. sql := `UPDATE eta_trial_approval SET approval_status=2,modify_time=NOW()
  82. WHERE approval_id=? `
  83. _, err = o.Raw(sql, approvalId).Exec()
  84. return
  85. }
  86. func GetETATrialApprovalById(approvalId int) (item *EtaTrialApproval, err error) {
  87. sql := `SELECT * FROM eta_trial_approval WHERE approval_id = ? `
  88. o := orm.NewOrm()
  89. err = o.Raw(sql, approvalId).QueryRow(&item)
  90. return
  91. }
  92. func GetETATrialApprovalBySellerId(condition, sortStr string, pars []interface{}, startSize, pageSize int) (items []*EtaTrialApprovalResp, err error) {
  93. sql := `SELECT
  94. a.*, b.account, b.password
  95. FROM
  96. eta_trial_approval AS a
  97. LEFT JOIN eta_trial AS b ON a.mobile = b.mobile AND a.approval_status = '已审批'
  98. WHERE
  99. 1 = 1 AND a.seller_id = ? `
  100. o := orm.NewOrm()
  101. if condition != "" {
  102. sql += condition
  103. }
  104. sql += sortStr + ` LIMIT ?,? `
  105. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  106. return
  107. }
  108. func GetETATrialApprovalCountBySellerId(condition, sortStr string, pars []interface{}) (count int, err error) {
  109. sql := `SELECT COUNT(1) AS count FROM eta_trial_approval AS a WHERE 1=1 AND a.seller_id = ? `
  110. o := orm.NewOrm()
  111. if condition != "" {
  112. sql += condition
  113. }
  114. err = o.Raw(sql, pars).QueryRow(&count)
  115. return
  116. }
  117. type ETATrialApprovalListRespList struct {
  118. List []*EtaTrialApprovalResp
  119. Paging *paging.PagingItem
  120. }
  121. type EtaTrialApprovalResp struct {
  122. ApprovalId int `orm:"column(approval_id);pk" description:"eta审批id"`
  123. UserName string `description:"客户名称"`
  124. CompanyName string `description:"客户公司姓名"`
  125. Position string `description:"职位"`
  126. Mobile string `description:"手机号"`
  127. SellerId int `description:"销售id"`
  128. Seller string `description:"销售员名称"`
  129. CreateTime string
  130. ModifyTime string
  131. ApprovalContent string `description:"待审内容"`
  132. ApplyMethod int `description:"申请类型:1:申请账号 2:申请启用"`
  133. ApplyReasons string `description:"申请理由"`
  134. ApprovalRemark string `description:"审批描述"`
  135. ApprovalStatus string `description:"审批状态 '待审批','已审批','驳回','已撤回'"`
  136. Account string `description:"账号"`
  137. Password string `description:"密码-明文"`
  138. }
  139. func GetETATrialApprovalList(condition, sortStr string, pars []interface{}, startSize, pageSize int) (items []*EtaTrialApprovalResp, err error) {
  140. sql := `SELECT * FROM eta_trial_approval WHERE 1=1 `
  141. o := orm.NewOrm()
  142. if condition != "" {
  143. sql += condition
  144. }
  145. sql += sortStr + ` LIMIT ?,? `
  146. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  147. return
  148. }
  149. func GetETATrialApprovalListCount(condition string, pars []interface{}) (count int, err error) {
  150. sql := `SELECT COUNT(1) AS count FROM eta_trial_approval WHERE 1=1 `
  151. o := orm.NewOrm()
  152. if condition != "" {
  153. sql += condition
  154. }
  155. err = o.Raw(sql, pars).QueryRow(&count)
  156. return
  157. }
  158. type RevokeReq struct {
  159. Mobile string
  160. }
  161. type DelReq struct {
  162. ApprovalId int
  163. }
  164. type RejectReq struct {
  165. ApprovalId int
  166. RejectReason string
  167. }
  168. func ResubmitTrialNoReasons(userName, companyName, position string, approvalId int) (err error) {
  169. o := orm.NewOrm()
  170. sql := `UPDATE eta_trial_approval SET approval_status=1,modify_time=NOW(), user_name = ?,company_name=?, position= ?
  171. WHERE approval_id=? `
  172. _, err = o.Raw(sql, userName, companyName, position, approvalId).Exec()
  173. return
  174. }
  175. func ResubmitTrial(approvalId int, applyReasons string) (err error) {
  176. o := orm.NewOrm()
  177. sql := `UPDATE eta_trial_approval SET approval_status=1,modify_time=NOW(), apply_reasons = ?
  178. WHERE approval_id=? `
  179. _, err = o.Raw(sql, applyReasons, approvalId).Exec()
  180. return
  181. }