StatBookController.php 5.8 KB

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