StatBookController.php 5.3 KB

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