company_apply.go 13 KB

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