order_processing.dart 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  3. import 'package:bbyyy/beans/template_bean_entity.dart';
  4. import 'package:bbyyy/https/MyDio.dart';
  5. import 'package:bbyyy/https/url.dart';
  6. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  7. import 'package:flustars/flustars.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter/services.dart';
  10. import '../const.dart';
  11. import '../dims.dart';
  12. import '../event_bus.dart';
  13. import '../my_colors.dart';
  14. import '../my_cookie.dart';
  15. import '../my_tools.dart';
  16. import '../my_views.dart';
  17. import '../order.dart';
  18. import '../pop_up_queue.dart';
  19. class OrderProcessing {
  20. OrderProcessing._internal();
  21. static OrderProcessing _singleton = OrderProcessing._internal();
  22. factory OrderProcessing() => _singleton;
  23. List<MyShopBeanDataData> shops = []; //所属货帮
  24. List<MyShopBeanDataData> showShops = []; //展示货帮
  25. List<TemplateBeanData> orderTemplate = []; //订单模板
  26. List<TemplateBeanData> matchTemplates = []; //订单模板
  27. String clipboardData = ''; //剪切板数据
  28. MyShopBeanDataData shop; //选中的店铺
  29. TemplateBeanData template; //匹配的模板
  30. //最大金额赢家数量 0---发送订单的人不是最大赢家 1---发订单的人是最大赢家 2---发订单的人是最大赢家且有两个一样的金额
  31. int commissionPayerNum = -1;
  32. String orderHash = ''; //订单hash值
  33. StateSetter ss;
  34. List<OrderInfo2> order; //订单
  35. BuildContext buildContext;
  36. int amountCompleted = 0;
  37. bool saving = false;
  38. Map idTemplate = Map();
  39. bool showOrderDetail = false;
  40. //初始化变量
  41. void initialization() {
  42. amountCompleted = 0;
  43. shops.clear();
  44. orderTemplate.clear();
  45. clipboardData = '';
  46. shop = null;
  47. template = null;
  48. commissionPayerNum = -1;
  49. orderHash = '';
  50. showOrderDetail = false;
  51. order.clear();
  52. EasyLoading.dismiss();
  53. showToast('发送成功');
  54. saving = false;
  55. EventBus().off('saveOrder');
  56. PopUpQueue().onShow = false;
  57. PopUpQueue().showNext();
  58. }
  59. //查询订单模板
  60. queryOrderTemplate(String clipboardData, BuildContext buildContext) {
  61. this.clipboardData = clipboardData;
  62. this.buildContext = buildContext;
  63. print('=======queryOrderTemplate========');
  64. MyDio().query(
  65. {'key': 'order_template', "dims": orderTemplateDims, "filters": {}},
  66. (response, hasError) {
  67. if (!hasError) {
  68. TemplateBeanEntity entity = TemplateBeanEntity()
  69. .fromJson(json.decode(response.data.toString()));
  70. orderTemplate = entity.data;
  71. // matchAllTemplates();
  72. queryTheStore();
  73. } else {
  74. PopUpQueue().onShow = false;
  75. PopUpQueue().showNext();
  76. }
  77. }, (error) {
  78. PopUpQueue().onShow = false;
  79. PopUpQueue().showNext();
  80. });
  81. }
  82. //查询所属店铺
  83. queryTheStore() {
  84. // print('=======queryTheStore========');
  85. MyDio().query({
  86. "key": "shop_user",
  87. "filters": {
  88. "or": true,
  89. "conditions": [
  90. "role!=0",
  91. "user_uid==${MyCookie().getUID()}",
  92. "review_state==1"
  93. ],
  94. "filters": [
  95. {
  96. "conditions": ["role==0", "user_uid==${MyCookie().getUID()}"]
  97. }
  98. ]
  99. },
  100. "dims": shopUserDims,
  101. "paging": [1, 20000]
  102. }, (response, hasError) {
  103. if (!hasError) {
  104. MyShopBeanEntity entity =
  105. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  106. if (entity.data.data == null || entity.data.data.isEmpty) {
  107. PopUpQueue().onShow = false;
  108. PopUpQueue().showNext();
  109. return;
  110. }
  111. shops = entity.data.data;
  112. shops.removeWhere((element) => !element.privateShop);
  113. shops.removeWhere((element) => !element.innerTrade);
  114. bool hasMatch = false;
  115. showShops.clear();
  116. for (int i = 0; i < shops.length; i++) {
  117. if (shop == null) {
  118. shop = shops[i];
  119. }
  120. matchTemplate();
  121. if (orderHash != '') {
  122. hasMatch = true;
  123. showShops.add(shops[i]);
  124. orderHash = '';
  125. } else {
  126. shop = null;
  127. }
  128. }
  129. if (hasMatch) {
  130. matchTemplate();
  131. showView();
  132. }
  133. if (!hasMatch) {
  134. print('noMatch');
  135. PopUpQueue().onShow = false;
  136. PopUpQueue().showNext();
  137. }
  138. } else {
  139. PopUpQueue().onShow = false;
  140. PopUpQueue().showNext();
  141. }
  142. }, (error) {
  143. PopUpQueue().onShow = false;
  144. PopUpQueue().showNext();
  145. });
  146. }
  147. //优先匹配店铺模板
  148. matchTemplate() {
  149. // print('=======================|matchTemplate|=======================');
  150. w:
  151. for (int i = 0; i < orderTemplate.length; i++) {
  152. // print(
  153. // '=======================|${orderTemplate[i].shopUid}||${shop.shopUid}|=======================');
  154. if (orderTemplate[i].shopUid == shop.shopUid) {
  155. if (parseOrder(orderTemplate[i])) {
  156. break w;
  157. }
  158. }
  159. }
  160. if (orderHash != '') {
  161. } else {
  162. v:
  163. for (int i = 0; i < orderTemplate.length; i++) {
  164. if (orderTemplate[i].shopUid == 0) {
  165. if (parseOrder(orderTemplate[i])) {
  166. break v;
  167. }
  168. }
  169. }
  170. }
  171. }
  172. bool parseOrder(TemplateBeanData element) {
  173. // print('=======parseOrder========');
  174. // print(
  175. // '=========================|${element.template}|=============================');
  176. // print(
  177. // '=========================|$clipboardData|=============================');
  178. var res;
  179. try {
  180. res = parseString2(
  181. element.template.replaceAll('\r', ''), '''$clipboardData''');
  182. } catch (e) {}
  183. print(res.toString());
  184. if (res != null) {
  185. print('-----------data[i].template-----------');
  186. print(element.template);
  187. print('json.encode(res) =============\n${json.encode(res)}');
  188. var order = parse2(res);
  189. print('order.toString()=============\n${order.toString()}');
  190. print('order.length=============\n${order.length}');
  191. var maxAmount = 0.0;
  192. int maxAmountNum = 0;
  193. List<String> maxAmountOwner = [];
  194. res.forEach((key, value) {
  195. if (key.contains('amount')) {
  196. try {
  197. if (double.parse(value) > maxAmount) {
  198. maxAmount = double.parse(value);
  199. maxAmountNum = 1;
  200. maxAmountOwner.clear();
  201. maxAmountOwner.add(res[key.replaceAll('amount', 'person')]);
  202. } else if (double.parse(value) == maxAmount) {
  203. maxAmountNum++;
  204. maxAmountOwner.add(res[key.replaceAll('amount', 'person')]);
  205. }
  206. } catch (e) {}
  207. }
  208. });
  209. if (maxAmountOwner.isNotEmpty) {
  210. maxAmountOwner.forEach((element) {
  211. if (MyCookie().getName().contains(element) ||
  212. element.contains(MyCookie().getName())) {
  213. commissionPayerNum = maxAmountNum;
  214. }
  215. });
  216. }
  217. print('maxAmount============\n$maxAmount\n==============');
  218. print('maxAmountNum==============\n$maxAmountNum\n==============');
  219. print(
  220. 'maxAmountOwner==============\n${maxAmountOwner.toString()}\n==============');
  221. print(
  222. 'commissionPayerNum================ \n$commissionPayerNum\n==============');
  223. order.removeWhere((element) =>
  224. !element.seller.name
  225. .contains(MyCookie().loginInformation.data.extra.name) &&
  226. !MyCookie()
  227. .loginInformation
  228. .data
  229. .extra
  230. .name
  231. .contains(element.seller.name));
  232. if (order.length > 0) {
  233. orderHash = computeOrderHash(res);
  234. this.order = order;
  235. idTemplate[element.shopUid] = order;
  236. return true;
  237. } else {
  238. return false;
  239. }
  240. } else {
  241. return false;
  242. }
  243. }
  244. showView() {
  245. print('=======|showView|========');
  246. Clipboard.setData(ClipboardData(text: ''));
  247. EasyLoading.instance
  248. ..contentPadding = EdgeInsets.symmetric(horizontal: 0, vertical: 12)
  249. ..alignment = Alignment.bottomCenter
  250. ..loadingStyle = EasyLoadingStyle.light
  251. ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65);
  252. EasyLoading.show(
  253. indicator: Material(
  254. color: Colors.white,
  255. child: StatefulBuilder(
  256. builder: (c, s) {
  257. ss = s;
  258. if (showOrderDetail) {
  259. return Column(
  260. children: [
  261. Container(
  262. child: Stack(
  263. children: [
  264. Container(
  265. child: MyViews().myText('订单详情', MyColors.c333333, 14),
  266. alignment: Alignment.center,
  267. height: 22,
  268. ),
  269. Positioned(
  270. right: 0,
  271. child: GestureDetector(
  272. onTap: () {
  273. initialization();
  274. PopUpQueue().onShow = false;
  275. PopUpQueue().showNext();
  276. },
  277. behavior: HitTestBehavior.translucent,
  278. child: Container(
  279. child: Icon(
  280. Icons.close,
  281. size: 20,
  282. color: Colors.white,
  283. ),
  284. decoration: BoxDecoration(
  285. color: MyColors.cB6B6B6,
  286. borderRadius: BorderRadius.circular(11)),
  287. height: 22,
  288. width: 22,
  289. ),
  290. ),
  291. )
  292. ],
  293. alignment: Alignment.center,
  294. ),
  295. height: 30,
  296. padding: EdgeInsets.symmetric(horizontal: 12),
  297. ),
  298. Container(
  299. child: Text(
  300. '¥${amount()}',
  301. style: TextStyle(color: MyColors.cFF4233, fontSize: 25),
  302. ),
  303. margin: EdgeInsets.only(top: 15,bottom: 10),
  304. ),
  305. Padding(
  306. padding: EdgeInsets.symmetric(horizontal: 16, vertical: 5),
  307. child: Row(
  308. children: [
  309. Text('所属店铺:'),
  310. Row(
  311. children: [
  312. ClipRRect(
  313. child: MyViews()
  314. .netImg(imgURL(shop.shopPic), 30, 30),
  315. borderRadius: BorderRadius.circular(15),
  316. ),
  317. Container(
  318. child: Text('${shop.shopName}(${shop.shopUid})'),
  319. margin: EdgeInsets.only(left: 10),
  320. )
  321. ],
  322. )
  323. ],
  324. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  325. ),
  326. ),
  327. Padding(
  328. padding: EdgeInsets.symmetric(horizontal: 16, vertical: 5),
  329. child: Row(
  330. children: [
  331. Text('收款人:'),
  332. Row(
  333. children: [
  334. ClipRRect(
  335. child: MyViews()
  336. .netImg(imgURL(MyCookie().getPic()), 30, 30),
  337. borderRadius: BorderRadius.circular(15),
  338. ),
  339. Container(
  340. child: Text(
  341. '${MyCookie().getName()}(${MyCookie().getUID().toString().replaceRange(0, 4, '****')})'),
  342. margin: EdgeInsets.only(left: 10),
  343. )
  344. ],
  345. )
  346. ],
  347. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  348. ),
  349. ),
  350. Container(
  351. child: GestureDetector(
  352. onTap: () {
  353. if (saving) {
  354. return;
  355. } else {
  356. ss((){
  357. saving = true;
  358. });
  359. EventBus().on('saveOrder', (arg) {
  360. amountCompleted++;
  361. if (amountCompleted == order.length) {
  362. initialization();
  363. }
  364. });
  365. order.forEach((element) {
  366. sendOrder(element);
  367. });
  368. }
  369. },
  370. behavior: HitTestBehavior.translucent,
  371. child: Container(
  372. decoration: BoxDecoration(
  373. color: MyColors.cFF4233,
  374. borderRadius: BorderRadius.circular(20),
  375. ),
  376. height: 40,
  377. width: 150,
  378. child: saving?Container(
  379. height: 30,width: 30,
  380. padding: const EdgeInsets.all(2.0),
  381. child: CircularProgressIndicator(
  382. backgroundColor: Colors.transparent,
  383. valueColor: AlwaysStoppedAnimation(Colors.white),
  384. strokeWidth: 2,
  385. ),
  386. ):MyViews().myText('发送订单', Colors.white, 14),
  387. alignment: Alignment.center,
  388. ),
  389. ),
  390. alignment: Alignment.center,
  391. margin: EdgeInsets.only(top: 15),
  392. )
  393. ],
  394. );
  395. } else {
  396. return Column(
  397. children: [
  398. Container(
  399. child: Stack(
  400. children: [
  401. Container(
  402. child: MyViews().myText('智能订单', MyColors.c333333, 14),
  403. alignment: Alignment.center,
  404. height: 22,
  405. ),
  406. Positioned(
  407. right: 0,
  408. child: GestureDetector(
  409. onTap: () {
  410. initialization();
  411. PopUpQueue().onShow = false;
  412. PopUpQueue().showNext();
  413. },
  414. behavior: HitTestBehavior.translucent,
  415. child: Container(
  416. child: Icon(
  417. Icons.close,
  418. size: 20,
  419. color: Colors.white,
  420. ),
  421. decoration: BoxDecoration(
  422. color: MyColors.cB6B6B6,
  423. borderRadius: BorderRadius.circular(11)),
  424. height: 22,
  425. width: 22,
  426. ),
  427. ),
  428. )
  429. ],
  430. alignment: Alignment.center,
  431. ),
  432. height: 30,
  433. padding: EdgeInsets.symmetric(horizontal: 12),
  434. ),
  435. Container(
  436. height: 5,
  437. color: MyColors.cF7F7F7,
  438. margin: EdgeInsets.only(top: 10),
  439. ),
  440. Column(
  441. children: items(order),
  442. ),
  443. Container(
  444. height: 5,
  445. color: MyColors.cF7F7F7,
  446. margin: EdgeInsets.only(top: 10),
  447. ),
  448. Visibility(
  449. child: Column(
  450. children: [
  451. Container(
  452. child: MyViews().myText('货帮选择', MyColors.c333333, 13),
  453. margin: EdgeInsets.only(left: 7, top: 11),
  454. ),
  455. Container(
  456. margin:
  457. EdgeInsets.symmetric(horizontal: 7, vertical: 10),
  458. height: (showShops.length * 1.0 / 2).ceil() *
  459. (double.parse(
  460. '${MediaQuery.of(buildContext).size.width - 74}') /
  461. 2 /
  462. 3.8 +
  463. 10) -
  464. 10,
  465. child: GridView(
  466. gridDelegate:
  467. SliverGridDelegateWithFixedCrossAxisCount(
  468. crossAxisCount: 2, //横轴三个子widget
  469. childAspectRatio: 3.8,
  470. crossAxisSpacing: 10,
  471. mainAxisSpacing: 8 //宽高比为1时,子widget
  472. ),
  473. children: shopItem(showShops),
  474. padding: EdgeInsets.all(0),
  475. ),
  476. ),
  477. ],
  478. crossAxisAlignment: CrossAxisAlignment.start,
  479. ),
  480. visible: showShops.length != 1,
  481. ),
  482. Container(
  483. height: 0.5,
  484. color: MyColors.cF7F7F7,
  485. margin: EdgeInsets.only(bottom: 10),
  486. ),
  487. Container(
  488. child: GestureDetector(
  489. onTap: () {
  490. // if (saving) {
  491. // return;
  492. // } else {
  493. // saving = true;
  494. // EventBus().on('saveOrder', (arg) {
  495. // amountCompleted++;
  496. // if (amountCompleted == order.length) {
  497. // initialization();
  498. // }
  499. // });
  500. // order.forEach((element) {
  501. // sendOrder(element);
  502. // });
  503. // }
  504. ss(() {
  505. showOrderDetail = true;
  506. });
  507. },
  508. behavior: HitTestBehavior.translucent,
  509. child: Container(
  510. decoration: BoxDecoration(
  511. color: MyColors.cFF4233,
  512. borderRadius: BorderRadius.circular(20),
  513. ),
  514. height: 40,
  515. width: 150,
  516. child: MyViews().myText('确认', Colors.white, 14),
  517. alignment: Alignment.center,
  518. ),
  519. ),
  520. alignment: Alignment.center,
  521. )
  522. ],
  523. mainAxisAlignment: MainAxisAlignment.start,
  524. crossAxisAlignment: CrossAxisAlignment.start,
  525. );
  526. }
  527. },
  528. ),
  529. ),
  530. );
  531. }
  532. //订单视图
  533. items(List<OrderInfo2> order) {
  534. List<Widget> items = [];
  535. order.forEach((element) {
  536. items.add(Container(
  537. child: Column(
  538. children: [
  539. Row(
  540. children: [
  541. Container(
  542. margin: EdgeInsets.only(left: 8, right: 7),
  543. child: ClipRRect(
  544. child: MyViews().netImg(
  545. imgURL(MyCookie().loginInformation.data.extra.picture),
  546. 35,
  547. 35),
  548. borderRadius: BorderRadius.circular(17.5),
  549. ),
  550. ),
  551. Expanded(
  552. child: Container(
  553. height: 35,
  554. child: Column(
  555. children: [
  556. Text(
  557. '付款人:${element.payer.name}',
  558. style: TextStyle(
  559. color: MyColors.c333333,
  560. fontSize: 13,
  561. decoration: TextDecoration.none,
  562. ),
  563. ),
  564. Text(
  565. '订单时间:${element.time}',
  566. style: TextStyle(
  567. color: MyColors.c666666,
  568. fontSize: 10,
  569. decoration: TextDecoration.none,
  570. ),
  571. ),
  572. ],
  573. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  574. crossAxisAlignment: CrossAxisAlignment.start,
  575. ),
  576. ),
  577. ),
  578. Container(
  579. margin: EdgeInsets.only(right: 10),
  580. child: Text(
  581. '¥${(element.payer.amount * element.factor).toStringAsFixed(2)}',
  582. style: TextStyle(
  583. color: MyColors.cFF4233,
  584. fontSize: 14,
  585. decoration: TextDecoration.none,
  586. ),
  587. ),
  588. ),
  589. ],
  590. crossAxisAlignment: CrossAxisAlignment.center,
  591. ),
  592. Container(
  593. height: 0.5,
  594. margin: EdgeInsets.only(right: 10, left: 50, top: 5),
  595. color: MyColors.cE7E7E7,
  596. )
  597. ],
  598. ),
  599. margin: EdgeInsets.only(top: 5),
  600. ));
  601. });
  602. return items;
  603. }
  604. //店铺视图
  605. shopItem(List<MyShopBeanDataData> shops) {
  606. List<Widget> items = [];
  607. for (int i = 0; i < shops.length; i++) {
  608. items.add(GestureDetector(
  609. onTap: () {
  610. MyShopBeanDataData oldShop = shop;
  611. shop = shops[i];
  612. orderHash = '';
  613. matchTemplate();
  614. if (orderHash == '') {
  615. // showToast('店铺选择错误');
  616. shop = oldShop;
  617. matchTemplate();
  618. } else {
  619. ss(() {});
  620. }
  621. },
  622. behavior: HitTestBehavior.translucent,
  623. child: Container(
  624. child: Row(
  625. children: [
  626. Container(
  627. margin: EdgeInsets.only(right: 5),
  628. child: ClipRRect(
  629. child: MyViews().netImg(imgURL(shops[i].shopPic), 30, 30),
  630. borderRadius: BorderRadius.circular(15),
  631. ),
  632. ),
  633. Expanded(
  634. child: Column(
  635. children: [
  636. Text(
  637. shops[i].shopName,
  638. style: TextStyle(
  639. color: shop.shopUid == shops[i].shopUid
  640. ? MyColors.cFF4233
  641. : MyColors.c666666,
  642. fontSize: 12,
  643. ),
  644. maxLines: 1,
  645. overflow: TextOverflow.ellipsis,
  646. softWrap: true,
  647. ),
  648. Text(
  649. 'ID:${shops[i].shopUid}',
  650. style: TextStyle(
  651. color: shop.shopUid == shops[i].shopUid
  652. ? MyColors.cFF4233
  653. : MyColors.c666666,
  654. fontSize: 10,
  655. ),
  656. maxLines: 1,
  657. overflow: TextOverflow.ellipsis,
  658. softWrap: true,
  659. ),
  660. ],
  661. crossAxisAlignment: CrossAxisAlignment.start,
  662. ),
  663. ),
  664. ],
  665. ),
  666. decoration: BoxDecoration(
  667. color: shop.shopUid == shops[i].shopUid
  668. ? MyColors.cFFECEB
  669. : MyColors.cEDEDED,
  670. borderRadius: BorderRadius.circular(4),
  671. ),
  672. constraints: BoxConstraints(maxWidth: 150),
  673. padding: EdgeInsets.symmetric(horizontal: 6, vertical: 6),
  674. ),
  675. ));
  676. }
  677. return items;
  678. }
  679. //发送订单
  680. void sendOrder(OrderInfo2 element) {
  681. MyDio().save({
  682. 'key': 'order',
  683. 'object': {
  684. 'uuid': orderHash,
  685. 'shop_uid': shop.shopUid,
  686. 'shop_pic': shop.shopPic,
  687. 'shop_name': shop.shopName,
  688. 'seller_pic': MyCookie().loginInformation.data.extra.picture,
  689. 'seller_uid': MyCookie().getUID(),
  690. 'seller_name': MyCookie().loginInformation.data.extra.name,
  691. 'buyer_name': element.payer.name,
  692. 'type': orderTypeThirdPlatform,
  693. 'amount': NumUtil.multiply(element.payer.amount, element.factor),
  694. 'commission_payer_num': commissionPayerNum
  695. }
  696. }, (response, hasError) {
  697. if (!hasError) {
  698. EventBus().emit('saveOrder');
  699. }
  700. }, (error) {});
  701. }
  702. //匹配所有模板
  703. void matchAllTemplates() {
  704. orderTemplate.forEach((element) {
  705. if (parseOrder2(element)) {
  706. print(
  707. '==============parseOrder(element)\n${element.template}\n===================');
  708. matchTemplates.add(element);
  709. }
  710. });
  711. checkMyStore();
  712. }
  713. void checkMyStore() {
  714. MyDio().query({
  715. "key": "shop_user",
  716. "filters": {
  717. "or": true,
  718. "conditions": [
  719. "role!=0",
  720. "user_uid==${MyCookie().getUID()}",
  721. "review_state==1"
  722. ],
  723. "filters": [
  724. {
  725. "conditions": ["role==0", "user_uid==${MyCookie().getUID()}"]
  726. }
  727. ]
  728. },
  729. "dims": shopUserDims,
  730. "paging": [1, 20000]
  731. }, (response, hasError) {
  732. if (!hasError) {
  733. MyShopBeanEntity entity =
  734. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  735. if (entity.data.data == null || entity.data.data.isEmpty) {
  736. PopUpQueue().onShow = false;
  737. PopUpQueue().showNext();
  738. return;
  739. }
  740. shops = entity.data.data;
  741. shops.removeWhere((element) => !element.privateShop);
  742. shops.removeWhere((element) => !element.innerTrade);
  743. List<MyShopBeanDataData> showShows = [];
  744. if (idTemplate.length == 0) {
  745. PopUpQueue().onShow = false;
  746. PopUpQueue().showNext();
  747. return;
  748. }
  749. if (idTemplate[0] == null) {
  750. shops.forEach((shop) {
  751. idTemplate.keys.forEach((element) {
  752. print('idTemplate.keys$element-------${shop.shopUid}');
  753. if (shop.shopUid == element) {
  754. showShows.add(shop);
  755. }
  756. });
  757. });
  758. shops = showShows;
  759. print('shops.length${shops.length}');
  760. }
  761. shop = shops[0];
  762. matchTemplate();
  763. showView();
  764. // bool hasMatch = false;
  765. // x:
  766. // for (int i = 0; i < shops.length; i++) {
  767. // shop = shops[i];
  768. // matchTemplate();
  769. // if (orderHash != '') {
  770. // hasMatch = true;
  771. // showView();
  772. // break x;
  773. // }
  774. // }
  775. // if (!hasMatch) {
  776. // print('noMatch');
  777. // PopUpQueue().onShow = false;
  778. // PopUpQueue().showNext();
  779. // }
  780. } else {
  781. PopUpQueue().onShow = false;
  782. PopUpQueue().showNext();
  783. }
  784. }, (error) {
  785. PopUpQueue().onShow = false;
  786. PopUpQueue().showNext();
  787. });
  788. }
  789. bool parseOrder2(TemplateBeanData element) {
  790. var res;
  791. try {
  792. res = parseString2(
  793. element.template.replaceAll('\r', ''), '''$clipboardData''');
  794. } catch (e) {}
  795. print(res.toString());
  796. if (res != null) {
  797. print('-----------data[i].template-----------');
  798. print(element.template);
  799. print('json.encode(res) =============\n${json.encode(res)}');
  800. var order = parse2(res);
  801. print('order.toString()=============\n${order.toString()}');
  802. print('order.length=============\n${order.length}');
  803. var maxAmount = 0.0;
  804. int maxAmountNum = 0;
  805. List<String> maxAmountOwner = [];
  806. res.forEach((key, value) {
  807. if (key.contains('amount')) {
  808. try {
  809. if (double.parse(value) > maxAmount) {
  810. maxAmount = double.parse(value);
  811. maxAmountNum = 1;
  812. maxAmountOwner.clear();
  813. maxAmountOwner.add(res[key.replaceAll('amount', 'person')]);
  814. } else if (double.parse(value) == maxAmount) {
  815. maxAmountNum++;
  816. maxAmountOwner.add(res[key.replaceAll('amount', 'person')]);
  817. }
  818. } catch (e) {}
  819. }
  820. });
  821. if (maxAmountOwner.isNotEmpty) {
  822. maxAmountOwner.forEach((element) {
  823. if (MyCookie().getName().contains(element) ||
  824. element.contains(MyCookie().getName())) {
  825. commissionPayerNum = maxAmountNum;
  826. }
  827. });
  828. }
  829. print('maxAmount============\n$maxAmount\n==============');
  830. print('maxAmountNum==============\n$maxAmountNum\n==============');
  831. print(
  832. 'maxAmountOwner==============\n${maxAmountOwner.toString()}\n==============');
  833. print(
  834. 'commissionPayerNum================ \n$commissionPayerNum\n==============');
  835. order.removeWhere((element) =>
  836. !element.seller.name
  837. .contains(MyCookie().loginInformation.data.extra.name) &&
  838. !MyCookie()
  839. .loginInformation
  840. .data
  841. .extra
  842. .name
  843. .contains(element.seller.name));
  844. if (order.length > 0) {
  845. orderHash = computeOrderHash(res);
  846. this.order = order;
  847. idTemplate[element.shopUid] = order;
  848. return true;
  849. } else {
  850. return false;
  851. }
  852. } else {
  853. return false;
  854. }
  855. }
  856. String amount() {
  857. double amount = 0.0;
  858. order.forEach((element) {
  859. amount += element.payer.amount * element.factor;
  860. });
  861. return amount.toStringAsFixed(2);
  862. }
  863. }