Cart_CheckoutC.m 24 KB

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