Merge branch 'master' of https://git.warp.ly/open-source/warply_sdk_framework
Showing
2 changed files
with
56 additions
and
6 deletions
No preview for this file type
| ... | @@ -140,6 +140,7 @@ public class swiftApi { | ... | @@ -140,6 +140,7 @@ public class swiftApi { |
| 140 | let category: String? | 140 | let category: String? |
| 141 | let barcode: String? | 141 | let barcode: String? |
| 142 | let status: Int? | 142 | let status: Int? |
| 143 | + var couponset_data: CouponSetItemModel? | ||
| 143 | 144 | ||
| 144 | init(dictionary: [String: Any]) { | 145 | init(dictionary: [String: Any]) { |
| 145 | self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? "" | 146 | self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? "" |
| ... | @@ -151,6 +152,7 @@ public class swiftApi { | ... | @@ -151,6 +152,7 @@ public class swiftApi { |
| 151 | self.category = dictionary["category"] as? String? ?? "" | 152 | self.category = dictionary["category"] as? String? ?? "" |
| 152 | self.barcode = dictionary["barcode"] as? String? ?? "" | 153 | self.barcode = dictionary["barcode"] as? String? ?? "" |
| 153 | self.status = dictionary["status"] as? Int? ?? nil | 154 | self.status = dictionary["status"] as? Int? ?? nil |
| 155 | + self.couponset_data = dictionary["couponset_data"] as? CouponSetItemModel? ?? nil | ||
| 154 | 156 | ||
| 155 | let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] | 157 | let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] |
| 156 | let expirationString = expirationObject?["value"] as? String? ?? "" | 158 | let expirationString = expirationObject?["value"] as? String? ?? "" |
| ... | @@ -170,6 +172,11 @@ public class swiftApi { | ... | @@ -170,6 +172,11 @@ public class swiftApi { |
| 170 | 172 | ||
| 171 | } | 173 | } |
| 172 | 174 | ||
| 175 | + | ||
| 176 | + public func setCouponSetData(_ couponSet: CouponSetItemModel) { | ||
| 177 | + self.couponset_data = couponSet | ||
| 178 | + } | ||
| 179 | + | ||
| 173 | // var asDictionary : [String:Any] { | 180 | // var asDictionary : [String:Any] { |
| 174 | // let mirror = Mirror(reflecting: self) | 181 | // let mirror = Mirror(reflecting: self) |
| 175 | // let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in | 182 | // let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in |
| ... | @@ -186,26 +193,69 @@ public class swiftApi { | ... | @@ -186,26 +193,69 @@ public class swiftApi { |
| 186 | init() { //initializer method | 193 | init() { //initializer method |
| 187 | let instanceOfMyApi = MyApi() | 194 | let instanceOfMyApi = MyApi() |
| 188 | let coupons = instanceOfMyApi.getCoupons() | 195 | let coupons = instanceOfMyApi.getCoupons() |
| 189 | - var couponsArray:Array<CouponItemModel> = [] | 196 | + let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) |
| 190 | 197 | ||
| 191 | - if let myCouponsDictionary = coupons as? [String : AnyObject] { | 198 | + var couponsArray:Array<CouponItemModel> = [] |
| 192 | - let couponsData = (myCouponsDictionary["result"] as! NSArray) | ||
| 193 | 199 | ||
| 194 | 200 | ||
| 195 | - for coupon in couponsData { | 201 | + if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { |
| 196 | - let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) | 202 | + let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) |
| 203 | + if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
| 204 | + let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>) | ||
| 205 | + if let sets = couponSetsData as? NSArray { | ||
| 206 | + for set in sets { | ||
| 207 | + let s = set as! [String : Any] | ||
| 208 | + if let cpns = couponsData as? NSArray { | ||
| 209 | + for coupon in cpns { | ||
| 210 | + var c = coupon as! [String : Any] | ||
| 211 | + // var temp = NSMutableDictionary(dictionary: s); | ||
| 212 | + if c["couponset_uuid"] as! String == s["uuid"] as! String { | ||
| 213 | + let temp = NSMutableDictionary(dictionary: c); | ||
| 214 | + | ||
| 215 | + temp.setValue(s as [AnyHashable : Any],forKey: "couponset_data") | ||
| 216 | + | ||
| 217 | + let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any]) | ||
| 197 | couponsArray.append(tempCoupon) | 218 | couponsArray.append(tempCoupon) |
| 198 | } | 219 | } |
| 199 | 220 | ||
| 200 | } | 221 | } |
| 222 | + } | ||
| 223 | + | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | +// if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
| 230 | +// let couponsData = (myCouponsDictionary["result"] as! NSArray) | ||
| 231 | +// | ||
| 232 | +// | ||
| 233 | +// for coupon in couponsData { | ||
| 234 | +// let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) | ||
| 235 | +// couponsArray.append(tempCoupon) | ||
| 236 | +// } | ||
| 237 | +// | ||
| 238 | +// } | ||
| 201 | self.data = couponsArray | 239 | self.data = couponsArray |
| 202 | } | 240 | } |
| 203 | 241 | ||
| 204 | var getData: Array<CouponItemModel> { | 242 | var getData: Array<CouponItemModel> { |
| 205 | get { // getter | 243 | get { // getter |
| 206 | - return data | 244 | + return data.filter({ |
| 245 | + return $0.status == 1 | ||
| 246 | + }) | ||
| 207 | } | 247 | } |
| 208 | } | 248 | } |
| 249 | + | ||
| 250 | + | ||
| 251 | + var getOldCoupons: Array<CouponItemModel> { | ||
| 252 | + get { // getter | ||
| 253 | + return data.filter({ | ||
| 254 | + return $0.status != 1 | ||
| 255 | + }) | ||
| 256 | + } | ||
| 257 | + } | ||
| 258 | + | ||
| 209 | } | 259 | } |
| 210 | 260 | ||
| 211 | public func getCoupons() -> Array<CouponItemModel> { | 261 | public func getCoupons() -> Array<CouponItemModel> { | ... | ... |
-
Please register or login to post a comment