Cart_CheckoutC.m 26 KB

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