| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace ghs\controllers;
- use biz\shop\classes\ShopExtClass;
- use biz\stat\classes\StatBookClass;
- use common\components\dateUtil;
- use common\components\printUtil;
- use Yii;
- use common\components\util;
- class StatBookController extends BaseController
- {
- //花材销量 ssh 20211021
- public function actionProfile()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $searchTime = $get['searchTime'] ?? 'today';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
- util::success(['list' => $list]);
- }
- public function actionPrintOrder()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $searchTime = $get['searchTime'] ?? 'today';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $list = StatBookClass::getAllByCondition($where, 'time DESC', '*');
- if (empty($list)) {
- util::fail('没有花材需要打印');
- }
- $shop = $this->shop;
- $num = count($list);
- $pageSize = 30;
- $ratio = ceil($num / $pageSize);
- if ($ratio > 1) {
- for ($i = 1; $i <= $ratio; $i++) {
- $offset = ($i - 1) * $pageSize;
- $current = array_slice($list, $offset, $pageSize);
- self::printOrder($current, $shop, $i);
- }
- } else {
- self::printOrder($list, $shop);
- }
- util::complete('打印成功');
- }
- public static function printOrder($list, $shop, $order = 0)
- {
- $content = "<CB>预订汇总</CB><BR><BR>";
- if ($order > 0) {
- $content .= "<CB>第{$order}页</CB><BR><BR>";
- }
- $content .= '日期 / 花材 / 数量<BR>';
- $content .= '--------------------------------<BR>';
- foreach ($list as $item) {
- $date1 = $item['time'];
- $date2 = substr($date1, 4, 4);
- $name = $item['name'] ?? '';
- $num = $item['num'] ?? 0;
- $content .= $date2 . ' ' . $name . ' ' . $num . '<BR>';
- $content .= '--------------------------------<BR>';
- }
- $shopId = $shop->id ?? 0;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
- $printSn = $ext['printSn'] ?? '';
- if (empty($printSn)) {
- util::fail('没有找到打印机');
- }
- $p = new printUtil($printSn);
- $p->printMsg($content, $shop);
- }
- }
|