company_apply.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. package company
  2. import (
  3. "errors"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_api/utils"
  6. "time"
  7. )
  8. // 申请服务更新请求参数
  9. type CompanyApplyServiceUpdateReq struct {
  10. CompanyId int `description:"客户id"`
  11. CompanyApprovalId int `description:"申请单id,没有传0"`
  12. ContractType string `description:"合同类型,枚举值:'新签合同','续约合同','补充协议'"`
  13. CompanyType string `description:"客户类型,ficc/权益"`
  14. StartDate string `description:"合同开始日期"`
  15. EndDate string `description:"合同结束日期"`
  16. Money float64 `description:"合同金额"`
  17. PayMethod string `description:"付款方式"`
  18. PayChannel string `description:"付款渠道"`
  19. PermissionIds string `description:"权限id,多个用英文逗号隔开"`
  20. ImgUrl string `description:"合同图片,多个用英文#隔开"`
  21. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  22. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w套餐; 2-45w套餐"`
  23. }
  24. type ApproveUser struct {
  25. AdminId int
  26. RealName string
  27. Mobile string
  28. }
  29. // 获取审批人
  30. func GetApproveUser(roleTypeCode string) (items []*ApproveUser, err error) {
  31. o := orm.NewOrm()
  32. sql := `SELECT admin_id,real_name,mobile FROM admin WHERE role_type_code=? AND admin_name<>'qshi' `
  33. _, err = o.Raw(sql, roleTypeCode).QueryRows(&items)
  34. return
  35. }
  36. type CompanyContractHistory struct {
  37. CompanyContractId int `json:"-" description:"合同id"`
  38. CompanyId int `description:"客户id"`
  39. ContractCode string `description:"合同编码"`
  40. ContractType string `description:"合同类型,枚举值:'新签合同','续约合同','补充协议'"`
  41. StartDate string `description:"合同开始时间"`
  42. EndDate string `description:"合同结束时间"`
  43. Money float64 `description:"合同金额"`
  44. PayMethod string `description:"支付方式"`
  45. PayChannel string `description:"支付渠道"`
  46. ImgUrl string `description:"合同图片,多个用#隔开"`
  47. CreateTime time.Time `description:"合同创建时间"`
  48. ModifyTime time.Time `description:"合同修改时间";json:"-"`
  49. ModifyTimeStr string `description:"合同修改时间"`
  50. Status int `description:"状态"`
  51. ProductId int `description:"产品id"`
  52. ContractId int `description:"合同ID"`
  53. PermissionList []*ContractPermissionList
  54. }
  55. type CompanyContractHistoryResp struct {
  56. List []*CompanyContractHistory
  57. }
  58. func GetCompanyContractHistoryList(companyId int, productId string) (items []*CompanyContractHistory, err error) {
  59. o := orm.NewOrm()
  60. //sql := `SELECT * FROM company_contract WHERE company_id=? AND product_id IN(` + productId + `) AND status="1" ORDER BY modify_time DESC `
  61. sql := `SELECT
  62. a.*,
  63. b.contract_id
  64. FROM
  65. company_contract AS a
  66. LEFT JOIN contract AS b ON a.contract_code = b.contract_code
  67. WHERE
  68. a.company_id = ? AND a.product_id IN (` + productId + `) AND a.status = 1
  69. ORDER BY
  70. a.modify_time DESC`
  71. _, err = o.Raw(sql, companyId).QueryRows(&items)
  72. return
  73. }
  74. type CompanyContractDetail struct {
  75. CompanyContractId int
  76. CompanyId int `description:"客户id"`
  77. ProductId int `description:"产品id"`
  78. ContractCode string `description:"合同编码"`
  79. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  80. StartDate string `description:"合同开始时间"`
  81. EndDate string `description:"合同结束时间"`
  82. Money float64 `description:"合同金额"`
  83. PayMethod string `description:"支付方式"`
  84. PayChannel string `description:"支付渠道"`
  85. ImgUrl string `description:"合同图片,多个用#隔开"`
  86. CreateTime time.Time `description:"合同创建时间"`
  87. ModifyTime time.Time `description:"合同修改时间"`
  88. Status int `description:"状态"`
  89. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  90. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w套餐; 2-45w套餐"`
  91. Source string `description:"合同来源:上传附件, 系统合同"`
  92. SourceTag string `description:"合同来源标签:非标合同,标准合同"`
  93. PermissionList []*PermissionLookList
  94. }
  95. type CompanyContractDetailResp struct {
  96. Item *CompanyContractDetail
  97. }
  98. func GetCompanyContractDetail(companyId, productId, companyContractId int) (item *CompanyContractDetail, err error) {
  99. o := orm.NewOrm()
  100. if companyContractId == 0 {
  101. if productId <= 0 {
  102. err = errors.New("客户类型异常")
  103. }
  104. sql := `SELECT * FROM company_contract WHERE company_id=? AND product_id=? AND status=0 `
  105. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  106. } else {
  107. sql := `SELECT * FROM company_contract WHERE company_contract_id=? `
  108. err = o.Raw(sql, companyContractId).QueryRow(&item)
  109. }
  110. return
  111. }
  112. // 获取客户大于今天的最后一份有效合同
  113. func GetCompanyLastContractDetail(companyId, productId int) (item *CompanyContractDetail, err error) {
  114. o := orm.NewOrm()
  115. endDate := utils.GetToday(utils.FormatDate)
  116. sql := `SELECT * FROM company_contract WHERE company_id=? AND product_id=? AND status=1 AND end_date >= ? AND contract_type in ("新签合同","续约合同") order by end_date desc limit 1`
  117. err = o.Raw(sql, companyId, productId, endDate).QueryRow(&item)
  118. return
  119. }
  120. // 最后一次
  121. type ContractPermissionLookItemRes struct {
  122. ChartPermissionId int `description:"权限id"`
  123. PermissionName string `description:"权限名称"`
  124. StartDate time.Time `description:"权限开始日期"`
  125. EndDate time.Time `description:"权限结束日期"`
  126. //Status string `description:"'正式','试用','关闭'"`
  127. //ExpireDay string `description:"到期天数"`
  128. ClassifyName string `description:"分类"`
  129. }
  130. // 获取客户大于今天的所有有效合同
  131. func GetCompanyWillContractList(companyId, productId int) (list []*CompanyContractDetail, err error) {
  132. o := orm.NewOrm()
  133. endDate := utils.GetToday(utils.FormatDate)
  134. sql := `SELECT * FROM company_contract WHERE company_id=? AND product_id=? AND status=1 AND end_date >= ? AND contract_type in ("新签合同","续约合同") order by end_date desc`
  135. _, err = o.Raw(sql, companyId, productId, endDate).QueryRows(&list)
  136. return
  137. }
  138. func GetCompanyContractApproveCount(companyId, productId int) (count int, err error) {
  139. o := orm.NewOrm()
  140. sql := `SELECT COUNT(1) AS count FROM company_contract WHERE company_id=? AND product_id=? AND status=0 `
  141. err = o.Raw(sql, companyId, productId).QueryRow(&count)
  142. return
  143. }
  144. type CompanyApplyApproveReq struct {
  145. CompanyId int `description:"客户id"`
  146. Status int `description:"审批状态,1:通过,2:拒绝"`
  147. Remark string `description:"审批理由"`
  148. CompanyContractId int `description:"合同id"`
  149. ProductId int `description:"客户产品id"`
  150. }
  151. // 审批通过
  152. func ApproveAgree(companyId, productId int, approveStatus, approveRemark, startDate, endDate string, applyMethod int) (err error) {
  153. o := orm.NewOrm()
  154. to, err := o.Begin()
  155. if err != nil {
  156. return
  157. }
  158. defer func() {
  159. if err != nil {
  160. _ = to.Rollback()
  161. } else {
  162. _ = to.Commit()
  163. }
  164. }()
  165. sql := `UPDATE company_product
  166. SET
  167. approve_status = ?,
  168. approve_time = NOW(),
  169. approve_remark = ?,
  170. start_date=?,
  171. end_date=?,
  172. modify_time=NOW()
  173. WHERE company_id = ? AND product_id=? `
  174. _, err = to.Raw(sql, approveStatus, approveRemark, startDate, endDate, companyId, productId).Exec()
  175. if err != nil {
  176. return
  177. }
  178. if applyMethod == 6 {
  179. sql := `UPDATE company_contract
  180. SET
  181. status = 1,
  182. modify_time=NOW()
  183. WHERE company_id = ? AND product_id=? `
  184. _, err = to.Raw(sql, companyId, productId).Exec()
  185. }
  186. return
  187. }
  188. // 审批拒绝
  189. func ApproveRefuse(companyId, productId int, approveStatus, approveRemark string) (err error) {
  190. o := orm.NewOrm()
  191. to, err := o.Begin()
  192. if err != nil {
  193. return
  194. }
  195. defer func() {
  196. if err != nil {
  197. _ = to.Rollback()
  198. } else {
  199. _ = to.Commit()
  200. }
  201. }()
  202. sql := `UPDATE company_product
  203. SET
  204. approve_status = '驳回',
  205. modify_time=NOW()
  206. WHERE company_id = ? AND product_id=? `
  207. _, err = to.Raw(sql, companyId, productId).Exec()
  208. if err != nil {
  209. return
  210. }
  211. sql = ` UPDATE company_approval
  212. SET
  213. approve_status = '驳回',
  214. approve_remark=?,
  215. approve_time=NOW(),
  216. modify_time=NOW()
  217. WHERE company_id = ? AND product_id=? AND approve_status='待审批' `
  218. _, err = to.Raw(sql, approveRemark, companyId, productId).Exec()
  219. return
  220. }
  221. // 申请转正请求参数
  222. type CompanyApplyTurnPositiveReq struct {
  223. CompanyId int
  224. CompanyApprovalId int `description:"申请单id,没有传0"`
  225. ContractType string `description:"合同类型,枚举值:'新签合同','续约合同','补充协议'"`
  226. StartDate string `description:"合同开始日期"`
  227. EndDate string `description:"合同结束日期"`
  228. Money float64 `description:"合同金额"`
  229. PayMethod string `description:"付款方式"`
  230. PayChannel string `description:"付款渠道"`
  231. PermissionIds string `description:"权限id,多个用英文逗号隔开"`
  232. PermissionNames string `description:"权限名称,多个用英文逗号隔开"`
  233. ImgUrl string `description:"合同图片,多个用英文#隔开"`
  234. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  235. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
  236. }
  237. // 申请转正请求参数
  238. type CompanyApplyBySystemContractReq struct {
  239. CompanyId int
  240. CompanyApprovalId int `description:"申请单id,没有传0"`
  241. ContractId int `description:"合同id,没有传0"`
  242. }
  243. // 申请解冻参数
  244. type CompanyApplyThawReq struct {
  245. CompanyId int `description:"客户id"`
  246. CompanyApprovalId int `description:"申请单id,没有传0"`
  247. ApplyRemark string `description:"申请解冻理由"`
  248. PermissionIds string `description:"权限id,多个用英文逗号隔开"`
  249. }
  250. // 申请延期参数
  251. type CompanyApplyDelayReq struct {
  252. CompanyId int `description:"客户id"`
  253. CompanyApprovalId int `description:"申请单id,没有传0"`
  254. ApplyRemark string `description:"申请解冻理由"`
  255. PermissionIds string `description:"权限id,多个用英文逗号隔开"`
  256. }
  257. // 申请领取参数
  258. type CompanyApplyReceiveReq struct {
  259. CompanyId int `description:"客户id"`
  260. CompanyApprovalId int `description:"申请单id,没有传0"`
  261. ApplyRemark string `description:"申请解冻理由"`
  262. PermissionIds string `description:"权限id,多个用英文逗号隔开"`
  263. }
  264. type CompanyApplyDetailResp struct {
  265. Item *CompanyDetail `description:"客户信息"`
  266. FiccItem *CompanyProductDetail `description:"Ficc客户产品详情"`
  267. RaiItem *CompanyProductDetail `description:"权益客户产品详情"`
  268. ProductName string `description:"部门名称:ficc/权益/admin"`
  269. Approval *CompanyApproval `description:"审批详情"`
  270. }
  271. type CompanyApplyRevokeReq struct {
  272. CompanyId int `description:"客户id"`
  273. }
  274. func ApplyRevoke(companyApprovalId, companyId, productId int) (err error) {
  275. o := orm.NewOrm()
  276. to, err := o.Begin()
  277. if err != nil {
  278. return
  279. }
  280. defer func() {
  281. if err != nil {
  282. _ = to.Rollback()
  283. } else {
  284. _ = to.Commit()
  285. }
  286. }()
  287. sql := `UPDATE company_approval SET approve_status='已撤回' WHERE company_approval_id=? `
  288. _, err = to.Raw(sql, companyApprovalId).Exec()
  289. sql = `UPDATE company_product SET approve_status='已撤回' WHERE company_id=? AND product_id=? `
  290. _, err = to.Raw(sql, companyId, productId).Exec()
  291. sql = `UPDATE company_approval_message SET operation_status=2 WHERE company_approval_id=? AND operation_status=1 `
  292. _, err = to.Raw(sql, companyApprovalId).Exec()
  293. return
  294. }
  295. func GetCompanyApprovalByCompanyApprovalId(companyApprovalId int) (item *CompanyApproval, err error) {
  296. sql := `SELECT * FROM company_approval WHERE company_approval_id=? `
  297. o := orm.NewOrm()
  298. err = o.Raw(sql, companyApprovalId).QueryRow(&item)
  299. return
  300. }
  301. func GetCompanyContractById(companyContractId int) (item *CompanyContractDetail, err error) {
  302. o := orm.NewOrm()
  303. sql := `SELECT * FROM company_contract WHERE company_contract_id=? `
  304. err = o.Raw(sql, companyContractId).QueryRow(&item)
  305. return
  306. }
  307. type ApplyContractResp struct {
  308. Item *CompanyContractDetail
  309. }
  310. // 获取申请转正时的合同类型
  311. type ApplyContractTypeResp struct {
  312. ContractType string
  313. }