company_apply.go 13 KB

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