StatBookController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use biz\stat\classes\StatBookClass;
  5. use common\components\dateUtil;
  6. use common\components\printUtil;
  7. use Yii;
  8. use common\components\util;
  9. class StatBookController extends BaseController
  10. {
  11. public function actionList()
  12. {
  13. $get = Yii::$app->request->get();
  14. $where = [];
  15. $where['mainId'] = $this->mainId;
  16. $searchTime = $get['searchTime'] ?? 'today';
  17. if (!empty($searchTime)) {
  18. $startTime = $get['startTime'] ?? '';
  19. $endTime = $get['endTime'] ?? '';
  20. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  21. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  22. }
  23. $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
  24. util::success(['list' => $list]);
  25. }
  26. //花材销量 ssh 20211021
  27. public function actionProfile()
  28. {
  29. $get = Yii::$app->request->get();
  30. $where = [];
  31. $where['mainId'] = $this->mainId;
  32. $searchTime = $get['searchTime'] ?? 'today';
  33. if (!empty($searchTime)) {
  34. $startTime = $get['startTime'] ?? '';
  35. $endTime = $get['endTime'] ?? '';
  36. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  37. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  38. }
  39. $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
  40. util::success(['list' => $list, 'moreData' => 0, 'totalPage' => 1, 'totalNum' => 1]);
  41. }
  42. public function actionPrintOrder()
  43. {
  44. $get = Yii::$app->request->get();
  45. $where = [];
  46. $where['mainId'] = $this->mainId;
  47. $searchTime = $get['searchTime'] ?? 'today';
  48. if (!empty($searchTime)) {
  49. $startTime = $get['startTime'] ?? '';
  50. $endTime = $get['endTime'] ?? '';
  51. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  52. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  53. }
  54. $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
  55. if (empty($list)) {
  56. util::fail('没有花材需要打印');
  57. }
  58. $shop = $this->shop;
  59. $num = count($list);
  60. $pageSize = 30;
  61. $ratio = ceil($num / $pageSize);
  62. if ($ratio > 1) {
  63. for ($i = 1; $i <= $ratio; $i++) {
  64. $offset = ($i - 1) * $pageSize;
  65. $current = array_slice($list, $offset, $pageSize);
  66. self::printOrder($current, $shop, $i);
  67. }
  68. } else {
  69. self::printOrder($list, $shop);
  70. }
  71. util::complete('打印成功');
  72. }
  73. public static function printOrder($list, $shop, $order = 0)
  74. {
  75. $content = "<CB>预订汇总</CB><BR><BR>";
  76. if ($order > 0) {
  77. $content .= "<CB>第{$order}页</CB><BR><BR>";
  78. }
  79. $content .= '日期 / 花材 / 数量<BR>';
  80. $content .= '--------------------------------<BR>';
  81. foreach ($list as $item) {
  82. $date1 = $item['time'];
  83. $date2 = substr($date1, 4, 4);
  84. $name = $item['name'] ?? '';
  85. $num = $item['num'] ?? 0;
  86. $content .= $date2 . ' ' . $name . ' ' . $num . '<BR>';
  87. $content .= '--------------------------------<BR>';
  88. }
  89. $content .= "<BR><BR><BR>";
  90. $shopId = $shop->id ?? 0;
  91. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  92. $printSn = $ext['printSn'] ?? '';
  93. if (empty($printSn)) {
  94. util::fail('没有找到打印机');
  95. }
  96. $p = new printUtil($printSn);
  97. $p->printMsg($content, $shop);
  98. }
  99. }