StatBookController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. $shopId = $shop->id ?? 0;
  75. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  76. $printSn = $ext['printSn'] ?? '';
  77. if (empty($printSn)) {
  78. util::fail('没有找到打印机');
  79. }
  80. $p = new printUtil($printSn);
  81. $p->printMsg($content, $shop);
  82. }
  83. }