company.go 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  1. package company
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. type Company struct {
  12. CompanyId int `orm:"column(company_id);pk"`
  13. CompanyName string `description:"客户名称"`
  14. CompanyType int `orm:"column(type)"`
  15. CreditCode string `description:"社会统一信用码"`
  16. CompanyCode string `description:"客户编码"`
  17. Sort int `description:"优先级"`
  18. IsFeeCustomer int `description:"是否付费用户"`
  19. Country string `description:"国家编码"`
  20. Province string `description:"省"`
  21. City string `description:"市"`
  22. Address string `description:"详细地址"`
  23. Enabled int `description:"用户状态"`
  24. CreatedTime time.Time `description:"创建时间"`
  25. LastUpdatedTime time.Time `description:"最后一次阅读时间"`
  26. Seller string `description:"销售员"`
  27. SellsId int `description:"销售员id"`
  28. ShareSeller string `description:"共享销售员"`
  29. ShareSellerId int `description:"共享销售员id"`
  30. CompanyBelong string `description:"客户所属,ficc:ficc客户,public_offering:公募客户,partner:合作伙伴"`
  31. StartDate string `description:"合同开始日期"`
  32. EndDate string `description:"合同结束日期"`
  33. LastType int `description:"原客户标签"`
  34. IsVip int `description:"0:普通用户,1:大客户"`
  35. IsShare int `description:"0:非共享用户,1:共享客户"`
  36. FirstStartDate string `description:"首次设置为试用客户开始时间"`
  37. FirstEndDate string `description:"首次设置为试用客户结束时间"`
  38. DateType int `description:"设置流失类型,1:1个月,2:2个月,3:3个月"`
  39. Remark string `description:"备注信息"`
  40. RegionType string `description:"地区类型,国内,国外"`
  41. OpenCompanyCode string `description:"开放给第三方的客户编码,不让第三方定位我们的客户信息"`
  42. }
  43. // 新增客户
  44. func AddCompany(item *Company) (lastId int64, err error) {
  45. o := orm.NewOrm()
  46. lastId, err = o.Insert(item)
  47. return
  48. }
  49. // 根据企业id获取企业信息
  50. func GetCompanyById(companyId int) (items *Company, err error) {
  51. o := orm.NewOrm()
  52. sql := ` SELECT * FROM company where company_id= ? `
  53. err = o.Raw(sql, companyId).QueryRow(&items)
  54. return
  55. }
  56. type CompanySearchItem struct {
  57. CompanyId int `orm:"column(company_id);pk"`
  58. CompanyName string `description:"客户名称"`
  59. CreditCode string `description:"社会统一信用码"`
  60. CompanyCode string `description:"客户编码"`
  61. StartDate string `description:"合同开始日期"`
  62. EndDate string `description:"合同结束日期"`
  63. LoseReason string `description:"流失原因"`
  64. LossTime string `description:"流失时间"`
  65. Status string `description:"客户状态:'试用','永续','冻结','流失','正式' "`
  66. CompanyType string `description:"客户类型:ficc/权益"`
  67. ApproveStatus string `description:"审批状态:'审批中','通过','驳回' 审批状态为空时,表示没有审批申请"`
  68. SellerName string `description:"销售:吉根龙/颖丹"`
  69. SellerIds string `description:"销售ID集合,包含ficc和权益的销售id" json:"-"`
  70. Duration string `description:"时长"`
  71. FreezeTime string `description:"冻结时间"`
  72. GroupId int `description:"分组id"`
  73. GroupIds string `json:"-" description:"分组id集合,包含ficc和权益的小组id"`
  74. DepartmentId int `description:"部门id"`
  75. IsSuspend int `description:"是否暂停:1:暂停,0:启用 "`
  76. ProductId int `description:"产品id"`
  77. ProductIds string `json:"-";description:"分组id集合,包含ficc和权益的小组id"`
  78. IsMoveShow int `description:"按钮显示控制:1:显示,移动按钮,0:不显示移动按钮"`
  79. SellerId int `description:"销售id"`
  80. BtnItem *ButtonPermission
  81. FormalTime string `description:"转正时间"`
  82. FreezeStartDate string `description:"冻结开始日期"`
  83. FreezeEndDate string `description:"冻结结束日期"`
  84. RegionType string `description:"地区类型,国内,国外"`
  85. ShareSeller string `description:"共享销售员"`
  86. ShareSellerId int `description:"共享销售员id"`
  87. IsShare int `description:"0:非共享用户,1:共享客户"`
  88. IsResearchShow int `description:"研选详情展示控制:1:显示,0:不显示"`
  89. }
  90. type CompanySearchListResp struct {
  91. Paging *paging.PagingItem
  92. List []*CompanySearchItem
  93. }
  94. func GetCompanySearchList(condition string, pars []interface{}, limitParam ...int) (items []*CompanySearchItem, err error) {
  95. o := orm.NewOrm()
  96. sql := `SELECT DISTINCT a.company_id,a.company_name,a.credit_code,a.company_code,a.region_type,a.share_seller_id,a.share_seller,a.is_share,
  97. GROUP_CONCAT(b.status ORDER BY b.product_id ASC SEPARATOR '/') AS status,
  98. GROUP_CONCAT(DISTINCT b.seller_name ORDER BY b.product_id ASC SEPARATOR '/' ) AS seller_name,
  99. GROUP_CONCAT(DISTINCT b.seller_id ORDER BY b.product_id ASC SEPARATOR '/') AS seller_ids,
  100. GROUP_CONCAT(DISTINCT b.group_id ORDER BY b.product_id ASC SEPARATOR '/' ) AS group_ids,
  101. GROUP_CONCAT(DISTINCT b.product_id ORDER BY b.product_id ASC SEPARATOR '/' ) AS product_ids,
  102. b.freeze_time,b.loss_time,a.lose_reason,b.is_suspend,b.seller_id,b.product_id,b.group_id,b.formal_time,b.freeze_time,
  103. GROUP_CONCAT(b.start_date ORDER BY b.product_id ASC SEPARATOR '/') AS start_date,
  104. GROUP_CONCAT(b.end_date ORDER BY b.product_id ASC SEPARATOR '/') AS end_date,
  105. GROUP_CONCAT(DISTINCT b.company_type ORDER BY b.product_id ASC SEPARATOR '/') AS company_type,
  106. GROUP_CONCAT(DISTINCT b.approve_status ORDER BY b.product_id ASC SEPARATOR '/') AS approve_status,
  107. GROUP_CONCAT(DISTINCT b.freeze_start_date ORDER BY b.product_id ASC SEPARATOR '/') AS freeze_start_date,
  108. GROUP_CONCAT(DISTINCT b.freeze_end_date ORDER BY b.product_id ASC SEPARATOR '/') AS freeze_end_date
  109. FROM company AS a
  110. INNER JOIN company_product AS b ON a.company_id=b.company_id
  111. WHERE a.enabled=1 `
  112. if condition != "" {
  113. sql += condition
  114. }
  115. sql += ` GROUP BY a.company_id ORDER BY a.last_updated_time DESC LIMIT ?,? `
  116. _, err = o.Raw(sql, pars, limitParam).QueryRows(&items)
  117. return
  118. }
  119. func GetCompanySearchCount(condition string, pars []interface{}) (count int, err error) {
  120. o := orm.NewOrm()
  121. sql := `SELECT COUNT(1) AS count
  122. FROM company AS a
  123. INNER JOIN company_product AS b ON a.company_id=b.company_id
  124. WHERE a.enabled=1 `
  125. if condition != "" {
  126. sql += condition
  127. }
  128. sql += ` GROUP BY a.company_id `
  129. qsql := `SELECT COUNT(1) AS count FROM (` + sql + `) AS t`
  130. err = o.Raw(qsql, pars).QueryRow(&count)
  131. return
  132. }
  133. type CompanyItem struct {
  134. CompanyId int `orm:"column(company_id);pk"`
  135. CompanyName string `description:"客户名称"`
  136. CreditCode string `description:"社会统一信用码"`
  137. CompanyCode string `description:"客户编码"`
  138. StartDate string `description:"合同开始日期"`
  139. EndDate string `description:"合同结束日期"`
  140. LoseReason string `description:"流失原因"`
  141. RenewalReason string `description:"续约说明"`
  142. FreezeReason string `description:"冻结理由"`
  143. LossTime string `description:"流失时间"`
  144. Status string `description:"客户状态:'试用','永续','冻结','流失','正式' "`
  145. CompanyType string `description:"客户类型:ficc/权益"`
  146. ApproveStatus string `description:"审批状态:'待审批','已审批','驳回' 审批状态为空时,表示没有审批申请"`
  147. SellerName string `description:"销售:吉根龙/颖丹"`
  148. SellerId int `description:"销售ID"`
  149. SellerIds string `description:"销售ID集合,包含ficc和权益的销售id"`
  150. ShareSeller string `description:"共享销售员"`
  151. ShareSellerId int `description:"共享销售员id"`
  152. PackageTypes string `description:"套餐类型集合,包含ficc和权益的套餐类型" json:"-"`
  153. FiccPackageType int `description:"ficc的套餐类型"`
  154. ExpireDay string `description:"到期天数"`
  155. FreezeTime string `description:"冻结时间"`
  156. GroupId int `description:"分组id"`
  157. GroupIds string `description:"分组id集合,包含ficc和权益的小组id" json:"-"`
  158. DepartmentId int `description:"部门id"`
  159. IndustryName string `description:"所属行业"`
  160. IsSuspend int `description:"是否暂停:1:暂停,0:启用 "`
  161. CreatedTime string `description:"创建时间"`
  162. Source string `description:"客户来源"`
  163. Province string `description:"省"`
  164. City string `description:"市"`
  165. Address string `description:"详细地址"`
  166. Reasons string `description:"新增理由"`
  167. FreezeStartDate string `description:"冻结开始日期"`
  168. FreezeEndDate string `description:"冻结结束日期"`
  169. FreezeExpireDays int `description:"冻结到期天数"`
  170. BtnItem *ButtonPermission
  171. ProductId int `json:"-"`
  172. ProductIds string `description:"产品id集合,包含ficc和权益的产品id" json:"-"`
  173. FormalTime string `description:"转正时间"`
  174. IsShared bool `description:"是否共享客户"`
  175. RegionType string `description:"区域:国内,海外"`
  176. FiccLastViewTime string `description:"ficc最近一次阅读时间"`
  177. RaiLastViewTime string `description:"权益最近一次阅读时间"`
  178. ViewTotals string `description:"阅读次数集合,包含ficc和权益的阅读次数" json:"-"`
  179. LastViewTimes string `description:"最近一次阅读时间集合,包含ficc和权益的最近一次阅读时间" json:"-"`
  180. FiccView int `description:"Ficc报告阅读次数" json:"-"`
  181. RaiView int `description:"权益报告阅读次数" json:"-"`
  182. RoadShowTotal int `description:"累计路演次数"`
  183. TodoStatuss string `description:"任务状态"`
  184. TryStageStr string `description:"试用客户子标签"`
  185. TryStageSlice []*TryStageSliceItem `description:"试用状态相关"`
  186. AllViewTotal int `description:"总阅读数"`
  187. Deadline string `description:"未完成的todo任务的截止日期,截止目前还剩余的天数"`
  188. TodoEndTimeStr string `description:"未完成的todo任务的截止日期拼接格式"`
  189. TodoEndTime time.Time `description:"未完成的todo任务的截止日期"`
  190. TryOutDayTotals string `description:"试用天数集合,包含ficc和权益的试用天数" json:"-"`
  191. FiccTryOutDay int `description:"Ficc试用天数" json:"-"`
  192. RaiTryOutDay int `description:"权益试用天数" json:"-"`
  193. WeekViewActive int `description:"周阅读活跃: 0-七日内无阅读; 1-活跃"`
  194. IsShare int `description:"0:非共享用户,1:共享客户"`
  195. LastServiceTime string `description:"最后服务时间"`
  196. ServiceTimes int `description:"服务次数"`
  197. CloseReason string `description:"关闭原因"`
  198. CloseTime string `description:"关闭时间"`
  199. }
  200. type CompanyListItem struct {
  201. CompanyId int `orm:"column(company_id);pk"`
  202. CompanyName string `description:"客户名称"`
  203. CreditCode string `description:"社会统一信用码"`
  204. CompanyCode string `description:"客户编码"`
  205. StartDate string `description:"合同开始日期"`
  206. EndDate string `description:"合同结束日期"`
  207. LoseReason string `description:"流失原因"`
  208. RenewalReason string `description:"续约说明"`
  209. FreezeReason string `description:"冻结理由"`
  210. LossTime string `description:"流失时间"`
  211. Status string `description:"客户状态:'试用','永续','冻结','流失','正式' "`
  212. CompanyType string `description:"客户类型:ficc/权益"`
  213. ApproveStatus string `description:"审批状态:'待审批','已审批','驳回' 审批状态为空时,表示没有审批申请"`
  214. SellerName string `description:"销售:吉根龙/颖丹"`
  215. SellerId int `description:"销售ID"`
  216. SellerIds string `description:"销售ID集合,包含ficc和权益的销售id"`
  217. FiccPackageType int `description:"ficc的套餐类型"`
  218. ExpireDay string `description:"到期天数"`
  219. FreezeTime string `description:"冻结时间"`
  220. GroupId int `description:"分组id"`
  221. GroupIds string `description:"分组id集合,包含ficc和权益的小组id" json:"-"`
  222. DepartmentId int `description:"部门id"`
  223. IndustryName string `description:"所属行业"`
  224. IsSuspend int `description:"是否暂停:1:暂停,0:启用 "`
  225. CreatedTime string `description:"创建时间"`
  226. Source string `description:"客户来源"`
  227. Province string `description:"省"`
  228. City string `description:"市"`
  229. Address string `description:"详细地址"`
  230. Reasons string `description:"新增理由"`
  231. FreezeStartDate string `description:"冻结开始日期"`
  232. FreezeEndDate string `description:"冻结结束日期"`
  233. FreezeExpireDays int `description:"冻结到期天数"`
  234. BtnItem *ButtonPermission
  235. ProductId int `json:"-"`
  236. FormalTime string `description:"转正时间"`
  237. IsShared bool `description:"是否共享客户"`
  238. RegionType string `description:"区域:国内,海外"`
  239. FiccView int `description:"Ficc报告阅读次数"`
  240. RaiView int `description:"权益报告阅读次数"`
  241. FiccLastViewTime string `description:"ficc最近一次阅读时间"`
  242. RaiLastViewTime string `description:"权益最近一次阅读时间"`
  243. RoadShowTotal int `description:"累计路演次数"`
  244. TodoStatus bool `description:"是否存在进行中任务,true:存在待处理的任务"`
  245. CanConfirm bool `description:"是否允许完成任务,true:允许完成任务"`
  246. HiddenConfirm bool `description:"是否隐藏完成任务按钮,true:隐藏完成任务按钮"`
  247. HiddenCreate bool `description:"是否隐藏新增/编辑按钮,true:隐藏新增/编辑按钮"`
  248. TodoButtonColor string `description:"任务按钮颜色:red,green,gray"`
  249. TryStageSlice []*TryStageSliceItem `description:"试用状态相关"`
  250. AllViewTotal int `description:"总阅读数"`
  251. Deadline string `description:"未完成的todo任务的截止日期,截止目前还剩余的天数"`
  252. FiccTryOutDay int `description:"Ficc总试用天数"`
  253. RaiTryOutDay int `description:"权益总试用天数"`
  254. WeekViewActive int `description:"周阅读活跃: 0-七日内无阅读; 1-活跃"`
  255. IsShare int `description:"0:非共享用户,1:共享客户"`
  256. ShareSeller string `description:"共享销售员"`
  257. ShareSellerId int `description:"共享销售员id"`
  258. LastServiceTime string `description:"最后服务时间"`
  259. ServiceTimes int `description:"服务次数"`
  260. CloseReason string `description:"关闭客户原因"`
  261. CloseTime string `description:"关闭客户时间"`
  262. }
  263. type TryStageSliceItem struct {
  264. ProductId int `description:"产品ID"`
  265. TryStage int `description:"试用客户子标签1未分类、2 推进、3 跟踪、4 预备"`
  266. HasPermission bool `description:"是否有权限设置标签"`
  267. }
  268. type CompanyListResp struct {
  269. Paging *paging.PagingItem
  270. List []*CompanyListItem
  271. StatusCount []*CompanyStatus
  272. TryStageCount []*CompanyTryStageCount
  273. AddCompanyBtn bool
  274. }
  275. func GetCompanyListCount(condition string, pars []interface{}) (count int, err error) {
  276. o := orm.NewOrm()
  277. sql := `SELECT COUNT(DISTINCT b.company_id) AS count
  278. FROM company AS a
  279. INNER JOIN company_product AS b ON a.company_id=b.company_id
  280. WHERE a.enabled=1 `
  281. if condition != "" {
  282. sql += condition
  283. }
  284. err = o.Raw(sql, pars).QueryRow(&count)
  285. return
  286. }
  287. func GetCompanyList(condition, status, sortStr string, pars []interface{}, startSize, pageSize int) (items []*CompanyItem, err error) {
  288. o := orm.NewOrm()
  289. // 七天前的时间-用于查询周阅读活跃, 此处的需求是
  290. // FICC客户、共享客户: 以FICC最后一次阅读时间作为参考, 七日内有阅读量则为活跃
  291. // 权益客户: 以权益最后一次阅读时间作为参考
  292. t := time.Now().Local().AddDate(0, 0, -7).Format(utils.FormatDate)
  293. sql := `SELECT a.company_id,a.company_name,a.credit_code,a.company_code,a.created_time,a.province,a.city,a.address,a.region_type,b.group_id,b.road_show_total,a.is_share,
  294. CASE
  295. WHEN GROUP_CONCAT(b.status) LIKE "%永续%" THEN 1
  296. WHEN GROUP_CONCAT(b.status) LIKE "%正式%" THEN 2
  297. WHEN GROUP_CONCAT(b.status) LIKE "%试用%" THEN 3
  298. WHEN GROUP_CONCAT(b.status) LIKE "%冻结%" THEN 4
  299. WHEN GROUP_CONCAT(b.status) LIKE "%流失%" THEN 5
  300. ELSE 10 END
  301. as sort_status,
  302. CASE
  303. WHEN GROUP_CONCAT(b.try_stage) LIKE "%2%" THEN 1
  304. WHEN GROUP_CONCAT(b.try_stage) LIKE "%3%" THEN 2
  305. WHEN GROUP_CONCAT(b.try_stage) LIKE "%4%" THEN 3
  306. WHEN GROUP_CONCAT(b.try_stage) LIKE "%1%" THEN 4
  307. ELSE 10 END
  308. as sort_try_stage,
  309. CASE
  310. WHEN GROUP_CONCAT(b.todo_status) LIKE "%未完成%" AND GROUP_CONCAT(b.todo_end_time) is not null THEN GROUP_CONCAT(b.todo_end_time)
  311. ELSE "9999-01-01" END
  312. as sort_todo_end_time,
  313. GROUP_CONCAT(b.status ORDER BY b.product_id ASC SEPARATOR '/') AS status,
  314. GROUP_CONCAT(DISTINCT b.seller_name ORDER BY b.product_id ASC SEPARATOR '/') AS seller_name,
  315. GROUP_CONCAT(DISTINCT b.seller_id ORDER BY b.product_id ASC SEPARATOR '/') AS seller_ids,
  316. GROUP_CONCAT(DISTINCT b.package_type ORDER BY b.product_id ASC SEPARATOR '/') AS package_types,
  317. GROUP_CONCAT(DISTINCT b.industry_name ORDER BY b.product_id ASC SEPARATOR '/') AS industry_name,
  318. GROUP_CONCAT(DISTINCT b.product_name ORDER BY b.product_id ASC SEPARATOR '/') AS company_type,
  319. GROUP_CONCAT(DISTINCT b.product_id ORDER BY b.product_id ASC SEPARATOR '/') AS product_ids,
  320. GROUP_CONCAT(DISTINCT b.view_total ORDER BY b.product_id ASC SEPARATOR '/') AS view_totals,
  321. GROUP_CONCAT(DISTINCT b.last_view_time ORDER BY b.product_id ASC SEPARATOR '/') AS last_view_times,
  322. GROUP_CONCAT(b.start_date ORDER BY b.product_id ASC SEPARATOR '/') AS start_date,
  323. GROUP_CONCAT(b.end_date ORDER BY b.product_id ASC SEPARATOR '/') AS end_date,
  324. GROUP_CONCAT(DISTINCT b.loss_time ORDER BY b.product_id ASC SEPARATOR '/') AS loss_time,
  325. GROUP_CONCAT(DISTINCT b.lose_reason ORDER BY b.product_id ASC SEPARATOR '/') AS lose_reason,
  326. GROUP_CONCAT(DISTINCT b.close_time ORDER BY b.product_id ASC SEPARATOR '/') AS close_time,
  327. GROUP_CONCAT(DISTINCT b.close_reason ORDER BY b.product_id ASC SEPARATOR '/') AS close_reason,
  328. GROUP_CONCAT(DISTINCT b.source ORDER BY b.product_id ASC SEPARATOR '/') AS source,
  329. GROUP_CONCAT(DISTINCT b.reasons ORDER BY b.product_id ASC SEPARATOR '/') AS reasons,
  330. GROUP_CONCAT(DISTINCT b.approve_status ORDER BY b.product_id ASC SEPARATOR '/') AS approve_status,
  331. GROUP_CONCAT(b.try_stage ORDER BY b.product_id ASC SEPARATOR '/') AS try_stage_str,
  332. GROUP_CONCAT(DISTINCT b.group_id ORDER BY b.product_id ASC SEPARATOR '/') AS group_ids,
  333. GROUP_CONCAT(DISTINCT b.todo_status ORDER BY b.product_id ASC SEPARATOR '/') AS todo_statuss,
  334. GROUP_CONCAT(DISTINCT b.todo_end_time ORDER BY b.product_id ASC SEPARATOR '/') AS todo_end_time_str,
  335. GROUP_CONCAT(DISTINCT b.try_out_day_total ORDER BY b.product_id ASC SEPARATOR '/') AS try_out_day_totals,
  336. b.is_suspend,
  337. b.freeze_start_date,
  338. b.freeze_end_date,
  339. b.seller_id,
  340. b.product_id,
  341. b.formal_time,
  342. b.freeze_time,b.freeze_reason,b.renewal_reason,
  343. b.view_total,
  344. b.last_view_time,
  345. MAX(b.last_view_time) as max_last_view_time,
  346. MIN(b.last_view_time) as min_last_view_time,
  347. MAX(b.end_date) as max_end_date,
  348. MIN(b.end_date) as min_end_date,
  349. SUM(b.view_total) as all_view_total,
  350. SUM(b.try_out_day_total) as all_try_out_day_total,
  351. IF(LEFT(GROUP_CONCAT(DISTINCT b.last_view_time ORDER BY b.product_id), 19) >= "` + t + `", 1, 0) AS week_view_active
  352. FROM company AS a
  353. INNER JOIN company_product AS b ON a.company_id=b.company_id
  354. WHERE a.enabled=1 `
  355. if condition != "" {
  356. sql += condition
  357. }
  358. //sortStr := ``
  359. //如果没有传入排序字段,那么按照状态排序
  360. if sortStr == "" {
  361. if status == "全部" || status == utils.COMPANY_STATUS_TRY_OUT { //试用
  362. sortStr = " ORDER BY a.created_time DESC "
  363. } else if status == utils.COMPANY_STATUS_FORMAL { //正式
  364. // 正式客户默认按照周阅读活跃ASC, 同为不活跃则按照转正时间DESC
  365. sortStr = " ORDER BY week_view_active ASC, b.formal_time DESC"
  366. //sortStr = " ORDER BY b.formal_time DESC "
  367. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  368. sortStr = " ORDER BY b.freeze_time DESC "
  369. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  370. sortStr = " ORDER BY b.loss_time DESC "
  371. } else if status == utils.COMPANY_STATUS_CLOSE { //关闭
  372. sortStr = " ORDER BY b.close_time DESC "
  373. } else {
  374. sortStr = " ORDER BY a.created_time DESC "
  375. }
  376. }
  377. sql += ` GROUP BY a.company_id ` + sortStr + ` LIMIT ?,? `
  378. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  379. return
  380. }
  381. // GetCountCygxArticleHistoryRecordByCompanyName 查研观向阅读次数
  382. func GetCountCygxArticleHistoryRecordByCompanyName(companyName string) (count int, err error) {
  383. o := orm.NewOrm()
  384. sql := `SELECT count(1) total FROM cygx_article_history_record WHERE company_name=? `
  385. _ = o.Raw(sql, companyName).QueryRow(&count)
  386. return
  387. }
  388. // GetCountUserViewHistoryByCompanyName 晨报阅读次数
  389. func GetCountUserViewHistoryByCompanyName(companyName string) (count int, err error) {
  390. o := orm.NewOrm()
  391. sql := `SELECT count(1) total FROM user_view_history WHERE company_name=? `
  392. _ = o.Raw(sql, companyName).QueryRow(&count)
  393. return
  394. }
  395. // GetCountReportViewRecordByCompanyName 日评阅读次数
  396. func GetCountReportViewRecordByCompanyName(companyName string) (count int, err error) {
  397. o := orm.NewOrm()
  398. sql := `SELECT count(1) total FROM report_view_record WHERE company_name=? `
  399. _ = o.Raw(sql, companyName).QueryRow(&count)
  400. return
  401. }
  402. // GetCountAdvisoryUserChartArticleRecordByCompanyName 每日资讯阅读次数
  403. func GetCountAdvisoryUserChartArticleRecordByCompanyName(companyName string) (count int, err error) {
  404. o := orm.NewOrm()
  405. sql := `SELECT count(1) total FROM advisory_user_chart_article_record WHERE company_name=? `
  406. _ = o.Raw(sql, companyName).QueryRow(&count)
  407. return
  408. }
  409. type CompanyStatus struct {
  410. Status string `description:"客户状态:'试用','永续','冻结','流失','正式','试用-活跃','试用-非活跃' "`
  411. Count int `description:"数量 "`
  412. }
  413. type CompanyTryStageCount struct {
  414. TryStageStr string `description:"试用客户子标签:未分类、推进、跟踪、预备"`
  415. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  416. Count int `description:"数量 "`
  417. }
  418. func GetCompanyStatusCount(condition string, pars []interface{}) (items []*CompanyStatus, err error) {
  419. o := orm.NewOrm()
  420. sql := ` SELECT b.status,COUNT(DISTINCT a.company_id) AS count FROM company AS a
  421. INNER JOIN company_product AS b ON a.company_id=b.company_id
  422. WHERE a.enabled=1 AND b.status IN('正式','试用','冻结','永续','关闭') `
  423. if condition != "" {
  424. sql += condition
  425. }
  426. //sql += `GROUP BY b.status `
  427. //_, err = o.Raw(sql, pars).QueryRows(&items)
  428. sql += ` GROUP BY b.status `
  429. _, err = o.Raw(sql, pars).QueryRows(&items)
  430. return
  431. }
  432. // GetCompanyTryStageCount 获取试用客户标签的总数
  433. func GetCompanyTryStageCount(condition string, pars []interface{}) (items []*CompanyTryStageCount, err error) {
  434. o := orm.NewOrm()
  435. sql := ` SELECT b.try_stage,COUNT(DISTINCT a.company_id) AS count FROM company AS a
  436. INNER JOIN company_product AS b ON a.company_id=b.company_id
  437. WHERE a.enabled=1 AND b.status = "试用"`
  438. if condition != "" {
  439. sql += condition
  440. }
  441. //sql += `GROUP BY b.status `
  442. //_, err = o.Raw(sql, pars).QueryRows(&items)
  443. sql += ` GROUP BY b.try_stage `
  444. _, err = o.Raw(sql, pars).QueryRows(&items)
  445. return
  446. }
  447. // GetCompanyTryOutStatusCount 获取试用状态的客户数
  448. func GetCompanyTryOutStatusCount(condition string, pars []interface{}) (item *CompanyStatus, err error) {
  449. o := orm.NewOrm()
  450. sql := ` SELECT b.status,COUNT(DISTINCT a.company_id) AS count FROM company AS a
  451. INNER JOIN company_product AS b ON a.company_id=b.company_id
  452. WHERE a.enabled=1 AND b.status = "试用" `
  453. if condition != "" {
  454. sql += condition
  455. }
  456. //sql += `GROUP BY b.status `
  457. //_, err = o.Raw(sql, pars).QueryRows(&items)
  458. err = o.Raw(sql, pars).QueryRow(&item)
  459. return
  460. }
  461. func GetCompanyStatusLoseCount(condition string, pars []interface{}) (items *CompanyStatus, err error) {
  462. o := orm.NewOrm()
  463. sql := ` SELECT b.status,COUNT(DISTINCT a.company_id) AS count FROM company AS a
  464. INNER JOIN company_product AS b ON a.company_id=b.company_id
  465. WHERE a.enabled=1 AND b.status='流失' `
  466. if condition != "" {
  467. sql += condition
  468. }
  469. err = o.Raw(sql, pars).QueryRow(&items)
  470. return
  471. }
  472. func GetCompanyStatusFreezeCount(condition string, pars []interface{}) (items *CompanyStatus, err error) {
  473. o := orm.NewOrm()
  474. sql := ` SELECT b.status,COUNT(DISTINCT a.company_id) AS count FROM company AS a
  475. INNER JOIN company_product AS b ON a.company_id=b.company_id
  476. WHERE a.enabled=1 AND b.status='冻结' `
  477. if condition != "" {
  478. sql += condition
  479. }
  480. err = o.Raw(sql, pars).QueryRow(&items)
  481. return
  482. }
  483. func GetCompanyStatusForverCount(condition string, pars []interface{}) (items *CompanyStatus, err error) {
  484. o := orm.NewOrm()
  485. sql := ` SELECT b.status,COUNT(DISTINCT a.company_id) AS count FROM company AS a
  486. INNER JOIN company_product AS b ON a.company_id=b.company_id
  487. WHERE a.enabled=1 AND b.status='永续' `
  488. if condition != "" {
  489. sql += condition
  490. }
  491. err = o.Raw(sql, pars).QueryRow(&items)
  492. return
  493. }
  494. // 新增客户请求参数
  495. type CompanyAddReq struct {
  496. CompanyName string `description:"客户名称"`
  497. CreditCode string `description:"社会统一信用码"`
  498. CompanyCode string `description:"客户编码"`
  499. Province string `description:"省"`
  500. City string `description:"市"`
  501. Status string `description:"客户状态,'试用','永续','冻结','流失','正式','潜在'"`
  502. CompanyType string `description:"客户类型,ficc/权益"`
  503. IndustryId int `description:"所属行业id"`
  504. Source string `description:"来源"`
  505. SellsId int `description:"销售员id"`
  506. Reasons string `description:"新增理由,备注"`
  507. PermissionIds string `description:"权限id,多个用英文逗号隔开"`
  508. RegionType string `description:"地区类型,国内,海外"`
  509. UserId int `description:"联系人ID"`
  510. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  511. }
  512. // 新增客户请求参数
  513. type CompanyAddResp struct {
  514. CompanyId int `description:"客户ID"`
  515. }
  516. func GetCompanyCode() (companyCode string, err error) {
  517. var num int
  518. o := orm.NewOrm()
  519. sql := `SELECT COUNT(1) AS num FROM company WHERE created_time >=? `
  520. err = o.Raw(sql, time.Now().Format(utils.FormatDate)).QueryRow(&num)
  521. if err != nil {
  522. return
  523. }
  524. fmt.Println("num", num)
  525. companyCode = "KH" + time.Now().Format("20060102") + fmt.Sprintf("%03d", num)
  526. return
  527. }
  528. type CompanyDetail struct {
  529. CompanyId int `orm:"column(company_id);pk"`
  530. CompanyName string `description:"客户名称"`
  531. CreditCode string `description:"社会统一信用码"`
  532. CompanyCode string `description:"客户编码"`
  533. Province string `description:"省"`
  534. City string `description:"市"`
  535. Address string `description:"详细地址"`
  536. RegionType string `description:"地区类型,1:国内,2:国外"`
  537. OpenCompanyCode string `description:"开放给第三方的客户编码,不让第三方定位我们的客户信息"`
  538. IsShare int `description:"0:非共享用户,1:共享客户"`
  539. ShareSeller string `description:"共享销售员"`
  540. ShareSellerId int `description:"共享销售员id"`
  541. }
  542. type CompanyDetailResp struct {
  543. Item *CompanyDetail `description:"客户信息"`
  544. FiccItem *CompanyProductDetail `description:"Ficc客户产品详情"`
  545. RaiItem *CompanyProductDetail `description:"权益客户产品详情"`
  546. CreateAuth int `description:"创建人:1:ficc,2:权益"`
  547. ProductName string `description:"部门名称:ficc/权益/admin"`
  548. IsButtonShow int `description:"1:显示编辑和删除按钮,0:不显示"`
  549. IsContractButtonShow bool `description:"true:显示联系人操作按钮,新增、编辑、导入和删除按钮,false:不显示"`
  550. BtnItem *ButtonDetailPermission
  551. }
  552. // 客户权限列表
  553. type CompanyPermissionResp struct {
  554. FiccPermissionList []*PermissionLookList `description:"Ficc权限列表"`
  555. PermissionList []*PermissionLookList `description:"权益权限列表"`
  556. }
  557. func GetCompanyDetailById(companyId int) (item *CompanyDetail, err error) {
  558. o := orm.NewOrm()
  559. sql := `SELECT * FROM company WHERE company_id =? `
  560. err = o.Raw(sql, companyId).QueryRow(&item)
  561. return
  562. }
  563. func GetCompanyCountByCompanyName(companyName string) (count int, err error) {
  564. o := orm.NewOrm()
  565. sql := ` SELECT COUNT(1) AS COUNT FROM company AS a WHERE a.company_name=? `
  566. err = o.Raw(sql, companyName).QueryRow(&count)
  567. return
  568. }
  569. func GetCompanyCountByCreditCode(creditCode string) (count int, err error) {
  570. o := orm.NewOrm()
  571. sql := ` SELECT COUNT(1) AS COUNT FROM company AS a WHERE a.credit_code=? `
  572. err = o.Raw(sql, creditCode).QueryRow(&count)
  573. return
  574. }
  575. func GetCompanyCountByCompanyNameAndCompanyId(companyId int, companyName string) (count int, err error) {
  576. o := orm.NewOrm()
  577. sql := ` SELECT COUNT(1) AS COUNT FROM company AS a WHERE a.company_id<>? AND a.company_name=? `
  578. err = o.Raw(sql, companyId, companyName).QueryRow(&count)
  579. return
  580. }
  581. func GetCompanyCountByCreditCodeAndCompanyId(companyId int, creditCode string) (count int, err error) {
  582. o := orm.NewOrm()
  583. sql := ` SELECT COUNT(1) AS COUNT FROM company AS a WHERE a.company_id<>? AND a.credit_code=? `
  584. err = o.Raw(sql, companyId, creditCode).QueryRow(&count)
  585. return
  586. }
  587. // GetCompanyByCreditCode 根据社会信用码获取客户信息
  588. func GetCompanyByCreditCode(creditCode string) (companyInfo *Company, err error) {
  589. o := orm.NewOrm()
  590. sql := ` SELECT * FROM company AS a WHERE a.credit_code=? `
  591. err = o.Raw(sql, creditCode).QueryRow(&companyInfo)
  592. return
  593. }
  594. // GetCompanyDetailByCreditCode 根据社会信用码获取客户详情接口
  595. func GetCompanyDetailByCreditCode(creditCode string) (companyDetail *CompanyDetail, err error) {
  596. o := orm.NewOrm()
  597. sql := ` SELECT * FROM company AS a WHERE a.credit_code=? `
  598. err = o.Raw(sql, creditCode).QueryRow(&companyDetail)
  599. return
  600. }
  601. func GetCompanyTryOutCount(status string, sellerId int) (count int, err error) {
  602. o := orm.NewOrm()
  603. sql := ` SELECT COUNT(DISTINCT a.company_id) AS count FROM company AS a
  604. INNER JOIN company_product AS b ON a.company_id=b.company_id
  605. WHERE b.status=?
  606. AND b.seller_id=? `
  607. err = o.Raw(sql, status, sellerId).QueryRow(&count)
  608. return
  609. }
  610. type CompanySearchResp struct {
  611. List []*CompanyItem
  612. }
  613. func GetCompanyBySearch(keyWord string) (item []*CompanyItem, err error) {
  614. o := orm.NewOrm()
  615. var sql string
  616. if keyWord == "##" {
  617. sql = ` SELECT * FROM company ORDER BY RAND() LIMIT 5 `
  618. } else {
  619. sql = `SELECT * FROM company WHERE company_name LIKE '%` + keyWord + `%' LIMIT 50`
  620. }
  621. _, err = o.Raw(sql).QueryRows(&item)
  622. return
  623. }
  624. // 编辑客户请求参数
  625. type CompanyEditReq struct {
  626. CompanyId int `description:"客户id"`
  627. CompanyName string `description:"客户名称"`
  628. CreditCode string `description:"社会统一信用码"`
  629. Province string `description:"省"`
  630. City string `description:"市"`
  631. Products []*CompanyProductEditReq `description:"产品信息"`
  632. }
  633. // 编辑客户信息请求参数
  634. type CompanyInfoEditReq struct {
  635. CompanyId int `description:"客户id"`
  636. CompanyName string `description:"客户名称"`
  637. CreditCode string `description:"社会统一信用码"`
  638. Province string `description:"省"`
  639. City string `description:"市"`
  640. IndustryId int `description:"所属行业id"`
  641. IndustryName string `description:"所属行业id"`
  642. Source string `description:"来源"`
  643. }
  644. type CompanyProductEditReq struct {
  645. CompanyProductId int `description:"客户产品id"`
  646. Status string `description:"客户状态,试用,永续"`
  647. CompanyType string `description:"客户类型,ficc/权益"`
  648. IndustryId int `description:"所属行业id"`
  649. Source string `description:"来源"`
  650. SellsId int `description:"销售员id"`
  651. Reasons string `description:"新增理由"`
  652. PermissionIds string `description:"权限id,多个用英文逗号隔开"`
  653. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  654. }
  655. type CompanyFuzzySearch struct {
  656. CompanyId int `orm:"column(company_id);pk"`
  657. CompanyName string `description:"客户名称"`
  658. CreditCode string `description:"社会统一信用码"`
  659. CompanyCode string `description:"客户编码"`
  660. }
  661. // 新增客户请求参数
  662. type CompanyFuzzySearchReq struct {
  663. List []*CompanyFuzzySearch
  664. }
  665. func GetCompanyFuzzySearch(keyWord string) (items []*CompanyFuzzySearch, err error) {
  666. o := orm.NewOrm()
  667. sql := `SELECT * FROM company WHERE company_name LIKE '%` + keyWord + `%' `
  668. _, err = o.Raw(sql).QueryRows(&items)
  669. return
  670. }
  671. // 修改客户
  672. func ModifyCompany(item *Company) (err error) {
  673. o := orm.NewOrm()
  674. sql := `UPDATE company
  675. SET
  676. company_name = ?,
  677. credit_code = ?,
  678. address = ?,
  679. last_updated_time = NOW(),
  680. province = ?,
  681. city = ?
  682. WHERE company_id =?`
  683. _, err = o.Raw(sql, item.CompanyName, item.CreditCode, item.Address, item.Province, item.City, item.CompanyId).Exec()
  684. return
  685. }
  686. // 更新客户基础信息
  687. func (company *Company) Update(cols []string) (err error) {
  688. o := orm.NewOrm()
  689. _, err = o.Update(company, cols...)
  690. return
  691. }
  692. type DeletePptReq struct {
  693. CompanyId int `description:"客户id"`
  694. }
  695. func DeleteCompanyById(companyId int) (err error) {
  696. o := orm.NewOrm()
  697. to, err := o.Begin()
  698. if err != nil {
  699. return
  700. }
  701. defer func() {
  702. if err != nil {
  703. _ = to.Rollback()
  704. } else {
  705. _ = to.Commit()
  706. }
  707. }()
  708. sql := `DELETE FROM company_product WHERE company_id=? `
  709. _, err = to.Raw(sql, companyId).Exec()
  710. if err != nil {
  711. return
  712. }
  713. sql = `DELETE FROM company_report_permission WHERE company_id=? `
  714. _, err = to.Raw(sql, companyId).Exec()
  715. if err != nil {
  716. return
  717. }
  718. //联系人表
  719. sql = `DELETE FROM wx_user WHERE company_id=? `
  720. _, err = to.Raw(sql, companyId).Exec()
  721. if err != nil {
  722. return
  723. }
  724. //联系人 与 销售 关系表
  725. sql = `DELETE FROM user_seller_relation WHERE company_id=? `
  726. _, err = to.Raw(sql, companyId).Exec()
  727. if err != nil {
  728. return
  729. }
  730. //sql = `DELETE FROM company_operation_record WHERE company_id=? `
  731. //_, err = to.Raw(sql, companyId).Exec()
  732. //if err != nil {
  733. // return
  734. //}
  735. sql = `DELETE FROM company_contract WHERE company_id=? `
  736. _, err = to.Raw(sql, companyId).Exec()
  737. if err != nil {
  738. return
  739. }
  740. sql = `DELETE FROM company_contract_permission WHERE company_id=? `
  741. _, err = to.Raw(sql, companyId).Exec()
  742. if err != nil {
  743. return
  744. }
  745. sql = `DELETE FROM company WHERE company_id=? `
  746. _, err = to.Raw(sql, companyId).Exec()
  747. return
  748. }
  749. type CompanyReceiveItem struct {
  750. CompanyId int `orm:"column(company_id);pk"`
  751. CompanyName string `description:"客户名称"`
  752. StartDate string `description:"合同开始日期"`
  753. EndDate string `description:"合同结束日期"`
  754. Status string `description:"客户状态:'试用','永续','冻结','流失','正式' "`
  755. ProductName string `description:"客户类型:ficc/权益"`
  756. SellerName string `description:"销售:吉根龙/颖丹"`
  757. CreatedTime string `description:"创建时间"`
  758. ExpireDay string `description:"到期天数"`
  759. IndustryName string `description:"行业"`
  760. }
  761. type CompanyReceiveListResp struct {
  762. Paging *paging.PagingItem
  763. List []*CompanyReceiveItem
  764. }
  765. func GetCompanyReceiveListCount(condition string, pars []interface{}, productId, receiveProductId int) (count int, err error) {
  766. o := orm.NewOrm()
  767. sql := `SELECT
  768. COUNT(DISTINCT a.company_id ) AS COUNT
  769. FROM company AS a
  770. LEFT JOIN wx_user AS b ON a.company_id=b.company_id
  771. LEFT JOIN company_product AS c ON a.company_id=c.company_id
  772. WHERE a.enabled=1
  773. AND c.product_id=?
  774. AND c.company_id NOT IN (SELECT company_id FROM company_product WHERE product_id=?) `
  775. if condition != "" {
  776. sql += condition
  777. }
  778. err = o.Raw(sql, receiveProductId, productId, pars).QueryRow(&count)
  779. return
  780. }
  781. func GetCompanyReceiveList(condition string, pars []interface{}, productId, receiveProductId, startSize, pageSize int) (items []*CompanyReceiveItem, err error) {
  782. o := orm.NewOrm()
  783. sql := `SELECT
  784. c.company_id,a.company_name,c.product_name,c.industry_name,c.seller_name,c.status,c.start_date,c.end_date,a.created_time
  785. FROM company AS a
  786. LEFT JOIN wx_user AS b ON a.company_id=b.company_id
  787. LEFT JOIN company_product AS c ON a.company_id=c.company_id
  788. WHERE a.enabled=1
  789. AND c.product_id=?
  790. AND c.company_id NOT IN (SELECT company_id FROM company_product WHERE product_id=?) `
  791. if condition != "" {
  792. sql += condition
  793. }
  794. sql += ` GROUP BY a.company_id ORDER BY a.last_updated_time DESC LIMIT ?,? `
  795. _, err = o.Raw(sql, receiveProductId, productId, pars, startSize, pageSize).QueryRows(&items)
  796. return
  797. }
  798. // 编辑客户请求参数
  799. type CompanyReceiveReq struct {
  800. CompanyId int `description:"客户id"`
  801. Status string `description:"客户状态,试用,永续"`
  802. IndustryId int `description:"所属行业id"`
  803. Source string `description:"来源"`
  804. SellsId int `description:"销售员id,流失状态下直接领取,请传 0"`
  805. Reasons string `description:"新增理由"`
  806. PermissionIds string `description:"权限id,多个用英文逗号隔开"`
  807. CompanyType string `description:"客户类型"`
  808. }
  809. // 移动销售
  810. type MoveSellerReq struct {
  811. CompanyId int `description:"客户id"`
  812. SellsId int `description:"销售员id"`
  813. CompanyType string `description:"客户类型"`
  814. }
  815. // 修改试用客户标签
  816. type UpdateTryStageReq struct {
  817. CompanyId int `description:"客户id"`
  818. ProductId int `description:"产品ID"`
  819. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  820. }
  821. // MoveSeller 移动客户到另外的销售(销售领取客户时使用该接口)
  822. func MoveSeller(companyId, productId, sellerId, groupId, departmentId int, sellerName string) (items []*CompanyReportPermission, startDateTime, endDateTime time.Time, err error) {
  823. o := orm.NewOrm()
  824. to, err := o.Begin()
  825. if err != nil {
  826. return
  827. }
  828. defer func() {
  829. if err != nil {
  830. _ = to.Rollback()
  831. } else {
  832. _ = to.Commit()
  833. }
  834. }()
  835. startDateTime = time.Now()
  836. endDateTime = time.Now().AddDate(0, 2, 0)
  837. startDate := startDateTime.Format(utils.FormatDate)
  838. endDate := endDateTime.Format(utils.FormatDate)
  839. //更改 客户状态为 试用
  840. sql := `UPDATE company SET start_date=?,end_date=?,last_updated_time=NOW() WHERE company_id=? `
  841. _, err = to.Raw(sql, startDate, endDate, companyId).Exec()
  842. if err != nil {
  843. return
  844. }
  845. //更改 客户产品 状态为 试用
  846. //重置tryout时间,上次修改未续约说明时间
  847. sql = `UPDATE company_product SET status='试用',try_out_time=NULL,last_description_time=NULL,is_suspend=0,start_date=?,end_date=?,seller_id=?,seller_name=?,group_id=?,department_id=?,modify_time=NOW(),try_stage=1,todo_status="无任务",todo_create_time=null,todo_approve_time=null,todo_modify_time=null,todo_end_time=null WHERE company_id=? AND product_id=? `
  848. _, err = to.Raw(sql, startDate, endDate, sellerId, sellerName, groupId, departmentId, companyId, productId).Exec()
  849. if err != nil {
  850. return
  851. }
  852. //修改原有的 客户产品权限 的服务时间
  853. items = make([]*CompanyReportPermission, 0)
  854. sql = `SELECT * FROM company_report_permission WHERE company_id=? AND product_id=? `
  855. _, err = to.Raw(sql, companyId, productId).QueryRows(&items)
  856. for _, pv := range items {
  857. cpLog := new(CompanyPermissionLog)
  858. cpLog.CompanyId = companyId
  859. cpLog.ChartPermissionId = pv.ChartPermissionId
  860. cpLog.CreateTime = time.Now()
  861. cpLog.SysUserId = sellerId
  862. cpLog.SysUserName = sellerName
  863. cpLog.StartDate = pv.StartDate
  864. cpLog.EndDate = pv.EndDate
  865. cpLog.ProductId = productId
  866. cpLog.ProductName = pv.ProductName
  867. go AddCompanyPermissionLog(cpLog)
  868. }
  869. sql = `UPDATE company_report_permission SET status='试用',start_date=?,end_date=?,modify_time=NOW() WHERE company_id=? AND product_id=? `
  870. _, err = to.Raw(sql, startDate, endDate, companyId, productId).Exec()
  871. //修改 该联系人 与 当前销售的关系
  872. sql = `UPDATE user_seller_relation SET seller_id=?,seller = ? ,modify_time=NOW() WHERE company_id = ? AND product_id=?`
  873. _, err = to.Raw(sql, sellerId, sellerName, companyId, productId).Exec()
  874. //如果是权益客户,则把对应的主观客观一起开通
  875. if productId == 2 {
  876. //获取公司现有的权限,并通过现有的权限找出对应的主观客观权限
  877. oldPermissionId, tmpErr := GetCompanyPermissionIdById(companyId)
  878. if tmpErr != nil {
  879. err = tmpErr
  880. return
  881. }
  882. newPermissionId, tmpErr := GetPermissionIdById(oldPermissionId)
  883. if tmpErr != nil {
  884. err = tmpErr
  885. return
  886. }
  887. permissionArr := strings.Split(newPermissionId, ",")
  888. for _, v := range permissionArr {
  889. permissionId, tmpErr := strconv.Atoi(v)
  890. if tmpErr != nil {
  891. err = tmpErr
  892. return
  893. }
  894. //判断这个权限是否存在,如果不存在则新增
  895. count, tmpErr := GetCompanyPermissionCheck(companyId, permissionId)
  896. if tmpErr != nil {
  897. err = tmpErr
  898. return
  899. }
  900. if count == 0 {
  901. permission := new(CompanyReportPermission)
  902. permission.CompanyId = companyId
  903. permission.ReportPermissionId = permissionId
  904. permission.CreatedTime = time.Now()
  905. permission.LastUpdatedTime = time.Now()
  906. permission.ChartPermissionId = permissionId
  907. permission.StartDate = startDate
  908. permission.EndDate = endDate
  909. permission.ProductId = productId
  910. permission.ProductName = "权益"
  911. permission.ModifyTime = time.Now()
  912. permission.Status = "试用"
  913. err = AddCompanyReportPermission(permission)
  914. if err != nil {
  915. return
  916. }
  917. items = append(items, permission)
  918. }
  919. }
  920. }
  921. // 将历史的任务给标记删除掉
  922. sql = `UPDATE company_todo SET is_delete=1,modify_time=NOW() WHERE company_id=? AND product_id=? AND is_delete = 0 `
  923. _, err = to.Raw(sql, companyId, productId).Exec()
  924. if err != nil {
  925. return
  926. }
  927. return
  928. }
  929. func GetExportCompanyIds(condition string, pars []interface{}) (company_id string, err error) {
  930. o := orm.NewOrm()
  931. sql := `SELECT
  932. GROUP_CONCAT(DISTINCT b.company_id SEPARATOR ',') AS company_id
  933. FROM company AS a
  934. INNER JOIN company_product AS b ON a.company_id=b.company_id
  935. LEFT JOIN wx_user AS c ON a.company_id=c.company_id
  936. WHERE 1=1 and a.enabled=1 `
  937. if condition != "" {
  938. sql += condition
  939. }
  940. err = o.Raw(sql, pars).QueryRow(&company_id)
  941. return
  942. }
  943. type ExportUser struct {
  944. RealName string
  945. Mobile string
  946. Email string
  947. Position string
  948. IsMaker int
  949. DepartmentName string
  950. CompanyId int
  951. IsSubscribe int `description:"是否关注了公众号(弘则研究)"`
  952. }
  953. func GetExportUser(companyId string) (items []*ExportUser, err error) {
  954. o := orm.NewOrm()
  955. sql := `SELECT a.real_name,a.mobile,a.email,a.position,a.is_maker,department_name,a.company_id,b.subscribe AS is_subscribe
  956. FROM wx_user AS a
  957. LEFT JOIN (SELECT * FROM user_record WHERE create_platform = 1 GROUP BY user_id) AS b ON a.user_id = b.user_id
  958. WHERE a.company_id<>1 AND a.company_id IN(` + companyId + `)
  959. GROUP BY a.user_id ORDER BY a.company_id ASC `
  960. _, err = o.Raw(sql).QueryRows(&items)
  961. return
  962. }
  963. type ExportCompanyProduct struct {
  964. CompanyName string
  965. ProductId int
  966. ProductName string
  967. IndustryName string
  968. SellerName string
  969. Status string
  970. StartDate time.Time
  971. EndDate time.Time
  972. CreateTime string
  973. Source string
  974. CreditCode string
  975. RegionType string
  976. LossTime string
  977. IsSuspend int
  978. }
  979. func GetExportCompanyProduct(companyId int) (items []*ExportCompanyProduct, err error) {
  980. o := orm.NewOrm()
  981. sql := ` SELECT a.company_name,b.product_id,b.product_name,b.industry_name,b.seller_name,b.status,b.start_date,b.end_date,b.create_time,
  982. b.source,a.credit_code,a.region_type,b.loss_time, b.is_suspend
  983. FROM company AS a
  984. INNER JOIN company_product AS b ON a.company_id=b.company_id
  985. WHERE a.company_id=?
  986. ORDER BY b.product_id ASC `
  987. _, err = o.Raw(sql, companyId).QueryRows(&items)
  988. return
  989. }
  990. func GetExportPermissionName(companyId, productId int) (chart_permission_name string, err error) {
  991. o := orm.NewOrm()
  992. sql := ` SELECT GROUP_CONCAT(DISTINCT c.permission_name ORDER BY sort ASC SEPARATOR '/') AS chart_permission_name FROM company_product AS a
  993. INNER JOIN company_report_permission AS b ON a.company_id=b.company_id AND a.product_id=b.product_id
  994. INNER JOIN chart_permission AS c ON b.chart_permission_id=c.chart_permission_id AND b.product_id=c.product_id
  995. WHERE a.company_id=? AND a.product_id=? `
  996. err = o.Raw(sql, companyId, productId).QueryRow(&chart_permission_name)
  997. return
  998. }
  999. // 移动销售
  1000. type SuspendReq struct {
  1001. CompanyId int `description:"客户id"`
  1002. }
  1003. // MoveCompanySeller 移动客户销售
  1004. func MoveCompanySeller(companyId, productId, sellerId, groupId, departmentId int, sellerName string) (err error) {
  1005. o := orm.NewOrm()
  1006. to, err := o.Begin()
  1007. if err != nil {
  1008. return
  1009. }
  1010. defer func() {
  1011. if err != nil {
  1012. _ = to.Rollback()
  1013. } else {
  1014. _ = to.Commit()
  1015. }
  1016. }()
  1017. if sellerName != "" {
  1018. sql := `UPDATE company_product SET seller_id=?,seller_name=?,group_id=?,department_id=?,modify_time=NOW(),todo_status="无任务",todo_create_time=null,todo_approve_time=null,todo_modify_time=null,todo_end_time=null WHERE company_id=? AND product_id=? `
  1019. _, err = to.Raw(sql, sellerId, sellerName, groupId, departmentId, companyId, productId).Exec()
  1020. if err != nil {
  1021. return
  1022. }
  1023. } else {
  1024. sql := `UPDATE company_product SET seller_id=?,group_id=?,department_id=?,modify_time=NOW(),todo_status="无任务",todo_create_time=null,todo_approve_time=null,todo_modify_time=null,todo_end_time=null WHERE company_id=? AND product_id=? `
  1025. _, err = to.Raw(sql, sellerId, groupId, departmentId, companyId, productId).Exec()
  1026. if err != nil {
  1027. return
  1028. }
  1029. }
  1030. // 将历史的任务给标记删除掉
  1031. sql := `UPDATE company_todo SET is_delete=1,modify_time=NOW() WHERE company_id=? AND product_id=? AND is_delete = 0 `
  1032. _, err = to.Raw(sql, companyId, productId).Exec()
  1033. if err != nil {
  1034. return
  1035. }
  1036. return
  1037. }
  1038. // UpdateCompanyTryStage 更新试用客户标签
  1039. func UpdateCompanyTryStage(companyId, productId, tryStage int) (err error) {
  1040. o := orm.NewOrm()
  1041. sql := `UPDATE company_product SET try_stage=? WHERE company_id=? AND product_id=? and status="试用"`
  1042. _, err = o.Raw(sql, tryStage, companyId, productId).Exec()
  1043. return
  1044. }
  1045. func CheckCompanyProductByName(companyName string, productId int) (item *CompanyProductDetail, err error) {
  1046. o := orm.NewOrm()
  1047. sql := ` SELECT * FROM company AS a
  1048. INNER JOIN company_product AS b ON a.company_id=b.company_id
  1049. WHERE a.company_name=?
  1050. AND b.product_id=? `
  1051. err = o.Raw(sql, companyName, productId).QueryRow(&item)
  1052. return
  1053. }
  1054. func CheckCompanyProductById(companyId, productId int) (item *CompanyProductDetail, err error) {
  1055. o := orm.NewOrm()
  1056. sql := ` SELECT * FROM company AS a
  1057. INNER JOIN company_product AS b ON a.company_id=b.company_id
  1058. WHERE a.company_id=?
  1059. AND b.product_id=? `
  1060. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  1061. return
  1062. }
  1063. func CheckCompanyProductByCreditCode(creditCode string, productId int) (item *CompanyProductDetail, err error) {
  1064. o := orm.NewOrm()
  1065. sql := ` SELECT * FROM company AS a
  1066. INNER JOIN company_product AS b ON a.company_id=b.company_id
  1067. WHERE a.credit_code=?
  1068. AND b.product_id=? `
  1069. err = o.Raw(sql, creditCode, productId).QueryRow(&item)
  1070. return
  1071. }
  1072. // 新增客户请求参数
  1073. type CheckCompanyInfoResp struct {
  1074. Status int `description:"检测状态:1:跳转到领取页面,0:不跳转,继续操作"`
  1075. CompanyId int `description:"客户id"`
  1076. ProductName string `description:"产品名称"`
  1077. }
  1078. type CheckCompanyInfoRepeatResp struct {
  1079. Status int `description:"检测状态:1:跳转到领取页面,0:不跳转,继续操作"`
  1080. RepeatStatus int `description:"检测状态:0:无重复 1:信用码重复 2:公司名重复"`
  1081. CompanyId int `description:"客户id"`
  1082. ProductName string `description:"产品名称"`
  1083. }
  1084. type ButtonPermission struct {
  1085. BtnView bool `description:"查看按钮权限:true显示,false不显示"`
  1086. BtnEdit bool `description:"编辑按钮权限:true显示,false不显示"`
  1087. BtnDelete bool `description:"删除按钮权限:true显示,false不显示"`
  1088. BtnSuspend bool `description:"暂停/启用按钮权限:true显示,false不显示"`
  1089. BtnDelay bool `description:"申请延期按钮权限:true显示,false不显示"`
  1090. BtnTurnPositive bool `description:"申请转正按钮权限:true显示,false不显示"`
  1091. BtnUpdate bool `description:"服务更新按钮权限:true显示,false不显示"`
  1092. BtnAddAgreement bool `description:"补充协议按钮权限:true显示,false不显示"`
  1093. BtnThaw bool `description:"申请解冻按钮权限:true显示,false不显示"`
  1094. BtnApplyReceive bool `description:"申请领取按钮权限:true显示,false不显示"`
  1095. BtnReceive bool `description:"领取客户按钮权限:true显示,false不显示"`
  1096. BtnModifySeller bool `description:"修改销售按钮权限:true显示,false不显示"`
  1097. BtnReceiveOther bool `description:"领取其他部门客户按钮权限:true显示,false不显示"`
  1098. BtnFreeze bool `description:"冻结按钮权限:true显示,false不显示"`
  1099. BtnTryOut bool `description:"增开试用:true显示,false不显示"`
  1100. BtnDetail bool `description:"详情按钮:true显示,false不显示"`
  1101. BtnRemarkEdit bool `description:"编辑备注按钮:true显示,false不显示"`
  1102. BtnRemarkView bool `description:"查看备注按钮:true显示,false不显示"`
  1103. BtnShare bool `description:"设置共享按钮:true显示,false不显示"`
  1104. BtnServiceRecord bool `description:"查看服务记录按钮:true显示,false不显示"`
  1105. BtnClose bool `description:"关闭客户按钮:true显示,false不显示"`
  1106. BtnLoss bool `description:"转流失按钮:true显示,false不显示"`
  1107. }
  1108. type ButtonSearchPermission struct {
  1109. BtnView bool `description:"查看按钮权限:true显示,false不显示"`
  1110. BtnUpdate bool `description:"服务更新按钮权限:true显示,false不显示"`
  1111. BtnEdit bool `description:"编辑按钮权限:true显示,false不显示"`
  1112. BtnDelete bool `description:"删除按钮权限:true显示,false不显示"`
  1113. BtnSuspend bool `description:"暂停/启用按钮权限:true显示,false不显示"`
  1114. BtnDelay bool `description:"申请延期按钮权限:true显示,false不显示"`
  1115. BtnTurnPositive bool `description:"申请转正按钮权限:true显示,false不显示"`
  1116. BtnThaw bool `description:"申请解冻按钮权限:true显示,false不显示"`
  1117. BtnApplyReceive bool `description:"申请领取按钮权限:true显示,false不显示"`
  1118. BtnReceive bool `description:"领取客户按钮权限:true显示,false不显示"`
  1119. BtnModifySeller bool `description:"修改销售按钮权限:true显示,false不显示"`
  1120. BtnReceiveOther bool `description:"领取其他部门客户按钮权限:true显示,false不显示"`
  1121. }
  1122. type ButtonDetailPermission struct {
  1123. BtnEdit bool `description:"编辑按钮权限:true显示,false不显示"`
  1124. BtnDelete bool `description:"删除按钮权限:true显示,false不显示"`
  1125. BtnHistoryList bool `description:"历史签约按钮权限:true显示,false不显示"`
  1126. BaseInfoEdit bool `description:"客户基础信息编辑操作:true可操作,false不可操作"`
  1127. FiccEdit bool `description:"ficc类型,编辑按钮权限:true显示,false不显示"`
  1128. FiccDelete bool `description:"ficc类型,删除按钮权限:true显示,false不显示"`
  1129. RaiEdit bool `description:"权益类型,编辑按钮权限:true显示,false不显示"`
  1130. RaiDelete bool `description:"权益类型,删除按钮权限:true显示,false不显示"`
  1131. }
  1132. func GetCompanyListExport(condition string, pars []interface{}) (items []*CompanyItem, err error) {
  1133. o := orm.NewOrm()
  1134. sql := `SELECT a.company_id,a.company_name,a.credit_code,a.company_code,a.created_time,a.address,
  1135. GROUP_CONCAT(b.status ORDER BY b.product_id ASC SEPARATOR '/') AS status,
  1136. GROUP_CONCAT(DISTINCT b.seller_name ORDER BY b.product_id ASC SEPARATOR '/') AS seller_name,
  1137. GROUP_CONCAT(DISTINCT b.industry_name ORDER BY b.product_id ASC SEPARATOR '/') AS industry_name,
  1138. GROUP_CONCAT(DISTINCT b.product_name ORDER BY b.product_id ASC SEPARATOR '/') AS company_type,
  1139. GROUP_CONCAT(b.start_date ORDER BY b.product_id ASC SEPARATOR '/') AS start_date,
  1140. GROUP_CONCAT(b.end_date ORDER BY b.product_id ASC SEPARATOR '/') AS end_date,
  1141. GROUP_CONCAT(DISTINCT b.loss_time ORDER BY b.product_id ASC SEPARATOR '/') AS loss_time,
  1142. GROUP_CONCAT(DISTINCT b.lose_reason ORDER BY b.product_id ASC SEPARATOR '/') AS lose_reason,
  1143. GROUP_CONCAT(DISTINCT b.source ORDER BY b.product_id ASC SEPARATOR '/') AS source,
  1144. GROUP_CONCAT(DISTINCT b.reasons ORDER BY b.product_id ASC SEPARATOR '/') AS reasons,
  1145. GROUP_CONCAT(DISTINCT b.approve_status ORDER BY b.product_id ASC SEPARATOR '/') AS approve_status,
  1146. GROUP_CONCAT(DISTINCT b.group_id ORDER BY b.product_id ASC SEPARATOR '/') AS group_id,
  1147. b.is_suspend,
  1148. b.freeze_start_date,
  1149. b.freeze_end_date,
  1150. b.seller_id,
  1151. b.product_id
  1152. FROM company AS a
  1153. INNER JOIN company_product AS b ON a.company_id=b.company_id
  1154. WHERE a.enabled=1 AND a.company_id<>1 `
  1155. if condition != "" {
  1156. sql += condition
  1157. }
  1158. sql += ` GROUP BY a.company_id ORDER BY a.last_updated_time DESC `
  1159. _, err = o.Raw(sql, pars).QueryRows(&items)
  1160. return
  1161. }
  1162. // 冻结客户请求参数
  1163. type CompanyFreezeReq struct {
  1164. CompanyId int `description:"客户id"`
  1165. CompanyType string `description:"客户类型:ficc/权益"`
  1166. Remark string `description:"备注"`
  1167. }
  1168. // 冻结客户
  1169. func CompanyFreeze(companyId, productId int, freezeReason string) (err error) {
  1170. o := orm.NewOrm()
  1171. to, err := o.Begin()
  1172. if err != nil {
  1173. return
  1174. }
  1175. defer func() {
  1176. if err != nil {
  1177. _ = to.Rollback()
  1178. } else {
  1179. _ = to.Commit()
  1180. }
  1181. }()
  1182. freezeStartDate := time.Now().Format(utils.FormatDate)
  1183. freezeEndDate := time.Now().AddDate(0, 3, 0).Format(utils.FormatDate)
  1184. // ficc是两个月的冻结期
  1185. if productId == 1 {
  1186. freezeEndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  1187. }
  1188. // 权益也调整为 两个月的冻结期
  1189. if productId == 2 {
  1190. freezeEndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  1191. }
  1192. //修改用户产品状态
  1193. sql := `UPDATE company_product SET status='冻结',is_formal=0,is_suspend=0,freeze_time=NOW(),modify_time=NOW(),start_date=?,end_date=?,freeze_start_date=?,freeze_end_date=?,freeze_reason=?,try_stage=1 WHERE company_id=? AND product_id=? `
  1194. _, err = to.Raw(sql, freezeStartDate, freezeEndDate, freezeStartDate, freezeEndDate, freezeReason, companyId, productId).Exec()
  1195. if err != nil {
  1196. return err
  1197. }
  1198. //修改产品权限状态为关闭
  1199. sql = `UPDATE company_report_permission SET status='关闭',modify_time=NOW() WHERE company_id= ? AND product_id = ? `
  1200. _, err = to.Raw(sql, companyId, productId).Exec()
  1201. if err != nil {
  1202. return err
  1203. }
  1204. //修改客户为关闭
  1205. sql = `UPDATE company SET type=3,last_updated_time=NOW(),start_date=?,end_date=? WHERE company_id=? `
  1206. _, err = to.Raw(sql, freezeStartDate, freezeEndDate, companyId).Exec()
  1207. if err != nil {
  1208. return err
  1209. }
  1210. return
  1211. }
  1212. func ModifyCompanyGroupId(sellerId, groupId int) (err error) {
  1213. o := orm.NewOrm()
  1214. sql := `UPDATE company_product SET group_id=? WHERE seller_id=? `
  1215. _, err = o.Raw(sql, groupId, sellerId).Exec()
  1216. return
  1217. }
  1218. func ModifyCompanyDepartmentId(sellerId, departmentId int) (err error) {
  1219. o := orm.NewOrm()
  1220. sql := `UPDATE company_product SET department_id=? WHERE seller_id=? `
  1221. _, err = o.Raw(sql, departmentId, sellerId).Exec()
  1222. return
  1223. }
  1224. // CompanyTryOutReasonReq 编辑客户未续约情况说明请求参数
  1225. type CompanyTryOutReasonReq struct {
  1226. CompanyId int `description:"客户id"`
  1227. ProductId int `description:"客户产品id:ficc:1;权益:2"`
  1228. Remark string `description:"备注"`
  1229. }
  1230. // RenewalReasonReq 新增客户未续约情况说明请求参数
  1231. type RenewalReasonReq struct {
  1232. CompanyId int `description:"客户id"`
  1233. ProductId int `description:"客户产品id:ficc:1;权益:2"`
  1234. Remark string `description:"未续约理由"`
  1235. Renew int `description:"是否勾选不再跟进 1:勾选,0:未勾选"`
  1236. RenewalTodo string `description:"待办事项说明"`
  1237. }
  1238. // TryOutReq 新增客户未续约情况说明请求参数
  1239. type TryOutReq struct {
  1240. CompanyId int `description:"客户id"`
  1241. ProductId int `description:"客户产品id:ficc:1;权益:2"`
  1242. OperationId int `description:"operation record id"`
  1243. Remark string `description:"未续约理由"`
  1244. Renew int `description:"是否勾选不再跟进 1:勾选,0:未勾选"`
  1245. RenewalTodo string `description:"待办事项说明"`
  1246. }
  1247. func GetFiccReportListByMobile(mobiles string) (items []*ViewReportList, err error) {
  1248. dataName := ""
  1249. sql := ``
  1250. if utils.RunMode == "debug" {
  1251. dataName = "test_v2_hongze_rddp"
  1252. } else {
  1253. dataName = "hongze_rddp"
  1254. }
  1255. ficcSql := `SELECT
  1256. rr.research_report_name,
  1257. rr.type AS report_type,
  1258. 'ficc' AS txt_type,
  1259. '--' AS match_type_name,
  1260. '--' AS stop_time,
  1261. uvh.created_time AS created_time
  1262. FROM
  1263. user_view_history uvh
  1264. LEFT JOIN research_report rr ON rr.research_report_id = uvh.research_report_id
  1265. WHERE
  1266. uvh.mobile in (` + mobiles + `)
  1267. UNION ALL
  1268. SELECT
  1269. r.title AS research_report_name,
  1270. 'rddp' AS report_type,
  1271. 'ficc' AS txt_type,
  1272. r.classify_name_first AS match_type_name,
  1273. '--' AS stop_time,
  1274. rvr.create_time AS created_time
  1275. FROM %s.report_view_record rvr
  1276. LEFT JOIN %s.report r ON r.id = rvr.report_id
  1277. WHERE
  1278. rvr.mobile in (` + mobiles + `)
  1279. UNION ALL
  1280. SELECT
  1281. cha.permission_name AS research_report_name,
  1282. 'advisory' AS report_type,
  1283. 'ficc' AS txt_type,
  1284. cha.classify_name AS match_type_name,
  1285. '--' AS stop_time,
  1286. auc.create_time AS created_time
  1287. FROM
  1288. advisory_user_chart_article_record auc
  1289. LEFT JOIN chart_permission cha ON cha.chart_permission_id = auc.chart_permission_id
  1290. WHERE
  1291. auc.mobile in (` + mobiles + `)`
  1292. sql = ` SELECT * FROM ( ` + ficcSql + `
  1293. )AS t ORDER BY t.created_time DESC`
  1294. o := orm.NewOrm()
  1295. sql = fmt.Sprintf(sql, dataName, dataName)
  1296. _, err = o.Raw(sql).QueryRows(&items)
  1297. return
  1298. }
  1299. func GetRightsReportListByMobile(mobiles string) (items []*ViewReportList, err error) {
  1300. rightsSql := `SELECT
  1301. art.title AS research_report_name,
  1302. 'cygx' AS report_type,
  1303. 'rights' AS txt_type,
  1304. art.match_type_name,
  1305. h.stop_time,
  1306. h.create_time AS created_time
  1307. FROM
  1308. cygx_article_history_record_newpv h
  1309. LEFT JOIN cygx_article art ON art.article_id = h.article_id
  1310. WHERE
  1311. h.mobile in (` + mobiles + `) AND h.company_id != 16 `
  1312. sql := ` SELECT * FROM ( ` + rightsSql + `
  1313. )AS t ORDER BY t.created_time DESC`
  1314. o := orm.NewOrm()
  1315. _, err = o.Raw(sql).QueryRows(&items)
  1316. return
  1317. }
  1318. func GetFiccReportListByEmail(emails string) (items []*ViewReportList, err error) {
  1319. dataName := ""
  1320. sql := ``
  1321. if utils.RunMode == "debug" {
  1322. dataName = "test_v2_hongze_rddp"
  1323. } else {
  1324. dataName = "hongze_rddp"
  1325. }
  1326. ficcSql := `SELECT
  1327. rr.research_report_name,
  1328. rr.type AS report_type,
  1329. 'ficc' AS txt_type,
  1330. '--' AS match_type_name,
  1331. '--' AS stop_time,
  1332. uvh.created_time AS created_time
  1333. FROM
  1334. user_view_history uvh
  1335. INNER JOIN research_report rr ON rr.research_report_id = uvh.research_report_id
  1336. WHERE
  1337. uvh.email in (` + emails + `)
  1338. UNION ALL
  1339. SELECT
  1340. r.title AS research_report_name,
  1341. 'rddp' AS report_type,
  1342. 'ficc' AS txt_type,
  1343. r.classify_name_first AS match_type_name,
  1344. '--' AS stop_time,
  1345. rvr.create_time AS created_time
  1346. FROM %s.report_view_record rvr
  1347. INNER JOIN %s.report r ON r.id = rvr.report_id
  1348. WHERE
  1349. rvr.email in (` + emails + `)
  1350. UNION ALL
  1351. SELECT
  1352. cha.permission_name AS research_report_name,
  1353. 'advisory' AS report_type,
  1354. 'ficc' AS txt_type,
  1355. cha.classify_name AS match_type_name,
  1356. '--' AS stop_time,
  1357. auc.create_time AS created_time
  1358. FROM
  1359. advisory_user_chart_article_record auc
  1360. INNER JOIN chart_permission cha ON cha.chart_permission_id = auc.chart_permission_id
  1361. WHERE
  1362. auc.email in (` + emails + `) `
  1363. sql = ` SELECT * FROM ( ` + ficcSql + `
  1364. )AS t ORDER BY t.created_time DESC`
  1365. o := orm.NewOrm()
  1366. sql = fmt.Sprintf(sql, dataName, dataName)
  1367. _, err = o.Raw(sql).QueryRows(&items)
  1368. return
  1369. }
  1370. func GetRightsReportListByEmail(emails string) (items []*ViewReportList, err error) {
  1371. rightsSql := `SELECT
  1372. art.title AS research_report_name,
  1373. 'cygx' AS report_type,
  1374. 'rights' AS txt_type,
  1375. art.match_type_name,
  1376. h.stop_time,
  1377. h.create_time AS created_time
  1378. FROM
  1379. cygx_article_history_record_newpv h
  1380. INNER JOIN cygx_article art ON art.article_id = h.article_id
  1381. WHERE
  1382. h.email in (` + emails + `) AND h.company_id != 16 `
  1383. sql := ` SELECT * FROM ( ` + rightsSql + `
  1384. )AS t ORDER BY t.created_time DESC`
  1385. o := orm.NewOrm()
  1386. _, err = o.Raw(sql).QueryRows(&items)
  1387. return
  1388. }
  1389. // ModifyCompanyProductLastViewData 修改客户产品的总共阅读次数以及最近阅读时间
  1390. func ModifyCompanyProductLastViewData(companyId, productId, viewTotal int, lastViewTime string) (err error) {
  1391. o := orm.NewOrm()
  1392. sql := `UPDATE company_product SET view_total=?,last_view_time=? WHERE company_id=? AND product_id=? `
  1393. _, err = o.Raw(sql, viewTotal, lastViewTime, companyId, productId).Exec()
  1394. if err != nil {
  1395. return err
  1396. }
  1397. return
  1398. }
  1399. // RemarkReq 新增备注请求
  1400. type RemarkReq struct {
  1401. CompanyId int `description:"客户id"`
  1402. Remark string `description:"备注"`
  1403. }
  1404. // RemarkResp 备注说明
  1405. type RemarkResp struct {
  1406. Remark string `description:"未续约说明"`
  1407. ProductName string `description:"客户产品:ficc:权益:"`
  1408. CreateTime string `description:"添加时间"`
  1409. }
  1410. type RoadShowTotalSlice struct {
  1411. Total int `description:"总路演数"`
  1412. CompanyId int `description:"用户id"`
  1413. }
  1414. // 根据用户id字符串获取企业用户的路演总次数
  1415. func GetRoadShowTotal(companyIds, date, endTime string) (items []*RoadShowTotalSlice, err error) {
  1416. //如果companyIds是空串,那么直接返回
  1417. if companyIds == "" {
  1418. return
  1419. }
  1420. o := orm.NewOrm()
  1421. sql := `SELECT
  1422. COUNT(1) total,
  1423. t.company_id
  1424. FROM
  1425. (
  1426. SELECT
  1427. a.rs_calendar_id,
  1428. a.company_id
  1429. FROM
  1430. rs_calendar AS a
  1431. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
  1432. WHERE
  1433. a.company_id in (` + companyIds + `)
  1434. AND a.activity_type = '路演'
  1435. AND b.status = 2
  1436. AND b.end_date <= ?
  1437. AND b.end_time < ?
  1438. ) AS t
  1439. GROUP BY
  1440. company_id`
  1441. _, err = o.Raw(sql, date, endTime).QueryRows(&items)
  1442. return
  1443. }
  1444. type RoadShowCalendar struct {
  1445. RsCalendarId int `orm:"column(rs_calendar_id);pk"`
  1446. SysUserId int `description:"创建人id"`
  1447. SysUserRealName string `description:"创建人名称"`
  1448. ActivityType string `description:"活动类型"`
  1449. RoadshowType string `description:"路演形式"`
  1450. RoadshowPlatform string `description:"路演平台"`
  1451. CompanyId int `description:"客户id"`
  1452. CompanyName string `description:"客户名称"`
  1453. Province string `description:"省"`
  1454. ProvinceCode string `description:"省编码"`
  1455. City string `description:"市"`
  1456. CityCode string `description:"市编码"`
  1457. Theme string `description:"会议主题"`
  1458. CooperationName string `description:"合作方名称"`
  1459. Title string `description:"展示在日历的标题"`
  1460. Source int8 `description:"来源,0:自系统,1:上海方的"`
  1461. CreateTime time.Time
  1462. ModifyTime time.Time
  1463. ActivityCategory string `description:"活动类别"`
  1464. IsSynced int `description:"是否与上海同步 0:未同步 1:已同步"`
  1465. EndDate time.Time
  1466. }
  1467. func GetRoadShowList(companyId string) (items []*RoadShowCalendar, err error) {
  1468. o := orm.NewOrm()
  1469. sql := `SELECT
  1470. a.*,b.end_date
  1471. FROM
  1472. rs_calendar AS a
  1473. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id
  1474. WHERE
  1475. a.source = 0
  1476. AND a.company_id=?
  1477. AND b.status = 2
  1478. AND NOW()> DATE_FORMAT( CONCAT( end_date, " ", end_time ), '%Y-%m-%d %H:%i:%S' )
  1479. GROUP BY rs_calendar_id ORDER BY create_time DESC `
  1480. _, err = o.Raw(sql, companyId).QueryRows(&items)
  1481. return
  1482. }
  1483. type RoadShowListResp struct {
  1484. SysUserRealName string `description:"对接销售"`
  1485. RoadshowType string `description:"路演形式"`
  1486. RoadshowPlatform string `description:"路演平台:线上时为平台,线下时为省市"`
  1487. RoadShowTime string `description:"路演时间"`
  1488. Researchers string `description:"研究员"`
  1489. }
  1490. func GetRoadShowResearchers(calendarId int) (items []*string, err error) {
  1491. o := orm.NewOrm()
  1492. sql := `SELECT researcher_name FROM rs_calendar_researcher WHERE rs_calendar_id=? AND status=2 AND NOW()> DATE_FORMAT( CONCAT( end_date, " ", end_time ), '%Y-%m-%d %H:%i:%S' ) `
  1493. _, err = o.Raw(sql, calendarId).QueryRows(&items)
  1494. return
  1495. }
  1496. type CompanyNameAndId struct {
  1497. CompanyId int `description:"公司id"`
  1498. CompanyName string `description:"公司名称"`
  1499. }
  1500. type CompanyNameAndIdListResp struct {
  1501. List []*CompanyNameAndId
  1502. }
  1503. // GetCompanyIdListByproductName 获取不同种类不同状态下的公司ID
  1504. func GetCompanyIdListByproductName(condition string, pars []interface{}) (items []*CompanyNameAndId, err error) {
  1505. o := orm.NewOrm()
  1506. sql := `SELECT
  1507. a.company_id,a.company_name
  1508. FROM
  1509. company AS a
  1510. INNER JOIN company_product AS b ON a.company_id = b.company_id
  1511. WHERE
  1512. a.enabled = 1 `
  1513. if condition != `` {
  1514. sql += condition
  1515. }
  1516. _, err = o.Raw(sql, pars).QueryRows(&items)
  1517. return
  1518. }
  1519. // CompanyTryOutDayListResp 客户累计试用天数
  1520. type CompanyTryOutDayListResp struct {
  1521. Paging *paging.PagingItem
  1522. List []*CompanyProductTryOutUpdateLog
  1523. }
  1524. // 共享客户
  1525. type CompanyShareReq struct {
  1526. CompanyId int `description:"客户id"`
  1527. IsShare int `description:"0取消共享 1共享"`
  1528. }
  1529. func GetShareCompanyListCount(condition string, pars []interface{}) (count int, err error) {
  1530. o := orm.NewOrm()
  1531. sql := `SELECT COUNT(DISTINCT b.company_id) AS count
  1532. FROM company AS a
  1533. INNER JOIN company_product AS b ON a.company_id=b.company_id
  1534. WHERE a.enabled=1 `
  1535. if condition != "" {
  1536. sql += condition
  1537. }
  1538. err = o.Raw(sql, pars).QueryRow(&count)
  1539. return
  1540. }
  1541. func GetShareCompanyList(condition, sortStr string, pars []interface{}, startSize, pageSize int) (items []*CompanyItem, err error) {
  1542. o := orm.NewOrm()
  1543. // 七天前的时间-用于查询周阅读活跃, 此处的需求是
  1544. // FICC客户、共享客户: 以FICC最后一次阅读时间作为参考, 七日内有阅读量则为活跃
  1545. // 权益客户: 以权益最后一次阅读时间作为参考
  1546. t := time.Now().Local().AddDate(0, 0, -7).Format(utils.FormatDate)
  1547. sql := `SELECT a.company_id,a.company_name,a.credit_code,a.company_code,a.created_time,a.province,a.city,
  1548. a.address,a.region_type,b.group_id,b.road_show_total,a.is_share,a.share_seller_id,a.share_seller,
  1549. CASE
  1550. WHEN GROUP_CONCAT(b.status) LIKE "%永续%" THEN 1
  1551. WHEN GROUP_CONCAT(b.status) LIKE "%正式%" THEN 2
  1552. WHEN GROUP_CONCAT(b.status) LIKE "%试用%" THEN 3
  1553. WHEN GROUP_CONCAT(b.status) LIKE "%冻结%" THEN 4
  1554. WHEN GROUP_CONCAT(b.status) LIKE "%流失%" THEN 5
  1555. ELSE 10 END
  1556. as sort_status,
  1557. CASE
  1558. WHEN GROUP_CONCAT(b.try_stage) LIKE "%2%" THEN 1
  1559. WHEN GROUP_CONCAT(b.try_stage) LIKE "%3%" THEN 2
  1560. WHEN GROUP_CONCAT(b.try_stage) LIKE "%4%" THEN 3
  1561. WHEN GROUP_CONCAT(b.try_stage) LIKE "%1%" THEN 4
  1562. ELSE 10 END
  1563. as sort_try_stage,
  1564. CASE
  1565. WHEN GROUP_CONCAT(b.todo_status) LIKE "%未完成%" AND GROUP_CONCAT(b.todo_end_time) is not null THEN GROUP_CONCAT(b.todo_end_time)
  1566. ELSE "9999-01-01" END
  1567. as sort_todo_end_time,
  1568. GROUP_CONCAT(b.status ORDER BY b.product_id ASC SEPARATOR '/') AS status,
  1569. GROUP_CONCAT(DISTINCT b.seller_name ORDER BY b.product_id ASC SEPARATOR '/') AS seller_name,
  1570. GROUP_CONCAT(DISTINCT b.seller_id ORDER BY b.product_id ASC SEPARATOR '/') AS seller_ids,
  1571. GROUP_CONCAT(DISTINCT b.package_type ORDER BY b.product_id ASC SEPARATOR '/') AS package_types,
  1572. GROUP_CONCAT(DISTINCT b.industry_name ORDER BY b.product_id ASC SEPARATOR '/') AS industry_name,
  1573. GROUP_CONCAT(DISTINCT b.product_name ORDER BY b.product_id ASC SEPARATOR '/') AS company_type,
  1574. GROUP_CONCAT(DISTINCT b.product_id ORDER BY b.product_id ASC SEPARATOR '/') AS product_ids,
  1575. GROUP_CONCAT(DISTINCT b.view_total ORDER BY b.product_id ASC SEPARATOR '/') AS view_totals,
  1576. GROUP_CONCAT(DISTINCT b.last_view_time ORDER BY b.product_id ASC SEPARATOR '/') AS last_view_times,
  1577. GROUP_CONCAT(b.start_date ORDER BY b.product_id ASC SEPARATOR '/') AS start_date,
  1578. GROUP_CONCAT(b.end_date ORDER BY b.product_id ASC SEPARATOR '/') AS end_date,
  1579. GROUP_CONCAT(DISTINCT b.loss_time ORDER BY b.product_id ASC SEPARATOR '/') AS loss_time,
  1580. GROUP_CONCAT(DISTINCT b.lose_reason ORDER BY b.product_id ASC SEPARATOR '/') AS lose_reason,
  1581. GROUP_CONCAT(DISTINCT b.source ORDER BY b.product_id ASC SEPARATOR '/') AS source,
  1582. GROUP_CONCAT(DISTINCT b.reasons ORDER BY b.product_id ASC SEPARATOR '/') AS reasons,
  1583. GROUP_CONCAT(DISTINCT b.approve_status ORDER BY b.product_id ASC SEPARATOR '/') AS approve_status,
  1584. GROUP_CONCAT(b.try_stage ORDER BY b.product_id ASC SEPARATOR '/') AS try_stage_str,
  1585. GROUP_CONCAT(DISTINCT b.group_id ORDER BY b.product_id ASC SEPARATOR '/') AS group_ids,
  1586. GROUP_CONCAT(DISTINCT b.todo_status ORDER BY b.product_id ASC SEPARATOR '/') AS todo_statuss,
  1587. GROUP_CONCAT(DISTINCT b.todo_end_time ORDER BY b.product_id ASC SEPARATOR '/') AS todo_end_time_str,
  1588. GROUP_CONCAT(DISTINCT b.try_out_day_total ORDER BY b.product_id ASC SEPARATOR '/') AS try_out_day_totals,
  1589. b.is_suspend,
  1590. b.freeze_start_date,
  1591. b.freeze_end_date,
  1592. b.seller_id,
  1593. b.product_id,
  1594. b.formal_time,
  1595. b.freeze_time,b.freeze_reason,b.renewal_reason,
  1596. b.view_total,
  1597. b.last_view_time,
  1598. MAX(b.last_view_time) as max_last_view_time,
  1599. MIN(b.last_view_time) as min_last_view_time,
  1600. MAX(b.end_date) as max_end_date,
  1601. MIN(b.end_date) as min_end_date,
  1602. SUM(b.view_total) as all_view_total,
  1603. SUM(b.try_out_day_total) as all_try_out_day_total,
  1604. IF(LEFT(GROUP_CONCAT(DISTINCT b.last_view_time ORDER BY b.product_id), 19) >= "` + t + `", 1, 0) AS week_view_active,
  1605. (SELECT MAX(create_time) FROM company_service_record WHERE company_id = a.company_id) AS last_service_time,
  1606. (SELECT COUNT(company_service_record_id) FROM company_service_record WHERE company_id = a.company_id) AS service_times
  1607. FROM company AS a
  1608. INNER JOIN company_product AS b ON a.company_id=b.company_id
  1609. WHERE a.enabled=1 `
  1610. if condition != "" {
  1611. sql += condition
  1612. }
  1613. //sortStr := ``
  1614. //如果没有传入排序字段,那么按照状态排序
  1615. if sortStr == "" {
  1616. sortStr = " ORDER BY a.created_time DESC "
  1617. }
  1618. sql += ` GROUP BY a.company_id ` + sortStr + ` LIMIT ?,? `
  1619. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1620. return
  1621. }
  1622. // 分配共享销售
  1623. type MoveShareSellerReq struct {
  1624. CompanyId int `description:"客户id"`
  1625. SellsId int `description:"销售员id"`
  1626. }
  1627. // ExportUserCompanyStatus 联系人导出客户状态
  1628. type ExportUserCompanyStatus struct {
  1629. CompanyId int `description:"客户ID"`
  1630. CompanyName string `description:"客户名称"`
  1631. CompanyStatus string `description:"客户状态: FICC状态/权益状态"`
  1632. }
  1633. // GetExportUserCompanyStatus 获取联系人导出客户状态
  1634. func GetExportUserCompanyStatus(condition string, pars []interface{}) (items []*ExportUserCompanyStatus, err error) {
  1635. o := orm.NewOrm()
  1636. sql := `SELECT
  1637. a.company_id,
  1638. a.company_name,
  1639. GROUP_CONCAT(b.status SEPARATOR '/') AS company_status
  1640. FROM
  1641. company AS a
  1642. INNER JOIN company_product AS b ON a.company_id = b.company_id
  1643. WHERE 1 = 1 `
  1644. if condition != "" {
  1645. sql += condition
  1646. }
  1647. sql += ` GROUP BY a.company_id `
  1648. _, err = o.Raw(sql, pars).QueryRows(&items)
  1649. return
  1650. }
  1651. func GetExportUserByProductId(companyId string, productId int) (items []*ExportUser, err error) {
  1652. o := orm.NewOrm()
  1653. sql := `SELECT a.real_name,a.mobile,a.email,a.position,a.is_maker,department_name,a.company_id,b.subscribe AS is_subscribe
  1654. FROM wx_user AS a
  1655. LEFT JOIN (SELECT * FROM user_record WHERE create_platform = 1 GROUP BY user_id) AS b ON a.user_id = b.user_id
  1656. LEFT JOIN user_seller_relation AS c ON a.user_id = c.user_id
  1657. WHERE a.company_id<>1 AND a.company_id IN(` + companyId + `) AND c.product_id = ?
  1658. GROUP BY a.user_id ORDER BY a.company_id ASC `
  1659. _, err = o.Raw(sql, productId).QueryRows(&items)
  1660. return
  1661. }
  1662. // CloseCompanyReq 关闭客户请求体
  1663. type CloseCompanyReq struct {
  1664. CompanyId int `description:"客户id"`
  1665. Remark string `description:"备注"`
  1666. }
  1667. // CloseCompany 关闭客户
  1668. func CloseCompany(companyId, productId int, reason string) (err error) {
  1669. o := orm.NewOrm()
  1670. tx, e := o.Begin()
  1671. if e != nil {
  1672. err = fmt.Errorf("orm begin err: %s", e.Error())
  1673. return
  1674. }
  1675. defer func() {
  1676. if err != nil {
  1677. _ = tx.Rollback()
  1678. return
  1679. }
  1680. _ = tx.Commit()
  1681. }()
  1682. // 修改产品状态
  1683. sql := `UPDATE company_product SET status = '关闭', is_formal = 0, close_reason = ?, close_time = NOW(), modify_time=NOW(), try_stage = 1, todo_status = "无任务", todo_create_time = null, todo_approve_time = null, todo_modify_time = null, todo_end_time = null WHERE company_id = ? AND product_id = ?`
  1684. _, e = tx.Raw(sql, reason, companyId, productId).Exec()
  1685. if e != nil {
  1686. err = fmt.Errorf("update company product err: %s", e.Error())
  1687. return
  1688. }
  1689. // 修改产品权限
  1690. sql = `UPDATE company_report_permission SET status='关闭', modify_time=NOW() WHERE company_id = ? AND product_id = ?`
  1691. _, e = tx.Raw(sql, companyId, productId).Exec()
  1692. if e != nil {
  1693. err = fmt.Errorf("update company report permission err: %s", e.Error())
  1694. return
  1695. }
  1696. // 将历史的任务给标记删除掉
  1697. sql = `UPDATE company_todo SET is_delete = 1, modify_time=NOW() WHERE company_id = ? AND product_id = ? AND is_delete = 0`
  1698. _, e = tx.Raw(sql, companyId, productId).Exec()
  1699. if e != nil {
  1700. err = fmt.Errorf("update company todo err: %s", e.Error())
  1701. return
  1702. }
  1703. return
  1704. }
  1705. // Close2LossReq 关闭转流失请求体
  1706. type Close2LossReq struct {
  1707. CompanyId int `description:"客户id"`
  1708. }
  1709. // Close2Loss 关闭转流失
  1710. func Close2Loss(companyId, productId int) (err error) {
  1711. o := orm.NewOrm()
  1712. sql := `UPDATE company_product SET status = '流失', is_formal=0, loss_time = NOW(), modify_time = NOW(), lose_reason = '关闭转流失', try_stage = 1, todo_status = "无任务", todo_create_time = null, todo_approve_time = null, todo_modify_time = null, todo_end_time = null, close_reason = '', close_time = null WHERE company_id = ? AND product_id = ?`
  1713. _, err = o.Raw(sql, companyId, productId).Exec()
  1714. return
  1715. }