company_apply.go 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/contract"
  8. "hongze/hz_crm_api/models/contract/response"
  9. "hongze/hz_crm_api/services"
  10. contractService "hongze/hz_crm_api/services/contract"
  11. "hongze/hz_crm_api/utils"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // 申请管理
  17. type CompanyApplyController struct {
  18. BaseAuthController
  19. }
  20. // @Title 申请服务更新-签约历史
  21. // @Description 申请服务更新-签约历史接口
  22. // @Param CompanyId query int true "客户ID"
  23. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  24. // @Success 200 {object} company.CompanyContractHistoryResp
  25. // @router /apply/contract/history/list [get]
  26. func (this *CompanyApplyController) ApplyContractHistoryList() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. companyId, _ := this.GetInt("CompanyId")
  40. if companyId <= 0 {
  41. br.Msg = "参数错误"
  42. br.ErrMsg = "参数错误,客户id小于等于0"
  43. return
  44. }
  45. roleTypeCode := sysUser.RoleTypeCode
  46. productId := services.GetProductId(roleTypeCode)
  47. productIdStr := ``
  48. if productId == 0 {
  49. productIdStr = "1,2"
  50. } else {
  51. productIdStr = strconv.Itoa(productId)
  52. }
  53. list, err := company.GetCompanyContractHistoryList(companyId, productIdStr)
  54. if err != nil {
  55. br.Msg = "获取信息失败"
  56. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  57. return
  58. }
  59. listLen := len(list)
  60. // 权益permissions
  61. //raiPermissions := make([]*company.PermissionLookItem, 0)
  62. //if strings.Contains(productIdStr, "2") {
  63. // ps, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
  64. // if e != nil {
  65. // br.Msg = "获取失败"
  66. // br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
  67. // return
  68. // }
  69. // raiPermissions = ps
  70. //}
  71. //expMap := map[int]string{0: "(3w)", 1: "(5w)"} // 买方研选价格
  72. for i := 0; i < listLen; i++ {
  73. companyContract := list[i]
  74. list[i].ModifyTimeStr = companyContract.ModifyTime.Format(utils.FormatDateTime)
  75. productId = list[i].ProductId
  76. if productId == 1 {
  77. permissionClassifyArr, e := services.GetPermissionFirstArr(utils.COMPANY_PRODUCT_FICC_ID)
  78. if e != nil {
  79. br.Msg = "获取失败"
  80. br.ErrMsg = "获取权限分类失败,Err:" + e.Error()
  81. return
  82. }
  83. for _, v := range permissionClassifyArr {
  84. checkList := make([]int, 0)
  85. plist := new(company.ContractPermissionList)
  86. plist.Items = make([]*company.PermissionLookItem, 0)
  87. items, err := company.GetPermissionLookItemsExtByParentId(productIdStr, v.ChartPermissionId)
  88. if err != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  91. return
  92. }
  93. if len(items) > 0 {
  94. for _, n := range items {
  95. count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, companyContract.CompanyContractId, n.ChartPermissionId)
  96. if err != nil {
  97. br.Msg = "获取失败"
  98. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  99. return
  100. }
  101. if count > 0 {
  102. checkList = append(checkList, n.ChartPermissionId)
  103. }
  104. }
  105. plist.Items = items
  106. }
  107. plist.ClassifyName = v.PermissionName
  108. plist.CheckList = checkList
  109. list[i].PermissionList = append(list[i].PermissionList, plist)
  110. }
  111. continue
  112. }
  113. // 权益
  114. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  115. //classifyName := "权益"
  116. checkList := make([]int, 0)
  117. plist := new(company.ContractPermissionList)
  118. //items, err := company.GetPermissionLookItemsExt(productIdStr, utils.COMPANY_PRODUCT_RAI_NAME)
  119. //if err != nil {
  120. // br.Msg = "获取失败"
  121. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  122. // return
  123. //}
  124. var expensiveYx int
  125. var pints float64 // 现在就一个行业有点数,先这么写吧
  126. hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContract.CompanyContractId)
  127. if e != nil {
  128. br.Msg = "获取失败"
  129. br.ErrMsg = "获取合同权限信息失败,Err:" + e.Error()
  130. return
  131. }
  132. hasMap := make(map[int]*company.CompanyContractPermission)
  133. for _, p := range hasPermissions {
  134. hasMap[p.ChartPermissionId] = p
  135. if p.ExpensiveYx > 0 {
  136. expensiveYx = p.ExpensiveYx
  137. }
  138. if p.Points > 0 {
  139. pints = p.Points
  140. }
  141. }
  142. checkItems := make([]*company.PermissionLookItem, 0)
  143. raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
  144. if e != nil {
  145. br.Msg = "获取失败"
  146. br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
  147. return
  148. }
  149. //大套餐类型单独展示
  150. if companyContract.RaiPackageType > 0 {
  151. n := new(company.PermissionLookItem)
  152. if companyContract.RaiPackageType == 1 {
  153. n.PermissionName = "70W套餐"
  154. } else if companyContract.RaiPackageType == 2 {
  155. n.PermissionName = "45W套餐"
  156. }
  157. checkList = append(checkList, 0)
  158. checkItems = append(checkItems, n)
  159. for _, n := range raiPermissions {
  160. match := hasMap[n.ChartPermissionId]
  161. if match == nil {
  162. continue
  163. }
  164. //研选订阅、研选扣点包、专家也要单独处理
  165. if n.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN || n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID || n.ChartPermissionId == utils.ZHUAN_JIA_ID {
  166. if n.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  167. if expensiveYx == 1 {
  168. n.PermissionName += "(5w)"
  169. } else if expensiveYx == 2 {
  170. n.PermissionName += "(10w)"
  171. } else if expensiveYx == 0 {
  172. //n.PermissionName += "(3w)"
  173. }
  174. }
  175. if n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  176. n.PermissionName += "(" + fmt.Sprint(pints) + "点)"
  177. }
  178. checkList = append(checkList, n.ChartPermissionId)
  179. checkItems = append(checkItems, n)
  180. }
  181. }
  182. } else {
  183. // PS:本来想把这个移到循环外面去优化一下...但是发现有指针引用变量被改掉的问题, BUG太多了改不完了先这样吧=_=!
  184. for _, n := range raiPermissions {
  185. match := hasMap[n.ChartPermissionId]
  186. if match == nil {
  187. continue
  188. }
  189. // 升级
  190. if match.IsUpgrade == 1 {
  191. n.IsUpgrade = 1
  192. checkList = append(checkList, n.ChartPermissionId)
  193. checkItems = append(checkItems, n)
  194. continue
  195. }
  196. // 买方研选(3w/5w)、 研选扣点包,拼接点数
  197. if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN || n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  198. if expensiveYx == 1 {
  199. n.PermissionName += "(5w)"
  200. } else if expensiveYx == 2 {
  201. n.PermissionName += "(10w)"
  202. } else if expensiveYx == 0 {
  203. //n.PermissionName += "(3w)"
  204. }
  205. if n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  206. n.PermissionName += "(" + fmt.Sprint(pints) + "点)"
  207. }
  208. //n.PermissionName += expMap[match.ExpensiveYx]
  209. checkList = append(checkList, n.ChartPermissionId)
  210. checkItems = append(checkItems, n)
  211. continue
  212. }
  213. checkList = append(checkList, n.ChartPermissionId)
  214. checkItems = append(checkItems, n)
  215. //count, err := company.GetCompanyContractUpgradePermissionCheckByContractId(companyId, companyContract.CompanyContractId, n.ChartPermissionId, 0)
  216. //if err != nil {
  217. // br.Msg = "获取失败"
  218. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  219. // return
  220. //}
  221. //if count > 0 {
  222. // checkList = append(checkList, n.ChartPermissionId)
  223. // checkItems = append(checkItems, n)
  224. //} else {
  225. // count2, err := company.GetCompanyContractUpgradePermissionCheckByContractId(companyId, companyContract.CompanyContractId, n.ChartPermissionId, 1)
  226. // if err != nil {
  227. // br.Msg = "获取失败"
  228. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  229. // return
  230. // }
  231. // if count2 > 0 {
  232. // n.IsUpgrade = 1
  233. // checkList = append(checkList, n.ChartPermissionId)
  234. // checkItems = append(checkItems, n)
  235. // }
  236. //}
  237. }
  238. }
  239. //合并主观客观
  240. //mapPermissionNameList := make(map[string]int)
  241. //for _, v := range items {
  242. // if mapPermissionNameList[v.PermissionName] == 0 {
  243. // plist.Items = append(plist.Items, v)
  244. // mapPermissionNameList[v.PermissionName] = v.ChartPermissionId
  245. // }
  246. //}
  247. plist.Items = checkItems
  248. plist.ClassifyName = utils.COMPANY_PRODUCT_RAI_NAME
  249. plist.CheckList = checkList
  250. list[i].PermissionList = append(list[i].PermissionList, plist)
  251. // CRM8.8-权限主客观合并
  252. newPermissionLookList := contractService.HandleEquityContractPermissionList(list[i].PermissionList)
  253. list[i].PermissionList = newPermissionLookList
  254. }
  255. }
  256. resp := new(company.CompanyContractHistoryResp)
  257. resp.List = list
  258. br.Ret = 200
  259. br.Success = true
  260. br.Msg = "获取成功"
  261. br.Data = resp
  262. }
  263. // GetApplyTurnContractType
  264. // @Title 获取客户申请转正的合同类型
  265. // @Description 获取客户申请转正的合同类型接口
  266. // @Param CompanyId query int true "客户ID"
  267. // @Success 200 {object} company.ApplyContractTypeResp
  268. // @router /apply/contract/getApplyTurnContractType [get]
  269. func (this *CompanyApplyController) GetApplyTurnContractType() {
  270. br := new(models.BaseResponse).Init()
  271. defer func() {
  272. this.Data["json"] = br
  273. this.ServeJSON()
  274. }()
  275. sysUser := this.SysUser
  276. if sysUser == nil {
  277. br.Msg = "请登录"
  278. br.ErrMsg = "请登录,SysUser Is Empty"
  279. br.Ret = 408
  280. return
  281. }
  282. companyId, _ := this.GetInt("CompanyId")
  283. if companyId <= 0 {
  284. br.Msg = "参数错误"
  285. br.ErrMsg = "参数错误,客户id小于等于0"
  286. return
  287. }
  288. roleTypeCode := sysUser.RoleTypeCode
  289. productId := services.GetProductId(roleTypeCode)
  290. if productId == 0 {
  291. br.Msg = "账户异常"
  292. br.ErrMsg = "账户类型异常为:" + roleTypeCode
  293. return
  294. }
  295. contractType, err := services.GetApplyTurnContractType(companyId, productId)
  296. if err != nil {
  297. br.Msg = "获取失败"
  298. br.ErrMsg = "获取合同类型失败,Err:" + err.Error()
  299. return
  300. }
  301. //companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  302. //if err != nil {
  303. // br.Msg = "获取客户信息失败"
  304. // br.ErrMsg = "获取客户信息失败"
  305. // return
  306. //}
  307. //
  308. ////合同类型
  309. //contractType := "新签合同"
  310. //var condition string
  311. //var pars []interface{}
  312. //condition += " AND product_id = ?"
  313. //pars = append(pars, productId)
  314. //condition += " AND status = ?"
  315. //pars = append(pars, 1)
  316. //list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  317. //if err != nil {
  318. // br.Msg = "获取合同信息失败"
  319. // br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
  320. // return
  321. //}
  322. //if len(list) > 0 {
  323. // contractType = "续约合同"
  324. //}
  325. ////查询是否存在正式转试用的记录,如果存在,那么合同类型是续约合同
  326. //total, err := company.GetCompanyProductOperationRecordCount(companyProduct.CompanyId, companyProduct.ProductId)
  327. //if err != nil {
  328. // br.Msg = "查询用户信息异常"
  329. // br.ErrMsg = "查询用户变更记录异常"
  330. // return
  331. //}
  332. //if total > 0 {
  333. // contractType = "续约合同"
  334. //}
  335. resp := company.ApplyContractTypeResp{
  336. ContractType: contractType,
  337. }
  338. br.Data = resp
  339. //合同类型 end
  340. br.Ret = 200
  341. br.Success = true
  342. br.Msg = "获取成功"
  343. }
  344. // @Title 申请服务更新-续约申请详情
  345. // @Description 申请服务更新-续约申请详情接口
  346. // @Param CompanyId query int true "客户ID"
  347. // @Param CompanyContractId query int true "合同id"
  348. // @Success 200 {object} company.CompanyContractDetailResp
  349. // @router /apply/contract/detail [get]
  350. func (this *CompanyApplyController) ApplyContractDetail() {
  351. br := new(models.BaseResponse).Init()
  352. defer func() {
  353. this.Data["json"] = br
  354. this.ServeJSON()
  355. }()
  356. sysUser := this.SysUser
  357. if sysUser == nil {
  358. br.Msg = "请登录"
  359. br.ErrMsg = "请登录,SysUser Is Empty"
  360. br.Ret = 408
  361. return
  362. }
  363. companyId, _ := this.GetInt("CompanyId")
  364. if companyId <= 0 {
  365. br.Msg = "参数错误"
  366. br.ErrMsg = "参数错误,客户id小于等于0"
  367. return
  368. }
  369. companyContractId, _ := this.GetInt("CompanyContractId")
  370. roleTypeCode := sysUser.RoleTypeCode
  371. productId := services.GetProductId(roleTypeCode)
  372. //if productId == 0 {
  373. // br.Msg = "参数错误"
  374. // br.ErrMsg = "客户类型为:" + roleTypeCode
  375. // return
  376. //}
  377. detail, err := company.GetCompanyContractDetail(companyId, productId, companyContractId)
  378. if err != nil {
  379. br.Msg = "获取信息失败"
  380. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  381. return
  382. }
  383. if detail.Source == "系统合同" {
  384. detail.SourceTag = "标准合同"
  385. } else {
  386. detail.SourceTag = "非标合同"
  387. }
  388. if detail.ProductId == 1 {
  389. //子权限切片集合
  390. allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
  391. if e != nil {
  392. br.Msg = "查询基础权限失败"
  393. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  394. return
  395. }
  396. //遍历获取
  397. for _, v := range allFiccPermissions {
  398. if v.ParentId == 0 {
  399. checkList := make([]int, 0)
  400. plist := new(company.PermissionLookList)
  401. items, ok := permissionMap[v.ChartPermissionId]
  402. if !ok {
  403. br.Msg = "获取权限信息失败"
  404. return
  405. }
  406. for _, n := range items {
  407. count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, detail.CompanyContractId, n.ChartPermissionId)
  408. if err != nil {
  409. br.Msg = "获取失败"
  410. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  411. return
  412. }
  413. if count > 0 {
  414. checkList = append(checkList, n.ChartPermissionId)
  415. }
  416. }
  417. plist.Items = items
  418. plist.ClassifyName = v.PermissionName
  419. plist.CheckList = checkList
  420. detail.PermissionList = append(detail.PermissionList, plist)
  421. }
  422. }
  423. }
  424. if detail.ProductId == 2 {
  425. classifyName := "权益"
  426. checkList := make([]int, 0)
  427. plist := new(company.PermissionLookList)
  428. plist.ClassifyName = classifyName
  429. items, e := company.GetPermissionLookItems(detail.ProductId, classifyName)
  430. if e != nil {
  431. br.Msg = "获取失败"
  432. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  433. return
  434. }
  435. mapExpensive := make(map[int]bool) // 通过合同获取所勾选的买方研选5w
  436. permissionList, err := company.GetCompanyContractPermissionByCompanyContractId(companyContractId)
  437. if err != nil {
  438. br.Msg = "获取失败"
  439. br.ErrMsg = "获取合同权限信息失败,Err:" + err.Error()
  440. return
  441. }
  442. permissions := make([]int, 0) // 合同权限IDs
  443. checkItems := make([]*company.PermissionLookItem, 0)
  444. //expMap := map[bool]string{false: "(3w)", true: "(5w)"} // 买方研选价格
  445. //var expensiveYx int
  446. // 未选大套餐, 走老逻辑
  447. var points float64
  448. if detail.RaiPackageType == 0 {
  449. totalForever, err := company.GetCompanyProductRaiForeverCount(companyId) //判断是否是权益的永续客户
  450. if err != nil {
  451. br.Msg = "获取失败"
  452. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  453. return
  454. }
  455. if totalForever > 0 {
  456. detail.Quarter, err = utils.GetQuarterStrStartDatesInRange(detail.StartDate, detail.EndDate) //通过开始时间,结束时间,获取对应季度的拼接字符串
  457. if err != nil {
  458. br.Msg = "获取失败"
  459. br.ErrMsg = "获取季度息失败,Err:" + err.Error()
  460. return
  461. }
  462. }
  463. mapUpgrade := make(map[int]bool) // 通过合同获取所勾选的升级行业权限
  464. for _, v := range permissionList {
  465. if v.IsUpgrade == 1 {
  466. mapUpgrade[v.ChartPermissionId] = true
  467. }
  468. if v.ExpensiveYx > 0 {
  469. mapExpensive[v.ChartPermissionId] = true
  470. //expensiveYx = v.ExpensiveYx
  471. }
  472. if v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  473. points = v.Points
  474. }
  475. permissions = append(permissions, v.ChartPermissionId)
  476. }
  477. for _, n := range items {
  478. if n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  479. n.PermissionName += fmt.Sprint("(", points, "点)")
  480. }
  481. if utils.InArrayByInt(permissions, n.ChartPermissionId) {
  482. checkList = append(checkList, n.ChartPermissionId)
  483. checkItems = append(checkItems, n)
  484. }
  485. }
  486. plist.Items = checkItems
  487. plist.CheckList = checkList
  488. detail.PermissionList = append(detail.PermissionList, plist)
  489. // CRM8.8-权限主客观合并
  490. newPermissionLookList := contractService.HandleEquityPermissionLookList(detail.PermissionList)
  491. for _, c := range newPermissionLookList {
  492. if c.ClassifyName != "权益" {
  493. continue
  494. }
  495. for _, p := range c.Items {
  496. // 行业升级
  497. if mapUpgrade[p.ChartPermissionId] {
  498. if strings.Contains(p.PermissionName, "主观") {
  499. p.PermissionName = strings.Replace(p.PermissionName, "主观", "升级", -1)
  500. continue
  501. }
  502. if strings.Contains(p.PermissionName, "客观") {
  503. p.PermissionName = strings.Replace(p.PermissionName, "客观", "升级", -1)
  504. continue
  505. }
  506. p.PermissionName += "(升级)"
  507. continue
  508. }
  509. // 买方研选
  510. //if p.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  511. // if expensiveYx == 1 {
  512. // p.PermissionName += "(5w)"
  513. // } else if expensiveYx == 2 {
  514. // p.PermissionName += "(10w)"
  515. // }
  516. // //p.PermissionName += expMap[mapExpensive[p.ChartPermissionId]]
  517. //}
  518. }
  519. }
  520. detail.PermissionList = newPermissionLookList
  521. }
  522. // 如果选择的是大套餐, 那么不再展示每个具体的权限, 除大套餐外还需遍历一下专家和研选3w/5w是否有选(这两个与大套餐不互斥, 可额外选择)
  523. if detail.RaiPackageType > 0 {
  524. // 大套餐
  525. bigPackage := new(company.PermissionLookItem)
  526. if detail.RaiPackageType == 1 {
  527. bigPackage.PermissionName = utils.CHART_PERMISSION_NAME_70W
  528. bigPackage.ChartPermissionId = utils.CHART_PERMISSION_ID_70W
  529. checkList = append(checkList, utils.CHART_PERMISSION_ID_70W)
  530. }
  531. if detail.RaiPackageType == 2 {
  532. bigPackage.PermissionName = utils.CHART_PERMISSION_NAME_45W
  533. bigPackage.ChartPermissionId = utils.CHART_PERMISSION_ID_45W
  534. checkList = append(checkList, utils.CHART_PERMISSION_ID_45W)
  535. }
  536. checkItems = append(checkItems, bigPackage)
  537. for _, v := range permissionList {
  538. if v.ExpensiveYx == 1 {
  539. mapExpensive[v.ChartPermissionId] = true
  540. }
  541. if v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  542. points = v.Points
  543. }
  544. permissions = append(permissions, v.ChartPermissionId)
  545. }
  546. // 专家、研选订阅、研选扣点包
  547. for _, n := range items {
  548. if n.ChartPermissionId != utils.ZHUAN_JIA_ID && n.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && n.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  549. continue
  550. }
  551. //if n.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  552. // //n.PermissionName += expMap[mapExpensive[n.ChartPermissionId]]
  553. // if expensiveYx == 1 {
  554. // n.PermissionName += "(5w)"
  555. // } else if expensiveYx == 2 {
  556. // n.PermissionName += "(10w)"
  557. // }
  558. //}
  559. if n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  560. n.PermissionName += fmt.Sprint("(", points, "点)")
  561. }
  562. if utils.InArrayByInt(permissions, n.ChartPermissionId) {
  563. checkList = append(checkList, n.ChartPermissionId)
  564. checkItems = append(checkItems, n)
  565. }
  566. }
  567. plist.Items = checkItems
  568. plist.CheckList = checkList
  569. detail.PermissionList = append(detail.PermissionList, plist)
  570. }
  571. }
  572. resp := new(company.CompanyContractDetailResp)
  573. resp.Item = detail
  574. br.Ret = 200
  575. br.Success = true
  576. br.Msg = "获取成功"
  577. br.Data = resp
  578. }
  579. // @Title 获取客户大于今天的有效合同权限详情
  580. // @Description 获取客户大于今天的有效合同权限详情接口
  581. // @Param CompanyId query int true "客户ID"
  582. // @Success 200 {object} []company.PermissionLookItem
  583. // @router /company/last_contract/detail [get]
  584. func (this *CompanyApplyController) GetLastContractDetail() {
  585. br := new(models.BaseResponse).Init()
  586. defer func() {
  587. this.Data["json"] = br
  588. this.ServeJSON()
  589. }()
  590. sysUser := this.SysUser
  591. if sysUser == nil {
  592. br.Msg = "请登录"
  593. br.ErrMsg = "请登录,SysUser Is Empty"
  594. br.Ret = 408
  595. return
  596. }
  597. companyId, _ := this.GetInt("CompanyId")
  598. if companyId <= 0 {
  599. br.Msg = "参数错误"
  600. br.ErrMsg = "参数错误,客户id小于等于0"
  601. return
  602. }
  603. roleTypeCode := sysUser.RoleTypeCode
  604. productId := services.GetProductId(roleTypeCode)
  605. if productId == 0 {
  606. br.Msg = "参数错误"
  607. br.ErrMsg = "客户类型为:" + roleTypeCode
  608. return
  609. }
  610. //permissionMap := make(map[int]company.PermissionLookItem)
  611. //contractList, err := company.GetCompanyWillContractList(companyId, productId)
  612. //if err != nil {
  613. // br.Msg = "获取合同信息失败"
  614. // br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
  615. // return
  616. //}
  617. //for _, contractInfo := range contractList {
  618. // permissionList, permissionErr := company.GetCompanyContractPermissionListByContractIds(strconv.Itoa(contractInfo.CompanyContractId))
  619. // if permissionErr != nil {
  620. // br.Msg = "获取权限失败"
  621. // br.ErrMsg = "获取权限失败,Err:" + permissionErr.Error()
  622. // return
  623. // }
  624. // for _, v := range permissionList {
  625. // if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  626. // nowEndDateTime, err := time.Parse(utils.FormatDate, v.EndDate)
  627. // if err != nil {
  628. // br.Msg = "获取合同信息失败"
  629. // br.ErrMsg = "获取合同信息失败,合同结束日期格式化失败,Err:" + err.Error()
  630. // return
  631. // }
  632. // perEndDateTime, err := time.Parse(utils.FormatDate, permission.EndDate)
  633. // if err != nil {
  634. // br.Msg = "获取合同信息失败"
  635. // br.ErrMsg = "获取合同信息失败,合同结束日期格式化失败2,Err:" + err.Error()
  636. // return
  637. // }
  638. // //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  639. // if nowEndDateTime.After(perEndDateTime) {
  640. // permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  641. // ChartPermissionId: v.ChartPermissionId,
  642. // PermissionName: v.ChartPermissionName,
  643. // StartDate: v.StartDate,
  644. // EndDate: v.EndDate,
  645. // //Status string `description:"'正式','试用','关闭'"`
  646. // //ExpireDay string `description:"到期天数"`
  647. // ClassifyName: v.ClassifyName,
  648. // }
  649. // }
  650. // } else {
  651. // permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  652. // ChartPermissionId: v.ChartPermissionId,
  653. // PermissionName: v.ChartPermissionName,
  654. // StartDate: v.StartDate,
  655. // EndDate: v.EndDate,
  656. // //Status string `description:"'正式','试用','关闭'"`
  657. // //ExpireDay string `description:"到期天数"`
  658. // ClassifyName: v.ClassifyName,
  659. // }
  660. // }
  661. // }
  662. //}
  663. //
  664. ////获取权限
  665. //permissionList, permissionErr := company.GetCompanyReportPermissionListByProductId(companyId, productId)
  666. //if permissionErr != nil {
  667. // br.Msg = "获取权限失败"
  668. // br.ErrMsg = "获取权限失败,Err:" + permissionErr.Error()
  669. // return
  670. //}
  671. //for _, v := range permissionList {
  672. // if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  673. // nowEndDateTime, err := time.Parse(utils.FormatDate, v.EndDate)
  674. // if err != nil {
  675. // br.Msg = "获取合同信息失败"
  676. // br.ErrMsg = "获取合同信息失败,合同结束日期格式化失败,Err:" + err.Error()
  677. // return
  678. // }
  679. // perEndDateTime, err := time.Parse(utils.FormatDate, permission.EndDate)
  680. // if err != nil {
  681. // br.Msg = "获取合同信息失败"
  682. // br.ErrMsg = "获取合同信息失败,合同结束日期格式化失败2,Err:" + err.Error()
  683. // return
  684. // }
  685. // //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  686. // if nowEndDateTime.After(perEndDateTime) {
  687. // permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  688. // ChartPermissionId: v.ChartPermissionId,
  689. // PermissionName: v.PermissionName,
  690. // StartDate: v.StartDate,
  691. // EndDate: v.EndDate,
  692. // //Status string `description:"'正式','试用','关闭'"`
  693. // //ExpireDay string `description:"到期天数"`
  694. // ClassifyName: v.ClassifyName,
  695. // }
  696. // }
  697. // } else {
  698. // permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  699. // ChartPermissionId: v.ChartPermissionId,
  700. // PermissionName: v.PermissionName,
  701. // StartDate: v.StartDate,
  702. // EndDate: v.EndDate,
  703. // //Status string `description:"'正式','试用','关闭'"`
  704. // //ExpireDay string `description:"到期天数"`
  705. // ClassifyName: v.ClassifyName,
  706. // }
  707. // }
  708. //}
  709. permissionMap, err := services.GetLastContractPermissionList(companyId, productId)
  710. if err != nil {
  711. br.Msg = "获取合同权限信息失败"
  712. br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
  713. return
  714. }
  715. //数据处理
  716. permissionSlice := make([]company.PermissionLookItem, 0)
  717. for _, permission := range permissionMap {
  718. permissionSlice = append(permissionSlice, permission)
  719. }
  720. br.Ret = 200
  721. br.Success = true
  722. br.Msg = "获取成功"
  723. br.Data = permissionSlice
  724. }
  725. // ApplyServiceUpdateOld
  726. // @Title 申请服务更新
  727. // @Description 申请服务更新接口
  728. // @Param request body company.CompanyApplyServiceUpdateReq true "type json string"
  729. // @Success Ret=200 申请成功
  730. //func (this *CompanyApplyController) ApplyServiceUpdateOld() {
  731. // br := new(models.BaseResponse).Init()
  732. // defer func() {
  733. // this.Data["json"] = br
  734. // this.ServeJSON()
  735. // }()
  736. // sysUser := this.SysUser
  737. // if sysUser == nil {
  738. // br.Msg = "请登录"
  739. // br.ErrMsg = "请登录,SysUser Is Empty"
  740. // br.Ret = 408
  741. // return
  742. // }
  743. // var req company.CompanyApplyServiceUpdateReq
  744. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  745. // if err != nil {
  746. // br.Msg = "参数解析异常!"
  747. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  748. // return
  749. // }
  750. // if req.CompanyId <= 0 {
  751. // br.Msg = "参数错误"
  752. // br.ErrMsg = "参数错误,客户id小于等于0"
  753. // return
  754. // }
  755. // if req.StartDate == "" {
  756. // br.Msg = "请选择合同开始日期"
  757. // return
  758. // }
  759. // if req.EndDate == "" {
  760. // br.Msg = "请选择合同结束日期"
  761. // return
  762. // }
  763. // if req.Money <= 0 {
  764. // br.Msg = "合同金额不能小于等于0"
  765. // }
  766. //
  767. // if req.ContractType == "" {
  768. // req.ContractType = "续约合同"
  769. // //br.Msg = "请选择合同类型"
  770. // //return
  771. // }
  772. // roleTypeCode := sysUser.RoleTypeCode
  773. // productId := services.GetProductId(roleTypeCode)
  774. // if productId == 0 {
  775. // br.Msg = "参数错误"
  776. // br.ErrMsg = "客户类型为:" + req.CompanyType
  777. // return
  778. // }
  779. // approveRoleTypeCode := ""
  780. // if productId == 1 {
  781. // approveRoleTypeCode = utils.ROLE_TYPE_CODE_FICC_ADMIN
  782. // } else {
  783. // approveRoleTypeCode = utils.ROLE_TYPE_CODE_RAI_ADMIN
  784. // }
  785. // companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  786. // if err != nil {
  787. // br.Msg = "获取客户信息失败"
  788. // br.ErrMsg = "获取客户信息失败"
  789. // return
  790. // }
  791. // if companyProduct.Status != utils.COMPANY_STATUS_FORMAL {
  792. // br.Msg = "客户状态为:" + companyProduct.Status + ";不可进行服务更新申请"
  793. // br.ErrMsg = "客户状态为:" + companyProduct.Status + ";不可进行服务更新申请"
  794. // return
  795. // }
  796. // var approveUserId int
  797. // var approveUserRealName string
  798. // approveContent := `正式客户申请服务更新`
  799. //
  800. // approveUser, err := company.GetApproveUser(approveRoleTypeCode)
  801. // if err != nil && err.Error() != utils.ErrNoRow() {
  802. // br.Msg = "获取审批信息失败"
  803. // br.ErrMsg = "获取审批人信息失败,Err:" + err.Error()
  804. // return
  805. // }
  806. // if approveUser == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  807. // br.Msg = "审批用户不存在"
  808. // br.ErrMsg = "审批用户不存在"
  809. // return
  810. // }
  811. //
  812. // var companyApprovalId int
  813. // if req.CompanyApprovalId <= 0 {
  814. // contractCode, err := company.GetCompanyContractCode()
  815. // if err != nil {
  816. // br.Msg = "生成合同编码失败"
  817. // br.ErrMsg = "生成合同编码失败,Err:" + err.Error()
  818. // return
  819. // }
  820. // //当前待审批的合同,有且只能存在一条
  821. // count, err := company.GetCompanyContractApproveCount(req.CompanyId, productId)
  822. // if err != nil {
  823. // br.Msg = "获取信息失败"
  824. // br.ErrMsg = "判断是否已存在待审批合同失败,Err:" + err.Error()
  825. // return
  826. // }
  827. // if count > 0 {
  828. // br.Msg = "此客户已提交过申请,请在客户审批列表重新提交"
  829. // return
  830. // }
  831. // contract := new(company.CompanyContract)
  832. // contract.CompanyId = req.CompanyId
  833. // contract.ProductId = productId
  834. // contract.ProductName = companyProduct.ProductName
  835. // contract.CompanyProductId = companyProduct.CompanyProductId
  836. // contract.ContractType = req.ContractType
  837. // contract.ContractCode = contractCode
  838. // contract.StartDate = req.StartDate
  839. // contract.EndDate = req.EndDate
  840. // contract.Money = req.Money
  841. // contract.PayMethod = req.PayMethod
  842. // contract.PayChannel = req.PayChannel
  843. // contract.ImgUrl = req.ImgUrl
  844. // contract.Status = 0
  845. // contract.Source = "上传附件"
  846. // contract.CreateTime = time.Now()
  847. // contract.ModifyTime = time.Now()
  848. // newId, err := company.AddCompanyContract(contract)
  849. // if err != nil {
  850. // br.Msg = "新增合同失败"
  851. // br.ErrMsg = "新增合同失败,Err:" + err.Error()
  852. // return
  853. // }
  854. // permissionArr := strings.Split(req.PermissionIds, ",")
  855. // for _, v := range permissionArr {
  856. // item := new(company.CompanyContractPermission)
  857. // item.CompanyId = req.CompanyId
  858. // item.CompanyContractId = int(newId)
  859. //
  860. // chartPermissionId, tmpErr := strconv.Atoi(v)
  861. // if tmpErr != nil {
  862. // err = tmpErr
  863. // return
  864. // }
  865. // item.ChartPermissionId = chartPermissionId
  866. //
  867. // item.StartDate = req.StartDate
  868. // item.EndDate = req.EndDate
  869. // item.ModifyTime = time.Now()
  870. // item.CreateTime = time.Now()
  871. // err = company.AddCompanyContractPermission(item)
  872. // if err != nil {
  873. // br.Msg = "新增合同失败"
  874. // br.ErrMsg = "新增合同权限失败,Err:" + err.Error()
  875. // return
  876. // }
  877. // //新增日志
  878. // {
  879. // itemLog := new(company.CompanyContractPermissionLog)
  880. // itemLog.CompanyId = req.CompanyId
  881. // itemLog.CompanyContractId = int(newId)
  882. // itemLog.ChartPermissionId = v
  883. // itemLog.StartDate = req.StartDate
  884. // itemLog.EndDate = req.EndDate
  885. // itemLog.ModifyTime = time.Now()
  886. // itemLog.CreateTime = time.Now()
  887. // itemLog.LogCreateTime = time.Now()
  888. // go company.AddCompanyContractPermissionLog(itemLog)
  889. // }
  890. // }
  891. // applyMethod := 5
  892. // //申请类型:1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户,5:正式客户申请服务更新,6:正式客户补充协议
  893. // approval := new(company.CompanyApproval)
  894. // approval.CompanyId = req.CompanyId
  895. // approval.ProductId = productId
  896. // approval.ApproveStatus = "待审批"
  897. // approval.ApproveUserId = 0
  898. // approval.ApproveRoleTypeCode = approveRoleTypeCode
  899. // approval.ApproveRealName = ""
  900. // approval.ApproveTime = time.Now()
  901. // approval.ApproveContent = "服务更新"
  902. // approval.ApplyMethod = applyMethod
  903. // approval.ApplyReasons = ""
  904. // approval.ApplyUserId = sysUser.AdminId
  905. // approval.ApplyRealName = sysUser.RealName
  906. // approval.CreateTime = time.Now()
  907. // approval.ModifyTime = time.Now()
  908. // approval.CompanyContractId = int(newId)
  909. // companyApprovalId, err = company.AddCompanyApproval(approval)
  910. // if err != nil {
  911. // br.Msg = "申请失败"
  912. // br.ErrMsg = "申请失败,Err:" + err.Error()
  913. // return
  914. // }
  915. // } else {
  916. // recode, err := company.GetCompanyApprovalByApprovalId(req.CompanyApprovalId)
  917. // if err != nil {
  918. // br.Msg = "申请失败"
  919. // br.ErrMsg = "获取审批记录失败,Err:" + err.Error()
  920. // return
  921. // }
  922. // err = company.ModifyCompanyApplyServiceUpdate(&req, productId, companyProduct.IsFormal, recode.CompanyContractId)
  923. // if err != nil {
  924. // br.Msg = "申请失败"
  925. // br.ErrMsg = "申请失败,Err:" + err.Error()
  926. // return
  927. // }
  928. // companyApprovalId = req.CompanyApprovalId
  929. // }
  930. // //新增操作记录
  931. // {
  932. // remark := "服务更新"
  933. // operation := "service_update"
  934. // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, approveUserId, companyProduct.CompanyName,
  935. // companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveUserRealName, "", companyProduct.Status)
  936. // }
  937. // //新增客户产品日志
  938. // {
  939. // logType := "modify"
  940. // go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, logType)
  941. // }
  942. // //待办通知
  943. // {
  944. // for _, v := range approveUser {
  945. // approveUserId = v.AdminId
  946. // approveUserRealName = v.RealName
  947. // mobile := v.Mobile
  948. // content := "服务更新申请单"
  949. // err = services.AddCompanyApprovalMessage(sysUser.AdminId, approveUserId, req.CompanyId, companyApprovalId, 1, 1, 1, companyProduct.CompanyName, content, content, mobile)
  950. // if err != nil {
  951. // br.Msg = "申请失败"
  952. // br.ErrMsg = "新增待办通知失败,Err:" + err.Error()
  953. // return
  954. // }
  955. // }
  956. // }
  957. // br.Ret = 200
  958. // br.Success = true
  959. // br.Msg = "申请成功"
  960. //}
  961. // ApplyTurnPositiveOld
  962. // @Title 申请转正
  963. // @Description 申请转正接口
  964. // @Param request body company.CompanyApplyTurnPositiveReq true "type json string"
  965. // @Success Ret=200 申请成功
  966. //func (this *CompanyApplyController) ApplyTurnPositiveOld() {
  967. // br := new(models.BaseResponse).Init()
  968. // defer func() {
  969. // this.Data["json"] = br
  970. // this.ServeJSON()
  971. // }()
  972. // sysUser := this.SysUser
  973. // if sysUser == nil {
  974. // br.Msg = "请登录"
  975. // br.ErrMsg = "请登录,SysUser Is Empty"
  976. // br.Ret = 408
  977. // return
  978. // }
  979. // var req company.CompanyApplyTurnPositiveReq
  980. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  981. // if err != nil {
  982. // br.Msg = "参数解析异常!"
  983. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  984. // return
  985. // }
  986. // if req.CompanyId <= 0 {
  987. // br.Msg = "参数错误"
  988. // br.ErrMsg = "参数错误,客户id小于等于0"
  989. // return
  990. // }
  991. // if req.StartDate == "" {
  992. // br.Msg = "请选择合同开始日期"
  993. // return
  994. // }
  995. // if req.EndDate == "" {
  996. // br.Msg = "请选择合同结束日期"
  997. // return
  998. // }
  999. //
  1000. // if req.Money <= 0 {
  1001. // br.Msg = "合同金额不能小于等于0"
  1002. // return
  1003. // }
  1004. // roleTypeCode := sysUser.RoleTypeCode
  1005. // productId := services.GetProductId(roleTypeCode)
  1006. // if productId == 0 {
  1007. // br.Msg = "参数错误"
  1008. // br.ErrMsg = "客户类型为:" + roleTypeCode
  1009. // return
  1010. // }
  1011. // companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  1012. // if err != nil {
  1013. // br.Msg = "获取客户信息失败"
  1014. // br.ErrMsg = "获取客户信息失败"
  1015. // return
  1016. // }
  1017. // if companyProduct == nil {
  1018. // br.Msg = "获取客户信息失败"
  1019. // br.ErrMsg = "客户不存在,不可提交审批:companyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1020. // return
  1021. // }
  1022. // if companyProduct.Status != utils.COMPANY_STATUS_TRY_OUT {
  1023. // br.Msg = "客户状态为:" + companyProduct.Status + ";不可进行转正申请"
  1024. // br.ErrMsg = "客户状态为:" + companyProduct.Status + ";不可进行转正申请"
  1025. // return
  1026. // }
  1027. //
  1028. // if companyProduct.ApproveStatus == "待审批" {
  1029. // br.Msg = "存在待审批订单,不可重复提交"
  1030. // return
  1031. // }
  1032. // approveContent := `试用转正式`
  1033. // var approveUserId int
  1034. // var approveUserRealName string
  1035. // approveRoleTypeCode := ""
  1036. // if productId == 1 {
  1037. // approveRoleTypeCode = utils.ROLE_TYPE_CODE_FICC_ADMIN
  1038. // } else {
  1039. // approveRoleTypeCode = utils.ROLE_TYPE_CODE_RAI_ADMIN
  1040. // }
  1041. // approveUser, err := company.GetApproveUser(approveRoleTypeCode)
  1042. // if err != nil && err.Error() != utils.ErrNoRow() {
  1043. // br.Msg = "获取审批信息失败"
  1044. // br.ErrMsg = "获取审批人信息失败,Err:" + err.Error()
  1045. // return
  1046. // }
  1047. // if approveUser == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1048. // br.Msg = "审批用户不存在"
  1049. // br.ErrMsg = "审批用户不存在"
  1050. // return
  1051. // }
  1052. //
  1053. // //合同类型
  1054. // contractType := req.ContractType
  1055. // if contractType == "" {
  1056. // contractType = "新签合同"
  1057. // }
  1058. // var condition string
  1059. // var pars []interface{}
  1060. // condition += " AND product_id = ?"
  1061. // pars = append(pars, productId)
  1062. // condition += " AND status = ?"
  1063. // pars = append(pars, 1)
  1064. // list, err := company.GetCompanyContractListByCompanyId(req.CompanyId, condition, pars)
  1065. // if err != nil {
  1066. // br.Msg = "获取合同信息失败"
  1067. // br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
  1068. // return
  1069. // }
  1070. // if len(list) > 0 {
  1071. // contractType = "续约合同"
  1072. // }
  1073. // //查询是否存在正式转试用的记录,如果存在,那么合同类型是续约合同
  1074. // total, err := company.GetCompanyProductOperationRecordCount(companyProduct.CompanyId, companyProduct.ProductId)
  1075. // if err != nil {
  1076. // br.Msg = "查询用户信息异常"
  1077. // br.ErrMsg = "查询用户变更记录异常"
  1078. // return
  1079. // }
  1080. // if total > 0 {
  1081. // contractType = "续约合同"
  1082. // }
  1083. // //合同类型 end
  1084. //
  1085. // var companyApprovalId int
  1086. // if req.CompanyApprovalId <= 0 {
  1087. // contractCode, err := company.GetCompanyContractCode()
  1088. // if err != nil {
  1089. // br.Msg = "生成合同编码失败"
  1090. // br.ErrMsg = "生成合同编码失败,Err:" + err.Error()
  1091. // return
  1092. // }
  1093. // //当前待审批的合同,有且只能存在一条
  1094. // count, err := company.GetCompanyContractApproveCount(req.CompanyId, productId)
  1095. // if err != nil {
  1096. // br.Msg = "获取信息失败"
  1097. // br.ErrMsg = "判断是否已存在待审批合同失败,Err:" + err.Error()
  1098. // return
  1099. // }
  1100. // if count > 0 {
  1101. // br.Msg = "此客户已提交过申请,请在客户审批列表重新提交"
  1102. // return
  1103. // }
  1104. // contract := new(company.CompanyContract)
  1105. // contract.CompanyId = req.CompanyId
  1106. // contract.ProductId = productId
  1107. // contract.ContractType = contractType
  1108. // contract.ProductName = companyProduct.ProductName
  1109. // contract.CompanyProductId = companyProduct.CompanyProductId
  1110. // contract.ContractCode = contractCode
  1111. // contract.StartDate = req.StartDate
  1112. // contract.EndDate = req.EndDate
  1113. // contract.Money = req.Money
  1114. // contract.PayMethod = req.PayMethod
  1115. // contract.PayChannel = req.PayChannel
  1116. // contract.ImgUrl = req.ImgUrl
  1117. // contract.Status = 0
  1118. // contract.Source = "上传附件"
  1119. // contract.CreateTime = time.Now()
  1120. // contract.ModifyTime = time.Now()
  1121. // newId, err := company.AddCompanyContract(contract)
  1122. // if err != nil {
  1123. // br.Msg = "新增合同失败"
  1124. // br.ErrMsg = "新增合同失败,Err:" + err.Error()
  1125. // return
  1126. // }
  1127. // permissionArr := strings.Split(req.PermissionIds, ",")
  1128. // for _, v := range permissionArr {
  1129. // item := new(company.CompanyContractPermission)
  1130. // item.CompanyId = req.CompanyId
  1131. // item.CompanyContractId = int(newId)
  1132. //
  1133. // chartPermissionId, tmpErr := strconv.Atoi(v)
  1134. // if tmpErr != nil {
  1135. // err = tmpErr
  1136. // return
  1137. // }
  1138. // item.ChartPermissionId = chartPermissionId
  1139. //
  1140. // item.StartDate = req.StartDate
  1141. // item.EndDate = req.EndDate
  1142. // item.ModifyTime = time.Now()
  1143. // item.CreateTime = time.Now()
  1144. // err = company.AddCompanyContractPermission(item)
  1145. // if err != nil {
  1146. // br.Msg = "新增合同失败"
  1147. // br.ErrMsg = "新增合同权限失败,Err:" + err.Error()
  1148. // return
  1149. // }
  1150. // //新增日志
  1151. // {
  1152. // itemLog := new(company.CompanyContractPermissionLog)
  1153. // itemLog.CompanyId = req.CompanyId
  1154. // itemLog.CompanyContractId = int(newId)
  1155. // itemLog.ChartPermissionId = v
  1156. // itemLog.StartDate = req.StartDate
  1157. // itemLog.EndDate = req.EndDate
  1158. // itemLog.ModifyTime = time.Now()
  1159. // itemLog.CreateTime = time.Now()
  1160. // itemLog.LogCreateTime = time.Now()
  1161. // go company.AddCompanyContractPermissionLog(itemLog)
  1162. // }
  1163. // }
  1164. // applyMethod := 1
  1165. // approval := new(company.CompanyApproval)
  1166. // approval.CompanyId = req.CompanyId
  1167. // approval.ProductId = productId
  1168. // approval.ApproveStatus = "待审批"
  1169. // approval.ApproveUserId = 0
  1170. // approval.ApproveRoleTypeCode = approveRoleTypeCode
  1171. // approval.ApproveRealName = ""
  1172. // approval.ApproveTime = time.Now()
  1173. // approval.ApproveContent = "试用转正式"
  1174. // approval.ApplyMethod = applyMethod
  1175. // approval.ApplyReasons = ""
  1176. // approval.ApplyUserId = sysUser.AdminId
  1177. // approval.ApplyRealName = sysUser.RealName
  1178. // approval.CreateTime = time.Now()
  1179. // approval.ModifyTime = time.Now()
  1180. // approval.CompanyContractId = int(newId)
  1181. // companyApprovalId, err = company.AddCompanyApproval(approval)
  1182. // if err != nil {
  1183. // br.Msg = "申请失败"
  1184. // br.ErrMsg = "申请失败,Err:" + err.Error()
  1185. // return
  1186. // }
  1187. // } else {
  1188. // recode, err := company.GetCompanyApprovalByApprovalId(req.CompanyApprovalId)
  1189. // if err != nil {
  1190. // br.Msg = "申请失败"
  1191. // br.ErrMsg = "获取审批记录失败,Err:" + err.Error()
  1192. // return
  1193. // }
  1194. // err = company.ModifyCompanyTurnPositive(&req, productId, recode.CompanyContractId, companyProduct.IsFormal, map[int]int{})
  1195. // if err != nil {
  1196. // br.Msg = "申请失败"
  1197. // br.ErrMsg = "申请失败,Err:" + err.Error()
  1198. // return
  1199. // }
  1200. // companyApprovalId = req.CompanyApprovalId
  1201. // }
  1202. // //新增操作记录
  1203. // {
  1204. // remark := "申请转正"
  1205. // operation := "turn_positive"
  1206. // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, approveUserId, companyProduct.CompanyName,
  1207. // companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveUserRealName, "", companyProduct.Status)
  1208. // }
  1209. // //新增客户产品日志
  1210. // {
  1211. // logType := "modify"
  1212. // go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, logType)
  1213. // }
  1214. // //待办通知
  1215. // {
  1216. // for _, v := range approveUser {
  1217. // approveUserId = v.AdminId
  1218. // approveUserRealName = v.RealName
  1219. // mobile := v.Mobile
  1220. // content := "试用转正式申请单"
  1221. // err = services.AddCompanyApprovalMessage(sysUser.AdminId, approveUserId, req.CompanyId, companyApprovalId, 1, 1, 1, companyProduct.CompanyName, content, content, mobile)
  1222. // if err != nil {
  1223. // br.Msg = "申请失败"
  1224. // br.ErrMsg = "新增待办通知失败,Err:" + err.Error()
  1225. // return
  1226. // }
  1227. // }
  1228. // }
  1229. // br.Ret = 200
  1230. // br.Success = true
  1231. // br.Msg = "申请成功"
  1232. //}
  1233. // ApplyThawOld
  1234. // @Title 申请解冻
  1235. // @Description 申请解冻接口
  1236. // @Param request body company.CompanyApplyThawReq true "type json string"
  1237. // @Success Ret=200 申请成功
  1238. func (this *CompanyApplyController) ApplyThawOld() {
  1239. br := new(models.BaseResponse).Init()
  1240. defer func() {
  1241. this.Data["json"] = br
  1242. this.ServeJSON()
  1243. }()
  1244. sysUser := this.SysUser
  1245. if sysUser == nil {
  1246. br.Msg = "请登录"
  1247. br.ErrMsg = "请登录,SysUser Is Empty"
  1248. br.Ret = 408
  1249. return
  1250. }
  1251. var req company.CompanyApplyThawReq
  1252. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1253. if err != nil {
  1254. br.Msg = "参数解析异常!"
  1255. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1256. return
  1257. }
  1258. if req.CompanyId <= 0 {
  1259. br.Msg = "参数错误"
  1260. br.ErrMsg = "参数错误,客户id小于等于0"
  1261. return
  1262. }
  1263. roleTypeCode := sysUser.RoleTypeCode
  1264. productId := services.GetProductId(roleTypeCode)
  1265. if productId == 0 {
  1266. br.Msg = "参数错误"
  1267. br.ErrMsg = "客户类型为:" + roleTypeCode
  1268. return
  1269. }
  1270. approveRoleTypeCode := ""
  1271. if productId == 1 {
  1272. approveRoleTypeCode = utils.ROLE_TYPE_CODE_FICC_ADMIN
  1273. } else {
  1274. approveRoleTypeCode = utils.ROLE_TYPE_CODE_RAI_ADMIN
  1275. }
  1276. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  1277. if err != nil {
  1278. br.Msg = "获取客户信息失败"
  1279. br.ErrMsg = "获取客户信息失败"
  1280. return
  1281. }
  1282. if companyProduct == nil {
  1283. br.Msg = "获取客户信息失败"
  1284. br.ErrMsg = "客户不存在,不可提交审批:companyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1285. return
  1286. }
  1287. if companyProduct.Status != utils.COMPANY_STATUS_FREEZE {
  1288. br.Msg = "客户状态为:" + companyProduct.Status + ";不可进行解冻申请"
  1289. br.ErrMsg = "客户状态为:" + companyProduct.Status + ";不可进行解冻申请"
  1290. return
  1291. }
  1292. if companyProduct.ApproveStatus == utils.COMPANY_APPROVE_STATUS {
  1293. br.Msg = "存在待审批订单,不可重复提交"
  1294. return
  1295. }
  1296. approveUser, err := company.GetApproveUser(approveRoleTypeCode)
  1297. if err != nil && err.Error() != utils.ErrNoRow() {
  1298. br.Msg = "获取审批信息失败"
  1299. br.ErrMsg = "获取审批人信息失败,Err:" + err.Error()
  1300. return
  1301. }
  1302. if approveUser == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1303. br.Msg = "审批用户不存在"
  1304. br.ErrMsg = "审批用户不存在"
  1305. return
  1306. }
  1307. //申请类型:1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户,5:正式客户申请服务更新,6:正式客户补充协议
  1308. approveContent := `冻结转试用`
  1309. var companyApprovalId int
  1310. if req.CompanyApprovalId <= 0 {
  1311. applyMethod := 2
  1312. approval := new(company.CompanyApproval)
  1313. approval.CompanyId = req.CompanyId
  1314. approval.ProductId = productId
  1315. approval.ApproveStatus = "待审批"
  1316. approval.ApproveUserId = 0
  1317. approval.ApproveRoleTypeCode = approveRoleTypeCode
  1318. approval.ApproveRealName = ""
  1319. approval.ApproveTime = time.Now()
  1320. approval.ApproveContent = approveContent
  1321. approval.ApplyMethod = applyMethod
  1322. approval.ApplyReasons = req.ApplyRemark
  1323. approval.ApplyUserId = sysUser.AdminId
  1324. approval.ApplyRealName = sysUser.RealName
  1325. approval.CreateTime = time.Now()
  1326. approval.ModifyTime = time.Now()
  1327. companyApprovalId, err = company.AddCompanyApproval(approval)
  1328. if err != nil {
  1329. br.Msg = "申请失败"
  1330. br.ErrMsg = "申请失败,Err:" + err.Error()
  1331. return
  1332. }
  1333. } else {
  1334. err = company.ModifyCompanyApproval(req.CompanyId, productId, req.CompanyApprovalId, approveContent, req.ApplyRemark)
  1335. if err != nil {
  1336. br.Msg = "申请失败"
  1337. br.ErrMsg = "申请失败,Err:" + err.Error()
  1338. return
  1339. }
  1340. companyApprovalId = req.CompanyApprovalId
  1341. //先删除之前申请的权限
  1342. _ = company.DeleteCompanyDelayPermission(req.CompanyApprovalId)
  1343. }
  1344. //处理权限
  1345. {
  1346. if req.PermissionIds != "" {
  1347. permissionArr := strings.Split(req.PermissionIds, ",")
  1348. for _, v := range permissionArr {
  1349. //fmt.Println(k, v)
  1350. //新增
  1351. if v != "" {
  1352. permissionId, err := strconv.Atoi(v)
  1353. if err != nil {
  1354. br.Msg = "申请失败"
  1355. br.ErrMsg = "权限格式转换失败,Err:" + err.Error()
  1356. return
  1357. }
  1358. delayItem := new(company.CompanyDelayPermission)
  1359. delayItem.CompanyId = req.CompanyId
  1360. delayItem.CompanyApplyId = companyApprovalId
  1361. delayItem.ChartPermissionId = permissionId
  1362. delayItem.StartDate = time.Now().Format(utils.FormatDate)
  1363. delayItem.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  1364. delayItem.CreateTime = time.Now()
  1365. delayItem.ModifyTime = time.Now()
  1366. err = company.AddCompanyDelayPermission(delayItem)
  1367. if err != nil {
  1368. br.Msg = "申请失败"
  1369. br.ErrMsg = "新增冻结转试用审批权限失败,Err:" + err.Error()
  1370. return
  1371. }
  1372. }
  1373. }
  1374. }
  1375. }
  1376. //新增操作记录
  1377. {
  1378. remark := "申请解冻"
  1379. operation := "thaw"
  1380. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, 0, companyProduct.CompanyName,
  1381. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, "", "", companyProduct.Status)
  1382. }
  1383. //新增客户产品日志
  1384. {
  1385. logType := "modify"
  1386. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, logType)
  1387. }
  1388. //待办通知
  1389. {
  1390. for _, v := range approveUser {
  1391. approveUserId := v.AdminId
  1392. //approveUserRealName := v.RealName
  1393. mobile := v.Mobile
  1394. content := "冻结转试用申请单"
  1395. err = services.AddCompanyApprovalMessage(sysUser.AdminId, approveUserId, req.CompanyId, companyApprovalId, 1, 1, 1, companyProduct.CompanyName, content, content, mobile)
  1396. if err != nil {
  1397. br.Msg = "申请失败"
  1398. br.ErrMsg = "新增待办通知失败,Err:" + err.Error()
  1399. return
  1400. }
  1401. }
  1402. }
  1403. br.Ret = 200
  1404. br.Success = true
  1405. br.Msg = "申请成功"
  1406. }
  1407. // ApplyDelayOld
  1408. // @Title 申请延期
  1409. // @Description 申请延期接口
  1410. // @Param request body company.CompanyApplyDelayReq true "type json string"
  1411. // @Success Ret=200 申请成功
  1412. func (this *CompanyApplyController) ApplyDelayOld() {
  1413. br := new(models.BaseResponse).Init()
  1414. defer func() {
  1415. this.Data["json"] = br
  1416. this.ServeJSON()
  1417. }()
  1418. sysUser := this.SysUser
  1419. if sysUser == nil {
  1420. br.Msg = "请登录"
  1421. br.ErrMsg = "请登录,SysUser Is Empty"
  1422. br.Ret = 408
  1423. return
  1424. }
  1425. var req company.CompanyApplyDelayReq
  1426. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1427. if err != nil {
  1428. br.Msg = "参数解析异常!"
  1429. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1430. return
  1431. }
  1432. if req.CompanyId <= 0 {
  1433. br.Msg = "参数错误"
  1434. br.ErrMsg = "参数错误,客户id小于等于0"
  1435. return
  1436. }
  1437. roleTypeCode := sysUser.RoleTypeCode
  1438. productId := services.GetProductId(roleTypeCode)
  1439. if productId == 0 {
  1440. br.Msg = "参数错误"
  1441. br.ErrMsg = "客户类型为:" + roleTypeCode
  1442. return
  1443. }
  1444. approveRoleTypeCode := ""
  1445. if productId == 1 {
  1446. approveRoleTypeCode = utils.ROLE_TYPE_CODE_FICC_ADMIN
  1447. } else {
  1448. approveRoleTypeCode = utils.ROLE_TYPE_CODE_RAI_ADMIN
  1449. }
  1450. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  1451. if err != nil {
  1452. br.Msg = "获取客户信息失败"
  1453. br.ErrMsg = "获取客户信息失败"
  1454. return
  1455. }
  1456. if companyProduct == nil {
  1457. br.Msg = "获取客户信息失败"
  1458. br.ErrMsg = "客户不存在,不可提交审批:companyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1459. return
  1460. }
  1461. if companyProduct.Status != utils.COMPANY_STATUS_TRY_OUT {
  1462. br.Msg = "客户状态为:" + companyProduct.Status + ";不可进行延期申请"
  1463. br.ErrMsg = "客户状态为:" + companyProduct.Status + ";不可进行延期申请"
  1464. return
  1465. }
  1466. if companyProduct.ApproveStatus == "待审批" {
  1467. br.Msg = "存在待审批订单,不可重复提交"
  1468. return
  1469. }
  1470. approveUser, err := company.GetApproveUser(approveRoleTypeCode)
  1471. if err != nil && err.Error() != utils.ErrNoRow() {
  1472. br.Msg = "获取审批信息失败"
  1473. br.ErrMsg = "获取审批人信息失败,Err:" + err.Error()
  1474. return
  1475. }
  1476. if approveUser == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1477. br.Msg = "审批用户不存在"
  1478. br.ErrMsg = "审批用户不存在"
  1479. return
  1480. }
  1481. //申请类型:1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户,5:正式客户申请服务更新,6:正式客户补充协议
  1482. approveContent := `试用延期`
  1483. var companyApprovalId int
  1484. utils.FileLog.Info("试用延期申请:%d", req.CompanyApprovalId)
  1485. if req.CompanyApprovalId > 0 {
  1486. utils.FileLog.Info("试用延期申请:%d", req.CompanyApprovalId)
  1487. err = company.ModifyCompanyApproval(req.CompanyId, productId, req.CompanyApprovalId, approveContent, req.ApplyRemark)
  1488. if err != nil {
  1489. br.Msg = "申请失败"
  1490. br.ErrMsg = "申请失败,Err:" + err.Error()
  1491. return
  1492. }
  1493. companyApprovalId = req.CompanyApprovalId
  1494. } else {
  1495. applyMethod := 3
  1496. approval := new(company.CompanyApproval)
  1497. approval.CompanyId = req.CompanyId
  1498. approval.ProductId = productId
  1499. approval.ApproveStatus = "待审批"
  1500. approval.ApproveUserId = 0
  1501. approval.ApproveRoleTypeCode = approveRoleTypeCode
  1502. approval.ApproveRealName = ""
  1503. approval.ApproveTime = time.Now()
  1504. approval.ApproveContent = "试用延期"
  1505. approval.ApplyMethod = applyMethod
  1506. approval.ApplyReasons = req.ApplyRemark
  1507. approval.ApplyUserId = sysUser.AdminId
  1508. approval.ApplyRealName = sysUser.RealName
  1509. approval.CreateTime = time.Now()
  1510. approval.ModifyTime = time.Now()
  1511. companyApprovalId, err = company.AddCompanyApproval(approval)
  1512. if err != nil {
  1513. br.Msg = "申请失败"
  1514. br.ErrMsg = "申请失败,Err:" + err.Error()
  1515. return
  1516. }
  1517. //处理权限
  1518. {
  1519. if req.PermissionIds != "" {
  1520. permissionArr := strings.Split(req.PermissionIds, ",")
  1521. for k, v := range permissionArr {
  1522. fmt.Println(k, v)
  1523. permissionId, _ := strconv.Atoi(v)
  1524. //companyId, companyApplyId, chartPermissionId int
  1525. count, err := company.GetDelayPermissionCount(req.CompanyId, companyApprovalId, permissionId)
  1526. if err != nil && err.Error() != utils.ErrNoRow() {
  1527. br.Msg = "申请失败"
  1528. br.ErrMsg = "判断权限是否存在失败,Err:" + err.Error()
  1529. return
  1530. }
  1531. if count > 0 { //修改
  1532. err = company.ModifyCompanyDelayPermission(req.CompanyId, companyApprovalId, permissionId)
  1533. if err != nil {
  1534. br.Msg = "申请失败"
  1535. br.ErrMsg = "修改权限失败,Err:" + err.Error()
  1536. return
  1537. }
  1538. } else { //新增
  1539. if v != "" {
  1540. permissionId, err := strconv.Atoi(v)
  1541. if err != nil {
  1542. br.Msg = "申请失败"
  1543. br.ErrMsg = "权限格式转换失败,Err:" + err.Error()
  1544. return
  1545. }
  1546. delayItem := new(company.CompanyDelayPermission)
  1547. delayItem.CompanyId = req.CompanyId
  1548. delayItem.CompanyApplyId = companyApprovalId
  1549. delayItem.ChartPermissionId = permissionId
  1550. delayItem.StartDate = time.Now().Format(utils.FormatDate)
  1551. delayItem.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  1552. delayItem.CreateTime = time.Now()
  1553. delayItem.ModifyTime = time.Now()
  1554. err = company.AddCompanyDelayPermission(delayItem)
  1555. if err != nil {
  1556. br.Msg = "申请失败"
  1557. br.ErrMsg = "新增延期审批权限失败,Err:" + err.Error()
  1558. return
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. //新增操作记录
  1567. {
  1568. remark := "申请延期"
  1569. operation := "delay"
  1570. go services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, 0, companyProduct.CompanyName,
  1571. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, "", "", companyProduct.Status)
  1572. }
  1573. //新增客户产品日志
  1574. {
  1575. logType := "modify"
  1576. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, logType)
  1577. }
  1578. //待办通知
  1579. {
  1580. for _, v := range approveUser {
  1581. approveUserId := v.AdminId
  1582. //approveUserRealName := v.RealName
  1583. mobile := v.Mobile
  1584. content := "试用延期申请单"
  1585. utils.FileLog.Info("mobile:%s", mobile)
  1586. go services.AddCompanyApprovalMessage(sysUser.AdminId, approveUserId, req.CompanyId, companyApprovalId, 1, 1, 1, companyProduct.CompanyName, content, content, mobile)
  1587. }
  1588. }
  1589. br.Ret = 200
  1590. br.Success = true
  1591. br.Msg = "申请成功"
  1592. }
  1593. // ApplyReceiveOld
  1594. // @Title 申请领取
  1595. // @Description 申请领取接口
  1596. // @Param request body company.CompanyApplyReceiveReq true "type json string"
  1597. // @Success Ret=200 申请成功
  1598. func (this *CompanyApplyController) ApplyReceiveOld() {
  1599. br := new(models.BaseResponse).Init()
  1600. defer func() {
  1601. this.Data["json"] = br
  1602. this.ServeJSON()
  1603. }()
  1604. sysUser := this.SysUser
  1605. if sysUser == nil {
  1606. br.Msg = "请登录"
  1607. br.ErrMsg = "请登录,SysUser Is Empty"
  1608. br.Ret = 408
  1609. return
  1610. }
  1611. var req company.CompanyApplyReceiveReq
  1612. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1613. if err != nil {
  1614. br.Msg = "参数解析异常!"
  1615. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1616. return
  1617. }
  1618. if req.CompanyId <= 0 {
  1619. br.Msg = "参数错误"
  1620. br.ErrMsg = "参数错误,客户id小于等于0"
  1621. return
  1622. }
  1623. roleTypeCode := sysUser.RoleTypeCode
  1624. productId := services.GetProductId(roleTypeCode)
  1625. if productId == 0 {
  1626. br.Msg = "参数错误"
  1627. br.ErrMsg = "客户类型为:" + roleTypeCode
  1628. return
  1629. }
  1630. approveRoleTypeCode := ""
  1631. if productId == 1 {
  1632. approveRoleTypeCode = utils.ROLE_TYPE_CODE_FICC_ADMIN
  1633. } else {
  1634. approveRoleTypeCode = utils.ROLE_TYPE_CODE_RAI_ADMIN
  1635. }
  1636. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  1637. if err != nil {
  1638. br.Msg = "获取客户信息失败"
  1639. br.ErrMsg = "获取客户信息失败"
  1640. return
  1641. }
  1642. if companyProduct == nil {
  1643. br.Msg = "获取客户信息失败"
  1644. br.ErrMsg = "客户不存在,不可提交审批:companyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1645. return
  1646. }
  1647. if companyProduct.Status != utils.COMPANY_STATUS_LOSE {
  1648. br.Msg = "客户状态为:" + companyProduct.Status + ";不可进行延期申请"
  1649. br.ErrMsg = "客户状态为:" + companyProduct.Status + ";不可进行延期申请"
  1650. return
  1651. }
  1652. if companyProduct.ApproveStatus == "待审批" {
  1653. br.Msg = "存在待审批订单,不可重复提交"
  1654. return
  1655. }
  1656. approveUser, err := company.GetApproveUser(approveRoleTypeCode)
  1657. if err != nil && err.Error() != utils.ErrNoRow() {
  1658. br.Msg = "获取审批信息失败"
  1659. br.ErrMsg = "获取审批人信息失败,Err:" + err.Error()
  1660. return
  1661. }
  1662. if approveUser == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1663. br.Msg = "审批用户不存在"
  1664. br.ErrMsg = "审批用户不存在"
  1665. return
  1666. }
  1667. approveContent := `原销售申领客户`
  1668. applyMethod := 4
  1669. var companyApprovalId int
  1670. //申请类型:1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户,5:正式客户申请服务更新,6:正式客户补充协议
  1671. if req.CompanyApprovalId <= 0 {
  1672. approval := new(company.CompanyApproval)
  1673. approval.CompanyId = req.CompanyId
  1674. approval.ProductId = productId
  1675. approval.ApproveStatus = "待审批"
  1676. approval.ApproveUserId = 0
  1677. approval.ApproveRoleTypeCode = approveRoleTypeCode
  1678. approval.ApproveRealName = ""
  1679. approval.ApproveTime = time.Now()
  1680. approval.ApproveContent = approveContent
  1681. approval.ApplyMethod = applyMethod
  1682. approval.ApplyReasons = req.ApplyRemark
  1683. approval.ApplyUserId = sysUser.AdminId
  1684. approval.ApplyRealName = sysUser.RealName
  1685. approval.CreateTime = time.Now()
  1686. approval.ModifyTime = time.Now()
  1687. companyApprovalId, err = company.AddCompanyApproval(approval)
  1688. if err != nil {
  1689. br.Msg = "申请失败"
  1690. br.ErrMsg = "申请失败,Err:" + err.Error()
  1691. return
  1692. }
  1693. } else {
  1694. err = company.ModifyCompanyApproval(req.CompanyId, productId, req.CompanyApprovalId, approveContent, req.ApplyRemark)
  1695. if err != nil {
  1696. br.Msg = "申请失败"
  1697. br.ErrMsg = "申请失败,Err:" + err.Error()
  1698. return
  1699. }
  1700. companyApprovalId = req.CompanyApprovalId
  1701. //先删除之前申请的权限
  1702. _ = company.DeleteCompanyDelayPermission(req.CompanyApprovalId)
  1703. }
  1704. //处理权限
  1705. {
  1706. if req.PermissionIds != "" {
  1707. permissionArr := strings.Split(req.PermissionIds, ",")
  1708. for _, v := range permissionArr {
  1709. if v != "" {
  1710. permissionId, err := strconv.Atoi(v)
  1711. if err != nil {
  1712. br.Msg = "申请失败"
  1713. br.ErrMsg = "权限格式转换失败,Err:" + err.Error()
  1714. return
  1715. }
  1716. delayItem := new(company.CompanyDelayPermission)
  1717. delayItem.CompanyId = req.CompanyId
  1718. delayItem.CompanyApplyId = companyApprovalId
  1719. delayItem.ChartPermissionId = permissionId
  1720. delayItem.StartDate = time.Now().Format(utils.FormatDate)
  1721. delayItem.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  1722. delayItem.CreateTime = time.Now()
  1723. delayItem.ModifyTime = time.Now()
  1724. err = company.AddCompanyDelayPermission(delayItem)
  1725. if err != nil {
  1726. br.Msg = "申请失败"
  1727. br.ErrMsg = "新增领取客户审批权限失败,Err:" + err.Error()
  1728. return
  1729. }
  1730. }
  1731. }
  1732. }
  1733. }
  1734. //新增操作记录
  1735. {
  1736. remark := "申请领取"
  1737. operation := "apply_receive"
  1738. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, 0, companyProduct.CompanyName,
  1739. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, "", "", companyProduct.Status)
  1740. }
  1741. //新增客户产品日志
  1742. {
  1743. logType := "modify"
  1744. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, logType)
  1745. }
  1746. //待办通知
  1747. {
  1748. for _, v := range approveUser {
  1749. approveUserId := v.AdminId
  1750. //approveUserRealName := v.RealName
  1751. mobile := v.Mobile
  1752. content := "申请领取申请单"
  1753. err = services.AddCompanyApprovalMessage(sysUser.AdminId, approveUserId, req.CompanyId, companyApprovalId, 1, 1, 1, companyProduct.CompanyName, content, content, mobile)
  1754. if err != nil {
  1755. br.Msg = "申请失败"
  1756. br.ErrMsg = "新增待办通知失败,Err:" + err.Error()
  1757. return
  1758. }
  1759. }
  1760. }
  1761. br.Ret = 200
  1762. br.Success = true
  1763. br.Msg = "申请成功"
  1764. }
  1765. // ApplyRevokeOld
  1766. // @Title 申请撤回
  1767. // @Description 申请撤回接口
  1768. // @Param request body company.CompanyApplyRevokeReq true "type json string"
  1769. // @Success Ret=200 成功
  1770. func (this *CompanyApprovalController) ApplyRevokeOld() {
  1771. br := new(models.BaseResponse).Init()
  1772. defer func() {
  1773. this.Data["json"] = br
  1774. this.ServeJSON()
  1775. }()
  1776. sysUser := this.SysUser
  1777. if sysUser == nil {
  1778. br.Msg = "请登录"
  1779. br.ErrMsg = "请登录,SysUser Is Empty"
  1780. br.Ret = 408
  1781. return
  1782. }
  1783. var req company.CompanyApplyRevokeReq
  1784. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1785. if err != nil {
  1786. br.Msg = "参数解析异常!"
  1787. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1788. return
  1789. }
  1790. if req.CompanyId <= 0 {
  1791. br.Msg = "参数错误"
  1792. br.ErrMsg = "客户Id小于等于0:"
  1793. return
  1794. }
  1795. roleTypeCode := sysUser.RoleTypeCode
  1796. productId := services.GetProductId(roleTypeCode)
  1797. if productId == 0 {
  1798. br.Msg = "参数错误"
  1799. br.ErrMsg = "客户类型为:" + roleTypeCode
  1800. return
  1801. }
  1802. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  1803. if err != nil {
  1804. br.Msg = "获取客户信息失败"
  1805. br.ErrMsg = "获取客户信息失败"
  1806. return
  1807. }
  1808. if companyProduct == nil {
  1809. br.Msg = "获取客户信息失败"
  1810. br.ErrMsg = "客户不存在,不可提交审批:companyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1811. return
  1812. }
  1813. approvalItem, err := company.GetCompanyApprovalById(req.CompanyId, productId)
  1814. if err != nil {
  1815. if err.Error() == utils.ErrNoRow() {
  1816. br.Msg = "待审批信息不存在"
  1817. br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1818. return
  1819. }
  1820. br.Msg = "获取信息失败"
  1821. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1822. return
  1823. }
  1824. if approvalItem == nil {
  1825. br.Msg = "待审批信息不存在"
  1826. br.ErrMsg = "待审批信息不存在,CompanyId:" + strconv.Itoa(req.CompanyId) + ";productId:" + strconv.Itoa(productId)
  1827. return
  1828. }
  1829. if approvalItem.ApproveStatus != "待审批" {
  1830. br.Msg = "客户状态为:" + companyProduct.Status + ";不可进行撤回操作"
  1831. br.ErrMsg = "客户状态为:" + companyProduct.Status + ";不可进行撤回操作"
  1832. return
  1833. }
  1834. err = company.ApplyRevoke(approvalItem.CompanyApprovalId, approvalItem.CompanyId, approvalItem.ProductId)
  1835. if err != nil {
  1836. br.Msg = "撤回失败"
  1837. br.ErrMsg = "撤回失败,Err:" + err.Error()
  1838. return
  1839. }
  1840. //新增操作记录
  1841. {
  1842. remark := "撤回"
  1843. operation := "apply_revoke"
  1844. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, productId, 0, companyProduct.CompanyName,
  1845. companyProduct.ProductName, sysUser.RealName, remark, operation, "", "", "", companyProduct.Status)
  1846. }
  1847. br.Ret = 200
  1848. br.Success = true
  1849. br.Msg = "撤回成功"
  1850. }
  1851. // ApplyContract
  1852. // @Title 申请服务更新/转正-审批合同信息
  1853. // @Description 申请服务更新/转正-审批合同信息接口
  1854. // @Param CompanyApprovalId query int true "审批记录ID"
  1855. // @Success 200 {object} company.ApplyContractResp
  1856. // @router /apply/contract [get]
  1857. func (this *CompanyApplyController) ApplyContract() {
  1858. br := new(models.BaseResponse).Init()
  1859. defer func() {
  1860. this.Data["json"] = br
  1861. this.ServeJSON()
  1862. }()
  1863. sysUser := this.SysUser
  1864. if sysUser == nil {
  1865. br.Msg = "请登录"
  1866. br.ErrMsg = "请登录,SysUser Is Empty"
  1867. br.Ret = 408
  1868. return
  1869. }
  1870. companyApprovalId, _ := this.GetInt("CompanyApprovalId")
  1871. if companyApprovalId <= 0 {
  1872. br.Msg = "参数错误"
  1873. br.ErrMsg = "参数错误,客户id小于等于0"
  1874. return
  1875. }
  1876. approvalRecord, err := company.GetCompanyApprovalByCompanyApprovalId(companyApprovalId)
  1877. if err != nil {
  1878. br.Msg = "获取信息失败"
  1879. br.ErrMsg = "获取审批信息失败,Err:" + err.Error()
  1880. return
  1881. }
  1882. contractItem, err := company.GetCompanyContractById(approvalRecord.CompanyContractId)
  1883. if err != nil {
  1884. br.Msg = "获取信息失败"
  1885. br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
  1886. return
  1887. }
  1888. productId := approvalRecord.ProductId
  1889. companyId := approvalRecord.CompanyId
  1890. if productId == 1 {
  1891. allFiccPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  1892. if e != nil {
  1893. br.Msg = "获取权限信息失败"
  1894. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  1895. return
  1896. }
  1897. permissionMap := make(map[int][]*company.PermissionLookItem, 0)
  1898. permissionCheckMap := make(map[int][]int, 0)
  1899. for _, v := range allFiccPermissions {
  1900. if v.ParentId > 0 {
  1901. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  1902. if v.IsPublic == 1 {
  1903. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  1904. }
  1905. }
  1906. }
  1907. for _, v := range allFiccPermissions {
  1908. if v.ParentId == 0 {
  1909. checkList := make([]int, 0)
  1910. plist := new(company.PermissionLookList)
  1911. plist.Items = make([]*company.PermissionLookItem, 0)
  1912. items, ok := permissionMap[v.ChartPermissionId]
  1913. if ok {
  1914. for _, n := range items {
  1915. count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, contractItem.CompanyContractId, n.ChartPermissionId)
  1916. if err != nil {
  1917. br.Msg = "获取失败"
  1918. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  1919. return
  1920. }
  1921. if count > 0 {
  1922. checkList = append(checkList, n.ChartPermissionId)
  1923. }
  1924. }
  1925. plist.Items = items
  1926. }
  1927. plist.ClassifyName = v.PermissionName
  1928. plist.CheckList = checkList
  1929. contractItem.PermissionList = append(contractItem.PermissionList, plist)
  1930. }
  1931. }
  1932. }
  1933. if productId == 2 {
  1934. name := "权益"
  1935. checkList := make([]int, 0)
  1936. //p := new(company.PermissionSetList)
  1937. plist := new(company.PermissionLookList)
  1938. //pListType := new(company.PermissionSetListType)
  1939. //p.ClassifyName = name
  1940. //pListType.ClassifyName = v
  1941. items, err := company.GetPermissionLookItems(productId, name)
  1942. if err != nil {
  1943. br.Msg = "获取失败"
  1944. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  1945. return
  1946. }
  1947. totalForever, err := company.GetCompanyProductRaiForeverCount(companyId) //判断是否是权益的永续客户
  1948. if err != nil {
  1949. br.Msg = "获取失败"
  1950. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1951. return
  1952. }
  1953. // 大套餐
  1954. bigPackage70, bigPackage45 := new(company.PermissionLookItem), new(company.PermissionLookItem)
  1955. if totalForever > 0 {
  1956. //filterPermissionName := []string{"专家", "路演服务", "调研", "研选订阅", "研选扣点包"} //权益的永续客户这些不展示
  1957. //for _, v := range items {
  1958. // if utils.InArrayByStr(filterPermissionName, v.PermissionName) {
  1959. // continue
  1960. // }
  1961. // p.Items = append(p.Items, v)
  1962. //}
  1963. } else {
  1964. bigPackage70.PermissionName = utils.CHART_PERMISSION_NAME_70W
  1965. bigPackage45.PermissionName = utils.CHART_PERMISSION_NAME_45W
  1966. plist.Items = append(plist.Items, bigPackage45, bigPackage70)
  1967. }
  1968. // 是否为内部人员, 内部人员需要拆分行业主客观
  1969. isRai, e := services.CheckRaiAdmin(sysUser.AdminId)
  1970. if e != nil {
  1971. br.Msg = "获取失败"
  1972. br.ErrMsg = "判断是否为权益内部人员失败, GetRaiAdmin Err: " + e.Error()
  1973. return
  1974. }
  1975. // 获取行业主客观权限ID
  1976. childSubMap, childObjMap := make(map[string]int), make(map[string]int)
  1977. {
  1978. permissions, e := models.GetChartPermissionList()
  1979. if e != nil {
  1980. br.Msg = "获取失败"
  1981. br.ErrMsg = "获取权限列表失败, GetChartPermissionList Err: " + e.Error()
  1982. return
  1983. }
  1984. for _, v := range permissions {
  1985. if !strings.Contains("医药消费科技智造", v.PermissionName) {
  1986. continue
  1987. }
  1988. if strings.Contains(v.Remark, "主观") {
  1989. childSubMap[v.PermissionName] = v.ChartPermissionId
  1990. continue
  1991. }
  1992. childObjMap[v.PermissionName] = v.ChartPermissionId
  1993. }
  1994. }
  1995. //升级
  1996. mapUpgrade := make(map[int]int)
  1997. mapExpensive := make(map[int]bool)
  1998. var expensiveYx int
  1999. permissionList, err := company.GetCompanyContractPermissionByCompanyContractId(contractItem.CompanyContractId)
  2000. if err != nil && err.Error() != utils.ErrNoRow() {
  2001. br.Msg = "获取失败"
  2002. br.ErrMsg = "获取合同权限信息失败,Err:" + err.Error()
  2003. return
  2004. }
  2005. permissionIds := make([]int, 0)
  2006. for _, v := range permissionList {
  2007. if v.IsUpgrade == 1 {
  2008. mapUpgrade[v.ChartPermissionId] = v.ChartPermissionId
  2009. }
  2010. if v.ExpensiveYx > 0 {
  2011. mapExpensive[v.ChartPermissionId] = true
  2012. expensiveYx = v.ExpensiveYx
  2013. }
  2014. permissionIds = append(permissionIds, v.ChartPermissionId)
  2015. }
  2016. //mapChartPermissionId := make(map[int]int)
  2017. mapChartPermissionName := make(map[string]string) // 行业主客观防止重复写入Items用的
  2018. filterPermissionName := []string{}
  2019. mapPermissionNameUpgrade := make(map[string]bool) //升级权限重复
  2020. if totalForever == 0 {
  2021. filterPermissionName = []string{"专家", "路演服务"} // 需要过滤不展示的行业
  2022. } else {
  2023. filterPermissionName = []string{"专家", "路演服务", "调研", "研选订阅", "研选扣点包"} //权益的永续客户这些不展示
  2024. }
  2025. for _, n := range items {
  2026. if utils.InArrayByStr(filterPermissionName, n.PermissionName) {
  2027. continue
  2028. }
  2029. if n.PermissionType == 2 && totalForever > 0 {
  2030. continue
  2031. }
  2032. if utils.InArrayByInt(permissionIds, n.ChartPermissionId) {
  2033. n.Checked = true
  2034. if _, ok := mapUpgrade[n.ChartPermissionId]; ok {
  2035. checkList = append(checkList, n.ChartPermissionId+utils.PERMISSION_ID_UPGRADE)
  2036. } else {
  2037. if mapExpensive[n.ChartPermissionId] {
  2038. // 研选5w与10W
  2039. if expensiveYx == 1 {
  2040. checkList = append(checkList, n.ChartPermissionId+utils.PERMISSION_ID_YANXUAN_DIFF) // 5W
  2041. } else {
  2042. checkList = append(checkList, utils.PERMISSION_ID_YANXUAN_10W_DIFF) // 10W
  2043. }
  2044. } else {
  2045. // 非内部人员, 忽略掉已有的客观权限, 否则前端升级的反选会出现问题, 重新提交的时候只提交主观权限也有对应的处理
  2046. if !strings.Contains(n.Remark, "客观") {
  2047. checkList = append(checkList, n.ChartPermissionId)
  2048. }
  2049. // 正常的非客观权限
  2050. if strings.Contains(n.Remark, "客观") && isRai {
  2051. checkList = append(checkList, n.ChartPermissionId)
  2052. }
  2053. }
  2054. }
  2055. }
  2056. // 买方研选3w/5w/10w
  2057. if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  2058. m3 := new(company.PermissionLookItem)
  2059. m3.ChartPermissionId = n.ChartPermissionId
  2060. m3.PermissionName = n.PermissionName
  2061. plist.Items = append(plist.Items, m3)
  2062. continue
  2063. }
  2064. //if totalForever == 0 {
  2065. // 四行业主客观/升级
  2066. if mapChartPermissionName[n.PermissionName] == "" {
  2067. mapChartPermissionName[n.PermissionName] = n.PermissionName
  2068. if !strings.Contains("医药消费科技智造", n.PermissionName) {
  2069. plist.Items = append(plist.Items, n)
  2070. continue
  2071. }
  2072. // 内部人员需要拆分主客观权限
  2073. if isRai && totalForever == 0 {
  2074. n.Child = make([]*company.PermissionLookItem, 0)
  2075. n.Child = append(n.Child, &company.PermissionLookItem{
  2076. ChartPermissionId: childSubMap[n.PermissionName],
  2077. PermissionName: "主观",
  2078. PermissionType: 1,
  2079. }, &company.PermissionLookItem{
  2080. ChartPermissionId: childObjMap[n.PermissionName],
  2081. PermissionName: "客观",
  2082. PermissionType: 2,
  2083. })
  2084. }
  2085. }
  2086. plist.Items = append(plist.Items, n)
  2087. if totalForever == 0 && !mapPermissionNameUpgrade[n.PermissionName] {
  2088. t := new(company.PermissionLookItem)
  2089. t.ChartPermissionId = n.ChartPermissionId + utils.PERMISSION_ID_UPGRADE
  2090. t.PermissionName = n.PermissionName + "(升级)"
  2091. t.PermissionType = n.PermissionType
  2092. t.Checked = n.Checked
  2093. plist.Items = append(plist.Items, t)
  2094. mapPermissionNameUpgrade[n.PermissionName] = true
  2095. }
  2096. }
  2097. //}
  2098. // 如果checklist 里的值 没有在items里,则不返回给前端
  2099. itemsIds := make([]int, 0)
  2100. itemsIdExist := make(map[int]bool)
  2101. for _, v := range plist.Items {
  2102. if v.Child != nil && len(v.Child) > 0 {
  2103. for _, v2 := range v.Child {
  2104. if !itemsIdExist[v2.ChartPermissionId] {
  2105. itemsIds = append(itemsIds, v2.ChartPermissionId)
  2106. itemsIdExist[v2.ChartPermissionId] = true
  2107. }
  2108. }
  2109. }
  2110. if !itemsIdExist[v.ChartPermissionId] {
  2111. itemsIds = append(itemsIds, v.ChartPermissionId)
  2112. itemsIdExist[v.ChartPermissionId] = true
  2113. }
  2114. }
  2115. checkList = utils.IntersectInt(checkList, itemsIds)
  2116. //finalCheckList := make([]int, 0)
  2117. //for _, v := range plist.Items {
  2118. // for _, i := range checkList {
  2119. // if v.ChartPermissionId == i {
  2120. // finalCheckList = append(finalCheckList, i)
  2121. // break
  2122. // }
  2123. // }
  2124. //}
  2125. //p.CheckList = checkList
  2126. //plist.ItemsType = pListType.Items
  2127. plist.ClassifyName = name
  2128. //plist.CheckList = finalCheckList
  2129. plist.CheckList = checkList
  2130. contractItem.PermissionList = append(contractItem.PermissionList, plist)
  2131. contractItem.Quarter, _ = utils.GetQuarterStrStartDatesInRangeHaveYear(contractItem.StartDate, contractItem.EndDate) //季度信息
  2132. }
  2133. resp := new(company.ApplyContractResp)
  2134. resp.Item = contractItem
  2135. br.Ret = 200
  2136. br.Success = true
  2137. br.Msg = "获取成功"
  2138. br.Data = resp
  2139. }
  2140. // SearchContractList
  2141. // @Title 系统合同搜索列表(用于申请转正、服务更新)
  2142. // @Description 系统合同搜索列表接口(用于申请转正、服务更新)
  2143. // @Param Keyword query string false "搜索关键字"
  2144. // @Param CreditCode query string false "社会组织信用码"
  2145. // @Success 200 {object} []contract.ContractList
  2146. // @router /system_contract/list [get]
  2147. func (this *CompanyApplyController) SearchContractList() {
  2148. br := new(models.BaseResponse).Init()
  2149. defer func() {
  2150. this.Data["json"] = br
  2151. this.ServeJSON()
  2152. }()
  2153. sysUser := this.SysUser
  2154. if sysUser == nil {
  2155. br.Msg = "请登录"
  2156. br.ErrMsg = "请登录,SysUser Is Empty"
  2157. br.Ret = 408
  2158. return
  2159. }
  2160. productId := services.GetProductId(sysUser.RoleTypeCode)
  2161. if productId <= 0 {
  2162. br.Msg = "获取合同列表失败!"
  2163. br.ErrMsg = "获取合同列表失败,当前账户类型异常:" + sysUser.RoleTypeCode
  2164. return
  2165. }
  2166. keyword := this.GetString("Keyword")
  2167. creditCode := this.GetString("CreditCode")
  2168. if keyword == "" && creditCode == "" {
  2169. br.Ret = 200
  2170. br.Success = true
  2171. br.Msg = "获取成功"
  2172. return
  2173. }
  2174. //companyIdStr, err := company.GetCompanyIdByKeyWordAll(keyword)
  2175. //if err != nil {
  2176. // br.Msg = "获取失败"
  2177. // br.ErrMsg = "获取失败,Err:" + err.Error()
  2178. // return
  2179. //}
  2180. //if companyIdStr != "" {
  2181. // companyIdStr = strings.Trim(companyIdStr, ",")
  2182. //}
  2183. list, err := contract.GetSearchContractList(productId, sysUser.AdminId, keyword, creditCode)
  2184. for _, v := range list {
  2185. v.StartDateStr = v.StartDate.Format(utils.FormatDate)
  2186. v.EndDateStr = v.EndDate.Format(utils.FormatDate)
  2187. }
  2188. if err != nil {
  2189. br.Msg = "获取合同列表失败!"
  2190. br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  2191. return
  2192. }
  2193. br.Ret = 200
  2194. br.Success = true
  2195. br.Msg = "获取成功"
  2196. br.Data = list
  2197. }
  2198. // GetContractApplyDetail
  2199. // @Title 系统合同详情(用于申请转正、服务更新)
  2200. // @Description 系统合同详情(用于申请转正、服务更新)
  2201. // @Param ContractId query int false "合同id"
  2202. // @Success 200 {object} []response.ContractApplyDetailResp
  2203. // @router /system_contract/detail [get]
  2204. func (this *CompanyApplyController) GetContractApplyDetail() {
  2205. br := new(models.BaseResponse).Init()
  2206. defer func() {
  2207. this.Data["json"] = br
  2208. this.ServeJSON()
  2209. }()
  2210. sysUser := this.SysUser
  2211. if sysUser == nil {
  2212. br.Msg = "请登录"
  2213. br.ErrMsg = "请登录,SysUser Is Empty"
  2214. br.Ret = 408
  2215. return
  2216. }
  2217. productId := services.GetProductId(sysUser.RoleTypeCode)
  2218. if productId <= 0 {
  2219. br.Msg = "获取合同列表失败!"
  2220. br.ErrMsg = "获取合同列表失败,当前账户类型异常:" + sysUser.RoleTypeCode
  2221. return
  2222. }
  2223. contractId, err := this.GetInt("ContractId")
  2224. if err != nil {
  2225. br.Msg = "获取失败"
  2226. br.ErrMsg = "获取失败,Err:" + err.Error()
  2227. return
  2228. }
  2229. //合同id
  2230. if contractId <= 0 {
  2231. br.Msg = "获取失败"
  2232. br.ErrMsg = "获取失败,合同id必传"
  2233. return
  2234. }
  2235. contractDetail, err := contractService.GetContractDetail(contractId)
  2236. if err != nil {
  2237. br.Msg = "获取失败"
  2238. br.ErrMsg = "获取失败,Err:" + err.Error()
  2239. return
  2240. }
  2241. permissionList, err := contractService.GetPermissionByContractService(contractDetail.ProductId, contractDetail.Service)
  2242. if contractDetail.ProductId == 2 {
  2243. newPermissionList := contractService.HandleEquityPermissionLookList(permissionList)
  2244. permissionList = newPermissionList
  2245. }
  2246. if err != nil {
  2247. br.Msg = "获取失败"
  2248. br.ErrMsg = "获取权限失败,Err:" + err.Error()
  2249. return
  2250. }
  2251. resp := response.ContractApplyDetailResp{
  2252. ContractDetail: contractDetail,
  2253. PermissionList: permissionList,
  2254. }
  2255. br.Ret = 200
  2256. br.Success = true
  2257. br.Msg = "获取成功"
  2258. br.Data = resp
  2259. }
  2260. // @Title 获取客户最近的历史合同权限详情
  2261. // @Description 获取客户最近的历史合同权限详情接口
  2262. // @Param CompanyId query int true "客户ID"
  2263. // @Success 200 {object} *company.CompanyContractDetail
  2264. // @router /company/last_contract/detail/withoutDate [get]
  2265. func (this *CompanyApplyController) GetLastContractDetailWithoutDate() {
  2266. br := new(models.BaseResponse).Init()
  2267. defer func() {
  2268. this.Data["json"] = br
  2269. this.ServeJSON()
  2270. }()
  2271. sysUser := this.SysUser
  2272. if sysUser == nil {
  2273. br.Msg = "请登录"
  2274. br.ErrMsg = "请登录,SysUser Is Empty"
  2275. br.Ret = 408
  2276. return
  2277. }
  2278. companyId, _ := this.GetInt("CompanyId")
  2279. if companyId <= 0 {
  2280. br.Msg = "参数错误"
  2281. br.ErrMsg = "参数错误,客户id小于等于0"
  2282. return
  2283. }
  2284. companyInfo, err := company.GetCompanyDetailById(companyId)
  2285. if err != nil {
  2286. if err.Error() == utils.ErrNoRow() {
  2287. br.Msg = "参数错误"
  2288. br.ErrMsg = "客户不存在"
  2289. return
  2290. } else {
  2291. br.Msg = "查询客户信息失败"
  2292. br.ErrMsg = "查询客户信息失败:" + err.Error()
  2293. return
  2294. }
  2295. }
  2296. contractInfo, err := contract.GetContractListByCompanyName(companyInfo.CompanyName)
  2297. if err != nil {
  2298. if err.Error() != utils.ErrNoRow() {
  2299. br.Msg = "获取合同失败"
  2300. br.ErrMsg = "获取合同失败:" + err.Error()
  2301. return
  2302. } else {
  2303. br.Ret = 200
  2304. br.Success = true
  2305. br.Msg = "获取成功"
  2306. return
  2307. }
  2308. }
  2309. br.Ret = 200
  2310. br.Success = true
  2311. br.Msg = "获取成功"
  2312. br.Data = contractInfo
  2313. }
  2314. // @Title 申请服务更新-签约历史(单个详情)
  2315. // @Description 申请服务更新-签约历史接口(单个详情)
  2316. // @Param ContractCode query string true "合同编码"
  2317. // @Success 200 {object} company.CompanyContractHistoryResp
  2318. // @router /apply/contract/history/detail [get]
  2319. func (this *CompanyApplyController) ApplyContractHistoryDetail() {
  2320. br := new(models.BaseResponse).Init()
  2321. defer func() {
  2322. this.Data["json"] = br
  2323. this.ServeJSON()
  2324. }()
  2325. sysUser := this.SysUser
  2326. if sysUser == nil {
  2327. br.Msg = "请登录"
  2328. br.ErrMsg = "请登录,SysUser Is Empty"
  2329. br.Ret = 408
  2330. return
  2331. }
  2332. contractCode := this.GetString("ContractCode")
  2333. if contractCode == "" {
  2334. br.Msg = "参数错误"
  2335. br.ErrMsg = "参数错误,客户id小于等于0"
  2336. return
  2337. }
  2338. roleTypeCode := sysUser.RoleTypeCode
  2339. productId := services.GetProductId(roleTypeCode)
  2340. list, err := company.GetCompanyContractHistoryListByContractCode(contractCode)
  2341. if err != nil {
  2342. br.Msg = "获取信息失败"
  2343. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2344. return
  2345. }
  2346. listLen := len(list)
  2347. if listLen == 0 {
  2348. br.Msg = "获取信息失败"
  2349. br.ErrMsg = "签约信息不存在 contractCode:" + contractCode
  2350. return
  2351. }
  2352. expMap := map[int]string{0: "(3w)", 1: "(5w)"} // 买方研选价格
  2353. for i := 0; i < listLen; i++ {
  2354. companyContract := list[i]
  2355. list[i].ModifyTimeStr = companyContract.ModifyTime.Format(utils.FormatDateTime)
  2356. productId = list[i].ProductId
  2357. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  2358. //classifyName := "权益"
  2359. checkList := make([]int, 0)
  2360. plist := new(company.ContractPermissionList)
  2361. hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContract.CompanyContractId)
  2362. if e != nil {
  2363. br.Msg = "获取失败"
  2364. br.ErrMsg = "获取合同权限信息失败,Err:" + e.Error()
  2365. return
  2366. }
  2367. hasMap := make(map[int]*company.CompanyContractPermission)
  2368. for _, p := range hasPermissions {
  2369. hasMap[p.ChartPermissionId] = p
  2370. }
  2371. checkItems := make([]*company.PermissionLookItem, 0)
  2372. // PS:本来想把这个移到循环外面去优化一下...但是发现有指针引用变量被改掉的问题, BUG太多了改不完了先这样吧=_=!
  2373. raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
  2374. if e != nil {
  2375. br.Msg = "获取失败"
  2376. br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
  2377. return
  2378. }
  2379. for _, n := range raiPermissions {
  2380. match := hasMap[n.ChartPermissionId]
  2381. if match == nil {
  2382. continue
  2383. }
  2384. // 升级
  2385. if match.IsUpgrade == 1 {
  2386. n.IsUpgrade = 1
  2387. checkList = append(checkList, n.ChartPermissionId)
  2388. checkItems = append(checkItems, n)
  2389. continue
  2390. }
  2391. // 买方研选(3w/5w)
  2392. if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  2393. n.PermissionName += expMap[match.ExpensiveYx]
  2394. checkList = append(checkList, n.ChartPermissionId)
  2395. checkItems = append(checkItems, n)
  2396. continue
  2397. }
  2398. checkList = append(checkList, n.ChartPermissionId)
  2399. checkItems = append(checkItems, n)
  2400. }
  2401. plist.Items = checkItems
  2402. plist.ClassifyName = utils.COMPANY_PRODUCT_RAI_NAME
  2403. plist.CheckList = checkList
  2404. list[i].PermissionList = append(list[i].PermissionList, plist)
  2405. // CRM8.8-权限主客观合并
  2406. newPermissionLookList := contractService.HandleEquityContractPermissionList(list[i].PermissionList)
  2407. list[i].PermissionList = newPermissionLookList
  2408. }
  2409. }
  2410. resp := new(company.CompanyContractHistoryResp)
  2411. resp.List = list
  2412. br.Ret = 200
  2413. br.Success = true
  2414. br.Msg = "获取成功"
  2415. br.Data = resp
  2416. }