CommonValue.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // CommonValue.swift
  3. // SparkEducation
  4. //
  5. // Created by virgil on 16/3/14.
  6. // Copyright © 2016年 virgil. All rights reserved.
  7. //
  8. import UIKit
  9. let brandList: Array = ["海付POS机", "海科传统POS", "快益刷传统POS", "快闪刷POS", "2021海科传统POS", "海科传统POS(山东河南)","海收付(直营非押)","海收付(渠道/免押)","海收付(渠道/押金)","海收付(直营押金)","小微收银"]
  10. let brandIdList = ["2", "300595e17ed94b5f8c2b3f437ce26116", "4", "4e7c6d802cf149e9b8e1fc0efca4e965", "5", "f391406346e04510ab6b3be081b2e4aa","777","888","999","9999","1df30df31e5a43c1b468b73a6abf586a"]
  11. var houseId = -1
  12. var isPrintLog = true
  13. var isAlertError = false
  14. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  15. var qiNiuUploadImageToken = ""
  16. /// 获取公用参数
  17. open class CommonValue: CommonBaseValue {
  18. class func checkIsAS() -> Bool {
  19. //CommonValue.setDefaultUserInfoForString(value: "1", key: "apver\(CommonUntils.getSystemVersion())")
  20. if CommonValue.getDefaultUserInfoForString(key: "apver\(CommonUntils.getSystemVersion())") == "1" {
  21. return false
  22. }
  23. if CommonUntils.getSystemVersion() != appDelegate.dicDefault.getString(key: "appstoreVersion") && appDelegate.dicDefault.getString(key: "appstoreVersion") != "" {
  24. CommonValue.setDefaultUserInfoForString(value: "1", key: "apver\(CommonUntils.getSystemVersion())")
  25. return false
  26. } else {
  27. return true
  28. }
  29. }
  30. class func formatPhone(phone: String) -> String {
  31. // if(phone.length() == 11)
  32. // {
  33. //
  34. // return phone.substringTo(index: 3) + "****" + phone.substringFrom(index:7);
  35. // }
  36. // else
  37. if phone.length() > 7 {
  38. let str = phone.substringFrom(start: 4, end: 8)
  39. return phone.replacingOccurrences(of: str, with: "****")
  40. } else {
  41. return phone
  42. }
  43. }
  44. class func formatCardNum(str: String) -> String {
  45. if str.length() > 7 {
  46. let str1 = str.substringFrom(start: 4, end: str.length() - 4)
  47. return str.replacingOccurrences(of: str1, with: "*********")
  48. } else {
  49. return str
  50. }
  51. }
  52. // MARK: ===== 公用部分=====
  53. ///获取初始化值
  54. class func getDefaultValueForKey(key: String) -> String {
  55. if appDelegate.dicDefault[key] as? String != nil {
  56. return appDelegate.dicDefault[key] as! String
  57. } else {
  58. return ""
  59. }
  60. }
  61. class func getHttp() -> AFHTTPSessionManager {
  62. let http = AFHTTPSessionManager()
  63. http.requestSerializer.setValue(CommonValue.getUserId(), forHTTPHeaderField: "userId")
  64. http.requestSerializer.setValue("1", forHTTPHeaderField: "phoneType")
  65. http.requestSerializer.setValue(CommonUntils.getSystemVersion(), forHTTPHeaderField: "apkVersion")
  66. return http
  67. }
  68. // MARK: ===== 用户登录信息部分 =====
  69. class func getUserId() -> String {
  70. //return "c3663a50d44b4cc28f3d721c80409d8a"; // 18005362777
  71. if self.getLoginUserInfo() == nil {
  72. return ""
  73. } else {
  74. if getLoginUserInfo()!.allKeys.count < 1 {
  75. CommonValue.clearLoginUser()
  76. return ""
  77. } else {
  78. print(getLoginUserInfo()!["id"] as! String)
  79. return getLoginUserInfo()!["id"] as! String
  80. }
  81. }
  82. }
  83. ///是否实名认证 :0:否 1:是 2:通过 3:审核驳回
  84. class func getUserIsAuthentication() -> Int {
  85. if self.getLoginUserInfo() == nil {
  86. return -1
  87. } else {
  88. //return 1;
  89. return getLoginUserInfo()!["isAuthentication"] as! Int
  90. }
  91. }
  92. ///会员等级 0黄金 1白金 2钻石
  93. class func getUserLevel() -> Int {
  94. if self.getLoginUserInfo() == nil {
  95. return 0
  96. } else {
  97. //return 1;
  98. if getLoginUserInfo()!["userLevel"] as? Int != nil {
  99. return getLoginUserInfo()!["userLevel"] as! Int
  100. } else {
  101. return 0
  102. }
  103. }
  104. }
  105. ///代理 数量
  106. class func getUserAgentNum() -> Int {
  107. if self.getLoginUserInfo() == nil {
  108. return 0
  109. } else {
  110. //return 1;
  111. return getLoginUserInfo()!["agentNum"] as! Int
  112. }
  113. }
  114. ///商户数量
  115. class func getUserMerchantNum() -> Int {
  116. if self.getLoginUserInfo() == nil {
  117. return 0
  118. } else {
  119. //return 1;
  120. return getLoginUserInfo()!["merchantNum"] as! Int
  121. }
  122. }
  123. ///累计收益
  124. class func getUserProfitTotal() -> Double {
  125. if self.getLoginUserInfo() == nil {
  126. return 0.00
  127. } else {
  128. //return 1;
  129. return getLoginUserInfo()!["profitTotal"] as! Double
  130. }
  131. }
  132. ///tu
  133. class func getULevelPic() -> String {
  134. if self.getLoginUserInfo() == nil {
  135. return ""
  136. } else {
  137. //return 1;
  138. return getLoginUserInfo()!["userLevelPic"] as? String ?? ""
  139. }
  140. }
  141. class func getUserLevelName() -> String {
  142. if self.getLoginUserInfo() == nil {
  143. return ""
  144. } else {
  145. //return 1;
  146. return getLoginUserInfo()!["userLevelName"] as? String ?? ""
  147. }
  148. }
  149. ///收益余额
  150. class func getUserProfitBalance() -> Double {
  151. if self.getLoginUserInfo() == nil || self.getLoginUserInfo()!["profitBalance"] as? Double == nil {
  152. return 0.00
  153. } else {
  154. return getLoginUserInfo()!["profitBalance"] as! Double
  155. }
  156. }
  157. ///pos机收益
  158. class func getUserProfitPos() -> Double {
  159. if self.getLoginUserInfo() == nil {
  160. return 0.00
  161. } else {
  162. //return 1;
  163. return getLoginUserInfo()!["profitPos"] as! Double
  164. }
  165. }
  166. ///办卡收益
  167. class func getUserProfitCard() -> Double {
  168. if self.getLoginUserInfo() == nil {
  169. return 0.00
  170. } else {
  171. //return 1;
  172. return getLoginUserInfo()!["profitCard"] as! Double
  173. }
  174. }
  175. ///积分收益
  176. class func getUserProfitIntegral() -> Double {
  177. if self.getLoginUserInfo() == nil {
  178. return 0.00
  179. } else {
  180. //return 1;
  181. return getLoginUserInfo()!["profitIntegral"] as! Double
  182. }
  183. }
  184. ///激活奖励
  185. class func getUserProfitActivation() -> Double {
  186. if self.getLoginUserInfo() == nil {
  187. return 0.00
  188. } else {
  189. //return 1;
  190. return getLoginUserInfo()!["profitActivation"] as! Double
  191. }
  192. }
  193. class func getUserAge() -> Int {
  194. if self.getLoginUserInfo() == nil {
  195. return -1
  196. } else {
  197. //return 1;
  198. return getLoginUserInfo()!["Age"] as! Int
  199. }
  200. }
  201. class func getUserRealName() -> String {
  202. if CommonValue.getUserId() == "" {
  203. return "未登录"
  204. }
  205. if self.getLoginUserInfo() == nil {
  206. return "未实名"
  207. } else {
  208. //return 1;
  209. if (getLoginUserInfo()!["realName"] as? String) == nil {
  210. return "未实名"
  211. } else {
  212. if (getLoginUserInfo()!["realName"] as! String) == "" {
  213. return "未实名"
  214. } else {
  215. return (getLoginUserInfo()!["realName"] as! String)
  216. }
  217. }
  218. }
  219. }
  220. class func getUserNickName() -> String {
  221. if self.getLoginUserInfo() == nil {
  222. return "未登录"
  223. } else {
  224. //return 1;
  225. return (getLoginUserInfo()!["nickName"] as! String)
  226. }
  227. }
  228. class func getUserPhone() -> String {
  229. if self.getLoginUserInfo() == nil {
  230. return ""
  231. } else {
  232. //return 1;
  233. return (getLoginUserInfo()!["phone"] as! String)
  234. }
  235. }
  236. class func getUserCardNo() -> String {
  237. if self.getLoginUserInfo() == nil {
  238. return ""
  239. } else {
  240. //return 1;
  241. return (getLoginUserInfo()!["cardNo"] as! String)
  242. }
  243. }
  244. class func getUserRecCode() -> String {
  245. if self.getLoginUserInfo() == nil {
  246. return ""
  247. } else {
  248. //return 1;
  249. return (getLoginUserInfo()!["recCode"] as! String)
  250. }
  251. }
  252. class func getUserLogo() -> String {
  253. if self.getLoginUserInfo() == nil {
  254. return ""
  255. } else {
  256. //return 1;
  257. return (getLoginUserInfo()!["headPortrait"] as! String) //getLoginUserInfo()!["LastName"] as! String + " " +
  258. }
  259. }
  260. ///更新登录用户的信息
  261. class func setUserLoginUser(key: String, value: Any) {
  262. let dicUser = NSMutableDictionary(dictionary: getLoginUserInfo()!)
  263. dicUser.setValue(value, forKey: key)
  264. setLoginUserInfo(loginUser: dicUser)
  265. }
  266. class func getDBPath() -> String {
  267. let userDefault = UserDefaults.standard
  268. let dbpath = userDefault.object(forKey: "local_db_path") as? String
  269. if dbpath != nil {
  270. return dbpath!
  271. } else {
  272. return ""
  273. }
  274. }
  275. class func setDBPath(dbPath: String) {
  276. let userDefault = UserDefaults.standard
  277. userDefault.setValue(dbPath, forKey: "local_db_path")
  278. }
  279. class func getIsValitePassword() -> Bool {
  280. if getDefaultUserInfoForString(key: "common_default_is_ss_password") == "1" && getUserId() != "" {
  281. return true
  282. } else {
  283. return false
  284. }
  285. }
  286. class func getInfoAddressId() -> String {
  287. return getDefaultUserInfoForString(key: "common_info_address_id")
  288. }
  289. class func getInfoAddressName() -> String {
  290. let name = getDefaultUserInfoForString(key: "common_info_address_name")
  291. if name == "" {
  292. return "全国"
  293. } else {
  294. return name
  295. }
  296. }
  297. class func setInfoAddress(id: String, name: String) {
  298. setDefaultUserInfoForString(value: id, key: "common_info_address_id")
  299. setDefaultUserInfoForString(value: name, key: "common_info_address_name")
  300. }
  301. }