StatBookController.php 5.0 KB

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