company.go 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/company"
  9. "hongze/hz_crm_api/models/company_user"
  10. "hongze/hz_crm_api/models/system"
  11. "hongze/hz_crm_api/services/alarm_msg"
  12. "hongze/hz_crm_api/utils"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // AddCompanyPermission 新增客户权限
  18. func AddCompanyPermission(companyId, sysUserId, productId int, productName, sysUserName, permissionStr, startDate, endDate string) (companyReportPermissionList []*company.CompanyReportPermission, err error) {
  19. if permissionStr == "" {
  20. return
  21. }
  22. permissionArr := strings.Split(permissionStr, ",")
  23. count, _ := company.GetCompanyReportPermissionCount(companyId, productId)
  24. //删除权限
  25. if count > 0 {
  26. err = company.DeleteCompanyReportPermission(companyId, productId)
  27. if err != nil {
  28. return
  29. }
  30. }
  31. //如果是ficc类型的客户,且权限列表中没有 宏观权限,那么需要默认将宏观加进去
  32. if productId == utils.COMPANY_PRODUCT_FICC_ID && !utils.InArrayByStr(permissionArr, "1") {
  33. permissionArr = append(permissionArr, "1")
  34. }
  35. for _, pv := range permissionArr {
  36. permissionId, tmpErr := strconv.Atoi(pv)
  37. if productId == utils.COMPANY_PRODUCT_RAI_ID && permissionId == 1 {
  38. continue
  39. }
  40. if tmpErr != nil {
  41. err = tmpErr
  42. return
  43. }
  44. permission := new(company.CompanyReportPermission)
  45. permission.CompanyId = companyId
  46. permission.ReportPermissionId = permissionId
  47. permission.CreatedTime = time.Now()
  48. permission.LastUpdatedTime = time.Now()
  49. permission.ChartPermissionId = permissionId
  50. permission.StartDate = startDate
  51. permission.EndDate = endDate
  52. permission.ProductId = productId
  53. permission.ProductName = productName
  54. permission.ModifyTime = time.Now()
  55. permission.Status = "试用"
  56. err = company.AddCompanyReportPermission(permission)
  57. if err != nil {
  58. return
  59. }
  60. companyReportPermissionList = append(companyReportPermissionList, permission)
  61. cpLog := new(company.CompanyPermissionLog)
  62. cpLog.CompanyId = companyId
  63. cpLog.ChartPermissionId = permissionId
  64. cpLog.CreateTime = time.Now()
  65. cpLog.SysUserId = sysUserId
  66. cpLog.SysUserName = sysUserName
  67. cpLog.StartDate = startDate
  68. cpLog.EndDate = endDate
  69. cpLog.ProductId = productId
  70. cpLog.ProductName = productName
  71. go company.AddCompanyPermissionLog(cpLog)
  72. }
  73. return
  74. }
  75. func AddCompanyProductLog(companyProduct *company.CompanyProduct, adminId int, logType string) (err error) {
  76. defer func() {
  77. if err != nil {
  78. go alarm_msg.SendAlarmMsg("services:AddCompanyProductLog;Err:"+err.Error(), 3)
  79. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyProductLog;Err:"+err.Error(), utils.EmailSendToUsers)
  80. }
  81. }()
  82. productLog := new(company.CompanyProductLog)
  83. productLog.CompanyProductId = companyProduct.CompanyProductId
  84. productLog.CompanyId = companyProduct.CompanyId
  85. productLog.ProductId = companyProduct.ProductId
  86. productLog.ProductName = companyProduct.ProductName
  87. productLog.CompanyName = companyProduct.CompanyName
  88. productLog.CompanyName = companyProduct.CompanyName
  89. productLog.Source = companyProduct.Source
  90. productLog.Reasons = companyProduct.Reasons
  91. productLog.Status = companyProduct.Status
  92. productLog.IndustryId = companyProduct.IndustryId
  93. productLog.IndustryName = companyProduct.IndustryName
  94. productLog.SellerId = companyProduct.SellerId
  95. productLog.SellerName = companyProduct.SellerName
  96. productLog.GroupId = companyProduct.GroupId
  97. productLog.DepartmentId = companyProduct.DepartmentId
  98. productLog.IsSuspend = companyProduct.IsSuspend
  99. productLog.SuspendTime = companyProduct.SuspendTime
  100. productLog.ApproveStatus = companyProduct.ApproveStatus
  101. productLog.FreezeTime = companyProduct.FreezeTime
  102. productLog.Remark = companyProduct.Remark
  103. productLog.StartDate = companyProduct.StartDate
  104. productLog.EndDate = companyProduct.EndDate
  105. productLog.CreateTime = companyProduct.CreateTime
  106. productLog.ModifyTime = companyProduct.ModifyTime
  107. productLog.LoseReason = companyProduct.LoseReason
  108. productLog.LossTime = companyProduct.LossTime
  109. productLog.LogType = logType
  110. productLog.LogCreateTime = time.Now()
  111. productLog.AdminId = adminId
  112. err = company.AddCompanyProductLog(productLog)
  113. //修改公司更新时间
  114. sql := `UPDATE company SET last_updated_time=NOW() WHERE company_id=? `
  115. o := orm.NewOrm()
  116. o.Raw(sql, companyProduct.CompanyId).Exec()
  117. return
  118. }
  119. func AddCompanyOperationRecord(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveUserRealName, approveRemark, status string) (err error) {
  120. defer func() {
  121. if err != nil {
  122. go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecord;Err:"+err.Error(), 3)
  123. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err:"+err.Error(), utils.EmailSendToUsers)
  124. }
  125. }()
  126. record := new(company.CompanyOperationRecord)
  127. record.CompanyId = companyId
  128. record.CompanyName = companyName
  129. record.SellerId = sellerId
  130. record.SysUserId = sysUserId
  131. record.SysRealName = sysUserRealName
  132. record.Remark = remark
  133. record.Operation = operation
  134. record.CreateTime = time.Now()
  135. record.ProductId = productId
  136. record.ProductName = productName
  137. record.ApproveUserId = approveAdminId
  138. record.ApproveRealName = approveUserRealName
  139. record.ApproveContent = approveContent
  140. record.ApproveRemark = approveRemark
  141. record.Status = status
  142. _, err = company.AddCompanyOperationRecord(record)
  143. return
  144. }
  145. // AddCompanyOperationRecordMore 添加操作记录(包含补充信息)
  146. func AddCompanyOperationRecordMore(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveContentExtra, approveUserRealName, approveRemark, status string) (err error) {
  147. defer func() {
  148. if err != nil {
  149. go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecordMore;Err:"+err.Error(), 3)
  150. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err:"+err.Error(), utils.EmailSendToUsers)
  151. }
  152. }()
  153. record := new(company.CompanyOperationRecord)
  154. record.CompanyId = companyId
  155. record.CompanyName = companyName
  156. record.SellerId = sellerId
  157. record.SysUserId = sysUserId
  158. record.SysRealName = sysUserRealName
  159. record.Remark = remark
  160. record.Operation = operation
  161. record.CreateTime = time.Now()
  162. record.ProductId = productId
  163. record.ProductName = productName
  164. record.ApproveUserId = approveAdminId
  165. record.ApproveRealName = approveUserRealName
  166. record.ApproveContent = approveContent
  167. record.ApproveContentExtra = approveContentExtra
  168. record.ApproveRemark = approveRemark
  169. record.Status = status
  170. _, err = company.AddCompanyOperationRecord(record)
  171. return
  172. }
  173. func GetProductId(roleTypeCode string) (productId int) {
  174. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  175. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  176. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  177. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  178. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT {
  179. productId = 1
  180. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  181. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  182. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  183. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  184. productId = 2
  185. } else {
  186. productId = 0
  187. }
  188. return
  189. }
  190. // CheckAdminIsSeller 根据用户权限码获取是否属于销售
  191. func CheckAdminIsSeller(roleTypeCode string) (isSeller bool) {
  192. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  193. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  194. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  195. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  196. isSeller = true
  197. }
  198. return
  199. }
  200. //func GetCompanyPermissionButton(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  201. // button.BtnView = true
  202. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  203. // if !strings.Contains(status, "/") {
  204. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  205. // //button.BtnModifySeller = true
  206. // return
  207. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  208. // button.BtnEdit = true
  209. // button.BtnDelete = true
  210. // //button.BtnModifySeller = true
  211. // return
  212. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  213. // //button.BtnModifySeller = true
  214. // return
  215. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  216. // //button.BtnModifySeller = true
  217. // button.BtnDelete = true
  218. // return
  219. // } else { //永续
  220. // //button.BtnModifySeller = true
  221. // button.BtnDelete = true
  222. // button.BtnEdit = true
  223. // return
  224. // }
  225. // }
  226. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  227. // if productId != 1 {
  228. // return
  229. // } else {
  230. // if !strings.Contains(status, "/") {
  231. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  232. // button.BtnModifySeller = true
  233. // return
  234. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  235. // button.BtnEdit = true
  236. // button.BtnDelete = true
  237. // button.BtnModifySeller = true
  238. // return
  239. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  240. // //button.BtnModifySeller = true
  241. // return
  242. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  243. // //button.BtnModifySeller = true
  244. // button.BtnDelete = true
  245. // return
  246. // } else { //永续
  247. // return
  248. // }
  249. // }
  250. // }
  251. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  252. // if !strings.Contains(status, "/") {
  253. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  254. // button.BtnModifySeller = true
  255. // return
  256. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  257. // button.BtnEdit = true
  258. // button.BtnDelete = true
  259. // return
  260. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  261. // return
  262. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  263. // button.BtnDelete = true
  264. // return
  265. // } else { //永续
  266. // return
  267. // }
  268. // }
  269. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  270. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  271. // return
  272. // }
  273. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  274. // return
  275. // }
  276. // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
  277. // if authority == 2 { //组长
  278. // if !strings.Contains(status, "/") {
  279. // if sysUserId == itemSellerId { //自己客户
  280. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  281. // button.BtnUpdate = true
  282. // button.BtnModifySeller = true
  283. // return
  284. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  285. // button.BtnEdit = true
  286. // button.BtnDelete = true
  287. // button.BtnSuspend = true
  288. // button.BtnDelay = true
  289. // button.BtnTurnPositive = true
  290. // button.BtnModifySeller = true
  291. // return
  292. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  293. // button.BtnThaw = true
  294. // return
  295. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  296. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  297. // button.BtnApplyReceive = true
  298. // } else {
  299. // button.BtnReceive = true
  300. // }
  301. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  302. // button.BtnDelete = true
  303. // }
  304. // return
  305. // } else { //永续
  306. // button.BtnDelete = true
  307. // return
  308. // }
  309. // } else {
  310. // if productId == 1 {
  311. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  312. // button.BtnModifySeller=true
  313. // return
  314. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  315. // button.BtnModifySeller=true
  316. // return
  317. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  318. // button.BtnThaw = true
  319. // return
  320. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  321. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  322. // button.BtnApplyReceive = true
  323. // } else {
  324. // button.BtnReceive = true
  325. // }
  326. // return
  327. // } else { //永续
  328. // button.BtnDelete = true
  329. // return
  330. // }
  331. // } else {
  332. // button.BtnReceive = true
  333. // }
  334. // }
  335. // }
  336. // } else { //销售
  337. // if !strings.Contains(status, "/") {
  338. // if itemSellerId == sysUserId {
  339. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  340. // button.BtnUpdate = true
  341. // return
  342. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  343. // button.BtnEdit = true
  344. // button.BtnDelete = true
  345. // button.BtnSuspend = true
  346. // button.BtnDelay = true
  347. // button.BtnTurnPositive = true
  348. // return
  349. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  350. // button.BtnThaw = true
  351. // return
  352. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  353. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  354. // button.BtnApplyReceive = true
  355. // } else {
  356. // button.BtnReceive = true
  357. // }
  358. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  359. // button.BtnDelete = true
  360. // }
  361. // return
  362. // } else { //永续
  363. // button.BtnDelete = true
  364. // return
  365. // }
  366. // } else {
  367. // if productId == 1 {
  368. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  369. // return
  370. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  371. // return
  372. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  373. // button.BtnThaw = true
  374. // return
  375. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  376. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  377. // button.BtnApplyReceive = true
  378. // } else {
  379. // button.BtnReceive = true
  380. // }
  381. // return
  382. // } else { //永续
  383. // button.BtnDelete = true
  384. // return
  385. // }
  386. // } else {
  387. // button.BtnReceive = true
  388. // }
  389. // }
  390. // }
  391. // }
  392. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  393. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  394. // return
  395. // }
  396. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  397. // return
  398. // }
  399. // if !strings.Contains(status, "/") {
  400. // if authority == 2 { //组长
  401. // if itemSellerId==sysUserId {
  402. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  403. // button.BtnUpdate = true
  404. // button.BtnModifySeller = true
  405. // return
  406. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  407. // button.BtnEdit = true
  408. // button.BtnDelete = true
  409. // button.BtnSuspend = true
  410. // button.BtnDelay = true
  411. // button.BtnTurnPositive = true
  412. // button.BtnModifySeller = true
  413. // return
  414. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  415. // button.BtnThaw = true
  416. // return
  417. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  418. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  419. // button.BtnApplyReceive = true
  420. // } else {
  421. // button.BtnReceive = true
  422. // }
  423. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  424. // button.BtnDelete = true
  425. // }
  426. // return
  427. // } else { //永续
  428. // button.BtnDelete = true
  429. // return
  430. // }
  431. // }else{
  432. // if productId==1 {
  433. // button.BtnReceive=true
  434. // }else{
  435. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  436. // button.BtnModifySeller=true
  437. // return
  438. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  439. // button.BtnModifySeller=true
  440. // return
  441. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  442. // button.BtnThaw = true
  443. // return
  444. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  445. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  446. // button.BtnApplyReceive = true
  447. // } else {
  448. // button.BtnReceive = true
  449. // }
  450. // return
  451. // } else { //永续
  452. // button.BtnDelete = true
  453. // return
  454. // }
  455. // }
  456. // }
  457. // } else {
  458. // if itemSellerId==sysUserId {
  459. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  460. // button.BtnUpdate = true
  461. // return
  462. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  463. // button.BtnEdit = true
  464. // button.BtnDelete = true
  465. // button.BtnSuspend = true
  466. // button.BtnDelay = true
  467. // button.BtnTurnPositive = true
  468. // return
  469. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  470. // button.BtnThaw = true
  471. // return
  472. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  473. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  474. // button.BtnApplyReceive = true
  475. // } else {
  476. // button.BtnReceive = true
  477. // }
  478. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  479. // button.BtnDelete = true
  480. // }
  481. // return
  482. // } else { //永续
  483. // button.BtnDelete = true
  484. // return
  485. // }
  486. // }else{
  487. // if productId==1 {
  488. // button.BtnReceive=true
  489. // }else{
  490. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  491. // return
  492. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  493. // return
  494. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  495. // button.BtnThaw = true
  496. // return
  497. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  498. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  499. // button.BtnApplyReceive = true
  500. // } else {
  501. // button.BtnReceive = true
  502. // }
  503. // return
  504. // } else { //永续
  505. // button.BtnDelete = true
  506. // return
  507. // }
  508. // }
  509. // }
  510. // }
  511. // }
  512. // }
  513. // return button
  514. //}
  515. //func GetCompanyPermissionButton(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  516. // button.BtnView = true
  517. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  518. // if !strings.Contains(status, "/") {
  519. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  520. // button.BtnView = true
  521. // button.BtnModifySeller = true
  522. // return
  523. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  524. // button.BtnEdit = true
  525. // button.BtnDelete = true
  526. // button.BtnFreeze=true
  527. // return
  528. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  529. // button.BtnModifySeller = true
  530. // button.BtnView = true
  531. // return
  532. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  533. // button.BtnDelete = true
  534. // button.BtnModifySeller = true
  535. // return
  536. // } else { //永续
  537. // button.BtnDelete = true
  538. // button.BtnEdit = true
  539. // return
  540. // }
  541. // }
  542. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  543. // fmt.Println("itemSellerId:",itemSellerId)
  544. // fmt.Println("sysUserId:",sysUserId)
  545. // if !strings.Contains(status, "/") {
  546. // if itemSellerId == sysUserId {
  547. // if productId == 1 {
  548. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  549. // button.BtnModifySeller = true
  550. // button.BtnUpdate = true
  551. // return
  552. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  553. // button.BtnEdit = true
  554. // button.BtnDelete = true
  555. // button.BtnModifySeller = true
  556. // button.BtnSuspend = true
  557. // button.BtnDelay = true
  558. // button.BtnTurnPositive = true
  559. // button.BtnFreeze=true
  560. // return
  561. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  562. // button.BtnModifySeller = true
  563. // button.BtnView = true
  564. // return
  565. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  566. // button.BtnModifySeller = true
  567. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  568. // button.BtnDelete = true
  569. // }
  570. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  571. // button.BtnApplyReceive = true
  572. // } else {
  573. // button.BtnReceive = true
  574. // }
  575. // return
  576. // } else { //永续
  577. // button.BtnDelete = true
  578. // return
  579. // }
  580. // } else {
  581. // //button.BtnReceiveOther=true
  582. // return
  583. // }
  584. // } else {
  585. // if productId == 1 {
  586. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  587. // button.BtnModifySeller = true
  588. // return
  589. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  590. // button.BtnEdit = true
  591. // button.BtnDelete = true
  592. // return
  593. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  594. // button.BtnModifySeller = true
  595. // button.BtnView = true
  596. // return
  597. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  598. // button.BtnModifySeller = true
  599. // button.BtnDelete = true
  600. // button.BtnView = true
  601. // return
  602. // } else { //永续
  603. // return
  604. // }
  605. // } else {
  606. // button.BtnReceiveOther = true
  607. // return
  608. // }
  609. // }
  610. // }
  611. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  612. // if !strings.Contains(status, "/") {
  613. // if itemSellerId == sysUserId {
  614. // if productId == 2 {
  615. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  616. // button.BtnModifySeller = true
  617. // button.BtnUpdate = true
  618. // return
  619. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  620. // button.BtnEdit = true
  621. // button.BtnDelete = true
  622. // button.BtnModifySeller = true
  623. // button.BtnSuspend = true
  624. // button.BtnDelay = true
  625. // button.BtnTurnPositive = true
  626. // button.BtnFreeze=true
  627. // return
  628. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  629. // button.BtnModifySeller = true
  630. // return
  631. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  632. // button.BtnModifySeller = true
  633. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  634. // button.BtnDelete = true
  635. // }
  636. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  637. // button.BtnApplyReceive = true
  638. // } else {
  639. // button.BtnReceive = true
  640. // }
  641. // return
  642. // } else { //永续
  643. // button.BtnDelete = true
  644. // return
  645. // }
  646. // } else {
  647. // return
  648. // }
  649. // } else {
  650. // if productId == 2 {
  651. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  652. // button.BtnModifySeller = true
  653. // button.BtnView = true
  654. // return
  655. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  656. // button.BtnEdit = true
  657. // button.BtnDelete = true
  658. // return
  659. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  660. // button.BtnView = true
  661. // button.BtnModifySeller = true
  662. // return
  663. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  664. // button.BtnModifySeller = true
  665. // button.BtnDelete = true
  666. // button.BtnView = true
  667. // return
  668. // } else { //永续
  669. // return
  670. // }
  671. // } else {
  672. // //button.BtnReceive = true
  673. // return
  674. // }
  675. // }
  676. // }
  677. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  678. // if !strings.Contains(status, "/") {
  679. // if itemSellerId == sysUserId {
  680. // if productId == 1 {
  681. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  682. // button.BtnUpdate = true
  683. // return
  684. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  685. // button.BtnDelete = true
  686. // button.BtnEdit = true
  687. // button.BtnSuspend = true
  688. // button.BtnDelay = true
  689. // button.BtnTurnPositive = true
  690. // button.BtnFreeze=true
  691. // return
  692. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  693. // button.BtnThaw = true
  694. // return
  695. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  696. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  697. // button.BtnApplyReceive = true
  698. // } else {
  699. // button.BtnReceive = true
  700. // }
  701. // if itemSellerId == sysUserId || (sysUserGroupId == itemGroupId && authority == 2) {
  702. // button.BtnDelete = true
  703. // }
  704. // return
  705. // } else { //永续
  706. // button.BtnDelete = true
  707. // return
  708. // }
  709. // } else {
  710. // button.BtnReceiveOther = true
  711. // return
  712. // }
  713. // } else {
  714. // if productId == 1 {
  715. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  716. // return
  717. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  718. // return
  719. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  720. // button.BtnApplyReceive = true
  721. // button.BtnView = false
  722. // return
  723. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  724. // if itemGroupId == sysUserGroupId {
  725. // button.BtnApplyReceive = true
  726. // } else {
  727. // button.BtnReceive = true
  728. // }
  729. // button.BtnView = false
  730. // return
  731. // } else { //永续
  732. // button.BtnDelete = true
  733. // return
  734. // }
  735. // } else {
  736. // button.BtnReceiveOther = true
  737. // button.BtnView = false
  738. // return
  739. // }
  740. // }
  741. // }
  742. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  743. // if !strings.Contains(status, "/") {
  744. // if itemSellerId == sysUserId {
  745. // if productId == 2 {
  746. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  747. // button.BtnUpdate = true
  748. // return
  749. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  750. // button.BtnDelete = true
  751. // button.BtnEdit = true
  752. // button.BtnSuspend = true
  753. // button.BtnDelay = true
  754. // button.BtnTurnPositive = true
  755. // button.BtnFreeze=true
  756. // return
  757. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  758. // button.BtnThaw = true
  759. // return
  760. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  761. // if itemGroupId == sysUserGroupId {
  762. // button.BtnApplyReceive = true
  763. // } else {
  764. // button.BtnReceive = true
  765. // }
  766. // if sysUserGroupId == itemGroupId && authority == 2 {
  767. // button.BtnDelete = true
  768. // }
  769. // return
  770. // } else { //永续
  771. // button.BtnDelete = true
  772. // return
  773. // }
  774. // } else {
  775. // button.BtnReceiveOther = true
  776. // return
  777. // }
  778. // } else {
  779. // if productId == 2 {
  780. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  781. // return
  782. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  783. // return
  784. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  785. // button.BtnApplyReceive = true
  786. // button.BtnView = false
  787. // return
  788. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  789. // if itemGroupId == sysUserGroupId {
  790. // button.BtnApplyReceive = true
  791. // } else {
  792. // button.BtnReceive = true
  793. // }
  794. // button.BtnView = false
  795. // return
  796. // } else { //永续
  797. // button.BtnDelete = true
  798. // return
  799. // }
  800. // } else {
  801. // button.BtnReceiveOther = true
  802. // button.BtnView = false
  803. // return
  804. // }
  805. // }
  806. // }
  807. // }
  808. // return button
  809. //}
  810. //
  811. func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupIdS string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId, shareSellerId int, shareSellerIds string) (button company.ButtonPermission) {
  812. //产品状态map
  813. productStatusMap := make(map[int]string)
  814. if productId == 1 {
  815. productStatusMap[1] = status
  816. } else if productId == 2 {
  817. productStatusMap[2] = status
  818. }
  819. if strings.Contains(status, "/") {
  820. statusSlice := strings.Split(status, "/")
  821. productStatusMap[1] = statusSlice[0]
  822. productStatusMap[2] = statusSlice[1]
  823. }
  824. //所属销售map
  825. sellerIdMap := make(map[int]int)
  826. if productId == 1 {
  827. sellerIdMap[1] = itemSellerId
  828. } else if productId == 2 {
  829. sellerIdMap[2] = itemSellerId
  830. }
  831. if strings.Contains(itemSellerIds, "/") {
  832. sellerIdSlice := strings.Split(itemSellerIds, "/")
  833. sellerIdMap[1], _ = strconv.Atoi(sellerIdSlice[0])
  834. sellerIdMap[2], _ = strconv.Atoi(sellerIdSlice[1])
  835. }
  836. //分组map
  837. groupIdMap := make(map[int]int)
  838. if productId == 1 {
  839. groupIdMap[1] = itemGroupId
  840. } else if productId == 2 {
  841. groupIdMap[2] = itemGroupId
  842. }
  843. if strings.Contains(itemGroupIdS, "/") {
  844. groupIdSlice := strings.Split(itemGroupIdS, "/")
  845. groupIdMap[1], _ = strconv.Atoi(groupIdSlice[0])
  846. groupIdMap[2], _ = strconv.Atoi(groupIdSlice[1])
  847. }
  848. shareSellerIdArr := strings.Split(shareSellerIds, ",")
  849. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  850. button.BtnView = true //查看详情权限
  851. if !strings.Contains(status, "/") {
  852. if status == utils.COMPANY_STATUS_FORMAL { //正式
  853. //button.BtnModifySeller = true
  854. button.BtnRemarkView = true
  855. return
  856. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  857. button.BtnEdit = true
  858. button.BtnDelete = true
  859. button.BtnRemarkView = true
  860. //button.BtnModifySeller = true
  861. button.BtnFreeze = false
  862. if productId == utils.COMPANY_PRODUCT_FICC_ID {
  863. button.BtnClose = true // 超管/FICC管理员可关闭试用客户
  864. }
  865. return
  866. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  867. //button.BtnModifySeller = true
  868. button.BtnRemarkView = true
  869. return
  870. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  871. //button.BtnModifySeller = true
  872. button.BtnDelete = true
  873. return
  874. } else if status == utils.COMPANY_STATUS_CLOSE { // 关闭
  875. //button.BtnModifySeller = true
  876. button.BtnDelete = true
  877. if productId == utils.COMPANY_PRODUCT_FICC_ID {
  878. button.BtnLoss = true // 超管/FICC管理员可关闭转流失
  879. }
  880. return
  881. } else { //永续
  882. //button.BtnModifySeller = true
  883. button.BtnDelete = true
  884. button.BtnEdit = true
  885. return
  886. }
  887. }
  888. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  889. //查看详情权限
  890. productStatus, hasProduct := productStatusMap[1]
  891. if hasProduct {
  892. button.BtnView = true
  893. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  894. button.BtnModifySeller = true
  895. button.BtnShare = true
  896. return
  897. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  898. button.BtnEdit = true
  899. //button.BtnDelete = true
  900. button.BtnModifySeller = true
  901. button.BtnFreeze = false
  902. button.BtnClose = true // 超管/FICC管理员可关闭试用客户
  903. return
  904. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  905. button.BtnModifySeller = true
  906. return
  907. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  908. //button.BtnModifySeller = true
  909. //button.BtnDelete = true
  910. return
  911. } else if productStatus == utils.COMPANY_STATUS_CLOSE { // 关闭
  912. button.BtnLoss = true // 超管/FICC管理员可关闭转流失
  913. return
  914. } else { //永续
  915. return
  916. }
  917. } else {
  918. productStatus2, hasProduct2 := productStatusMap[2]
  919. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  920. if hasProduct2 {
  921. //其他产品的流失客户可以有查看权限
  922. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  923. button.BtnView = true //查看权限
  924. }
  925. }
  926. }
  927. return
  928. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  929. //查看详情权限
  930. productStatus, hasProduct := productStatusMap[2]
  931. if hasProduct {
  932. button.BtnView = true
  933. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  934. button.BtnModifySeller = true
  935. button.BtnShare = true
  936. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  937. button.BtnEdit = true
  938. //button.BtnDelete = true
  939. button.BtnModifySeller = true
  940. button.BtnFreeze = false
  941. // CRM14.7.2 权益管理员可以设置试用客户为共享
  942. button.BtnShare = true
  943. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  944. button.BtnModifySeller = true
  945. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  946. //button.BtnDelete = true
  947. } else { //永续
  948. button.BtnModifySeller = true
  949. button.BtnShare = true
  950. }
  951. } else {
  952. productStatus2, hasProduct2 := productStatusMap[1]
  953. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  954. if hasProduct2 {
  955. //其他产品的流失客户可以有查看权限
  956. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  957. button.BtnView = true //查看权限
  958. }
  959. }
  960. }
  961. return
  962. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  963. //判断该客户是否有ficc权限
  964. productStatus, hasProduct := productStatusMap[1]
  965. if hasProduct {
  966. //如果有权限的话:
  967. //获取当前ficc的销售id
  968. sellerId, hasSellerId := sellerIdMap[1]
  969. //获取当前ficc的销售分组id
  970. groupId, hasGroupId := groupIdMap[1]
  971. //如果是自己客户,那么拥有查看权限
  972. if hasSellerId {
  973. if sellerId == sysUserId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  974. button.BtnView = true //显示权限、详情
  975. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  976. button.BtnUpdate = true //服务更新
  977. button.BtnAddAgreement = true //补充协议
  978. button.BtnTryOut = true
  979. button.BtnModifySeller = true
  980. button.BtnShare = true
  981. button.BtnRemarkEdit = true
  982. button.BtnRemarkView = true
  983. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  984. button.BtnEdit = true
  985. button.BtnDelete = true
  986. button.BtnSuspend = true
  987. button.BtnDelay = true
  988. button.BtnTurnPositive = true
  989. button.BtnFreeze = true
  990. button.BtnModifySeller = true
  991. button.BtnRemarkEdit = true
  992. button.BtnRemarkView = true
  993. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  994. button.BtnThaw = true
  995. button.BtnModifySeller = true
  996. button.BtnRemarkEdit = true
  997. button.BtnRemarkView = true
  998. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  999. button.BtnApplyReceive = true
  1000. } else { //永续
  1001. //button.BtnDelete = true
  1002. }
  1003. } else {
  1004. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1005. button.BtnView = true //显示权限、详情
  1006. //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
  1007. if groupId == sysUserGroupId {
  1008. button.BtnApplyReceive = true
  1009. } else {
  1010. button.BtnReceive = true
  1011. }
  1012. }
  1013. }
  1014. }
  1015. //如果是组长,且该客户属于本组客户
  1016. if authority == 4 && hasGroupId && groupId == sysUserGroupId && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  1017. button.BtnView = true //查看详情权限
  1018. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1019. button.BtnModifySeller = true
  1020. button.BtnShare = true
  1021. button.BtnRemarkView = true
  1022. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1023. button.BtnModifySeller = true
  1024. button.BtnRemarkView = true
  1025. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1026. button.BtnModifySeller = true
  1027. button.BtnRemarkView = true
  1028. //button.BtnThaw = false
  1029. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1030. if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1031. button.BtnApplyReceive = true
  1032. } else {
  1033. button.BtnReceive = true
  1034. }
  1035. } else { //永续
  1036. //button.BtnDelete = true
  1037. }
  1038. }
  1039. //如果是ficc销售主管,且该客户属于本组客户
  1040. //获取父级groupId
  1041. groupIdpid, err := company.GetParentIdFromGroup(groupId)
  1042. if err != nil {
  1043. fmt.Println(err.Error())
  1044. }
  1045. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUserGroupId)
  1046. if err != nil {
  1047. fmt.Println(err.Error())
  1048. }
  1049. var pidBool bool
  1050. //处理主管和销售在不同的二三级分组下的情况
  1051. if groupIdpid != nil && sysUserGroupIdpid != nil {
  1052. pidBool = *groupIdpid == *sysUserGroupIdpid || *groupIdpid == sysUserGroupId || groupId == sysUserGroupId || groupId == *sysUserGroupIdpid
  1053. }
  1054. if authority == 2 && hasGroupId && pidBool && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  1055. button.BtnView = true //查看详情权限
  1056. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1057. button.BtnModifySeller = true
  1058. button.BtnShare = true
  1059. button.BtnRemarkView = true
  1060. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1061. button.BtnModifySeller = true
  1062. button.BtnRemarkView = true
  1063. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1064. button.BtnModifySeller = true
  1065. button.BtnRemarkView = true
  1066. //button.BtnThaw = false
  1067. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1068. if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1069. button.BtnApplyReceive = true
  1070. } else {
  1071. button.BtnReceive = true
  1072. }
  1073. } else { //永续
  1074. //button.BtnDelete = true
  1075. }
  1076. }
  1077. //ficc同一个大组当作一个小组来处理领取按钮
  1078. var ids []*string
  1079. if groupIdpid != nil && *groupIdpid != 0 {
  1080. ids, err = company.GetGroupIdsByParentId(*groupIdpid)
  1081. if err != nil {
  1082. fmt.Println(err.Error())
  1083. }
  1084. }
  1085. var idSlice []string
  1086. var sid string
  1087. for _, id := range ids {
  1088. idSlice = append(idSlice, *id)
  1089. }
  1090. sid = strings.Join(idSlice, ",")
  1091. if strings.Contains(sid, strconv.Itoa(itemGroupId)) {
  1092. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1093. button.BtnApplyReceive = true
  1094. button.BtnReceive = false
  1095. }
  1096. }
  1097. } else {
  1098. productStatus2, hasProduct2 := productStatusMap[2]
  1099. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  1100. if hasProduct2 {
  1101. //如果客户ficc权限是永续,那么也没有其他部门客户的按钮权限
  1102. if productStatus2 != utils.COMPANY_STATUS_FOREVER {
  1103. button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1104. }
  1105. //其他产品的流失客户可以有查看权限
  1106. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  1107. button.BtnView = true //查看权限
  1108. }
  1109. }
  1110. }
  1111. return
  1112. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1113. //判断该客户是否有权益权限
  1114. productStatus, hasProduct := productStatusMap[2]
  1115. if hasProduct {
  1116. //如果有权限的话:
  1117. //获取当前 权益 的销售id
  1118. sellerId, hasSellerId := sellerIdMap[2]
  1119. //获取当前 权益 的销售分组id
  1120. groupId, hasGroupId := groupIdMap[2]
  1121. //如果是自己客户,那么拥有查看权限
  1122. if hasSellerId {
  1123. if sellerId == sysUserId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1124. button.BtnView = true //显示权限、详情
  1125. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1126. button.BtnUpdate = true
  1127. button.BtnTryOut = true
  1128. button.BtnModifySeller = true
  1129. //button.BtnShare = true
  1130. button.BtnRemarkEdit = true
  1131. button.BtnRemarkView = true
  1132. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1133. button.BtnEdit = true
  1134. button.BtnDelete = true
  1135. button.BtnSuspend = true
  1136. button.BtnDelay = true
  1137. button.BtnTurnPositive = true
  1138. button.BtnModifySeller = true
  1139. button.BtnFreeze = true
  1140. button.BtnRemarkEdit = true
  1141. button.BtnRemarkView = true
  1142. //button.BtnShare = true
  1143. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1144. button.BtnThaw = true
  1145. button.BtnModifySeller = true
  1146. button.BtnRemarkEdit = true
  1147. button.BtnRemarkView = true
  1148. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1149. button.BtnApplyReceive = true
  1150. } else if productStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1151. button.BtnTurnPositive = true
  1152. }
  1153. } else {
  1154. if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1155. button.BtnView = true //显示权限、详情
  1156. //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
  1157. if groupId == sysUserGroupId {
  1158. button.BtnApplyReceive = true
  1159. } else {
  1160. button.BtnReceive = true
  1161. }
  1162. }
  1163. }
  1164. }
  1165. //如果是组长,且该客户属于本组客户
  1166. if authority == 2 && hasGroupId && groupId == sysUserGroupId {
  1167. button.BtnView = true //查看详情权限
  1168. if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
  1169. button.BtnModifySeller = true
  1170. //button.BtnShare = true
  1171. button.BtnRemarkView = true
  1172. } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
  1173. button.BtnModifySeller = true
  1174. button.BtnRemarkView = true
  1175. //button.BtnShare = true
  1176. } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1177. button.BtnModifySeller = true
  1178. button.BtnRemarkView = true
  1179. } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
  1180. if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
  1181. button.BtnApplyReceive = true
  1182. } else {
  1183. button.BtnReceive = true
  1184. }
  1185. } else { //永续
  1186. //button.BtnDelete = true
  1187. }
  1188. }
  1189. } else {
  1190. productStatus2, hasProduct2 := productStatusMap[1]
  1191. //如果没有权限的话,那么允许领取其他部门客户按钮权限
  1192. if hasProduct2 {
  1193. //如果客户 权益 权限是永续,那么也没有其他部门客户的按钮权限
  1194. if productStatus2 != utils.COMPANY_STATUS_FOREVER {
  1195. button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1196. }
  1197. //其他产品的流失客户可以有查看权限
  1198. if productStatus2 == utils.COMPANY_STATUS_LOSE {
  1199. button.BtnView = true //查看权限
  1200. }
  1201. }
  1202. }
  1203. return
  1204. }
  1205. return button
  1206. }
  1207. // GetCompanyPermissionButtonByReceiveEnabled 查询当前销售 "添加客户" 权限来判断按钮权限
  1208. func GetCompanyPermissionButtonByReceiveEnabled(btnItem *company.ButtonPermission, receiveEnabled bool) (buttonNew *company.ButtonPermission) {
  1209. //查询当前销售 "添加客户" 权限是否为禁用
  1210. if !receiveEnabled {
  1211. //申请领取、领取客户、领取其他部门客户按钮权限按钮显示时
  1212. if btnItem.BtnApplyReceive || btnItem.BtnReceive || btnItem.BtnReceiveOther {
  1213. btnItem.BtnApplyReceive = false
  1214. btnItem.BtnReceive = false
  1215. btnItem.BtnReceiveOther = false
  1216. }
  1217. if btnItem.BtnThaw {
  1218. btnItem.BtnThaw = false
  1219. }
  1220. }
  1221. buttonNew = btnItem
  1222. return buttonNew
  1223. }
  1224. //func GetCompanyPermissionButtonOld(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
  1225. // button.BtnView = true
  1226. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
  1227. // if !strings.Contains(status, "/") {
  1228. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1229. // //button.BtnModifySeller = true
  1230. // return
  1231. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1232. // button.BtnEdit = true
  1233. // button.BtnDelete = true
  1234. // //button.BtnModifySeller = true
  1235. // button.BtnFreeze = false
  1236. // return
  1237. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1238. // //button.BtnModifySeller = true
  1239. // return
  1240. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1241. // //button.BtnModifySeller = true
  1242. // button.BtnDelete = true
  1243. // return
  1244. // } else { //永续
  1245. // //button.BtnModifySeller = true
  1246. // button.BtnDelete = true
  1247. // button.BtnEdit = true
  1248. // return
  1249. // }
  1250. // }
  1251. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1252. // if productId != 1 {
  1253. // return
  1254. // } else {
  1255. // if !strings.Contains(status, "/") {
  1256. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1257. // button.BtnModifySeller = true
  1258. // return
  1259. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1260. // //button.BtnEdit = true
  1261. // //button.BtnDelete = true
  1262. // button.BtnModifySeller = true
  1263. // button.BtnFreeze = false
  1264. // return
  1265. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1266. // //button.BtnModifySeller = true
  1267. // return
  1268. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1269. // //button.BtnModifySeller = true
  1270. // //button.BtnDelete = true
  1271. // return
  1272. // } else { //永续
  1273. // return
  1274. // }
  1275. // }
  1276. // }
  1277. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1278. // if !strings.Contains(status, "/") {
  1279. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1280. // button.BtnModifySeller = true
  1281. // return
  1282. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1283. // //button.BtnEdit = true
  1284. // //button.BtnDelete = true
  1285. // button.BtnModifySeller = true
  1286. // button.BtnFreeze = false
  1287. // return
  1288. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1289. // return
  1290. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1291. // //button.BtnDelete = true
  1292. // return
  1293. // } else { //永续
  1294. // return
  1295. // }
  1296. // }
  1297. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  1298. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  1299. // if !strings.Contains(status, "/") {
  1300. // button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1301. // } else {
  1302. // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
  1303. // statusSlice := strings.Split(status, "/")
  1304. // ficcStatus := statusSlice[0]
  1305. // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1306. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1307. // button.BtnApplyReceive = true //申请领取按钮权限
  1308. // } else {
  1309. // button.BtnReceive = true //领取客户按钮权限
  1310. // }
  1311. // return
  1312. // }
  1313. // }
  1314. // return
  1315. // }
  1316. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  1317. // return
  1318. // }
  1319. // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
  1320. // if authority == 2 { //组长
  1321. // if !strings.Contains(status, "/") {
  1322. // if sysUserId == itemSellerId { //自己客户
  1323. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1324. // button.BtnUpdate = true
  1325. // button.BtnModifySeller = true
  1326. // button.BtnTryOut = true
  1327. // return
  1328. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1329. // button.BtnEdit = true
  1330. // button.BtnDelete = true
  1331. // button.BtnSuspend = true
  1332. // button.BtnDelay = true
  1333. // button.BtnTurnPositive = true
  1334. // button.BtnModifySeller = true
  1335. // button.BtnFreeze = true
  1336. // return
  1337. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1338. // button.BtnThaw = true
  1339. // return
  1340. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1341. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1342. // button.BtnApplyReceive = true
  1343. // } else {
  1344. // button.BtnReceive = true
  1345. // }
  1346. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1347. // //button.BtnDelete = true
  1348. // }
  1349. // return
  1350. // } else { //永续
  1351. // button.BtnDelete = true
  1352. // return
  1353. // }
  1354. // } else {
  1355. // if productId == 1 {
  1356. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1357. // button.BtnModifySeller = true
  1358. // return
  1359. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1360. // button.BtnModifySeller = true
  1361. // return
  1362. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1363. // button.BtnThaw = false
  1364. // return
  1365. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1366. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1367. // button.BtnApplyReceive = true
  1368. // } else {
  1369. // button.BtnReceive = true
  1370. // }
  1371. // return
  1372. // } else { //永续
  1373. // button.BtnDelete = true
  1374. // return
  1375. // }
  1376. // } else {
  1377. // //button.BtnReceive = true
  1378. // }
  1379. // }
  1380. // }
  1381. // } else { //销售
  1382. // if !strings.Contains(status, "/") {
  1383. // if itemSellerId == sysUserId {
  1384. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1385. // button.BtnUpdate = true
  1386. // button.BtnTryOut = true
  1387. // return
  1388. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1389. // button.BtnEdit = true
  1390. // button.BtnDelete = true
  1391. // button.BtnSuspend = true
  1392. // button.BtnDelay = true
  1393. // button.BtnTurnPositive = true
  1394. // button.BtnFreeze = true
  1395. // return
  1396. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1397. // button.BtnThaw = true
  1398. // return
  1399. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1400. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1401. // button.BtnApplyReceive = true
  1402. // } else {
  1403. // button.BtnReceive = true
  1404. // }
  1405. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1406. // //button.BtnDelete = true
  1407. // }
  1408. // return
  1409. // } else { //永续
  1410. // button.BtnDelete = true
  1411. // return
  1412. // }
  1413. // } else {
  1414. // if productId == 1 {
  1415. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1416. // return
  1417. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1418. // return
  1419. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1420. // button.BtnThaw = false
  1421. // return
  1422. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1423. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1424. // button.BtnApplyReceive = true
  1425. // } else {
  1426. // button.BtnReceive = true
  1427. // }
  1428. // return
  1429. // } else { //永续
  1430. // button.BtnDelete = true
  1431. // return
  1432. // }
  1433. // } else {
  1434. // //button.BtnReceive = true
  1435. // }
  1436. // }
  1437. // } else {
  1438. // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
  1439. // statusSlice := strings.Split(status, "/")
  1440. // ficcStatus := statusSlice[0]
  1441. // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1442. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1443. // button.BtnApplyReceive = true //申请领取按钮权限
  1444. // } else {
  1445. // button.BtnReceive = true //领取客户按钮权限
  1446. // }
  1447. // return
  1448. // }
  1449. // }
  1450. // }
  1451. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  1452. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
  1453. // return
  1454. // }
  1455. // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
  1456. // if !strings.Contains(status, "/") {
  1457. // button.BtnReceiveOther = true //领取其他部门客户按钮权限
  1458. // } else {
  1459. // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
  1460. // statusSlice := strings.Split(status, "/")
  1461. // raiStatus := statusSlice[1]
  1462. // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1463. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1464. // button.BtnApplyReceive = true //申请领取按钮权限
  1465. // } else {
  1466. // button.BtnReceive = true //领取客户按钮权限
  1467. // }
  1468. // return
  1469. // }
  1470. // }
  1471. // return
  1472. // }
  1473. // if !strings.Contains(status, "/") {
  1474. // if authority == 2 { //组长
  1475. // if itemSellerId == sysUserId {
  1476. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1477. // button.BtnUpdate = true
  1478. // button.BtnModifySeller = true
  1479. // button.BtnTryOut = true
  1480. // return
  1481. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1482. // button.BtnEdit = true
  1483. // button.BtnDelete = true
  1484. // button.BtnSuspend = true
  1485. // button.BtnDelay = true
  1486. // button.BtnTurnPositive = true
  1487. // button.BtnModifySeller = true
  1488. // button.BtnFreeze = true
  1489. // return
  1490. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1491. // button.BtnThaw = true
  1492. // return
  1493. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1494. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1495. // button.BtnApplyReceive = true
  1496. // } else {
  1497. // button.BtnReceive = true
  1498. // }
  1499. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1500. // //button.BtnDelete = true
  1501. // }
  1502. // return
  1503. // } else { //永续
  1504. // button.BtnDelete = true
  1505. // return
  1506. // }
  1507. // } else {
  1508. // if productId == 1 {
  1509. // //button.BtnReceive = true
  1510. // } else {
  1511. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1512. // button.BtnModifySeller = true
  1513. // return
  1514. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1515. // button.BtnModifySeller = true
  1516. // return
  1517. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1518. // button.BtnThaw = false
  1519. // return
  1520. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1521. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1522. // button.BtnApplyReceive = true
  1523. // } else {
  1524. // button.BtnReceive = true
  1525. // }
  1526. // return
  1527. // } else { //永续
  1528. // button.BtnDelete = true
  1529. // return
  1530. // }
  1531. // }
  1532. // }
  1533. // } else {
  1534. // if itemSellerId == sysUserId {
  1535. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1536. // button.BtnUpdate = true
  1537. // button.BtnTryOut = true
  1538. // return
  1539. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1540. // button.BtnEdit = true
  1541. // button.BtnDelete = true
  1542. // button.BtnSuspend = true
  1543. // button.BtnDelay = true
  1544. // button.BtnTurnPositive = true
  1545. // button.BtnFreeze = true
  1546. // return
  1547. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1548. // button.BtnThaw = true
  1549. // return
  1550. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1551. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1552. // button.BtnApplyReceive = true //申请领取按钮权限
  1553. // } else {
  1554. // button.BtnReceive = true //领取客户按钮权限
  1555. // }
  1556. // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
  1557. // //button.BtnDelete = true
  1558. // }
  1559. // return
  1560. // } else { //永续
  1561. // button.BtnDelete = true
  1562. // return
  1563. // }
  1564. // } else {
  1565. // if productId == 1 {
  1566. // //button.BtnReceive = true
  1567. // } else {
  1568. // if status == utils.COMPANY_STATUS_FORMAL { //正式
  1569. // return
  1570. // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
  1571. // return
  1572. // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  1573. // button.BtnThaw = false
  1574. // return
  1575. // } else if status == utils.COMPANY_STATUS_LOSE { //流失
  1576. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1577. // button.BtnApplyReceive = true //申请领取按钮权限
  1578. // } else {
  1579. // button.BtnReceive = true //领取客户按钮权限
  1580. // }
  1581. // return
  1582. // } else { //永续
  1583. // button.BtnDelete = true
  1584. // return
  1585. // }
  1586. // }
  1587. // }
  1588. // }
  1589. // } else {
  1590. // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
  1591. // statusSlice := strings.Split(status, "/")
  1592. // raiStatus := statusSlice[1]
  1593. // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1594. // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
  1595. // button.BtnApplyReceive = true //申请领取按钮权限
  1596. // } else {
  1597. // button.BtnReceive = true //领取客户按钮权限
  1598. // }
  1599. // return
  1600. // }
  1601. // }
  1602. // }
  1603. // return button
  1604. //}
  1605. // 校验当前操作员是否具有联系人权限是否有操作权限
  1606. func CheckCompanyUserButton(roleTypeCode string, itemSellerId, sysUserId, productId, shareSellerId int, status string) (ok bool) {
  1607. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1608. ok = true
  1609. return
  1610. }
  1611. if sysUserId == itemSellerId || shareSellerId == sysUserId {
  1612. ok = true
  1613. //如果客户状态是流失,那么就无法操作
  1614. if status == utils.COMPANY_STATUS_LOSE || status == utils.COMPANY_STATUS_CLOSE {
  1615. ok = false
  1616. return
  1617. }
  1618. return
  1619. } else {
  1620. if productId == 1 && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1621. //如果是ficc类型,同时当前账户是ficc管理员
  1622. ok = true
  1623. } else if productId == 2 && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1624. //如果是权益类型,同时当前账户是 权益管理员
  1625. ok = true
  1626. }
  1627. }
  1628. return
  1629. }
  1630. // 校验当前操作员是否具给联系人开通个人研选的权限
  1631. func CheckCompanyUserYanXuanButton(roleTypeCode string, adminMobile string) (ok bool, err error) {
  1632. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1633. ok = true
  1634. return
  1635. }
  1636. crmConfig, err := company.GetConfigDetailByCode("rai_wx_user_yanxuan_button")
  1637. if err != nil {
  1638. return
  1639. }
  1640. sliceMobile := strings.Split(crmConfig.ConfigValue, ",")
  1641. for _, v := range sliceMobile {
  1642. if v == adminMobile {
  1643. ok = true
  1644. return
  1645. }
  1646. }
  1647. return
  1648. }
  1649. // GenerateOpenCompanyCode 生成第三方code编号
  1650. func GenerateOpenCompanyCode(companyId int) (openCode string) {
  1651. openCode = utils.MD5(fmt.Sprint(companyId, "hzyj20210902"))
  1652. return
  1653. }
  1654. // GenerateOpenCompanyProductCode 生成客户产品第三方code编号
  1655. func GenerateOpenCompanyProductCode(companyId, productId int) (openCode string) {
  1656. openCode = utils.MD5(fmt.Sprint(companyId, "_", productId, "hzyj20210902"))
  1657. return
  1658. }
  1659. // GetApplyTurnContractType
  1660. // 获取客户申请合同类型
  1661. func GetApplyTurnContractType(companyId, productId int) (contractType string, err error) {
  1662. //合同类型
  1663. contractType = "新签合同"
  1664. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  1665. if err != nil {
  1666. if err.Error() == utils.ErrNoRow() {
  1667. err = nil
  1668. return
  1669. }
  1670. err = errors.New("获取客户信息失败,Err:" + err.Error())
  1671. return
  1672. }
  1673. // 当前客户产品状态为试用,那么是续约合同
  1674. if companyProduct.Status == "正式" {
  1675. contractType = "续约合同"
  1676. }
  1677. var condition string
  1678. var pars []interface{}
  1679. condition += " AND product_id = ?"
  1680. pars = append(pars, productId)
  1681. condition += " AND status = ?"
  1682. pars = append(pars, 1)
  1683. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  1684. if err != nil {
  1685. err = errors.New("获取合同信息失败,Err:" + err.Error())
  1686. return
  1687. }
  1688. if len(list) > 0 {
  1689. contractType = "续约合同"
  1690. }
  1691. //查询是否存在正式转试用的记录,如果存在,那么合同类型是续约合同
  1692. total, err := company.GetCompanyProductOperationRecordCount(companyProduct.CompanyId, companyProduct.ProductId)
  1693. if err != nil {
  1694. err = errors.New("查询用户变更记录异常,Err:" + err.Error())
  1695. return
  1696. }
  1697. if total > 0 {
  1698. contractType = "续约合同"
  1699. }
  1700. return
  1701. }
  1702. // GetLastContractPermissionList
  1703. // 获取客户的最近合同的权限期限
  1704. func GetLastContractPermissionList(companyId, productId int) (permissionMap map[int]company.PermissionLookItem, err error) {
  1705. permissionMap = map[int]company.PermissionLookItem{}
  1706. contractList, err := company.GetCompanyWillContractList(companyId, productId)
  1707. if err != nil {
  1708. err = errors.New("获取合同信息失败,Err:" + err.Error())
  1709. return
  1710. }
  1711. for _, contractInfo := range contractList {
  1712. permissionList, permissionErr := company.GetCompanyContractPermissionListByContractIds(strconv.Itoa(contractInfo.CompanyContractId))
  1713. if permissionErr != nil {
  1714. err = errors.New("获取合同信息失败,Err:" + permissionErr.Error())
  1715. return
  1716. }
  1717. for _, v := range permissionList {
  1718. if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  1719. nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
  1720. if tmpErr != nil {
  1721. err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
  1722. return
  1723. }
  1724. perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
  1725. if err != nil {
  1726. err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
  1727. return
  1728. }
  1729. //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  1730. if nowEndDateTime.After(perEndDateTime) {
  1731. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1732. ChartPermissionId: v.ChartPermissionId,
  1733. PermissionName: v.ChartPermissionName,
  1734. StartDate: v.StartDate,
  1735. EndDate: v.EndDate,
  1736. //Status string `description:"'正式','试用','关闭'"`
  1737. //ExpireDay string `description:"到期天数"`
  1738. ClassifyName: v.ClassifyName,
  1739. }
  1740. }
  1741. } else {
  1742. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1743. ChartPermissionId: v.ChartPermissionId,
  1744. PermissionName: v.ChartPermissionName,
  1745. StartDate: v.StartDate,
  1746. EndDate: v.EndDate,
  1747. //Status string `description:"'正式','试用','关闭'"`
  1748. //ExpireDay string `description:"到期天数"`
  1749. ClassifyName: v.ClassifyName,
  1750. }
  1751. }
  1752. }
  1753. }
  1754. //获取权限
  1755. permissionList, permissionErr := company.GetCompanyReportPermissionListByProductId(companyId, productId)
  1756. if permissionErr != nil {
  1757. err = errors.New("获取权限失败,Err:" + permissionErr.Error())
  1758. return
  1759. }
  1760. for _, v := range permissionList {
  1761. if permission, ok := permissionMap[v.ChartPermissionId]; ok {
  1762. nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
  1763. if tmpErr != nil {
  1764. err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
  1765. return
  1766. }
  1767. perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
  1768. if err != nil {
  1769. err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
  1770. return
  1771. }
  1772. //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
  1773. if nowEndDateTime.After(perEndDateTime) {
  1774. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1775. ChartPermissionId: v.ChartPermissionId,
  1776. PermissionName: v.PermissionName,
  1777. StartDate: v.StartDate,
  1778. EndDate: v.EndDate,
  1779. //Status string `description:"'正式','试用','关闭'"`
  1780. //ExpireDay string `description:"到期天数"`
  1781. ClassifyName: v.ClassifyName,
  1782. }
  1783. }
  1784. } else {
  1785. permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
  1786. ChartPermissionId: v.ChartPermissionId,
  1787. PermissionName: v.PermissionName,
  1788. StartDate: v.StartDate,
  1789. EndDate: v.EndDate,
  1790. //Status string `description:"'正式','试用','关闭'"`
  1791. //ExpireDay string `description:"到期天数"`
  1792. ClassifyName: v.ClassifyName,
  1793. }
  1794. }
  1795. }
  1796. return
  1797. }
  1798. // GetFiccLastUserViewHistoryByCompanyIds 根据客户id集合map获取ficc最后一次阅读时间
  1799. func GetFiccLastUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTime map[int]time.Time, err error) {
  1800. //user_view_record mobile
  1801. companyViewTime = make(map[int]time.Time)
  1802. userViewList, err := models.GetLastUserViewHistoryByCompanyIdsMobile(companyIdStr)
  1803. if err != nil {
  1804. return
  1805. }
  1806. for _, userView := range userViewList {
  1807. companyViewTime[userView.CompanyId] = userView.ViewTime
  1808. }
  1809. //user_view_record email
  1810. userViewList, err = models.GetLastUserViewHistoryByCompanyIdsEmail(companyIdStr)
  1811. if err != nil {
  1812. return
  1813. }
  1814. checkLastTime(companyViewTime, userViewList)
  1815. //AdvisoryArticleViewRecord mobile
  1816. userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1817. if err != nil {
  1818. return
  1819. }
  1820. checkLastTime(companyViewTime, userViewList)
  1821. //AdvisoryArticleViewRecord email
  1822. userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1823. if err != nil {
  1824. return
  1825. }
  1826. checkLastTime(companyViewTime, userViewList)
  1827. //ReportViewRecord mobile
  1828. mobileOrEmailViewList, err := models.GetLastReportViewRecordByMobileList(mobileList)
  1829. if err != nil {
  1830. return
  1831. }
  1832. checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, mobileCompanyIdMap)
  1833. //ReportViewRecord email
  1834. mobileOrEmailViewList, err = models.GetLastReportViewRecordByEmailList(emailList)
  1835. if err != nil {
  1836. return
  1837. }
  1838. checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, emailCompanyIdMap)
  1839. //UserViewStatistics mobile
  1840. userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsMobile(companyIdStr)
  1841. if err != nil {
  1842. return
  1843. }
  1844. checkLastTime(companyViewTime, userViewList)
  1845. //UserViewStatistics email
  1846. userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsEmail(companyIdStr)
  1847. if err != nil {
  1848. return
  1849. }
  1850. checkLastTime(companyViewTime, userViewList)
  1851. return
  1852. }
  1853. // GetRaiLastUserViewHistoryByCompanyIds 根据客户id集合map获取权益最后一次阅读时间
  1854. func GetRaiLastUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTime map[int]time.Time, err error) {
  1855. //CygxArticleViewRecord mobile
  1856. companyViewTime = make(map[int]time.Time)
  1857. userViewList, err := models.GetLastCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1858. if err != nil {
  1859. return
  1860. }
  1861. for _, userView := range userViewList {
  1862. companyViewTime[userView.CompanyId] = userView.ViewTime
  1863. }
  1864. //CygxArticleViewRecord email
  1865. userViewList, err = models.GetLastCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1866. if err != nil {
  1867. return
  1868. }
  1869. checkLastTime(companyViewTime, userViewList)
  1870. return
  1871. }
  1872. // checkLastTime 检测最后的时间并重新赋值
  1873. func checkLastTime(companyViewTime map[int]time.Time, userViewList []*models.CompanyLastViewSlice) {
  1874. for _, userView := range userViewList {
  1875. if viewTime, ok := companyViewTime[userView.CompanyId]; ok {
  1876. if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
  1877. companyViewTime[userView.CompanyId] = userView.ViewTime
  1878. }
  1879. } else { //如果没有数据,那么直接赋值
  1880. companyViewTime[userView.CompanyId] = userView.ViewTime
  1881. }
  1882. }
  1883. return
  1884. }
  1885. // checkMobileOrEmailLastTime 根据用户信息检测最后的时间并重新赋值
  1886. func checkMobileOrEmailLastTime(companyViewTime map[int]time.Time, userViewList []*models.MobileOrEmailLastViewSlice, companyMap map[string]int) {
  1887. for _, userView := range userViewList {
  1888. // 先找到客户id
  1889. companyId, ok := companyMap[userView.Mobile]
  1890. if !ok {
  1891. continue
  1892. }
  1893. // 相同客户id的数据进行比较
  1894. if viewTime, ok := companyViewTime[companyId]; ok {
  1895. if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
  1896. companyViewTime[companyId] = userView.ViewTime
  1897. }
  1898. } else { //如果没有数据,那么直接赋值
  1899. companyViewTime[companyId] = userView.ViewTime
  1900. }
  1901. }
  1902. return
  1903. }
  1904. // GetFiccCountUserViewHistoryByCompanyIds 根据客户id集合map获取ficc的阅读次数
  1905. func GetFiccCountUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTotal map[int]int, err error) {
  1906. //user_view_record mobile
  1907. companyViewTotal = make(map[int]int)
  1908. userViewList, err := models.GetCountUserViewHistoryByCompanyIdsMobile(companyIdStr)
  1909. if err != nil {
  1910. return
  1911. }
  1912. for _, userView := range userViewList {
  1913. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  1914. }
  1915. userViewList, err = models.GetCountUserViewHistoryByCompanyIdsEmail(companyIdStr)
  1916. if err != nil {
  1917. return
  1918. }
  1919. checkCount(companyViewTotal, userViewList)
  1920. //AdvisoryArticleViewRecord mobile
  1921. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1922. if err != nil {
  1923. return
  1924. }
  1925. checkCount(companyViewTotal, userViewList)
  1926. //AdvisoryArticleViewRecord email
  1927. userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1928. if err != nil {
  1929. return
  1930. }
  1931. checkCount(companyViewTotal, userViewList)
  1932. //ReportViewRecord mobile
  1933. mobileOrEmailViewList, err := models.GetCountReportViewRecordByMobileList(mobileList)
  1934. if err != nil {
  1935. return
  1936. }
  1937. checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, mobileCompanyIdMap)
  1938. //ReportViewRecord email
  1939. mobileOrEmailViewList, err = models.GetCountReportViewRecordByEmailList(emailList)
  1940. if err != nil {
  1941. return
  1942. }
  1943. checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, emailCompanyIdMap)
  1944. //UserViewStatistics mobile
  1945. userViewList, err = models.GetUserViewStatisticsByCompanyIdsMobile(companyIdStr)
  1946. if err != nil {
  1947. return
  1948. }
  1949. checkCount(companyViewTotal, userViewList)
  1950. //UserViewStatistics email
  1951. userViewList, err = models.GetUserViewStatisticsByCompanyIdsEmail(companyIdStr)
  1952. if err != nil {
  1953. return
  1954. }
  1955. checkCount(companyViewTotal, userViewList)
  1956. return
  1957. }
  1958. // GetRaiCountUserViewHistoryByCompanyIds 根据客户id集合map获取权益的阅读次数
  1959. func GetRaiCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  1960. //CygxArticleViewRecord mobile
  1961. companyViewTotal = make(map[int]int)
  1962. userViewList, err := models.GetCountCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
  1963. if err != nil {
  1964. return
  1965. }
  1966. for _, userView := range userViewList {
  1967. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  1968. }
  1969. //CygxArticleViewRecord email
  1970. userViewList, err = models.GetCountCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
  1971. if err != nil {
  1972. return
  1973. }
  1974. checkCount(companyViewTotal, userViewList)
  1975. return
  1976. }
  1977. // GetAllCountUserViewHistoryByCompanyIds 根据客户id集合map获取所有的阅读次数
  1978. //func GetAllCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
  1979. // companyViewTotal = make(map[int]int)
  1980. // companyFiccViewTotal, err := GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
  1981. // if err != nil {
  1982. // return
  1983. // }
  1984. //
  1985. // companyRaiViewTotal, err := GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  1986. // if err != nil {
  1987. // return
  1988. // }
  1989. //
  1990. // companyIdList := strings.Split(companyIdStr, ",")
  1991. //
  1992. // for _, companyIdStr := range companyIdList {
  1993. // companyId, _ := strconv.Atoi(companyIdStr)
  1994. // ficcTotal, ok := companyFiccViewTotal[companyId]
  1995. // if !ok {
  1996. // ficcTotal = 0
  1997. // }
  1998. // raiTotal, ok := companyRaiViewTotal[companyId]
  1999. // if !ok {
  2000. // raiTotal = 0
  2001. // }
  2002. // companyViewTotal[companyId] = ficcTotal + raiTotal
  2003. // }
  2004. // return
  2005. //}
  2006. func checkCount(companyViewTotal map[int]int, userViewList []*models.CompanyViewTotalSlice) {
  2007. for _, userView := range userViewList {
  2008. if viewTotal, ok := companyViewTotal[userView.CompanyId]; ok {
  2009. companyViewTotal[userView.CompanyId] = viewTotal + userView.ViewTotal
  2010. } else { //如果没有数据,那么直接赋值
  2011. companyViewTotal[userView.CompanyId] = userView.ViewTotal
  2012. }
  2013. }
  2014. return
  2015. }
  2016. // checkMobileOrEmailCount 根据手机号或者邮箱进行数据比较
  2017. func checkMobileOrEmailCount(companyViewTotal map[int]int, mobileOrEmailViewList []*models.MobileOrEmailViewTotalSlice, companyMap map[string]int) {
  2018. for _, userView := range mobileOrEmailViewList {
  2019. // 先找到客户id
  2020. companyId, ok := companyMap[userView.Mobile]
  2021. if !ok {
  2022. continue
  2023. }
  2024. // 相同客户id的数据进行比较
  2025. if viewTotal, ok := companyViewTotal[companyId]; ok {
  2026. companyViewTotal[companyId] = viewTotal + userView.ViewTotal
  2027. } else { //如果没有数据,那么直接赋值
  2028. companyViewTotal[companyId] = userView.ViewTotal
  2029. }
  2030. }
  2031. return
  2032. }
  2033. // ModifyCompanyProductLastViewData 修改客户产品的总共阅读次数以及最近阅读时间
  2034. func ModifyCompanyProductLastViewData(companyIdList []int) (err error) {
  2035. defer func() {
  2036. if err != nil {
  2037. go alarm_msg.SendAlarmMsg("修改客户产品的总共阅读次数以及最近阅读时间失败,"+fmt.Sprint("companyIdList:", companyIdList, ";err:", err), 3)
  2038. //go utils.SendEmail("修改客户产品的总共阅读次数以及最近阅读时间失败", fmt.Sprint("companyIdList:", companyIdList, ";err:", err), utils.EmailSendToUsers)
  2039. }
  2040. }()
  2041. wxUserList, err := models.GetWxUserByCompanyIds(companyIdList)
  2042. if err != nil {
  2043. return
  2044. }
  2045. mobileList := make([]string, 0)
  2046. mobileCompanyIdMap := make(map[string]int, 0)
  2047. emailList := make([]string, 0)
  2048. emailCompanyIdMap := make(map[string]int, 0)
  2049. for _, v := range wxUserList {
  2050. if v.Mobile != `` {
  2051. mobileList = append(mobileList, v.Mobile)
  2052. mobileCompanyIdMap[v.Mobile] = v.CompanyId
  2053. }
  2054. if v.Email != `` {
  2055. emailList = append(emailList, v.Email)
  2056. emailCompanyIdMap[v.Email] = v.CompanyId
  2057. }
  2058. }
  2059. // 根据companyId列表获取客户公司的阅读情况
  2060. companyViewRecordList, err := models.GetUserViewHistoryByCompanyIdList(companyIdList)
  2061. if err != nil {
  2062. return
  2063. }
  2064. companyViewRecordMap := make(map[int]*models.CompanyViewRecord)
  2065. for _, v := range companyViewRecordList {
  2066. companyViewRecordMap[v.CompanyId] = v
  2067. }
  2068. for _, companyId := range companyIdList {
  2069. companyViewRecord, ok := companyViewRecordMap[companyId]
  2070. //ficc
  2071. var companyFiccViewTotal, companyRaiViewTotal int
  2072. var companyFiccLastView, companyRaiLastView time.Time
  2073. var companyFiccLastViewStr, companyRaiLastViewStr string
  2074. if ok && companyViewRecord != nil {
  2075. companyFiccViewTotal = companyViewRecord.FiccViewTotal
  2076. companyFiccLastView = companyViewRecord.FiccLastViewTime
  2077. companyRaiViewTotal = companyViewRecord.RaiViewTotal
  2078. companyRaiLastView = companyViewRecord.RaiLastViewTime
  2079. }
  2080. if companyFiccLastView.IsZero() {
  2081. companyFiccLastViewStr = "0000-00-00 00:00:00"
  2082. } else {
  2083. companyFiccLastViewStr = companyFiccLastView.Format(utils.FormatDateTime)
  2084. }
  2085. company.ModifyCompanyProductLastViewData(companyId, 1, companyFiccViewTotal, companyFiccLastViewStr)
  2086. //权益
  2087. if companyRaiLastView.IsZero() {
  2088. companyRaiLastViewStr = "0000-00-00 00:00:00"
  2089. } else {
  2090. companyRaiLastViewStr = companyRaiLastView.Format(utils.FormatDateTime)
  2091. }
  2092. company.ModifyCompanyProductLastViewData(companyId, 2, companyRaiViewTotal, companyRaiLastViewStr)
  2093. }
  2094. return
  2095. }
  2096. // CompanyDeleteBakInfo 删除客户时的备份信息
  2097. type CompanyDeleteBakInfo struct {
  2098. CompanyId int `description:"客户id"`
  2099. CompanyName string `description:"客户名称"`
  2100. CompanyInfo *company.Company `description:"客户主表信息"`
  2101. CompanyProductInfo []*company.CompanyProduct `description:"客户产品信息"`
  2102. CompanyPermissionInfo []*company.CompanyReportPermission `description:"客户产品权限信息"`
  2103. UserSellerRelationInfo []*models.UserSellerRelation `description:"联系人与销售关系信息"`
  2104. UserRecordInfo []*models.UserRecord `description:"联系人关系信息"`
  2105. UserInfo []*models.WxUser `description:"联系人信息"`
  2106. CompanyChartPermissionInfo []*company_user.ChartClassifyPermission `description:"客户图表权限信息"`
  2107. CompanyContract []*company.CompanyContract `description:"客户合同信息"`
  2108. CompanyContractPermission []*company.CompanyContractPermission `description:"客户合同权限信息"`
  2109. OpUserId int `description:"操作人id"`
  2110. OpUserName string `description:"操作人名称"`
  2111. }
  2112. // GetBeforeDeleteCompanyInfo 获取删除客户之前的信息
  2113. func GetBeforeDeleteCompanyInfo(companyId int) (companyProductLists []*company.CompanyProduct, companyReportPermissions []*company.CompanyReportPermission, wxUsers []*models.WxUser, userSellerRelations []*models.UserSellerRelation, companyContracts []*company.CompanyContract, companyContractPermissions []*company.CompanyContractPermission, companyInfo *company.Company, err error) {
  2114. o := orm.NewOrm()
  2115. //删除客户产品
  2116. bakSql := `SELECT * FROM company_product WHERE company_id=? `
  2117. _, err = o.Raw(bakSql, companyId).QueryRows(&companyProductLists)
  2118. if err != nil {
  2119. return
  2120. }
  2121. //删除客户权限
  2122. bakSql = `SELECT * FROM company_report_permission WHERE company_id=? `
  2123. _, err = o.Raw(bakSql, companyId).QueryRows(&companyReportPermissions)
  2124. if err != nil {
  2125. return
  2126. }
  2127. //联系人表
  2128. bakSql = `SELECT * FROM wx_user WHERE company_id=? `
  2129. _, err = o.Raw(bakSql, companyId).QueryRows(&wxUsers)
  2130. if err != nil {
  2131. return
  2132. }
  2133. //联系人 与 销售 关系表
  2134. bakSql = `SELECT * FROM user_seller_relation WHERE company_id=? `
  2135. _, err = o.Raw(bakSql, companyId).QueryRows(&userSellerRelations)
  2136. if err != nil {
  2137. return
  2138. }
  2139. // 合同
  2140. bakSql = `SELECT * FROM company_contract WHERE company_id=? `
  2141. _, err = o.Raw(bakSql, companyId).QueryRows(&companyContracts)
  2142. if err != nil {
  2143. return
  2144. }
  2145. // 合同权限
  2146. bakSql = `SELECT * FROM company_contract_permission WHERE company_id=? `
  2147. _, err = o.Raw(bakSql, companyId).QueryRows(&companyContractPermissions)
  2148. if err != nil {
  2149. return
  2150. }
  2151. // 客户
  2152. bakSql = `SELECT * FROM company WHERE company_id=? `
  2153. err = o.Raw(bakSql, companyId).QueryRow(&companyInfo)
  2154. if err != nil {
  2155. return
  2156. }
  2157. return
  2158. }
  2159. // CheckCompanyReceiveButton 查询领取客户按钮的权限
  2160. func CheckCompanyReceiveButton(adminId int) (receiveEnabled bool, err error) {
  2161. receiveEnabled = true
  2162. receivePermissionInfo, err := company.GetSellerCompanyPermissionByAdminIdType(adminId, 1)
  2163. if err != nil {
  2164. if err.Error() != utils.ErrNoRow() {
  2165. err = errors.New("获取账号权限失败,Err:" + err.Error())
  2166. return
  2167. }
  2168. } else {
  2169. if receivePermissionInfo != nil && receivePermissionInfo.Enabled == 0 {
  2170. receiveEnabled = false
  2171. }
  2172. }
  2173. return
  2174. }
  2175. // AddWxUserOpLog 记录新增用户的日志
  2176. func AddWxUserOpLog(wxUserOpLog company.WxUserOpLog) {
  2177. userSellerRelationList, err := models.GetUserSellerRelationList(wxUserOpLog.UserId)
  2178. if err != nil {
  2179. return
  2180. }
  2181. userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
  2182. wxUserOpLog.UserSellerInfo = string(userSellerRelationInfo)
  2183. company.AddWxUserOpLog(&wxUserOpLog)
  2184. }
  2185. // FilterReadAndContractAuth 根据已购品种和阅读权限获取筛选条件
  2186. func FilterReadAndContractAuth(chartPermissions, contractPermissions, condition string) (cond string, empty bool, err error) {
  2187. cond = condition
  2188. var queryChart, queryContract bool
  2189. if chartPermissions != "" && chartPermissions != "1" {
  2190. queryChart = true
  2191. }
  2192. if contractPermissions != "" && contractPermissions != "1" {
  2193. queryContract = true
  2194. }
  2195. if !queryChart && !queryContract {
  2196. return
  2197. }
  2198. readIds := make([]int, 0)
  2199. buyIds := make([]int, 0)
  2200. // 阅读权限
  2201. if queryChart {
  2202. {
  2203. // 处理权益的主观客观的筛选条件搜索
  2204. ids := make([]int, 0)
  2205. strIdArr := strings.Split(chartPermissions, ",")
  2206. for _, s := range strIdArr {
  2207. v, _ := strconv.Atoi(s)
  2208. ids = append(ids, v)
  2209. }
  2210. if len(ids) == 0 {
  2211. err = fmt.Errorf("权限ID有误")
  2212. return
  2213. }
  2214. names, e := company.GetPermissionNameByPermissionIds(ids)
  2215. if e != nil {
  2216. err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
  2217. return
  2218. }
  2219. permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
  2220. if e != nil {
  2221. err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
  2222. return
  2223. }
  2224. companyIds, e := company.GetCompanyIdsStrByReportPermissionIds(permissionIds)
  2225. if e != nil {
  2226. err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
  2227. return
  2228. }
  2229. readIds = companyIds
  2230. }
  2231. }
  2232. // 已购合同权限
  2233. if queryContract {
  2234. {
  2235. // 处理权益的主观客观的筛选条件搜索
  2236. ids := make([]int, 0)
  2237. strIdArr := strings.Split(contractPermissions, ",")
  2238. for _, s := range strIdArr {
  2239. v, _ := strconv.Atoi(s)
  2240. ids = append(ids, v)
  2241. }
  2242. if len(ids) == 0 {
  2243. err = fmt.Errorf("权限ID有误")
  2244. return
  2245. }
  2246. names, e := company.GetPermissionNameByPermissionIds(ids)
  2247. if e != nil {
  2248. err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
  2249. return
  2250. }
  2251. permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
  2252. if e != nil {
  2253. err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
  2254. return
  2255. }
  2256. companyIds, e := company.GetCompanyIdsStrByContractPermissionIds(permissionIds)
  2257. if e != nil {
  2258. err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
  2259. return
  2260. }
  2261. buyIds = companyIds
  2262. // 勾选了已购品种的, 仅筛选正式客户
  2263. cond += ` AND b.status = '正式'`
  2264. }
  2265. }
  2266. queryIds := make([]int, 0)
  2267. queryIdArr := make([]string, 0)
  2268. // 阅读权限和已购品种同时筛选取两者的companyIds交集
  2269. if queryChart && queryContract {
  2270. queryIds = utils.IntersectInt(readIds, buyIds)
  2271. } else if queryChart && !queryContract {
  2272. queryIds = readIds
  2273. } else if !queryChart && queryContract {
  2274. queryIds = buyIds
  2275. }
  2276. if len(queryIds) == 0 {
  2277. empty = true
  2278. return
  2279. }
  2280. for _, q := range queryIds {
  2281. queryIdArr = append(queryIdArr, strconv.Itoa(q))
  2282. }
  2283. cond += ` AND a.company_id IN (` + strings.Join(queryIdArr, ",") + `) `
  2284. return
  2285. }
  2286. // GetShareCompanyPermissionButton 正式客户共享-权限按钮
  2287. func GetShareCompanyPermissionButton(roleTypeCode, statuses string, productId int, item *company.CompanyItem, sysUser *system.Admin) (button *company.ButtonPermission) {
  2288. statusMap := make(map[int]string)
  2289. statusMap[productId] = statuses
  2290. if strings.Contains(statuses, "/") {
  2291. statusArr := strings.Split(statuses, "/")
  2292. statusMap[1] = statusArr[0]
  2293. statusMap[2] = statusArr[1]
  2294. }
  2295. //roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId
  2296. //所属销售map
  2297. sellerIdMap := make(map[int]string)
  2298. sellerIdMap[productId] = item.SellerIds
  2299. if strings.Contains(item.SellerIds, "/") {
  2300. sellerIdSlice := strings.Split(item.SellerIds, "/")
  2301. sellerIdMap[1] = sellerIdSlice[0]
  2302. sellerIdMap[2] = sellerIdSlice[1]
  2303. }
  2304. //分组map
  2305. groupIdMap := make(map[int]string)
  2306. groupIdMap[productId] = item.GroupIds
  2307. if strings.Contains(item.GroupIds, "/") {
  2308. groupIdSlice := strings.Split(item.GroupIds, "/")
  2309. groupIdMap[1] = groupIdSlice[0]
  2310. groupIdMap[2] = groupIdSlice[1]
  2311. }
  2312. // 查看权限均有
  2313. button = new(company.ButtonPermission)
  2314. button.BtnView = true
  2315. // 超管, FICC管理员
  2316. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2317. button.BtnModifySeller = true
  2318. button.BtnRemarkView = true
  2319. button.BtnServiceRecord = true
  2320. }
  2321. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2322. button.BtnModifySeller = false
  2323. }
  2324. status, _ := statusMap[1]
  2325. //if !ok {
  2326. // return
  2327. //}
  2328. // 客户非关闭状态可见沟通记录按钮
  2329. if status != utils.COMPANY_STATUS_CLOSE {
  2330. button.BtnServiceRecord = true
  2331. }
  2332. // 销售
  2333. sellerArr := []string{
  2334. utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER,
  2335. utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  2336. }
  2337. if !utils.InArrayByStr(sellerArr, roleTypeCode) {
  2338. return
  2339. }
  2340. if status == utils.COMPANY_STATUS_TRY_OUT {
  2341. button.BtnTurnPositive = true
  2342. button.BtnRemarkEdit = true
  2343. button.BtnRemarkView = true
  2344. button.BtnServiceRecord = true
  2345. }
  2346. if status == utils.COMPANY_STATUS_FORMAL {
  2347. button.BtnUpdate = true
  2348. button.BtnAddAgreement = true
  2349. button.BtnTryOut = true
  2350. button.BtnRemarkEdit = true
  2351. button.BtnRemarkView = true
  2352. button.BtnServiceRecord = true
  2353. }
  2354. companyButton := GetCompanyPermissionButton(roleTypeCode, statuses, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  2355. if companyButton.BtnShare == true {
  2356. button.BtnShare = true
  2357. }
  2358. return
  2359. }