StatBookController.php 5.5 KB

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