| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace ghs\controllers;
- use biz\shop\classes\ShopExtClass;
- use bizGhs\book\classes\BookItemClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\dateUtil;
- use common\components\printUtil;
- use common\components\stringUtil;
- use Yii;
- use common\components\util;
- class StatBookController extends BaseController
- {
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $bookSn = $get['bookSn'] ?? '';
- $itemList = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock', 'id', true);
- $list = BookItemClass::getAllByCondition($where, 'time DESC', '*');
- $table = [];
- if (!empty($list)) {
- foreach ($list as $key => $val) {
- $productId = $val['itemId'] ?? 0;
- $stock = 0;
- if (isset($itemList[$productId])) {
- $product = $itemList[$productId];
- $stock = $product->stock;
- }
- $stock = floatval($stock);
- $list[$key]['stock'] = $stock;
- $time = $val['time'];
- $shortTime = substr($time, 4, 4);
- $list[$key]['shortTime'] = $shortTime;
- $table[] = [
- 'shortTime' => $shortTime,
- 'name' => $val['name'],
- 'num' => $val['num'],
- 'stock' => $stock,
- 'remark' => '',
- ];
- }
- }
- $shop = $this->shop;
- $title = $shop->shopName == '首店' ? $shop->merchantName : $shop->merchantName . "({$shop->shopName})";
- $printData = [
- 'title' => "【{$title}】预订汇总",
- 'table' => $table,
- ];
- util::success(['list' => $list, 'printData' => $printData]);
- }
- //花材销量 ssh 20211021
- public function actionProfile()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $bookSn = $get['bookSn'] ?? '';
- $staffId = $get['staffId'] ?? 0;
- $search = $get['search'] ?? '';
- $shop = $this->shop;
- if (empty($bookSn)) {
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- util::success(['list' => [], 'shop' => $shop, 'hint' => 'no bookSn']);
- }
- }
- $where['bookSn'] = $bookSn;
- if (!empty($search)) {
- if (stringUtil::isLetter($search)) {
- $search = strtolower($search);
- $where['py'] = ['like', $search];
- } else {
- $where['name'] = ['like', $search];
- }
- }
- if (!empty($staffId)) {
- $where['cgStaffId'] = $staffId;
- }
- $list = BookItemClass::getAllByCondition($where, '(bookNum-onNum) DESC', '*');
- if (!empty($list)) {
- $ids = array_column($list, 'itemId');
- $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
- foreach ($list as $key => $val) {
- $productId = $val['itemId'] ?? 0;
- $onNum = $val['onNum'] ?? 0;
- $currentProduct = $productList[$productId] ?? [];
- $stock = $currentProduct->stock ?? 0;
- $remainNum = $stock > $onNum ? bcsub($stock, $onNum) : 0;
- $list[$key]['remainStockNum'] = $remainNum;
- }
- }
- util::success(['list' => $list, 'shop' => $shop]);
- }
- public function actionPrintOrder()
- {
- util::fail('开发中');
- $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 = BookItemClass::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)
- {
- util::fail('开发中');
- $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>';
- }
- $content .= "<BR><BR><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);
- }
- }
|