Cart_CheckoutC.m 26 KB

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