StatBookController.php 5.6 KB

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