StatBookController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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'] = $stock;
  35. }
  36. }
  37. util::success(['list' => $list]);
  38. }
  39. //花材销量 ssh 20211021
  40. public function actionProfile()
  41. {
  42. $get = Yii::$app->request->get();
  43. $where = [];
  44. $where['mainId'] = $this->mainId;
  45. $searchTime = $get['searchTime'] ?? 'today';
  46. if (!empty($searchTime)) {
  47. $startTime = $get['startTime'] ?? '';
  48. $endTime = $get['endTime'] ?? '';
  49. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  50. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  51. }
  52. $itemList = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock', 'id', true);
  53. $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
  54. if (!empty($list)) {
  55. foreach ($list as $key => $val) {
  56. $productId = $val['itemId'] ?? 0;
  57. $stock = 0;
  58. if (isset($itemList[$productId])) {
  59. $product = $itemList[$productId];
  60. $stock = $product->stock;
  61. }
  62. $list[$key]['stock'] = $stock;
  63. }
  64. }
  65. util::success(['list' => $list]);
  66. }
  67. public function actionPrintOrder()
  68. {
  69. $get = Yii::$app->request->get();
  70. $where = [];
  71. $where['mainId'] = $this->mainId;
  72. $searchTime = $get['searchTime'] ?? 'today';
  73. if (!empty($searchTime)) {
  74. $startTime = $get['startTime'] ?? '';
  75. $endTime = $get['endTime'] ?? '';
  76. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  77. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  78. }
  79. $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
  80. if (empty($list)) {
  81. util::fail('没有花材需要打印');
  82. }
  83. $shop = $this->shop;
  84. $num = count($list);
  85. $pageSize = 30;
  86. $ratio = ceil($num / $pageSize);
  87. if ($ratio > 1) {
  88. for ($i = 1; $i <= $ratio; $i++) {
  89. $offset = ($i - 1) * $pageSize;
  90. $current = array_slice($list, $offset, $pageSize);
  91. self::printOrder($current, $shop, $i);
  92. }
  93. } else {
  94. self::printOrder($list, $shop);
  95. }
  96. util::complete('打印成功');
  97. }
  98. public static function printOrder($list, $shop, $order = 0)
  99. {
  100. $content = "<CB>预订汇总</CB><BR><BR>";
  101. if ($order > 0) {
  102. $content .= "<CB>第{$order}页</CB><BR><BR>";
  103. }
  104. $content .= '日期 / 花材 / 数量<BR>';
  105. $content .= '--------------------------------<BR>';
  106. foreach ($list as $item) {
  107. $date1 = $item['time'];
  108. $date2 = substr($date1, 4, 4);
  109. $name = $item['name'] ?? '';
  110. $num = $item['num'] ?? 0;
  111. $content .= $date2 . ' ' . $name . ' ' . $num . '<BR>';
  112. $content .= '--------------------------------<BR>';
  113. }
  114. $content .= "<BR><BR><BR>";
  115. $shopId = $shop->id ?? 0;
  116. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  117. $printSn = $ext['printSn'] ?? '';
  118. if (empty($printSn)) {
  119. util::fail('没有找到打印机');
  120. }
  121. $p = new printUtil($printSn);
  122. $p->printMsg($content, $shop);
  123. }
  124. }