RAOrderEditViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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 = nil;
  234. if (location) {
  235. latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
  236. } else {
  237. latLon = @"-999,-999";
  238. }
  239. [params setObject:latLon forKey:@"location"];
  240. }
  241. NSMutableArray *emptyArr = [NSMutableArray array];
  242. NSMutableArray <RAEditImageBaseModel *> *photoArr = [self prepareParams:params checkRequired:emptyArr];
  243. if (emptyArr.count > 0) {
  244. RAEditRequiredAlert *alertVC = [RAEditRequiredAlert alertWithTile:@"Warning" message:[NSString stringWithFormat:@"please complete missing field:\n%@",[emptyArr componentsJoinedByString:@"\n"]]];
  245. [self presentViewController:alertVC animated:YES completion:nil];
  246. return;
  247. }
  248. // show progress
  249. RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
  250. __weak typeof(self) weakSelf = self;
  251. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  252. NSDictionary *json = [RADataProvider submitEditOrder:params];
  253. if (weakSelf) {
  254. __strong typeof(weakSelf) strongSelf = weakSelf;
  255. int result = [[json objectForKey:@"result"] intValue];
  256. if (result == RESULT_TRUE) {
  257. BOOL requiredLocation = [[json objectForKey:@"requiredLocation"] boolValue];
  258. [RASingleton sharedInstance].requiredLocation = requiredLocation;
  259. dispatch_async(dispatch_get_main_queue(), ^{
  260. if (photoArr.count > 0) {
  261. [strongSelf syncUploadPhotos:photoArr Json:json HUD:hud];
  262. } else {
  263. [self gobackHome];
  264. }
  265. });
  266. } else {
  267. // process error
  268. dispatch_async(dispatch_get_main_queue(), ^{
  269. // dismiss progress
  270. [hud dismiss:^{
  271. NSString *msg = [json objectForKey:@"err_msg"];
  272. [strongSelf showAlertTilte:@"Warning" message:msg];
  273. }];
  274. });
  275. }
  276. }
  277. });
  278. }
  279. - (void)backgroundUploadPhoto:(NSArray<RAEditImageBaseModel *> *)photos Json:(NSDictionary *)json {
  280. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  281. NSDate *date = [NSDate date];
  282. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  283. formatter.dateFormat = @"MM/dd/YYYY HH:mm";
  284. NSString *time = [formatter stringFromDate:date];
  285. NSString *serial = [json objectForKey:@"serial"];
  286. for (RAEditImageBaseModel *model in photos) {
  287. if (serial.length) {
  288. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  289. [params setObject:serial forKey:@"serial"];
  290. if (self.orderType2) {
  291. [params setObject:self.orderType2 forKey:@"orderType2"];
  292. }
  293. if (model.key) {
  294. [params setObject:model.key forKey:@"key"];
  295. }
  296. [params setObject:@(model.type) forKey:@"type"];
  297. [params setObject:[RASingleton.sharedInstance encryptUser] forKey:@"name"];
  298. [params setObject:[RASingleton.sharedInstance encryptPassword] forKey:@"password"];
  299. [params setObject:@"iOS" forKey:@"platform"];
  300. NSString *photoPath = [self.photoDir.lastPathComponent stringByAppendingPathComponent:model.imageName];
  301. NSMutableDictionary *task = [@{
  302. @"order" : self.orderID,
  303. @"action" : self.actionTitle,
  304. @"name" : model.title,
  305. @"time" : time,
  306. @"url" : URL_UPLOAD,
  307. @"file" : photoPath,
  308. @"params" : params
  309. } mutableCopy];
  310. [appDelegate.uploadManager addTask:task];
  311. }
  312. }
  313. }
  314. - (void)syncUploadPhotos:(NSMutableArray<RAEditImageBaseModel *> *)photoArr Json:(NSDictionary *)json HUD:(RAProgressHUD *)hud {
  315. dispatch_async(dispatch_get_main_queue(), ^{
  316. RAProgressHUD *innerHUD = hud;
  317. if (!innerHUD) {
  318. innerHUD = [RAProgressHUD showHUDOnView:self.view]; // main queue
  319. }
  320. dispatch_async(dispatch_get_global_queue(0, 0), ^{ // network
  321. int retryCount = 0;
  322. NSMutableArray *completArr = [NSMutableArray array];
  323. NSString *serial = [json objectForKey:@"serial"];
  324. // 同步上传照片
  325. for (int i = 0; i < photoArr.count; i++) {
  326. RAEditImageBaseModel *model = [photoArr objectAtIndex:i];
  327. if (serial.length) {
  328. NSMutableDictionary *fileParams = [NSMutableDictionary dictionary];
  329. [fileParams setObject:serial forKey:@"serial"];
  330. if (self.orderType2) {
  331. [fileParams setObject:self.orderType2 forKey:@"orderType2"];
  332. }
  333. if (model.key) {
  334. [fileParams setObject:model.key forKey:@"key"];
  335. }
  336. [fileParams setObject:@(model.type) forKey:@"type"];
  337. NSString *photoPath = [self.photoDir stringByAppendingPathComponent:model.imageName];
  338. NSDictionary *uploadJson = [RADataProvider uploadFile:photoPath parameters:fileParams];
  339. int uploadResult = [[uploadJson objectForKey:@"result"] intValue];
  340. if (uploadResult != RESULT_TRUE) { // 失败重试
  341. i--;
  342. retryCount++;
  343. if (retryCount >= 3) {
  344. break;
  345. }
  346. } else {
  347. [completArr addObject:model];
  348. retryCount = 0;
  349. // 删除文件
  350. if ([[NSFileManager defaultManager] fileExistsAtPath:photoPath]) {
  351. [[NSFileManager defaultManager] removeItemAtPath:photoPath error:nil];
  352. }
  353. }
  354. } // serial
  355. } // for
  356. // 将完成的model移除
  357. [photoArr removeObjectsInArray:completArr];
  358. __weak typeof(self) weakSelf = self;
  359. dispatch_async(dispatch_get_main_queue(), ^{
  360. [innerHUD dismiss:^{
  361. if (photoArr.count > 0) {
  362. // 上传失败,询问是否丢到后台线程上传,否则重启上传
  363. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"upload the photos failed,would you like to retry or do it background?" preferredStyle:UIAlertControllerStyleAlert];
  364. UIAlertAction *backgroundAction = [UIAlertAction actionWithTitle:@"Background" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  365. // 开启后台上传
  366. [weakSelf backgroundUploadPhoto:photoArr Json:json];
  367. // 返回首页
  368. [weakSelf gobackHome];
  369. }];
  370. UIAlertAction *retryAction = [UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  371. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  372. [weakSelf syncUploadPhotos:photoArr Json:json HUD:nil];
  373. });
  374. }];
  375. [alertVC addAction:backgroundAction];
  376. [alertVC addAction:retryAction];
  377. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  378. } else {
  379. // 上传完成,返回到首页
  380. [weakSelf gobackHome];
  381. }
  382. }];
  383. });
  384. });
  385. });
  386. }
  387. - (void)gobackHome {
  388. [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationReloadHome object:nil];
  389. [self.navigationController popToRootViewControllerAnimated:YES];
  390. }
  391. #pragma mark - Keyboard Listener
  392. - (void)keyboardWillChangeFrame:(NSNotification *)notification {
  393. CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  394. CGFloat screenHeight = CGRectGetHeight([UIScreen mainScreen].bounds);
  395. CGFloat keyboardHeight = screenHeight - CGRectGetMinY(end);
  396. UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, keyboardHeight, 0);
  397. self.orderEditTableView.contentInset = insets;
  398. if (self.editingIndexPath) {
  399. [self.orderEditTableView scrollToRowAtIndexPath:self.editingIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
  400. }
  401. }
  402. #pragma mark - Package Update Data
  403. - (NSString *)photoDir {
  404. if (!_photoDir) {
  405. NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
  406. NSString *photoDir = [cacheDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%ld_%@",self.orderID,(long)self.actionID,[NSUUID UUID].UUIDString]];
  407. NSError *error;
  408. // BOOL dirExist = YES;
  409. // for (int i = 0; i < INT_MAX; i++) {
  410. // if (i != 0) {
  411. // photoDir = [photoDir stringByAppendingString:[NSString stringWithFormat:@"(%d)",i]];
  412. // }
  413. // if (![[NSFileManager defaultManager] fileExistsAtPath:photoDir]) {
  414. // dirExist = NO;
  415. // break;
  416. // }
  417. // }
  418. [[NSFileManager defaultManager] createDirectoryAtPath:photoDir withIntermediateDirectories:YES attributes:nil error:&error];
  419. if (error) {
  420. NSLog(@"create dir %@ failed %@",photoDir,error.localizedDescription);
  421. return nil;
  422. }
  423. _photoDir = photoDir;
  424. }
  425. return _photoDir;
  426. }
  427. - (NSMutableArray <RAEditImageBaseModel *> *)prepareParams:(NSMutableDictionary *)params checkRequired:(NSMutableArray *)emptyArr {
  428. if (params == nil) {
  429. return nil;;
  430. }
  431. NSMutableArray <RAEditImageBaseModel *> *photoArr = [NSMutableArray array];
  432. NSString *photoDir = [self photoDir];
  433. [params setObject:self.orderID forKey:@"orderID"];
  434. [params setObject:@(self.actionID) forKey:@"actionID"];
  435. NSString* encryptu = [RASingleton sharedInstance].encryptUser;
  436. NSString* encryptp = [RASingleton sharedInstance].encryptPassword;
  437. [params setObject:encryptu forKey:@"name"];
  438. [params setObject:encryptp forKey:@"password"];
  439. [params setObject:@"iOS" forKey:@"platform"];
  440. for (RAEditSectionModel *section in self.sectionArray) {
  441. for (int i = 0; i < [section itemCount]; i++) {
  442. RAEditBaseModel *model = [section itemModelForIndex:i];
  443. switch (model.type) {
  444. case RAEditTypeLabel: {
  445. }
  446. break;
  447. case RAEditTypeInput: {
  448. RAEditInputModel *inputModel = (RAEditInputModel *)model;
  449. if (model.required && inputModel.value.length == 0) {
  450. [emptyArr addObject:[NSString stringWithFormat:@"%ld.%@",emptyArr.count + 1,model.title]];
  451. continue;
  452. }
  453. if (inputModel.key && inputModel.value.length > 0) {
  454. [params setObject:inputModel.value forKey:inputModel.key];
  455. }
  456. }
  457. break;
  458. case RAEditTypeMultInput: {
  459. RAEditMultInputModel *multInputModel = (RAEditMultInputModel *)model;
  460. if (model.required && multInputModel.value.length == 0) {
  461. [emptyArr addObject:[NSString stringWithFormat:@"%ld.%@",emptyArr.count + 1,model.title]];
  462. continue;
  463. }
  464. if (multInputModel.key && multInputModel.value.length > 0) {
  465. [params setObject:multInputModel.value forKey:multInputModel.key];
  466. }
  467. }
  468. break;
  469. case RAEditTypePhoto:
  470. case RAEditTypeSignature: {
  471. if (photoDir) {
  472. RAEditImageBaseModel *imageModel = (RAEditImageBaseModel *)model;
  473. if (model.required && imageModel.image == nil) {
  474. [emptyArr addObject:[NSString stringWithFormat:@"%ld.%@",emptyArr.count + 1,model.title]];
  475. continue;
  476. }
  477. if (imageModel.image) {
  478. NSString *photoPath = [photoDir stringByAppendingPathComponent:imageModel.imageName];
  479. NSData *imgData = UIImageJPEGRepresentation(imageModel.image, 1.0f);
  480. if (imgData) {
  481. [imgData writeToFile:photoPath atomically:NO];
  482. [params setObject:imageModel.imageName forKey:imageModel.key];
  483. [photoArr addObject:imageModel];
  484. }
  485. }
  486. }
  487. }
  488. break;
  489. default:
  490. break;
  491. }
  492. }
  493. }
  494. return photoArr;
  495. }
  496. //- (NSMutableDictionary *)preparePackage {
  497. //
  498. // NSMutableDictionary *params = [NSMutableDictionary dictionary];
  499. // NSInteger photoCount = [self prepareParams:params].count;
  500. // NSString *photoDir = [self photoDir];
  501. //
  502. // NSMutableDictionary *task = [@{
  503. // @"order" : self.orderID,
  504. // @"action" : self.actionTitle,
  505. // @"url" : URL_HOST,
  506. // @"noFile" : @(YES)
  507. // } mutableCopy];
  508. //
  509. // if (photoCount > 0) {
  510. //
  511. // // 压缩文件
  512. // NSString *zipPath = [photoDir stringByAppendingPathExtension:@".zip"];
  513. // ZipArchive *zip = [[ZipArchive alloc] init];
  514. // [zip CreateZipFile2:zipPath];
  515. // NSArray *subPaths = [[NSFileManager defaultManager] subpathsAtPath:photoDir];
  516. // for (NSString *subPath in subPaths) {
  517. // NSString *fullPath = [photoDir stringByAppendingPathComponent:subPath];
  518. // BOOL isDir;
  519. // if([[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDir]) {
  520. // if (!isDir) {
  521. // [zip addFileToZip:fullPath newname:subPath];
  522. // }
  523. // }
  524. // }
  525. // [zip CloseZipFile2];
  526. //
  527. // [[NSFileManager defaultManager] removeItemAtPath:photoDir error:nil];
  528. //
  529. // NSString *md5 = [RAUtils md5WithFile:zipPath];
  530. //
  531. // [params setObject:md5 forKey:@"md5"];
  532. // [task setObject:@"file" forKey:zipPath.lastPathComponent];
  533. // }
  534. //
  535. // [task setObject:params forKey:@"params"];
  536. //
  537. // return task;
  538. //}
  539. @end