company_apply.go 13 KB

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