Showing
2 changed files
with
56 additions
and
6 deletions
No preview for this file type
... | @@ -128,6 +128,7 @@ public class swiftApi { | ... | @@ -128,6 +128,7 @@ public class swiftApi { |
128 | let category: String? | 128 | let category: String? |
129 | let barcode: String? | 129 | let barcode: String? |
130 | let status: Int? | 130 | let status: Int? |
131 | + var couponset_data: CouponSetItemModel? | ||
131 | 132 | ||
132 | init(dictionary: [String: Any]) { | 133 | init(dictionary: [String: Any]) { |
133 | self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? "" | 134 | self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? "" |
... | @@ -139,6 +140,7 @@ public class swiftApi { | ... | @@ -139,6 +140,7 @@ public class swiftApi { |
139 | self.category = dictionary["category"] as? String? ?? "" | 140 | self.category = dictionary["category"] as? String? ?? "" |
140 | self.barcode = dictionary["barcode"] as? String? ?? "" | 141 | self.barcode = dictionary["barcode"] as? String? ?? "" |
141 | self.status = dictionary["status"] as? Int? ?? nil | 142 | self.status = dictionary["status"] as? Int? ?? nil |
143 | + self.couponset_data = dictionary["couponset_data"] as? CouponSetItemModel? ?? nil | ||
142 | 144 | ||
143 | let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] | 145 | let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] |
144 | let expirationString = expirationObject?["value"] as? String? ?? "" | 146 | let expirationString = expirationObject?["value"] as? String? ?? "" |
... | @@ -158,6 +160,11 @@ public class swiftApi { | ... | @@ -158,6 +160,11 @@ public class swiftApi { |
158 | 160 | ||
159 | } | 161 | } |
160 | 162 | ||
163 | + | ||
164 | + public func setCouponSetData(_ couponSet: CouponSetItemModel) { | ||
165 | + self.couponset_data = couponSet | ||
166 | + } | ||
167 | + | ||
161 | // var asDictionary : [String:Any] { | 168 | // var asDictionary : [String:Any] { |
162 | // let mirror = Mirror(reflecting: self) | 169 | // let mirror = Mirror(reflecting: self) |
163 | // let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in | 170 | // let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in |
... | @@ -174,26 +181,69 @@ public class swiftApi { | ... | @@ -174,26 +181,69 @@ public class swiftApi { |
174 | init() { //initializer method | 181 | init() { //initializer method |
175 | let instanceOfMyApi = MyApi() | 182 | let instanceOfMyApi = MyApi() |
176 | let coupons = instanceOfMyApi.getCoupons() | 183 | let coupons = instanceOfMyApi.getCoupons() |
177 | - var couponsArray:Array<CouponItemModel> = [] | 184 | + let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) |
178 | 185 | ||
179 | - if let myCouponsDictionary = coupons as? [String : AnyObject] { | 186 | + var couponsArray:Array<CouponItemModel> = [] |
180 | - let couponsData = (myCouponsDictionary["result"] as! NSArray) | ||
181 | 187 | ||
182 | 188 | ||
183 | - for coupon in couponsData { | 189 | + if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { |
184 | - let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) | 190 | + let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) |
191 | + if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
192 | + let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>) | ||
193 | + if let sets = couponSetsData as? NSArray { | ||
194 | + for set in sets { | ||
195 | + let s = set as! [String : Any] | ||
196 | + if let cpns = couponsData as? NSArray { | ||
197 | + for coupon in cpns { | ||
198 | + var c = coupon as! [String : Any] | ||
199 | + // var temp = NSMutableDictionary(dictionary: s); | ||
200 | + if c["couponset_uuid"] as! String == s["uuid"] as! String { | ||
201 | + let temp = NSMutableDictionary(dictionary: c); | ||
202 | + | ||
203 | + temp.setValue(s as [AnyHashable : Any],forKey: "couponset_data") | ||
204 | + | ||
205 | + let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any]) | ||
185 | couponsArray.append(tempCoupon) | 206 | couponsArray.append(tempCoupon) |
186 | } | 207 | } |
187 | 208 | ||
188 | } | 209 | } |
210 | + } | ||
211 | + | ||
212 | + } | ||
213 | + } | ||
214 | + } | ||
215 | + } | ||
216 | + | ||
217 | +// if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
218 | +// let couponsData = (myCouponsDictionary["result"] as! NSArray) | ||
219 | +// | ||
220 | +// | ||
221 | +// for coupon in couponsData { | ||
222 | +// let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) | ||
223 | +// couponsArray.append(tempCoupon) | ||
224 | +// } | ||
225 | +// | ||
226 | +// } | ||
189 | self.data = couponsArray | 227 | self.data = couponsArray |
190 | } | 228 | } |
191 | 229 | ||
192 | var getData: Array<CouponItemModel> { | 230 | var getData: Array<CouponItemModel> { |
193 | get { // getter | 231 | get { // getter |
194 | - return data | 232 | + return data.filter({ |
233 | + return $0.status == 1 | ||
234 | + }) | ||
195 | } | 235 | } |
196 | } | 236 | } |
237 | + | ||
238 | + | ||
239 | + var getOldCoupons: Array<CouponItemModel> { | ||
240 | + get { // getter | ||
241 | + return data.filter({ | ||
242 | + return $0.status != 1 | ||
243 | + }) | ||
244 | + } | ||
245 | + } | ||
246 | + | ||
197 | } | 247 | } |
198 | 248 | ||
199 | public func getCoupons() -> Array<CouponItemModel> { | 249 | public func getCoupons() -> Array<CouponItemModel> { | ... | ... |
-
Please register or login to post a comment