Cart_CheckoutC.m 29 KB

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