| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <?php
- namespace ghs\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\sj\classes\SjClass;
- use biz\wx\classes\WxMessageClass;
- use bizGhs\book\classes\BookItemClass;
- use bizGhs\cg\classes\CgRefundClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\order\classes\PurchaseOrderItemClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\shop\classes\ShopClass;
- use bizHd\purchase\classes\PurchaseClass;
- use common\components\dateUtil;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use biz\shop\classes\ShopExtClass;
- use Yii;
- use biz\shop\classes\MainClass;
- use biz\shop\classes\ShopCapitalClass;
- use biz\stat\classes\StatCgClass;
- use biz\stat\classes\StatCgGhsClass;
- use biz\stat\classes\StatOutClass;
- use bizGhs\base\classes\BaseClass;
- use bizGhs\book\classes\BookCustomClass;
- use bizGhs\book\classes\BookItemCustomClass;
- use bizGhs\book\classes\BookItemGhsClass;
- use bizGhs\cg\classes\CgOrderItemClass;
- use bizGhs\cg\classes\CgOrderItemSendClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\ghs\classes\GhsDebtRecordClass;
- use bizGhs\item\classes\CostChangeClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\order\traits\OrderTrait;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizGhs\stock\classes\OnStockRecordClass;
- use bizGhs\stock\classes\StockRecordClass;
- class CsController extends BaseController
- {
- public $guestAccess = ['list', 'read'];
- public function actionRead()
- {
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- $currentDirectory = getcwd();
- require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
- $spreadsheet = \PHPExcel_IOFactory::load($currentDirectory . "/123.xlsx");
- //print_r($objPHPExcel->getActiveSheet()->toArray());
- // foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) {
- // foreach ($row->getCellIterator() as $cell) {
- // if (!$cell->getValue()) { // 跳过空白单元格
- // continue;
- // }
- // echo 'Cell ' . $cell->getColumn() . $cell->getRow() . ' = ' . $cell->getValue() . '<br />';
- // }
- // }
- // 获取活动工作表
- $worksheet = $spreadsheet->getActiveSheet();
- // 遍历每一行
- foreach ($worksheet->getRowIterator() as $row) {
- $cellIterator = $row->getCellIterator();
- $cellIterator->setIterateOnlyExistingCells(FALSE); // 这里设置为迭代所有单元格,包括空单元格
- // 遍历每列
- $rowData = [];
- foreach ($cellIterator as $cell) {
- $rowData[] = $cell->getValue();
- }
- // 输出当前行数据
- echo implode(", ", $rowData) . "\n";
- }
- // // 加载Excel文件
- // $spreadsheet = IOFactory::load($filePath);
- //
- // // 获取活动工作表
- // $worksheet = $spreadsheet->getActiveSheet();
- //
- // // 遍历每一行
- // foreach ($worksheet->getRowIterator() as $row) {
- // $cellIterator = $row->getCellIterator();
- // $cellIterator->setIterateOnlyExistingCells(FALSE); // 这里设置为迭代所有单元格,包括空单元格
- //
- // // 遍历每列
- // $rowData = [];
- // foreach ($cellIterator as $cell) {
- // $rowData[] = $cell->getValue();
- // }
- //
- // // 输出当前行数据
- // echo implode(", ", $rowData) . "\n";
- // }
- }
- public function actionList()
- {
- $where = [];
- $get = Yii::$app->request->get();
- $export = 1;
- $search = $get['search'] ?? '';
- $where['shopId'] = 23580;
- $ghsId = $get['ghsId'] ?? 0;
- if (!empty($ghsId)) {
- $where['ghsId'] = $ghsId;
- }
- if (!empty($search)) {
- if (is_numeric($search) && strlen($search) == 4) {
- $where['orderSn'] = ['like', $search];
- } else {
- $where['ghsName'] = ['like', $search];
- }
- }
- $name = $get['name'] ?? '';
- if (!empty($name)) {
- $re = strstr($name, 'PH');
- if (!empty($re)) {
- $where['orderSn'] = $name;
- } else {
- $where['ghsName'] = ['like', $name];
- }
- }
- $searchTime = 'custom';
- $startTime = '2024-07-01';
- $endTime = '2024-07-31';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['entryTime'] = ['between', [$period['startTime'], $period['endTime']]];
- $cgStaffId = $get['cgStaffId'] ?? 0;
- if (!empty($cgStaffId)) {
- $where['cgStaffId'] = $cgStaffId;
- }
- if ($export == 1) {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- if (isset($where['entryTime']) == false) {
- util::fail('请选时间段');
- }
- $start = $where['entryTime'][1][0];
- $end = $where['entryTime'][1][1];
- $monthTime = bcmul(31, 86400);
- $startArea = strtotime($start);
- $endArea = strtotime($end);
- $diff = bcsub($endArea, $startArea);
- if ($diff > $monthTime) {
- util::fail('最长可导出一个月');
- }
- }
- $data = PurchaseOrderClass::getOrderList($where);
- if ($export == 1) {
- $this->exportOrderData($data, 23390);
- util::stop('');
- }
- //状态统计,很慢,暂时隐藏
- //$statData = PurchaseOrderClass::statNum($this->shopId);
- $statData = [
- 'allNum' => 0,
- 'unPayNum' => 0,
- 'unSendNum' => 0,
- 'sendingNum' => 0,
- 'finishNum' => 0,
- ];
- $data = array_merge($data, $statData);
- echo "<pre>";
- print_r($data);
- util::stop('');
- }
- public function exportOrderData($respond, $mainId)
- {
- $orderList = $respond['list'] ?? [];
- if (empty($orderList)) {
- util::fail('没有数据需要导出');
- }
- $orderSnList = array_column($orderList, 'orderSn');
- $orderItemData = PurchaseOrderItemClass::getAllByCondition(['orderSn' => ['in', $orderSnList]], null, '*');
- $orderItemList = [];
- if (!empty($orderItemData)) {
- foreach ($orderItemData as $itemInfo) {
- $orderSn = $itemInfo['orderSn'] ?? '';
- $orderItemList[$orderSn][] = $itemInfo;
- }
- }
- $totalActPrice = 0;
- $totalTkPrice = 0;
- $totalOnlyTkPrice = 0;
- $totalOrderPrice = 0;
- foreach ($orderList as $key => $orderInfo) {
- $orderSn = $orderInfo['orderSn'] ?? '';
- $status = $orderInfo['status'] ?? 0;
- $entryTime = $orderInfo['entryTime'] ?? '';
- //增加项
- $actPrice = $orderInfo['actPrice'] ?? 0;
- $tkPrice = $orderInfo['tkPrice'] ?? 0;
- $orderPrice = $orderInfo['orderPrice'] ?? 0;
- $discountAmount = $orderInfo['discountAmount'] ?? 0;
- $packingCharge = $orderInfo['packingCharge'] ?? 0;
- $shortCharge = $orderInfo['shortCharge'] ?? 0;
- $longCharge = $orderInfo['longCharge'] ?? 0;
- $pickCharge = $orderInfo['pickCharge'] ?? 0;
- $localCharge = $orderInfo['localCharge'] ?? 0;
- if ($status != 4) {
- unset($orderList[$key]);
- continue;
- }
- //增加项
- if ($actPrice <= 0) {
- unset($orderList[$key]);
- continue;
- }
- if ($discountAmount > 0 || $packingCharge > 0 || $shortCharge > 0 || $longCharge > 0 || $pickCharge > 0 || $localCharge > 0) {
- echo $orderSn . ' ' . $discountAmount . ' ' . $packingCharge . ' ' . $shortCharge . ' ' . $longCharge . ' ' . $pickCharge . ' ' . $localCharge . "<br/>\n";
- }
- $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
- $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
- $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
- $itemList = $orderItemList[$orderSn] ?? [];
- $orderList[$key]['itemList'] = $itemList;
- //增加项
- if ($tkPrice > 0) {
- $refundList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
- if (!empty($refundList)) {
- foreach ($refundList as $refundInfo) {
- if (isset($refundInfo->refundType) && $refundInfo->refundType == 2) {
- $refundPrice = $refundInfo->refundPrice ?? 0;
- $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
- }
- }
- }
- }
- $currentItemPrice = 0;
- if (!empty($itemList)) {
- foreach ($itemList as $itemData) {
- $bigPrice = $itemData['bigPrice'] ?? 0;
- $itemNum = $itemData['itemNum'] ?? 0;
- $total = bcmul($bigPrice, $itemNum, 2);
- $currentItemPrice = bcadd($currentItemPrice, $total, 2);
- }
- }
- $add1 = bcadd($currentItemPrice, $packingCharge, 2);
- $add2 = bcadd($add1, $shortCharge, 2);
- $add3 = bcadd($add2, $longCharge, 2);
- $last = bcsub($add3, $tkPrice, 2);
- // if (floatval($last) != floatval($actPrice)) {
- // echo $currentItemPrice . ' 优惠:' . $discountAmount . ' 打包:' . $packingCharge . ' 短途:' . $shortCharge . ' 长途:' . $longCharge . ' 提:' . $pickCharge . ' 本:' . $localCharge . ' 实:' . $actPrice . $entryTime . "<br/>\n";
- // echo $orderSn . " 不同<br/>\n";
- // die;
- // }
- }
- echo "<pre>";
- echo '订单金额:' . $totalOrderPrice . ' 实际金额:' . $totalActPrice . ' 退款金额:' . $totalTkPrice . ' 仅退款:' . $totalOnlyTkPrice;
- }
- }
|