Cart_CheckoutC.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. }
  163. }
  164. //首次进入展示购物车数据UI
  165. [self updateData];
  166. }
  167. } else if ([mark isEqualToString:Chectout_addShipAddress_id]) {
  168. if(sucessOrFail){
  169. NSArray *shipMethodArr = (NSArray *)data;
  170. if (shipMethodArr.count > 0) {
  171. self.shipmethodCellM.shipMethodArray = [ASCheckoutShipMethodModel mj_objectArrayWithKeyValuesArray:shipMethodArr];
  172. ASCheckoutShipMethodModel *firstModel = self.shipmethodCellM.shipMethodArray[0];
  173. firstModel.isSelect = YES;
  174. self.shipmethodCellM.shipMethodModel = firstModel;
  175. self.shipmethodCellM.shipmethodSymbol = self.totalsM.currency_symbol;
  176. //默认设置第一个运输方式
  177. [self requestSetShipMethodByAddress];
  178. }
  179. [self reqNet_Cart_cartsMineTotals];
  180. }
  181. } else if ([mark isEqualToString:Chectout_getShipMethod]) {
  182. if(sucessOrFail){
  183. NSArray *shipMethodArr = (NSArray *)data;
  184. if (shipMethodArr.count > 0) {
  185. self.shipmethodCellM.shipMethodArray = [ASCheckoutShipMethodModel mj_objectArrayWithKeyValuesArray:shipMethodArr];
  186. ASCheckoutShipMethodModel *firstModel = self.shipmethodCellM.shipMethodArray[0];
  187. firstModel.isSelect = YES;
  188. self.shipmethodCellM.shipMethodModel = firstModel;
  189. if (self.addressCellM.addressModel) {
  190. //默认设置第一个运输方式
  191. [self requestSetShipMethodByAddress];
  192. }
  193. }
  194. }
  195. [self updateData];
  196. } else if ([mark isEqualToString:Cart_cartsMineItems_Post]
  197. || [mark isEqualToString:DEL_cartsMineItems]
  198. || [mark isEqualToString:PUT_cartsMineCoupons]
  199. || [mark isEqualToString:Chectout_PUT_usePoints]
  200. || [mark isEqualToString:Chectout_DEL_cancelusePoints]
  201. || [mark isEqualToString:Chectout_setShipMethod]
  202. || [mark isEqualToString:Chectout_giftAddCart]
  203. || [mark isEqualToString:Chectout_lost_extrafee]){
  204. if(sucessOrFail){
  205. if ([mark isEqualToString:Chectout_giftAddCart]) {
  206. self.index --;
  207. if (self.index == 0) {
  208. [self reqNet_Cart_cartsMineTotals];
  209. }
  210. } else {
  211. [self reqNet_Cart_cartsMineTotals];
  212. }
  213. }else{
  214. [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
  215. }
  216. } else if ([mark isEqualToString:Goods_productGetProductsById]) {
  217. //请求赠品详情
  218. GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
  219. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{@"product_id":model.Id, @"isPromoItems":@"yes"}];
  220. if (model.options.count > 0) {
  221. NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
  222. for (OptionsModel *optionM in model.options) {
  223. OptionsValuesM *valuesM = optionM.values[0];
  224. NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
  225. optionDic[tempStr] =valuesM.option_type_id;
  226. }
  227. [param addEntriesFromDictionary:optionDic];
  228. }
  229. [self.addGiftParamArr addObject:param];
  230. if (self.giftShowCount < 2 && self.addGiftParamArr.count == 1 && self.addGiftView.hidden) {
  231. self.addGiftView.hidden = NO;
  232. [self.addGiftView setGiftData:model.add_gooodsImgUrl];
  233. }
  234. }
  235. }
  236. - (void)updateData{
  237. [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)]];
  238. [self.TableV.infodata removeAllObjects];
  239. self.TableV.infodata = [NSMutableArray arrayWithArray:self.totalsM.items];
  240. //邮寄地址--邮寄方式
  241. [self.TableV.infodata addObject:self.addressCellM];
  242. //运输方式
  243. self.shipmethodCellM.shipmethodSymbol = self.totalsM.currency_symbol;
  244. [self.TableV.infodata addObject:self.shipmethodCellM];
  245. //优惠券
  246. self.couponCellM.couponAry =[NSMutableArray arrayWithArray: [ASNetTools shared].xxx_couponAry];
  247. self.couponCellM.coupon_code = self.totalsM.coupon_code;
  248. self.couponCellM.discount_amount = self.totalsM.discount_amount;
  249. self.couponCellM.currency_symbol = self.totalsM.currency_symbol;
  250. [self.TableV.infodata addObject:self.couponCellM];
  251. //积分
  252. NSDictionary *pointScaleDic = [Current_normalTool dicFromjsonStr:[self.totalsM.extension_attributes objectForKey:@"mw_earn_points_data"]];
  253. if (pointScaleDic.count > 0) {
  254. self.pointCellM.pointScale = [[pointScaleDic allValues] objectAtIndex:0];
  255. self.pointCellM.priceScale = [[pointScaleDic allKeys] objectAtIndex:0];
  256. }
  257. self.pointCellM.usePoint = [NSString stringWithFormat:@"%@", [self.totalsM.extension_attributes objectForKey:@"mw_rwrdpoints_amnt"]];
  258. self.pointCellM.usePrice = [NSString stringWithFormat:@"%@", [self.totalsM.extension_attributes objectForKey:@"mw_rwrdpoints_cur_amnt"]];
  259. self.pointCellM.pointBalance = [ASUserInfoManager shared].userPoints;
  260. self.pointCellM.priceSymbol = self.totalsM.currency_symbol;
  261. [self.TableV.infodata addObject:self.pointCellM];
  262. //备注
  263. [self.TableV.infodata addObject:self.commentCellM];
  264. //价格明细
  265. self.totalCellM.total_segments = [NSMutableArray arrayWithArray:self.totalsM.total_segments];
  266. self.totalCellM.currency_symbol = self.totalsM.currency_symbol;
  267. [self.TableV.infodata addObject:self.totalCellM];
  268. //支付方式数据
  269. [self.TableV.infodata addObjectsFromArray:self.paymentArray];
  270. //手动添加赠品功能
  271. [self.addGiftParamArr removeAllObjects];
  272. NSDictionary *freeData = (NSDictionary *)[[self.totalsM.extension_attributes objectForKey:@"free_data"] mj_JSONObject];
  273. BOOL is_show = [[freeData objectForKey:@"is_show"] boolValue];
  274. if (is_show && self.giftShowCount< 2) {//显示存在赠品
  275. NSArray *productArr = [freeData objectForKey:@"products"];
  276. if (productArr.count > 0) { //存在赠品
  277. for (int i = 0; i < productArr.count; i++) {
  278. NSDictionary *productDic = productArr[i];
  279. NSString *entity_id = productDic[@"entity_id"];
  280. [self reqNet_GoodsDetails_productGetProduct:entity_id];
  281. }
  282. }
  283. }
  284. [self.TableV reloadData];
  285. }
  286. - (void)tapcellTriggereventIndex:(NSIndexPath *)index model:(id)model{
  287. if([model isKindOfClass:[CartTotalsItemsM class]]){
  288. CartTotalsItemsM *itemM = (CartTotalsItemsM *)model;
  289. if(itemM.isGift){
  290. return;
  291. }
  292. UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":itemM.product_id}];
  293. [self.navigationController pushViewController:viewController animated:YES];
  294. } else if ([model isKindOfClass:[ASCheckoutPaymentModel class]]) {
  295. ASCheckoutPaymentModel *paymentModel = (ASCheckoutPaymentModel *)model;
  296. if (paymentModel.isSelect) {
  297. return;
  298. }
  299. for (int i = 0; i < self.TableV.infodata.count; i++) {
  300. id itemModel = self.TableV.infodata[i];
  301. if ([itemModel isKindOfClass:[ASCheckoutPaymentModel class]]) {
  302. ASCheckoutPaymentModel *tempModel = (ASCheckoutPaymentModel *)itemModel;
  303. if (index.row == i) {
  304. tempModel.isSelect = YES;
  305. self.paymentModel = tempModel;
  306. [self.bottomView setBottomPayStyle:tempModel.code];
  307. } else {
  308. tempModel.isSelect = NO;
  309. }
  310. }
  311. }
  312. [self.TableV reloadData];
  313. } else if ([model isKindOfClass:[ASCheckoutAddressData class]]) {
  314. ASAddressListViewController *vc = [ASAddressListViewController new];
  315. vc.isSelMode = true;
  316. vc.sel_Id = self.addressCellM.addressModel.Id;
  317. @weakify(self)
  318. vc.selectAddressBlock = ^(ASAddressModel * _Nonnull addressM) {
  319. @strongify(self)
  320. self.addressCellM.addressModel = addressM;
  321. [self requestAddShipAddress];
  322. };
  323. [self.navigationController pushViewController:vc animated:true];
  324. }
  325. }
  326. #pragma mark - **************** reqNet ****************
  327. //获取支付方式
  328. - (void)requestPaymentMode {
  329. [self.VM ry_requestGetApi:Chectout_getPaymentMode param:@{}];
  330. }
  331. //添加邮寄地址
  332. - (void)requestAddShipAddress {
  333. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  334. [self.VM ry_requestPostApi:Chectout_addShipAddress_id param:@{@"addressId":self.addressCellM.addressModel.Id}];
  335. }
  336. //根据邮寄地址获取邮寄方式
  337. - (void)requestGetShipMethodByAddress {
  338. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  339. [self.VM ry_requestGetApi:Chectout_getShipMethod param:@{}];
  340. }
  341. //设置邮寄方式
  342. - (void)requestSetShipMethodByAddress {
  343. NSDictionary *addressDic1 = (NSDictionary *)[self.addressCellM.addressModel.region mj_JSONObject];
  344. NSDictionary *addressDic = (NSDictionary *)[self.addressCellM.addressModel mj_JSONObject];
  345. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:addressDic];
  346. [param addEntriesFromDictionary:addressDic1];
  347. [param removeObjectForKey:@"extension_attributes"];//移除格式不正确的无用参数
  348. if (NIL(self.shipmethodCellM.shipMethodModel.method_code) || NIL(self.shipmethodCellM.shipMethodModel.carrier_code)) {
  349. [self.view makeToast:@"运输方式获取失败"];
  350. return;
  351. }
  352. NSDictionary *params = @{@"shipping_address":param,
  353. @"shipping_method_code":self.shipmethodCellM.shipMethodModel.method_code,
  354. @"shipping_carrier_code":self.shipmethodCellM.shipMethodModel.carrier_code};
  355. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  356. [self.VM ry_requestPostApi:Chectout_setShipMethod param:@{@"addressInformation":params}];
  357. }
  358. //获取购物车信息(地址信息)
  359. - (void)requestCartInfo {
  360. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  361. [self.VM ry_requestGetApi:Cart_cartInfo param:@{}];
  362. }
  363. ///获取购物车信息(报价整合)
  364. -(void)reqNet_Cart_cartsMineTotals{
  365. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  366. [self.VM ry_requestGetApi:Cart_cartsMineTotals param:@{}];
  367. }
  368. ///修改商品的数量
  369. -(void)reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)itemM{
  370. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  371. NSDictionary *cartItemDic = @{
  372. @"item_id":itemM.item_id,
  373. @"qty":itemM.qty,
  374. @"quote_id":self.totalsM.cart_id
  375. };
  376. NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{
  377. @"cartItem":cartItemDic
  378. }];
  379. [self.VM ry_requestPostApi:Cart_cartsMineItems_Post param:param];
  380. }
  381. ///删除商品
  382. -(void)reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)itemM{
  383. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  384. [self.VM ry_requestDeleteApi:DEL_cartsMineItems paramStr:itemM.item_id];
  385. }
  386. -(void)reqNet_PUT_cartsMineCoupons:(NSString *)coupon{
  387. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  388. self.giftShowCount = 0;
  389. [self.VM ry_requestPutApi:PUT_cartsMineCoupons param:coupon];
  390. }
  391. -(void)reqNet_DEL_cartsMineCoupons{
  392. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  393. [self.VM ry_requestDeleteApi:DEL_cartsMineCoupons paramStr:@""];
  394. }
  395. //使用指定积分
  396. - (void)requestUseLimitPoint:(NSString *)point {
  397. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  398. [self.VM ry_requestPutApi:Chectout_PUT_usePoints param:point];
  399. }
  400. //取消使用积分
  401. - (void)requestCancelUsePoint {
  402. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  403. [self.VM ry_requestDeleteApi:Chectout_DEL_cancelusePoints paramStr:@""];
  404. }
  405. //下单
  406. -(void)requestSureOrder{
  407. NSString *paymentCode = self.paymentModel.code;
  408. [ASCheckoutPayManager sharedInstance].cartId = self.totalsM.cart_id;
  409. [ASCheckoutPayManager sharedInstance].addressModel = self.addressCellM.addressModel;
  410. [[ASCheckoutPayManager sharedInstance] checkoutPayWithMethodType:paymentCode param:@{@"price":self.totalsM.grand_total, @"currency":self.totalsM.currency_symbol}];
  411. K_WEAK_SELF;
  412. [ASCheckoutPayManager sharedInstance].payFinishBlock = ^(NSString * _Nonnull payMethod, NSUInteger isSucess, id _Nonnull payData) {
  413. K_STRONG_SELF;
  414. NSLog(@"payData======%@", payData);
  415. if (isSucess == 1) {
  416. [self.view makeToast:@"支付成功,正在为你下单" duration:0.5 position:CSToastPositionCenter];
  417. K_WEAK_SELF;
  418. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  419. K_STRONG_SELF;
  420. NSDictionary *payDic = (NSDictionary *)payData;
  421. NSString *orderidStr = [NSString stringWithFormat:@"%@", [payDic objectForKey:@"orderid"]];
  422. [self paymentResultStatus:orderidStr];
  423. // if ([payMethod isEqualToString:@"paypal_express"]) {
  424. // [self paymentResultStatus:orderidStr];
  425. // } else if ([payMethod isEqualToString:@"stripe_payments"]) {//visa
  426. // [self paymentResultStatus:orderidStr];
  427. // } else if ([payMethod isEqualToString:@"afterpay_payment"]) {//afterpay
  428. //
  429. // } else if ([payMethod isEqualToString:@"klarna_kco"]) {//klarna
  430. //// NSString *orderidStr = [NSString stringWithFormat:@"%@", [payDic objectForKey:@"orderid"]];
  431. //
  432. // }
  433. });
  434. } else {
  435. [self.view makeToast:@"支付失败/取消支付" duration:0.5 position:CSToastPositionCenter];
  436. K_WEAK_SELF;
  437. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  438. K_STRONG_SELF;
  439. //支付失败
  440. [self paymentResultStatus:@""];
  441. });
  442. }
  443. };
  444. }
  445. - (void)paymentResultStatus:(NSString *)orderid {
  446. if (AS_String_valid(orderid)) {
  447. ASOrderDetailsViewController *paySuccessVC = [[ASOrderDetailsViewController alloc] init];
  448. paySuccessVC.orderId = orderid;
  449. paySuccessVC.isPay = YES;
  450. [self.navigationController pushViewController:paySuccessVC animated:YES];
  451. } else {
  452. ASPayFailedViewController *payFailedVC = [[ASPayFailedViewController alloc] init];
  453. [self.navigationController pushViewController:payFailedVC animated:YES];
  454. }
  455. }
  456. //请求赠品商品详情
  457. -(void)reqNet_GoodsDetails_productGetProduct:(NSString *)enterId{
  458. NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
  459. // [params setObject:@"55475" forKey:@"productId"];
  460. [params setObject:enterId forKey:@"productId"];
  461. [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
  462. // [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  463. [self.goodsDetailsVM ry_requestGetApi:Goods_productGetProductsById param:params];
  464. }
  465. //赠品加车
  466. - (void)requestGiftAddCart {
  467. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  468. for (int i = 0; i < self.addGiftParamArr.count; i++) {
  469. NSDictionary *param = self.addGiftParamArr[i];
  470. self.index ++;
  471. self.giftShowCount = 2;
  472. [self.VM ry_formDataRequestPostApi:Chectout_giftAddCart param:param];
  473. }
  474. }
  475. //丢件险
  476. - (void)requestLostExtraFee:(BOOL)isOpen {
  477. NSDictionary *address = @{@"countryId":AS_String_valid(self.addressCellM.addressModel.country_id) ? AS_String_NotNull(self.addressCellM.addressModel.country_id) : @"US",
  478. @"region":AS_String_NotNull(self.addressCellM.addressModel.region.region),
  479. @"postcode":AS_String_NotNull(self.addressCellM.addressModel.postcode),
  480. @"city":AS_String_NotNull(self.addressCellM.addressModel.city)};
  481. NSDictionary *addressInformation = @{@"address":address,
  482. @"shipping_method_code":AS_String_valid(self.shipmethodCellM.shipMethodModel.method_code) ? self.shipmethodCellM.shipMethodModel.method_code : @"bestway",
  483. @"shipping_carrier_code":AS_String_valid(self.shipmethodCellM.shipMethodModel.carrier_code) ? self.shipmethodCellM.shipMethodModel.carrier_code : @"tablerate"};
  484. NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:1];
  485. if(isOpen ==0){ //取消丢件险
  486. NSDictionary *information = @{@"fee_id":@(1), @"options_ids":@[]};
  487. [params addEntriesFromDictionary:@{@"information":information}];
  488. }else if(isOpen == 1){//打开丢件险
  489. NSDictionary *information = @{@"fee_id":@(1), @"options_ids":@[@"1"]};
  490. [params addEntriesFromDictionary:@{@"information":information}];
  491. }
  492. [params setValue:addressInformation forKey:@"addressInformation"];
  493. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  494. [self.VM ry_requestPostApi:Chectout_lost_extrafee param:params];
  495. }
  496. #pragma mark --- 懒加载 ---
  497. - (void)ucm_bindvmmodel{
  498. self.VM = [[CartVM alloc] initDelegate:self];
  499. self.goodsDetailsVM = [[ASGoodsDetailsVM alloc] initDelegate:self];
  500. }
  501. - (MyCartCouponCellData *)couponCellM {
  502. if (!_couponCellM) {
  503. _couponCellM = [[MyCartCouponCellData alloc] init];
  504. }
  505. return _couponCellM;
  506. }
  507. - (MyCartGrandTotalCellData *)totalCellM {
  508. if (!_totalCellM) {
  509. _totalCellM = [[MyCartGrandTotalCellData alloc] init];
  510. }
  511. return _totalCellM;
  512. }
  513. - (ASCheckoutPointData *)pointCellM {
  514. if (!_pointCellM) {
  515. _pointCellM = [[ASCheckoutPointData alloc] init];
  516. }
  517. return _pointCellM;
  518. }
  519. - (ASCheckoutAddressData *)addressCellM {
  520. if (!_addressCellM) {
  521. _addressCellM = [[ASCheckoutAddressData alloc] init];
  522. }
  523. return _addressCellM;
  524. }
  525. - (ASCheckoutShipMethodData *)shipmethodCellM {
  526. if (!_shipmethodCellM) {
  527. _shipmethodCellM = [[ASCheckoutShipMethodData alloc] init];
  528. }
  529. return _shipmethodCellM;
  530. }
  531. - (ASCheckoutCommentData *)commentCellM {
  532. if (!_commentCellM) {
  533. _commentCellM = [[ASCheckoutCommentData alloc] init];
  534. _commentCellM.commentStr = @"";
  535. }
  536. return _commentCellM;
  537. }
  538. - (ASCheckoutTopView *)topView {
  539. if (!_topView) {
  540. // IPhoneXHeigh
  541. _topView = [[ASCheckoutTopView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 60)];
  542. @weakify(self)
  543. _topView.isFlodBlock = ^(BOOL isFlod) {
  544. @strongify(self)
  545. self.TableV.isFlod = isFlod;
  546. [self.TableV reloadData];
  547. };
  548. }
  549. return _topView;
  550. }
  551. - (ASCheckoutBottomView *)bottomView {
  552. if (!_bottomView) {
  553. _bottomView = [[ASCheckoutBottomView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 100)];
  554. @weakify(self)
  555. _bottomView.bottomBlock = ^{
  556. @strongify(self)
  557. // [self.view makeToast:@"调起支付"];
  558. [self requestSureOrder];
  559. };
  560. }
  561. return _bottomView;
  562. }
  563. - (ASAddGiftGoodsView *)addGiftView {
  564. if (!_addGiftView) {
  565. _addGiftView = [[ASAddGiftGoodsView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  566. @weakify(self)
  567. _addGiftView.addBlock = ^(int type) {
  568. @strongify(self)
  569. self.addGiftView.hidden = YES;
  570. if (type == 1) {
  571. [self requestGiftAddCart];
  572. } else {
  573. self.giftShowCount ++;
  574. }
  575. };
  576. _addGiftView.hidden = YES;
  577. [[UIApplication sharedApplication].keyWindow addSubview:_addGiftView];
  578. }
  579. return _addGiftView;
  580. }
  581. #pragma mark - **************** reqNet ****************
  582. @end