StatBookController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. if (empty($bookSn)) {
  59. $shop = $this->shop;
  60. $bookSn = $shop->bookSn ?? 0;
  61. if (empty($bookSn)) {
  62. util::fail('请选择预订活动');
  63. }
  64. }
  65. $where['bookSn'] = $bookSn;
  66. $list = BookItemClass::getAllByCondition($where, 'addTime DESC', '*');
  67. util::success(['list' => $list]);
  68. }
  69. public function actionPrintOrder()
  70. {
  71. $get = Yii::$app->request->get();
  72. $where = [];
  73. $where['mainId'] = $this->mainId;
  74. $searchTime = $get['searchTime'] ?? 'today';
  75. if (!empty($searchTime)) {
  76. $startTime = $get['startTime'] ?? '';
  77. $endTime = $get['endTime'] ?? '';
  78. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  79. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  80. }
  81. $list = BookItemClass::getAllByCondition($where, 'time DESC', '*');
  82. if (empty($list)) {
  83. util::fail('没有花材需要打印');
  84. }
  85. $shop = $this->shop;
  86. $num = count($list);
  87. $pageSize = 30;
  88. $ratio = ceil($num / $pageSize);
  89. if ($ratio > 1) {
  90. for ($i = 1; $i <= $ratio; $i++) {
  91. $offset = ($i - 1) * $pageSize;
  92. $current = array_slice($list, $offset, $pageSize);
  93. self::printOrder($current, $shop, $i);
  94. }
  95. } else {
  96. self::printOrder($list, $shop);
  97. }
  98. util::complete('打印成功');
  99. }
  100. public static function printOrder($list, $shop, $order = 0)
  101. {
  102. util::fail('开发中');
  103. $content = "<CB>预订汇总</CB><BR><BR>";
  104. if ($order > 0) {
  105. $content .= "<CB>第{$order}页</CB><BR><BR>";
  106. }
  107. $content .= '日期 / 花材 / 数量<BR>';
  108. $content .= '--------------------------------<BR>';
  109. foreach ($list as $item) {
  110. $date1 = $item['time'];
  111. $date2 = substr($date1, 4, 4);
  112. $name = $item['name'] ?? '';
  113. $num = $item['num'] ?? 0;
  114. $content .= $date2 . ' ' . $name . ' ' . $num . '<BR>';
  115. $content .= '--------------------------------<BR>';
  116. }
  117. $content .= "<BR><BR><BR>";
  118. $shopId = $shop->id ?? 0;
  119. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  120. $printSn = $ext['printSn'] ?? '';
  121. if (empty($printSn)) {
  122. util::fail('没有找到打印机');
  123. }
  124. $p = new printUtil($printSn);
  125. $p->printMsg($content, $shop);
  126. }
  127. }