RAOrderEditViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. //
  2. // RAOrderEditViewController.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/4.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAOrderEditViewController.h"
  9. #import "RAEditInputModel.h"
  10. #import "RAEditMultInputModel.h"
  11. #import "RAEditLabelModel.h"
  12. #import "RAEditImageBaseModel.h"
  13. #import "RAEditPhotoModel.h"
  14. #import "RAEditSignatureModel.h"
  15. #import "RAProgressHUD.h"
  16. #import "ZipArchive.h"
  17. #import "AppDelegate.h"
  18. #import "UIScrollView+Empty.h"
  19. #import "RAEmptyView.h"
  20. #import "RAEditRequiredAlert.h"
  21. #import <CoreLocation/CoreLocation.h>
  22. @interface RAEditSectionModel : NSObject
  23. @property (nonatomic,strong) NSArray <RAEditBaseModel *> *items;
  24. @property (nonatomic,copy) NSString *title;
  25. @end
  26. @implementation RAEditSectionModel
  27. - (void)setValue:(id)value forUndefinedKey:(NSString *)key {
  28. }
  29. - (void)setItems:(NSArray<RAEditBaseModel *> *)items {
  30. NSArray *tmpItems = items;
  31. NSMutableArray *itemArr = [NSMutableArray arrayWithCapacity:items.count];
  32. for (int i = 0; i < tmpItems.count; i++) {
  33. NSDictionary *item = [tmpItems objectAtIndex:i];
  34. RAEditType type = [[item objectForKey:@"type"] intValue];
  35. switch (type) {
  36. case RAEditTypeLabel: {
  37. RAEditLabelModel *model = [RAEditLabelModel new];
  38. // model.required = YES;
  39. [model setValuesForKeysWithDictionary:item];
  40. [itemArr addObject:model];
  41. }
  42. break;
  43. case RAEditTypeInput: {
  44. RAEditInputModel *model = [RAEditInputModel new];
  45. // model.required = YES;
  46. [model setValuesForKeysWithDictionary:item];
  47. [itemArr addObject:model];
  48. }
  49. break;
  50. case RAEditTypeMultInput: {
  51. RAEditMultInputModel *model = [RAEditMultInputModel new];
  52. // model.required = YES;
  53. [model setValuesForKeysWithDictionary:item];
  54. [itemArr addObject:model];
  55. }
  56. break;
  57. case RAEditTypePhoto: {
  58. RAEditPhotoModel *model = [RAEditPhotoModel new];
  59. // model.required = YES;
  60. [model setValuesForKeysWithDictionary:item];
  61. [itemArr addObject:model];
  62. }
  63. break;
  64. case RAEditTypeSignature: {
  65. RAEditSignatureModel *model = [RAEditSignatureModel new];
  66. // model.required = YES;
  67. [model setValuesForKeysWithDictionary:item];
  68. [itemArr addObject:model];
  69. }
  70. break;
  71. default:
  72. break;
  73. }
  74. }
  75. _items = itemArr;
  76. }
  77. - (NSInteger)itemCount {
  78. return self.items.count;
  79. }
  80. - (RAEditBaseModel *)itemModelForIndex:(NSInteger)index {
  81. return [self.items objectAtIndex:index];
  82. }
  83. @end
  84. #pragma mark - View Controller
  85. @interface RAOrderEditViewController ()
  86. @property (nonatomic,strong) IBOutlet UITableView *orderEditTableView;
  87. @property (nonatomic,strong) NSMutableArray *sectionArray;
  88. @property (nonatomic,copy) NSString *photoDir;
  89. @property (nonatomic,strong) UIRefreshControl *refreshControl;
  90. @end
  91. @implementation RAOrderEditViewController
  92. + (instancetype)viewControllerFromStoryboard {
  93. RAOrderEditViewController *editVC = [[UIStoryboard storyboardWithName:@"Edit" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
  94. return editVC;
  95. }
  96. - (void)viewDidLoad {
  97. [super viewDidLoad];
  98. // Do any additional setup after loading the view.
  99. [self configureTable];
  100. [self configureNavigationBar];
  101. [self loadData];
  102. }
  103. - (void)viewWillAppear:(BOOL)animated {
  104. [super viewWillAppear:animated];
  105. [self registKeyboardListener];
  106. }
  107. - (void)viewWillDisappear:(BOOL)animated {
  108. [super viewWillDisappear:animated];
  109. [self unregistKeyboardListener];
  110. }
  111. - (void)didReceiveMemoryWarning {
  112. [super didReceiveMemoryWarning];
  113. // Dispose of any resources that can be recreated.
  114. }
  115. #pragma mark - Configure
  116. - (void)configureTable {
  117. if (@available(iOS 11.0, *)) {
  118. self.orderEditTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  119. } else {
  120. self.automaticallyAdjustsScrollViewInsets = NO;
  121. }
  122. self.orderEditTableView.tableFooterView = [UIView new];
  123. self.orderEditTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  124. UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
  125. [refresh addTarget:self action:@selector(refreshControlValueChanged:) forControlEvents:UIControlEventValueChanged];
  126. [self.orderEditTableView addSubview:refresh];
  127. self.refreshControl = refresh;
  128. // empty
  129. __weak typeof(self) weakSelf = self;
  130. self.orderEditTableView.emptyView = [RAEmptyView emptyViewWithTapBlk:^(id sender) {
  131. [weakSelf loadData];
  132. }];
  133. }
  134. - (void)configureNavigationBar {
  135. UIBarButtonItem *updateItem = [[UIBarButtonItem alloc] initWithTitle:@"Update" style:UIBarButtonItemStylePlain target:self action:@selector(updateBtnClick:)];
  136. self.navigationItem.rightBarButtonItem = updateItem;
  137. }
  138. - (void)registKeyboardListener {
  139. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
  140. }
  141. - (void)unregistKeyboardListener {
  142. [[NSNotificationCenter defaultCenter] removeObserver:self];
  143. }
  144. #pragma mark - Action
  145. - (void)refreshControlValueChanged:(UIRefreshControl *)refresh {
  146. [self loadData];
  147. }
  148. #pragma mark - Getter
  149. - (NSMutableArray *)sectionArray {
  150. if (!_sectionArray) {
  151. _sectionArray = [NSMutableArray array];
  152. }
  153. return _sectionArray;
  154. }
  155. - (NSUInteger)editSectionCount {
  156. return self.sectionArray.count;
  157. }
  158. - (NSInteger)itemCountForSection:(NSInteger)section {
  159. return [[self.sectionArray objectAtIndex:section] itemCount];
  160. }
  161. - (RAEditBaseModel *)modelForIndexPath:(NSIndexPath *)indexPath {
  162. return [[self.sectionArray objectAtIndex:indexPath.section] itemModelForIndex:indexPath.row];
  163. }
  164. - (NSString *)titleForSection:(NSInteger)section {
  165. return [[self.sectionArray objectAtIndex:section] title];
  166. }
  167. - (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell {
  168. return [self.orderEditTableView indexPathForCell:cell];
  169. }
  170. #pragma mark - Data
  171. - (void)loadData {
  172. if (self.loading) {
  173. return;
  174. }
  175. self.loading = YES;
  176. [self.orderEditTableView hideEmpty];
  177. // show progress
  178. RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
  179. NSString *orderID = self.orderID;
  180. NSInteger actionID = self.actionID;
  181. __weak typeof(self) weakSelf = self;
  182. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  183. NSDictionary *json = [RADataProvider requestUpdateOrder:orderID driverAction:actionID];
  184. dispatch_async(dispatch_get_main_queue(), ^{
  185. // dismiss progress
  186. [hud dismiss];
  187. if (weakSelf.refreshControl.isRefreshing) {
  188. [weakSelf.refreshControl endRefreshing];
  189. }
  190. if (weakSelf) {
  191. __strong typeof(weakSelf) strongSelf = weakSelf;
  192. int result = [[json objectForKey:@"result"] intValue];
  193. if (result == RESULT_TRUE) {
  194. NSArray *sectionArray = [json objectForKey:@"sections"];
  195. [strongSelf.sectionArray removeAllObjects];
  196. for (int i = 0; i < sectionArray.count; i++) {
  197. NSDictionary *section = [sectionArray objectAtIndex:i];
  198. RAEditSectionModel *model = [RAEditSectionModel new];
  199. [model setValuesForKeysWithDictionary:section];
  200. [strongSelf.sectionArray addObject:model];
  201. }
  202. [strongSelf.orderEditTableView reloadData];
  203. } else {
  204. [strongSelf.sectionArray removeAllObjects];
  205. strongSelf.orderEditTableView.contentOffset = CGPointZero;
  206. [strongSelf.orderEditTableView reloadData];
  207. // process error
  208. NSString *msg = [json objectForKey:@"err_msg"];
  209. // [strongSelf showAlert:msg];
  210. [strongSelf showAlertTilte:@"Warning" message:msg];
  211. }
  212. }
  213. weakSelf.loading = NO;
  214. if (weakSelf.editSectionCount == 0) {
  215. [weakSelf.orderEditTableView showEmpty];
  216. } else {
  217. [weakSelf.orderEditTableView hideEmpty];
  218. }
  219. });
  220. });
  221. }
  222. #pragma mark - Tap Action
  223. - (IBAction)tapToResignFirstResponder:(UITapGestureRecognizer *)sender {
  224. [self.view endEditing:YES];
  225. }
  226. - (void)updateBtnClick:(UIBarButtonItem *)sender {
  227. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  228. if (self.orderType2) {
  229. [params setObject:self.orderType2 forKey:@"orderType2"];
  230. }
  231. if (RASingleton.sharedInstance.requiredLocation) {
  232. CLLocation *location = RASingleton.sharedInstance.currentLocation;
  233. NSString *latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
  234. [params setObject:latLon forKey:@"location"];
  235. }
  236. NSMutableArray *emptyArr = [NSMutableArray array];
  237. NSMutableArray <RAEditImageBaseModel *> *photoArr = [self prepareParams:params checkRequired:emptyArr];
  238. if (emptyArr.count > 0) {
  239. RAEditRequiredAlert *alertVC = [RAEditRequiredAlert alertWithTile:@"Warning" message:[NSString stringWithFormat:@"please complete missing field:\n%@",[emptyArr componentsJoinedByString:@"\n"]]];
  240. [self presentViewController:alertVC animated:YES completion:nil];
  241. return;
  242. }
  243. // show progress
  244. RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
  245. __weak typeof(self) weakSelf = self;
  246. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  247. NSDictionary *json = [RADataProvider submitEditOrder:params];
  248. if (weakSelf) {
  249. __strong typeof(weakSelf) strongSelf = weakSelf;
  250. int result = [[json objectForKey:@"result"] intValue];
  251. if (result == RESULT_TRUE) {
  252. BOOL requiredLocation = [[json objectForKey:@"requiredLocation"] boolValue];
  253. [RASingleton sharedInstance].requiredLocation = requiredLocation;
  254. dispatch_async(dispatch_get_main_queue(), ^{
  255. if (photoArr.count > 0) {
  256. [strongSelf syncUploadPhotos:photoArr Json:json HUD:hud];
  257. } else {
  258. [self gobackHome];
  259. }
  260. });
  261. } else {
  262. // process error
  263. dispatch_async(dispatch_get_main_queue(), ^{
  264. // dismiss progress
  265. [hud dismiss:^{
  266. NSString *msg = [json objectForKey:@"err_msg"];
  267. [strongSelf showAlertTilte:@"Warning" message:msg];
  268. }];
  269. });
  270. }
  271. }
  272. });
  273. }
  274. - (void)backgroundUploadPhoto:(NSArray<RAEditImageBaseModel *> *)photos Json:(NSDictionary *)json {
  275. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  276. NSDate *date = [NSDate date];
  277. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  278. formatter.dateFormat = @"MM/dd/YYYY HH:mm";
  279. NSString *time = [formatter stringFromDate:date];
  280. for (RAEditImageBaseModel *model in photos) {
  281. NSString *serial = [json objectForKey:model.key];
  282. if (serial.length) {
  283. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  284. [params setObject:serial forKey:@"serial"];
  285. if (self.orderType2) {
  286. [params setObject:self.orderType2 forKey:@"orderType2"];
  287. }
  288. [params setObject:[RASingleton.sharedInstance encryptUser] forKey:@"name"];
  289. [params setObject:[RASingleton.sharedInstance encryptPassword] forKey:@"password"];
  290. [params setObject:@"iOS" forKey:@"platform"];
  291. NSString *photoPath = [self.photoDir.lastPathComponent stringByAppendingPathComponent:model.imageName];
  292. NSMutableDictionary *task = [@{
  293. @"order" : self.orderID,
  294. @"action" : self.actionTitle,
  295. @"name" : model.title,
  296. @"time" : time,
  297. @"url" : URL_UPLOAD,
  298. @"file" : photoPath,
  299. @"params" : params
  300. } mutableCopy];
  301. [appDelegate.uploadManager addTask:task];
  302. }
  303. }
  304. }
  305. - (void)syncUploadPhotos:(NSMutableArray<RAEditImageBaseModel *> *)photoArr Json:(NSDictionary *)json HUD:(RAProgressHUD *)hud {
  306. dispatch_async(dispatch_get_main_queue(), ^{
  307. RAProgressHUD *innerHUD = hud;
  308. if (!innerHUD) {
  309. innerHUD = [RAProgressHUD showHUDOnView:self.view]; // main queue
  310. }
  311. dispatch_async(dispatch_get_global_queue(0, 0), ^{ // network
  312. int retryCount = 0;
  313. NSMutableArray *completArr = [NSMutableArray array];
  314. // 同步上传照片
  315. for (int i = 0; i < photoArr.count; i++) {
  316. RAEditImageBaseModel *model = [photoArr objectAtIndex:i];
  317. NSString *serial = [json objectForKey:model.key];
  318. if (serial.length) {
  319. NSMutableDictionary *fileParams = [NSMutableDictionary dictionary];
  320. [fileParams setObject:serial forKey:@"serial"];
  321. if (self.orderType2) {
  322. [fileParams setObject:self.orderType2 forKey:@"orderType2"];
  323. }
  324. NSString *photoPath = [self.photoDir stringByAppendingPathComponent:model.imageName];
  325. NSDictionary *uploadJson = [RADataProvider uploadFile:photoPath parameters:fileParams];
  326. int uploadResult = [[uploadJson objectForKey:@"result"] intValue];
  327. if (uploadResult != RESULT_TRUE) { // 失败重试
  328. i--;
  329. retryCount++;
  330. if (retryCount >= 3) {
  331. break;
  332. }
  333. } else {
  334. [completArr addObject:model];
  335. retryCount = 0;
  336. // 删除文件
  337. if ([[NSFileManager defaultManager] fileExistsAtPath:photoPath]) {
  338. [[NSFileManager defaultManager] removeItemAtPath:photoPath error:nil];
  339. }
  340. }
  341. } // serial
  342. } // for
  343. // 将完成的model移除
  344. [photoArr removeObjectsInArray:completArr];
  345. __weak typeof(self) weakSelf = self;
  346. dispatch_async(dispatch_get_main_queue(), ^{
  347. [innerHUD dismiss:^{
  348. if (photoArr.count > 0) {
  349. // 上传失败,询问是否丢到后台线程上传,否则重启上传
  350. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"upload the photos failed,would you like to retry or do it background?" preferredStyle:UIAlertControllerStyleAlert];
  351. UIAlertAction *backgroundAction = [UIAlertAction actionWithTitle:@"Background" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  352. // 开启后台上传
  353. [weakSelf backgroundUploadPhoto:photoArr Json:json];
  354. // 返回首页
  355. [weakSelf gobackHome];
  356. }];
  357. UIAlertAction *retryAction = [UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  358. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  359. [weakSelf syncUploadPhotos:photoArr Json:json HUD:nil];
  360. });
  361. }];
  362. [alertVC addAction:backgroundAction];
  363. [alertVC addAction:retryAction];
  364. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  365. } else {
  366. // 上传完成,返回到首页
  367. [weakSelf gobackHome];
  368. }
  369. }];
  370. });
  371. });
  372. });
  373. }
  374. - (void)gobackHome {
  375. [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationReloadHome object:nil];
  376. [self.navigationController popToRootViewControllerAnimated:YES];
  377. }
  378. #pragma mark - Keyboard Listener
  379. - (void)keyboardWillChangeFrame:(NSNotification *)notification {
  380. CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  381. CGFloat screenHeight = CGRectGetHeight([UIScreen mainScreen].bounds);
  382. CGFloat keyboardHeight = screenHeight - CGRectGetMinY(end);
  383. UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, keyboardHeight, 0);
  384. self.orderEditTableView.contentInset = insets;
  385. if (self.editingIndexPath) {
  386. [self.orderEditTableView scrollToRowAtIndexPath:self.editingIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
  387. }
  388. }
  389. #pragma mark - Package Update Data
  390. - (NSString *)photoDir {
  391. if (!_photoDir) {
  392. NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
  393. NSString *photoDir = [cacheDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%ld_%@",self.orderID,(long)self.actionID,[NSUUID UUID].UUIDString]];
  394. NSError *error;
  395. // BOOL dirExist = YES;
  396. // for (int i = 0; i < INT_MAX; i++) {
  397. // if (i != 0) {
  398. // photoDir = [photoDir stringByAppendingString:[NSString stringWithFormat:@"(%d)",i]];
  399. // }
  400. // if (![[NSFileManager defaultManager] fileExistsAtPath:photoDir]) {
  401. // dirExist = NO;
  402. // break;
  403. // }
  404. // }
  405. [[NSFileManager defaultManager] createDirectoryAtPath:photoDir withIntermediateDirectories:YES attributes:nil error:&error];
  406. if (error) {
  407. NSLog(@"create dir %@ failed %@",photoDir,error.localizedDescription);
  408. return nil;
  409. }
  410. _photoDir = photoDir;
  411. }
  412. return _photoDir;
  413. }
  414. - (NSMutableArray <RAEditImageBaseModel *> *)prepareParams:(NSMutableDictionary *)params checkRequired:(NSMutableArray *)emptyArr {
  415. if (params == nil) {
  416. return nil;;
  417. }
  418. NSMutableArray <RAEditImageBaseModel *> *photoArr = [NSMutableArray array];
  419. NSString *photoDir = [self photoDir];
  420. [params setObject:self.orderID forKey:@"orderID"];
  421. [params setObject:@(self.actionID) forKey:@"actionID"];
  422. NSString* encryptu = [RASingleton sharedInstance].encryptUser;
  423. NSString* encryptp = [RASingleton sharedInstance].encryptPassword;
  424. [params setObject:encryptu forKey:@"name"];
  425. [params setObject:encryptp forKey:@"password"];
  426. [params setObject:@"iOS" forKey:@"platform"];
  427. if ([RASingleton sharedInstance].currentLocation) {
  428. [params setObject:[NSString stringWithFormat:@"%f,%f",[RASingleton sharedInstance].currentLocation.coordinate.latitude,[RASingleton sharedInstance].currentLocation.coordinate.longitude] forKey:@"location"];
  429. }
  430. for (RAEditSectionModel *section in self.sectionArray) {
  431. for (int i = 0; i < [section itemCount]; i++) {
  432. RAEditBaseModel *model = [section itemModelForIndex:i];
  433. switch (model.type) {
  434. case RAEditTypeLabel: {
  435. }
  436. break;
  437. case RAEditTypeInput: {
  438. RAEditInputModel *inputModel = (RAEditInputModel *)model;
  439. if (model.required && inputModel.value.length == 0) {
  440. [emptyArr addObject:[NSString stringWithFormat:@"%ld.%@",emptyArr.count + 1,model.title]];
  441. continue;
  442. }
  443. if (inputModel.key && inputModel.value.length > 0) {
  444. [params setObject:inputModel.value forKey:inputModel.key];
  445. }
  446. }
  447. break;
  448. case RAEditTypeMultInput: {
  449. RAEditMultInputModel *multInputModel = (RAEditMultInputModel *)model;
  450. if (model.required && multInputModel.value.length == 0) {
  451. [emptyArr addObject:[NSString stringWithFormat:@"%ld.%@",emptyArr.count + 1,model.title]];
  452. continue;
  453. }
  454. if (multInputModel.key && multInputModel.value.length > 0) {
  455. [params setObject:multInputModel.value forKey:multInputModel.key];
  456. }
  457. }
  458. break;
  459. case RAEditTypePhoto:
  460. case RAEditTypeSignature: {
  461. if (photoDir) {
  462. RAEditImageBaseModel *imageModel = (RAEditImageBaseModel *)model;
  463. if (model.required && imageModel.image == nil) {
  464. [emptyArr addObject:[NSString stringWithFormat:@"%ld.%@",emptyArr.count + 1,model.title]];
  465. continue;
  466. }
  467. if (imageModel.image) {
  468. NSString *photoPath = [photoDir stringByAppendingPathComponent:imageModel.imageName];
  469. NSData *imgData = UIImageJPEGRepresentation(imageModel.image, 1.0f);
  470. if (imgData) {
  471. [imgData writeToFile:photoPath atomically:NO];
  472. [params setObject:imageModel.imageName forKey:imageModel.key];
  473. [photoArr addObject:imageModel];
  474. }
  475. }
  476. }
  477. }
  478. break;
  479. default:
  480. break;
  481. }
  482. }
  483. }
  484. return photoArr;
  485. }
  486. //- (NSMutableDictionary *)preparePackage {
  487. //
  488. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  489. // NSInteger photoCount = [self prepareParams:params].count;
  490. // NSString *photoDir = [self photoDir];
  491. //
  492. // NSMutableDictionary *task = [@{
  493. // @"order" : self.orderID,
  494. // @"action" : self.actionTitle,
  495. // @"url" : URL_HOST,
  496. // @"noFile" : @(YES)
  497. // } mutableCopy];
  498. //
  499. // if (photoCount > 0) {
  500. //
  501. // // 压缩文件
  502. // NSString *zipPath = [photoDir stringByAppendingPathExtension:@".zip"];
  503. // ZipArchive *zip = [[ZipArchive alloc] init];
  504. // [zip CreateZipFile2:zipPath];
  505. // NSArray *subPaths = [[NSFileManager defaultManager] subpathsAtPath:photoDir];
  506. // for (NSString *subPath in subPaths) {
  507. // NSString *fullPath = [photoDir stringByAppendingPathComponent:subPath];
  508. // BOOL isDir;
  509. // if([[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDir]) {
  510. // if (!isDir) {
  511. // [zip addFileToZip:fullPath newname:subPath];
  512. // }
  513. // }
  514. // }
  515. // [zip CloseZipFile2];
  516. //
  517. // [[NSFileManager defaultManager] removeItemAtPath:photoDir error:nil];
  518. //
  519. // NSString *md5 = [RAUtils md5WithFile:zipPath];
  520. //
  521. // [params setObject:md5 forKey:@"md5"];
  522. // [task setObject:@"file" forKey:zipPath.lastPathComponent];
  523. // }
  524. //
  525. // [task setObject:params forKey:@"params"];
  526. //
  527. // return task;
  528. //}
  529. @end