Cart_CheckoutC.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. //
  2. // Cart_CheckoutC.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2024/2/16.
  6. //
  7. #import "Cart_CheckoutC.h"
  8. #import "ASAddressListViewController.h"
  9. #import "ASPayFailedViewController.h"
  10. #import "ASOrderDetailsViewController.h"
  11. #import "ASCheckoutTopView.h"
  12. #import "ASCheckoutBottomView.h"
  13. #import "CartCheckTableV.h"
  14. #import "CartVM.h"
  15. #import "ASUserModel.h"
  16. #import "ASGoodsDetailsVM.h"
  17. #import "ASAddGiftGoodsView.h"
  18. #import "ASCheckoutPayManager.h"
  19. @interface Cart_CheckoutC ()<RY_baseVMprotocol>
  20. @property (nonatomic, strong) CartVM *VM;
  21. @property (nonatomic, strong) ASCheckoutTopView *topView;
  22. @property (nonatomic, strong) ASCheckoutBottomView *bottomView;
  23. @property (nonatomic, strong) CartCheckTableV *TableV;
  24. @property (nonatomic, strong) MyCartCouponCellData *couponCellM;
  25. @property (nonatomic, strong) MyCartGrandTotalCellData *totalCellM;
  26. @property (nonatomic, strong) ASCheckoutPointData *pointCellM;
  27. @property (nonatomic, strong) ASCheckoutAddressData *addressCellM;
  28. @property (nonatomic, strong) ASCheckoutShipMethodData *shipmethodCellM;
  29. @property (nonatomic, strong) ASCheckoutCommentData *commentCellM;
  30. //存放支付方式
  31. @property (nonatomic, strong) NSArray *paymentArray;
  32. //选中支付方式
  33. @property (nonatomic, strong) ASCheckoutPaymentModel *paymentModel;
  34. //手动添加赠品至购物车
  35. @property (nonatomic, strong) ASGoodsDetailsVM *goodsDetailsVM;
  36. @property (nonatomic, strong) ASAddGiftGoodsView *addGiftView;
  37. @property (nonatomic, strong) NSMutableArray *addGiftParamArr;
  38. @property (nonatomic, assign) int index;
  39. @property (nonatomic, assign) int giftShowCount;
  40. @end
  41. @implementation Cart_CheckoutC
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. self.title = @"Checkout";
  45. //获取支付方式
  46. [self requestPaymentMode];
  47. //获取运输方式
  48. [self requestGetShipMethodByAddress];
  49. //获取购物车信息(地址信息)
  50. [self requestCartInfo];
  51. if (!self.totalsM) {
  52. [self reqNet_Cart_cartsMineTotals];
  53. }
  54. }
  55. - (void)initSubviews {
  56. [super initSubviews];
  57. self.addGiftParamArr = [[NSMutableArray alloc] initWithCapacity:1];
  58. self.index = 0;
  59. self.giftShowCount = 0;
  60. IPhoneXHeigh
  61. [self setupTableV:[CartCheckTableV class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, KScreenHeight - securitytop_Y)];
  62. self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  63. self.TableV.tableHeaderView = self.topView;
  64. self.TableV.tableFooterView = self.bottomView;
  65. @weakify(self)
  66. self.TableV.tapClose = ^(NSInteger num, id data) {
  67. //num = 0 删除商品 ,1 修改数量 countV
  68. @strongify(self)
  69. if([data isKindOfClass:[CartTotalsItemsM class]]){
  70. switch (num) {
  71. case 0:
  72. [self reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)data];
  73. break;
  74. case 1:
  75. [self reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)data];
  76. break;
  77. default:
  78. break;
  79. }
  80. }else if ([data isKindOfClass:[MyCartCouponCellData class]]){
  81. MyCartCouponCellData *couponM = (MyCartCouponCellData *)data;
  82. if(num ==0){ //使用优惠券
  83. [self reqNet_PUT_cartsMineCoupons:couponM.coupon_code];
  84. }else if(num == 1){//删除优惠券
  85. [self reqNet_DEL_cartsMineCoupons];
  86. }
  87. } else if ([data isKindOfClass:[ASCheckoutPointData class]]) {
  88. ASCheckoutPointData *pointData = (ASCheckoutPointData *)data;
  89. if(num ==0){ //使用积分
  90. [self requestUseLimitPoint:pointData.usePoint];
  91. }else if(num == 1){//取消使用积分
  92. [self requestCancelUsePoint];
  93. }
  94. } else if ([data isKindOfClass:[ASCheckoutCommentData class]]) {
  95. ASCheckoutCommentData *commentData = (ASCheckoutCommentData *)data;
  96. if(num ==0){ //使用积分
  97. self.commentCellM.commentStr = commentData.commentStr;
  98. }
  99. } else if ([data isKindOfClass:[ASCheckoutShipMethodData class]]) {
  100. //选择运输方式、、、、并设置
  101. ASCheckoutShipMethodData *shipMethodData = (ASCheckoutShipMethodData *)data;
  102. self.shipmethodCellM = shipMethodData;
  103. for (int i = 0; i < self.shipmethodCellM.shipMethodArray.count; i++) {
  104. ASCheckoutShipMethodModel *shipModel = [self.shipmethodCellM.shipMethodArray objectAtIndex:i];
  105. if (i == num) {
  106. shipModel.isSelect = YES;
  107. self.shipmethodCellM.shipMethodModel = shipModel;
  108. } else {
  109. shipModel.isSelect = NO;
  110. }
  111. }
  112. [self requestSetShipMethodByAddress];
  113. } else if ([data isKindOfClass:[MyCartGrandTotalCellData class]]){
  114. // MyCartGrandTotalCellData *totalData = (MyCartGrandTotalCellData *)data;
  115. //丢件险
  116. [self requestLostExtraFee:num];
  117. }
  118. };
  119. }
  120. - (void)ry_respnsData:(id)data
  121. parseAry:(NSMutableArray *)arry
  122. sucess:(BOOL)sucessOrFail
  123. mark:(NSString *)mark
  124. reqNetType:(ReqNetType)reqNetType{
  125. [MBProgressHUD hideHUDForView:self.view animated:YES];
  126. if([mark isEqualToString:Cart_cartsMineTotals]){
  127. if(sucessOrFail){
  128. CartTotalsM *model = [arry firstObject];
  129. self.totalsM = model;
  130. [self updateData];
  131. }
  132. } else if ([mark isEqualToString:Chectout_getPaymentMode]) {
  133. if(sucessOrFail){
  134. // 更新支付方式
  135. self.paymentArray = arry;
  136. if (self.paymentArray.count > 0) {
  137. self.paymentModel = self.paymentArray[0];
  138. [self.bottomView setBottomPayStyle:self.paymentModel.code];
  139. }
  140. //首次进入展示购物车数据UI
  141. [self updateData];
  142. }
  143. } else if ([mark isEqualToString:Cart_cartInfo]) {
  144. if(sucessOrFail){
  145. // 获取上次下单地址
  146. NSDictionary *dic = (NSDictionary *)data;
  147. NSArray *array = [[dic objectForKey:@"extension_attributes"] objectForKey:@"shipping_assignments"];
  148. if (array.count > 0) {
  149. NSDictionary *shipping_assignments = array[0];
  150. NSDictionary *shippingDic = [shipping_assignments objectForKey:@"shipping"];
  151. NSDictionary *addressDic = [shippingDic objectForKey:@"address"];
  152. // ASAddressModel *addressModel = [ASAddressModel defualtData];
  153. ASAddressReginModel *reginModel = [ASAddressReginModel mj_objectWithKeyValues:addressDic];
  154. ASAddressModel *addressModel = [ASAddressModel mj_objectWithKeyValues:addressDic];
  155. addressModel.region = reginModel;
  156. if (!NIL(addressModel.postcode)) {
  157. self.addressCellM.addressModel = addressModel;
  158. if (self.shipmethodCellM.shipMethodModel) {
  159. //默认设置第一个运输方式
  160. [self requestSetShipMethodByAddress];
  161. }
  162. [self requestAddBillingAddress];
  163. }
  164. }
  165. //首次进入展示购物车数据UI
  166. [self updateData];
  167. }
  168. } else if ([mark isEqualToString:Chectout_addShipAddress_id]) {
  169. if(sucessOrFail){
  170. NSArray *shipMethodArr = (NSArray *)data;
  171. if (shipMethodArr.count > 0) {
  172. self.shipmethodCellM.shipMethodArray = [ASCheckoutShipMethodModel mj_objectArrayWithKeyValuesArray:shipMethodArr];
  173. ASCheckoutShipMethodModel *firstModel = self.shipmethodCellM.shipMethodArray[0];
  174. firstModel.isSelect = YES;
  175. self.shipmethodCellM.shipMethodModel = firstModel;
  176. self.shipmethodCellM.shipmethodSymbol = self.totalsM.currency_symbol;
  177. //默认设置第一个运输方式
  178. [self requestSetShipMethodByAddress];
  179. }
  180. // [self reqNet_Cart_cartsMineTotals];
  181. }
  182. /// || [mark isEqualToString:Chectout_addBillingAddress]
  183. } else if ([mark isEqualToString:Chectout_getShipMethod]) {
  184. if(sucessOrFail){
  185. NSArray *shipMethodArr = (NSArray *)data;
  186. if (shipMethodArr.count > 0) {
  187. self.shipmethodCellM.shipMethodArray = [ASCheckoutShipMethodModel mj_objectArrayWithKeyValuesArray:shipMethodArr];
  188. ASCheckoutShipMethodModel *firstModel = self.shipmethodCellM.shipMethodArray[0];
  189. firstModel.isSelect = YES;
  190. self.shipmethodCellM.shipMethodModel = firstModel;
  191. if (self.addressCellM.addressModel) {
  192. //默认设置第一个运输方式
  193. [self requestSetShipMethodByAddress];
  194. }
  195. }
  196. }else{
  197. [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
  198. }
  199. [self updateData];
  200. } else if ([mark isEqualToString:Cart_cartsMineItems_Post]
  201. || [mark isEqualToString:DEL_cartsMineItems]
  202. || [mark isEqualToString:PUT_cartsMineCoupons]
  203. || [mark isEqualToString:Chectout_PUT_usePoints]
  204. || [mark isEqualToString:Chectout_DEL_cancelusePoints]
  205. || [mark isEqualToString:Chectout_setShipMethod]
  206. || [mark isEqualToString:Chectout_giftAddCart]
  207. || [mark isEqualToString:Chectout_lost_extrafee]){
  208. if(sucessOrFail){
  209. if ([mark isEqualToString:Chectout_giftAddCart]) {
  210. self.index --;
  211. if (self.index == 0) {
  212. [self reqNet_Cart_cartsMineTotals];
  213. }
  214. } else {
  215. [self reqNet_Cart_cartsMineTotals];
  216. }
  217. }else{
  218. [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
  219. }
  220. } else if ([mark isEqualToString:Goods_productGetProductsById]) {
  221. //请求赠品详情
  222. if(sucessOrFail) {
  223. GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
  224. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{@"product_id":model.Id, @"isPromoItems":@"yes"}];
  225. if (model.options.count > 0) {
  226. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  227. for (OptionsModel *optionM in model.options) {
  228. OptionsValuesM *valuesM = optionM.values[0];
  229. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  230. optionDic[tempStr] =valuesM.option_type_id;
  231. }
  232. [param addEntriesFromDictionary:optionDic];
  233. }
  234. [self.addGiftParamArr addObject:param];
  235. if (self.giftShowCount < 1 && self.addGiftParamArr.count == 1 && self.addGiftView.hidden) {
  236. dispatch_async(dispatch_get_main_queue(), ^{
  237. self.addGiftView.hidden = NO;
  238. [self.addGiftView setGiftData:model.add_gooodsImgUrl];
  239. });
  240. }
  241. }
  242. }
  243. }
  244. - (void)updateData{
  245. [self.topView setTopViewData:AS_String_NotNull(self.totalsM.items_qty) price:[NSString stringWithFormat:@"%@%@",AS_String_NotNull(self.totalsM.currency_symbol),AS_String_NotNull(self.totalsM.subtotal)]];
  246. [self.TableV.infodata removeAllObjects];
  247. self.TableV.infodata = [NSMutableArray arrayWithArray:self.totalsM.items];
  248. //邮寄地址--邮寄方式
  249. [self.TableV.infodata addObject:self.addressCellM];
  250. //运输方式
  251. self.shipmethodCellM.shipmethodSymbol = self.totalsM.currency_symbol;
  252. [self.TableV.infodata addObject:self.shipmethodCellM];
  253. //优惠券
  254. self.couponCellM.couponAry =[NSMutableArray arrayWithArray: [ASNetTools shared].xxx_couponAry];
  255. self.couponCellM.coupon_code = self.totalsM.coupon_code;
  256. self.couponCellM.discount_amount = self.totalsM.discount_amount;
  257. self.couponCellM.currency_symbol = self.totalsM.currency_symbol;
  258. [self.TableV.infodata addObject:self.couponCellM];
  259. //积分
  260. NSDictionary *pointScaleDic = [Current_normalTool dicFromjsonStr:[self.totalsM.extension_attributes objectForKey:@"mw_earn_points_data"]];
  261. if (pointScaleDic.count > 0) {
  262. self.pointCellM.pointScale = [[pointScaleDic allValues] objectAtIndex:0];
  263. self.pointCellM.priceScale = [[pointScaleDic allKeys] objectAtIndex:0];
  264. }
  265. self.pointCellM.usePoint = [NSString stringWithFormat:@"%@", [self.totalsM.extension_attributes objectForKey:@"mw_rwrdpoints_amnt"]];
  266. self.pointCellM.usePrice = [NSString stringWithFormat:@"%@", [self.totalsM.extension_attributes objectForKey:@"mw_rwrdpoints_cur_amnt"]];
  267. self.pointCellM.pointBalance = [ASUserInfoManager shared].userPoints;
  268. self.pointCellM.priceSymbol = self.totalsM.currency_symbol;
  269. [self.TableV.infodata addObject:self.pointCellM];
  270. //备注
  271. [self.TableV.infodata addObject:self.commentCellM];
  272. //价格明细
  273. self.totalCellM.total_segments = [NSMutableArray arrayWithArray:self.totalsM.total_segments];
  274. self.totalCellM.currency_symbol = self.totalsM.currency_symbol;
  275. [self.TableV.infodata addObject:self.totalCellM];
  276. //支付方式数据
  277. [self.TableV.infodata addObjectsFromArray:self.paymentArray];
  278. //手动添加赠品功能
  279. [self.addGiftParamArr removeAllObjects];
  280. NSDictionary *freeData = (NSDictionary *)[[self.totalsM.extension_attributes objectForKey:@"free_data"] mj_JSONObject];
  281. BOOL is_show = [[freeData objectForKey:@"is_show"] boolValue];
  282. if (is_show && self.giftShowCount< 1) {//显示存在赠品
  283. NSArray *productArr = [freeData objectForKey:@"products"];
  284. if (productArr.count > 0) { //存在赠品
  285. for (int i = 0; i < productArr.count; i++) {
  286. NSDictionary *productDic = productArr[i];
  287. NSString *entity_id = productDic[@"entity_id"];
  288. [self reqNet_GoodsDetails_productGetProduct:entity_id];
  289. }
  290. }
  291. }
  292. [self.TableV reloadData];
  293. }
  294. - (void)tapcellTriggereventIndex:(NSIndexPath *)index model:(id)model{
  295. if([model isKindOfClass:[CartTotalsItemsM class]]){
  296. CartTotalsItemsM *itemM = (CartTotalsItemsM *)model;
  297. if(itemM.isGift){
  298. return;
  299. }
  300. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":itemM.product_id}];
  301. [self.navigationController pushViewController:viewController animated:YES];
  302. } else if ([model isKindOfClass:[ASCheckoutPaymentModel class]]) {
  303. ASCheckoutPaymentModel *paymentModel = (ASCheckoutPaymentModel *)model;
  304. if (paymentModel.isSelect) {
  305. return;
  306. }
  307. for (int i = 0; i < self.TableV.infodata.count; i++) {
  308. id itemModel = self.TableV.infodata[i];
  309. if ([itemModel isKindOfClass:[ASCheckoutPaymentModel class]]) {
  310. ASCheckoutPaymentModel *tempModel = (ASCheckoutPaymentModel *)itemModel;
  311. if (index.row == i) {
  312. tempModel.isSelect = YES;
  313. self.paymentModel = tempModel;
  314. [self.bottomView setBottomPayStyle:tempModel.code];
  315. } else {
  316. tempModel.isSelect = NO;
  317. }
  318. }
  319. }
  320. [self.TableV reloadData];
  321. } else if ([model isKindOfClass:[ASCheckoutAddressData class]]) {
  322. ASAddressListViewController *vc = [ASAddressListViewController new];
  323. vc.isSelMode = true;
  324. vc.sel_Id = self.addressCellM.addressModel.Id;
  325. @weakify(self)
  326. vc.selectAddressBlock = ^(ASAddressModel * _Nonnull addressM) {
  327. @strongify(self)
  328. self.addressCellM.addressModel = addressM;
  329. [self requestAddShipAddress];
  330. [self requestAddBillingAddress];
  331. };
  332. [self.navigationController pushViewController:vc animated:true];
  333. }
  334. }
  335. #pragma mark - **************** reqNet ****************
  336. //获取支付方式
  337. - (void)requestPaymentMode {
  338. [self.VM ry_requestGetApi:Chectout_getPaymentMode param:@{}];
  339. }
  340. //添加邮寄地址
  341. - (void)requestAddShipAddress {
  342. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  343. [self.VM ry_requestPostApi:Chectout_addShipAddress_id param:@{@"addressId":self.addressCellM.addressModel.Id}];
  344. }
  345. //添加账单地址
  346. - (void)requestAddBillingAddress {
  347. // [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  348. NSDictionary *addressDic1 = (NSDictionary *)[self.addressCellM.addressModel.region mj_JSONObject];
  349. NSDictionary *addressDic = (NSDictionary *)[self.addressCellM.addressModel mj_JSONObject];
  350. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:addressDic];
  351. [param addEntriesFromDictionary:addressDic1];
  352. [param removeObjectForKey:@"extension_attributes"];//移除格式不正确的无用参数
  353. [self.VM ry_requestPostApi:Chectout_addBillingAddress param:@{@"address":param, @"useForShipping":@"true"}];
  354. }
  355. //根据邮寄地址获取邮寄方式
  356. - (void)requestGetShipMethodByAddress {
  357. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  358. [self.VM ry_requestGetApi:Chectout_getShipMethod param:@{}];
  359. }
  360. //设置邮寄方式
  361. - (void)requestSetShipMethodByAddress {
  362. NSDictionary *addressDic1 = (NSDictionary *)[self.addressCellM.addressModel.region mj_JSONObject];
  363. NSDictionary *addressDic = (NSDictionary *)[self.addressCellM.addressModel mj_JSONObject];
  364. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:addressDic];
  365. [param addEntriesFromDictionary:addressDic1];
  366. [param removeObjectForKey:@"extension_attributes"];//移除格式不正确的无用参数
  367. if (NIL(self.shipmethodCellM.shipMethodModel.method_code) || NIL(self.shipmethodCellM.shipMethodModel.carrier_code)) {
  368. [self.view makeToast:self.shipmethodCellM.shipMethodModel.error_message];
  369. return;
  370. }
  371. NSDictionary *params = @{@"shipping_address":param,
  372. @"shipping_method_code":self.shipmethodCellM.shipMethodModel.method_code,
  373. @"shipping_carrier_code":self.shipmethodCellM.shipMethodModel.carrier_code};
  374. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  375. [self.VM ry_requestPostApi:Chectout_setShipMethod param:@{@"addressInformation":params}];
  376. }
  377. //获取购物车信息(地址信息)
  378. - (void)requestCartInfo {
  379. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  380. [self.VM ry_requestGetApi:Cart_cartInfo param:@{}];
  381. }
  382. ///获取购物车信息(报价整合)
  383. -(void)reqNet_Cart_cartsMineTotals{
  384. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  385. [self.VM ry_requestGetApi:Cart_cartsMineTotals param:@{}];
  386. }
  387. ///修改商品的数量
  388. -(void)reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)itemM{
  389. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  390. NSDictionary *cartItemDic = @{
  391. @"item_id":itemM.item_id,
  392. @"qty":itemM.qty,
  393. @"quote_id":self.totalsM.cart_id
  394. };
  395. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{
  396. @"cartItem":cartItemDic
  397. }];
  398. [self.VM ry_requestPostApi:Cart_cartsMineItems_Post param:param];
  399. }
  400. ///删除商品
  401. -(void)reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)itemM{
  402. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  403. [self.VM ry_requestDeleteApi:DEL_cartsMineItems paramStr:itemM.item_id];
  404. }
  405. -(void)reqNet_PUT_cartsMineCoupons:(NSString *)coupon{
  406. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  407. self.giftShowCount = 0;
  408. [self.VM ry_requestPutApi:PUT_cartsMineCoupons param:coupon];
  409. }
  410. -(void)reqNet_DEL_cartsMineCoupons{
  411. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  412. [self.VM ry_requestDeleteApi:DEL_cartsMineCoupons paramStr:@""];
  413. }
  414. //使用指定积分
  415. - (void)requestUseLimitPoint:(NSString *)point {
  416. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  417. [self.VM ry_requestPutApi:Chectout_PUT_usePoints param:point];
  418. }
  419. //取消使用积分
  420. - (void)requestCancelUsePoint {
  421. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  422. [self.VM ry_requestDeleteApi:Chectout_DEL_cancelusePoints paramStr:@""];
  423. }
  424. //下单
  425. -(void)requestSureOrder{
  426. NSString *paymentCode = self.paymentModel.code;
  427. [ASCheckoutPayManager sharedInstance].cartId = self.totalsM.cart_id;
  428. [ASCheckoutPayManager sharedInstance].addressModel = self.addressCellM.addressModel;
  429. [[ASCheckoutPayManager sharedInstance] checkoutPayWithMethodType:paymentCode param:@{@"price":self.totalsM.grand_total, @"currency":self.totalsM.currency_symbol}];
  430. K_WEAK_SELF;
  431. [ASCheckoutPayManager sharedInstance].payFinishBlock = ^(NSString * _Nonnull payMethod, NSUInteger isSucess, id _Nonnull payData) {
  432. K_STRONG_SELF;
  433. NSLog(@"payData======%@", payData);
  434. NSDictionary *payDic = (NSDictionary *)payData;
  435. if (isSucess == 1) {
  436. [self.view makeToast:@"Payment success" duration:0.5 position:CSToastPositionCenter];
  437. K_WEAK_SELF;
  438. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  439. K_STRONG_SELF;
  440. NSString *orderidStr = [NSString stringWithFormat:@"%@", [payDic objectForKey:@"orderid"]];
  441. [self paymentResultStatus:orderidStr];
  442. // if ([payMethod isEqualToString:@"paypal_express"]) {
  443. // [self paymentResultStatus:orderidStr];
  444. // } else if ([payMethod isEqualToString:@"stripe_payments"]) {//visa
  445. // [self paymentResultStatus:orderidStr];
  446. // } else if ([payMethod isEqualToString:@"afterpay_payment"]) {//afterpay
  447. //
  448. // } else if ([payMethod isEqualToString:@"klarna_kco"]) {//klarna
  449. //// NSString *orderidStr = [NSString stringWithFormat:@"%@", [payDic objectForKey:@"orderid"]];
  450. //
  451. // }
  452. });
  453. } else {
  454. NSString *msg = [NSString stringWithFormat:@"%@", [payDic objectForKey:@"msg"]];
  455. if ([msg isEqualToString:@"Payment anomaly"] && [payMethod isEqualToString:@"klarna_kco"]) {
  456. [self.view makeToast:@"Payment Failed" duration:0.5 position:CSToastPositionCenter];
  457. K_WEAK_SELF;
  458. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  459. K_STRONG_SELF;
  460. [self reqNet_Cart_cartsMineTotals];
  461. });
  462. return;
  463. }
  464. [self.view makeToast:@"Payment Failed" duration:0.5 position:CSToastPositionCenter];
  465. K_WEAK_SELF;
  466. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  467. K_STRONG_SELF;
  468. //支付失败
  469. [self paymentResultStatus:@""];
  470. });
  471. }
  472. };
  473. }
  474. - (void)paymentResultStatus:(NSString *)orderid {
  475. if (AS_String_valid(orderid)) {
  476. ASOrderDetailsViewController *paySuccessVC = [[ASOrderDetailsViewController alloc] init];
  477. paySuccessVC.orderId = orderid;
  478. paySuccessVC.isPay = YES;
  479. [self.navigationController pushViewController:paySuccessVC animated:YES];
  480. } else {
  481. ASPayFailedViewController *payFailedVC = [[ASPayFailedViewController alloc] init];
  482. [self.navigationController pushViewController:payFailedVC animated:YES];
  483. }
  484. }
  485. //请求赠品商品详情
  486. -(void)reqNet_GoodsDetails_productGetProduct:(NSString *)enterId{
  487. NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
  488. [params setObject:enterId forKey:@"productId"];
  489. [self.goodsDetailsVM ry_requestGetApi:Goods_productGetProductsById param:params];
  490. }
  491. //赠品加车
  492. - (void)requestGiftAddCart {
  493. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  494. for (int i = 0; i < self.addGiftParamArr.count; i++) {
  495. NSDictionary *param = self.addGiftParamArr[i];
  496. self.index ++;
  497. self.giftShowCount = 2;
  498. [self.VM ry_formDataRequestPostApi:Chectout_giftAddCart param:param];
  499. }
  500. }
  501. //丢件险
  502. - (void)requestLostExtraFee:(BOOL)isOpen {
  503. NSDictionary *address = @{@"countryId":AS_String_valid(self.addressCellM.addressModel.country_id) ? AS_String_NotNull(self.addressCellM.addressModel.country_id) : @"US",
  504. @"region":AS_String_NotNull(self.addressCellM.addressModel.region.region),
  505. @"postcode":AS_String_NotNull(self.addressCellM.addressModel.postcode),
  506. @"city":AS_String_NotNull(self.addressCellM.addressModel.city)};
  507. NSDictionary *addressInformation = @{@"address":address,
  508. @"shipping_method_code":AS_String_valid(self.shipmethodCellM.shipMethodModel.method_code) ? self.shipmethodCellM.shipMethodModel.method_code : @"bestway",
  509. @"shipping_carrier_code":AS_String_valid(self.shipmethodCellM.shipMethodModel.carrier_code) ? self.shipmethodCellM.shipMethodModel.carrier_code : @"tablerate"};
  510. NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:1];
  511. if(isOpen ==0){ //取消丢件险
  512. NSDictionary *information = @{@"fee_id":@(1), @"options_ids":@[]};
  513. [params addEntriesFromDictionary:@{@"information":information}];
  514. }else if(isOpen == 1){//打开丢件险
  515. NSDictionary *information = @{@"fee_id":@(1), @"options_ids":@[@"1"]};
  516. [params addEntriesFromDictionary:@{@"information":information}];
  517. }
  518. [params setValue:addressInformation forKey:@"addressInformation"];
  519. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  520. [self.VM ry_requestPostApi:Chectout_lost_extrafee param:params];
  521. }
  522. #pragma mark --- 懒加载 ---
  523. - (void)ucm_bindvmmodel{
  524. self.VM = [[CartVM alloc] initDelegate:self];
  525. self.goodsDetailsVM = [[ASGoodsDetailsVM alloc] initDelegate:self];
  526. }
  527. - (MyCartCouponCellData *)couponCellM {
  528. if (!_couponCellM) {
  529. _couponCellM = [[MyCartCouponCellData alloc] init];
  530. }
  531. return _couponCellM;
  532. }
  533. - (MyCartGrandTotalCellData *)totalCellM {
  534. if (!_totalCellM) {
  535. _totalCellM = [[MyCartGrandTotalCellData alloc] init];
  536. }
  537. return _totalCellM;
  538. }
  539. - (ASCheckoutPointData *)pointCellM {
  540. if (!_pointCellM) {
  541. _pointCellM = [[ASCheckoutPointData alloc] init];
  542. }
  543. return _pointCellM;
  544. }
  545. - (ASCheckoutAddressData *)addressCellM {
  546. if (!_addressCellM) {
  547. _addressCellM = [[ASCheckoutAddressData alloc] init];
  548. }
  549. return _addressCellM;
  550. }
  551. - (ASCheckoutShipMethodData *)shipmethodCellM {
  552. if (!_shipmethodCellM) {
  553. _shipmethodCellM = [[ASCheckoutShipMethodData alloc] init];
  554. }
  555. return _shipmethodCellM;
  556. }
  557. - (ASCheckoutCommentData *)commentCellM {
  558. if (!_commentCellM) {
  559. _commentCellM = [[ASCheckoutCommentData alloc] init];
  560. _commentCellM.commentStr = @"";
  561. }
  562. return _commentCellM;
  563. }
  564. - (ASCheckoutTopView *)topView {
  565. if (!_topView) {
  566. // IPhoneXHeigh
  567. _topView = [[ASCheckoutTopView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 60)];
  568. @weakify(self)
  569. _topView.isFlodBlock = ^(BOOL isFlod) {
  570. @strongify(self)
  571. self.TableV.isFlod = isFlod;
  572. [self.TableV reloadData];
  573. };
  574. }
  575. return _topView;
  576. }
  577. - (ASCheckoutBottomView *)bottomView {
  578. if (!_bottomView) {
  579. _bottomView = [[ASCheckoutBottomView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 100)];
  580. @weakify(self)
  581. _bottomView.bottomBlock = ^{
  582. @strongify(self)
  583. // [self.view makeToast:@"调起支付"];
  584. [self requestSureOrder];
  585. };
  586. }
  587. return _bottomView;
  588. }
  589. - (ASAddGiftGoodsView *)addGiftView {
  590. if (!_addGiftView) {
  591. _addGiftView = [[ASAddGiftGoodsView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  592. @weakify(self)
  593. _addGiftView.addBlock = ^(int type) {
  594. @strongify(self)
  595. self.addGiftView.hidden = YES;
  596. if (type == 1) {
  597. [self requestGiftAddCart];
  598. } else {
  599. self.giftShowCount ++;
  600. }
  601. };
  602. _addGiftView.hidden = YES;
  603. [[UIApplication sharedApplication].windows.firstObject addSubview:_addGiftView];
  604. }
  605. return _addGiftView;
  606. }
  607. #pragma mark - **************** reqNet ****************
  608. @end