StatBookController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use biz\stat\classes\StatBookClass;
  5. use common\components\dateUtil;
  6. use common\components\printUtil;
  7. use Yii;
  8. use common\components\util;
  9. class StatBookController extends BaseController
  10. {
  11. //花材销量 ssh 20211021
  12. public function actionProfile()
  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. $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
  25. util::success(['list' => $list]);
  26. }
  27. public function actionPrintOrder()
  28. {
  29. $get = Yii::$app->request->get();
  30. $where = [];
  31. $where['mainId'] = $this->mainId;
  32. $searchTime = $get['searchTime'] ?? 'today';
  33. if (!empty($searchTime)) {
  34. $startTime = $get['startTime'] ?? '';
  35. $endTime = $get['endTime'] ?? '';
  36. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  37. $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
  38. }
  39. $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
  40. if (empty($list)) {
  41. util::fail('没有花材需要打印');
  42. }
  43. $shop = $this->shop;
  44. $num = count($list);
  45. $pageSize = 30;
  46. $ratio = ceil($num / $pageSize);
  47. if ($ratio > 1) {
  48. for ($i = 1; $i <= $ratio; $i++) {
  49. $offset = ($i - 1) * $pageSize;
  50. $current = array_slice($list, $offset, $pageSize);
  51. self::printOrder($current, $shop, $i);
  52. }
  53. } else {
  54. self::printOrder($list, $shop);
  55. }
  56. util::complete('打印成功');
  57. }
  58. public static function printOrder($list, $shop, $order = 0)
  59. {
  60. $content = "<CB>预订汇总</CB><BR><BR>";
  61. if ($order > 0) {
  62. $content .= "<CB>第{$order}页</CB><BR><BR>";
  63. }
  64. $content .= '日期 / 花材 / 数量<BR>';
  65. $content .= '--------------------------------<BR>';
  66. foreach ($list as $item) {
  67. $date1 = $item['time'];
  68. $date2 = substr($date1, 4, 4);
  69. $name = $item['name'] ?? '';
  70. $num = $item['num'] ?? 0;
  71. $content .= $date2 . ' ' . $name . ' ' . $num . '<BR>';
  72. $content .= '--------------------------------<BR>';
  73. }
  74. $content .= "<BR><BR><BR>";
  75. $shopId = $shop->id ?? 0;
  76. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  77. $printSn = $ext['printSn'] ?? '';
  78. if (empty($printSn)) {
  79. util::fail('没有找到打印机');
  80. }
  81. $p = new printUtil($printSn);
  82. $p->printMsg($content, $shop);
  83. }
  84. }