| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <?php
- namespace ghs\controllers;
- use biz\stat\classes\StatCgGhsClass;
- use bizGhs\cg\classes\CgRefundClass;
- use bizGhs\ghs\classes\GhsClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\order\classes\PurchaseOrderItemClass;
- use common\components\arrayUtil;
- use common\components\dateUtil;
- use Yii;
- use common\components\util;
- class StatCgGhsController extends BaseController
- {
- //采购列表 ssh 20211017
- public function actionProfile()
- {
- $get = Yii::$app->request->get();
- $mainId = $this->mainId;
- $export = $get['export'] ?? 0;
- $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : 0;
- $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $start = $period['startTime'];
- $end = $period['endTime'];
- $ghsList = GhsClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
- $currentStartDate = date('Y-m-d', strtotime($start));
- $currentEndDate = date('Y-m-d', strtotime($end));
- $currentStartTime = $currentStartDate . ' 00:00:00';
- $currentEndTime = $currentEndDate . ' 23:59:59';
- $where = ['mainId' => $mainId];
- if (!empty($debt)) {
- $where['debt'] = $debt;
- }
- $where['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $orderList = PurchaseOrderClass::getAllByCondition($where, null, '*');
- $list = [];
- $totalActPrice = 0;
- $totalOrderPrice = 0;
- $totalCarton = 0;
- $totalPack = 0;
- $totalFreight = 0;
- $totalTkPrice = 0;
- //增加项
- $totalOnlyTkPrice = 0;
- $totalNum = 0;
- if (!empty($orderList)) {
- foreach ($orderList as $orderInfo) {
- $actPrice = $orderInfo['actPrice'] ?? 0;
- $orderPrice = $orderInfo['orderPrice'] ?? 0;
- $ghsId = $orderInfo['ghsId'] ?? 0;
- $status = $orderInfo['status'] ?? 0;
- $orderSn = $orderInfo['orderSn'] ?? '';
- $tkPrice = $orderInfo['tkPrice'] ?? 0;
- if ($status != 4) {
- continue;
- }
- $carton = 0;
- $pack = 0;
- $freight = 0;
- $orderItemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $orderItem) {
- $num = $orderItem['xhNum'] ?? 0;
- $unitPrice = $orderItem['xhUnitPrice'] ?? 0;
- $refundNum = $orderItem['refundNum'] ?? 0;
- $classId = $orderItem['classId'] ?? 0;
- if (getenv('YII_ENV') == 'production') {
- if ($mainId == 23390) {
- $remainNum = bcsub($num, $refundNum);
- $amount = bcmul($remainNum, $unitPrice, 2);
- if ($classId == 73120) {
- $freight = bcadd($freight, $amount, 2);
- }
- }
- }
- }
- }
- //增加项
- 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);
- }
- }
- }
- }
- $totalCarton = bcadd($totalCarton, $carton, 2);
- $totalPack = bcadd($totalPack, $pack, 2);
- $totalFreight = bcadd($totalFreight, $freight, 2);
- $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
- $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
- $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
- $totalNum++;
- if (isset($list[$ghsId])) {
- $list[$ghsId]['actPrice'] = bcadd($list[$ghsId]['actPrice'], $actPrice, 2);
- $list[$ghsId]['orderPrice'] = bcadd($list[$ghsId]['orderPrice'], $orderPrice, 2);
- $list[$ghsId]['num'] = bcadd($list[$ghsId]['num'], 1);
- $list[$ghsId]['carton'] = bcadd($list[$ghsId]['carton'], $carton, 2);
- $list[$ghsId]['pack'] = bcadd($list[$ghsId]['pack'], $pack, 2);
- $list[$ghsId]['freight'] = bcadd($list[$ghsId]['freight'], $freight, 2);
- $list[$ghsId]['tkPrice'] = bcadd($list[$ghsId]['tkPrice'], $tkPrice, 2);
- } else {
- $name = $ghsList[$ghsId] && $ghsList[$ghsId]['name'] ? $ghsList[$ghsId]['name'] : '未命名';
- $mobile = $ghsList[$ghsId] && $ghsList[$ghsId]['mobile'] ? $ghsList[$ghsId]['mobile'] : '0';
- $list[$ghsId] = [
- 'id' => $ghsId,
- 'name' => $name,
- 'mobile' => $mobile,
- 'orderPrice' => $orderPrice,
- 'actPrice' => $actPrice,
- 'num' => 1,
- 'carton' => $carton,
- 'pack' => $pack,
- 'freight' => $freight,
- 'tkPrice' => $tkPrice,
- ];
- }
- }
- foreach ($ghsList as $key => $ghs) {
- $ghsId = $ghs['id'] ?? 0;
- if (isset($list[$ghsId]) == false) {
- $list[$ghsId] = [
- 'id' => $ghsId,
- 'name' => $ghs['name'],
- 'mobile' => $ghs['mobile'],
- 'actPrice' => 0,
- 'num' => 0,
- 'carton' => 0,
- 'pack' => 0,
- 'freight' => 0,
- 'tkPrice' => 0,
- 'orderPrice' => 0,
- ];
- }
- }
- $list = array_values($list);
- }
- if ($export == 1) {
- if (empty($list)) {
- util::fail('没有数据需要导出');
- }
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- StatCgGhsClass::exportCgGhsYj($list, $mainId);
- util::stop();
- }
- util::success([
- 'list' => $list,
- 'totalActPrice' => $totalActPrice,
- 'totalOrderPrice' => $totalOrderPrice,
- 'totalCarton' => $totalCarton,
- 'totalNum' => $totalNum,
- 'totalPack' => $totalPack,
- 'totalFreight' => $totalFreight,
- 'totalTkPrice' => $totalTkPrice,
- //增加项
- 'totalOnlyTkPrice' => $totalOnlyTkPrice,
- ]);
- //[['amount','ghsId','ghsName','num','py']]
- }
- public function actionProfileOld()
- {
- $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 = StatCgGhsClass::getAllByCondition($where, null, '*');
- $ghsIds = [];
- $arr = [];
- if (!empty($list)) {
- foreach ($list as $ke => $item) {
- $ghsId = $item['ghsId'] ?? 0;
- $num = $item['num'] ?? 0;
- $refundNum = $item['refundNum'] ?? 0;
- $amount = $item['amount'] ?? 0;
- $refundAmount = $item['refundAmount'] ?? 0;
- $ghsIds[$ghsId] = 1;
- if (isset($arr[$ghsId]['num'])) {
- $arr[$ghsId]['num'] = bcadd($arr[$ghsId]['num'], $num, 2);
- } else {
- $arr[$ghsId]['num'] = $num;
- }
- if (isset($arr[$ghsId]['refundNum'])) {
- $arr[$ghsId]['refundNum'] = bcadd($arr[$ghsId]['refundNum'], $refundNum, 2);
- } else {
- $arr[$ghsId]['refundNum'] = $refundNum;
- }
- if (isset($arr[$ghsId]['amount'])) {
- $arr[$ghsId]['amount'] = bcadd($arr[$ghsId]['amount'], $amount, 2);
- } else {
- $arr[$ghsId]['amount'] = $amount;
- }
- if (isset($arr[$ghsId]['refundAmount'])) {
- $arr[$ghsId]['refundAmount'] = bcadd($arr[$ghsId]['refundAmount'], $refundAmount, 2);
- } else {
- $arr[$ghsId]['refundAmount'] = $refundAmount;
- }
- }
- }
- $ghsIds = array_keys($ghsIds);
- $ghsData = GhsClass::getByIds($ghsIds);
- $cg = [];
- foreach ($ghsData as $ghs) {
- $ghsId = $ghs['id'] ?? 0;
- $ghsName = $ghs['name'] ?? '';
- $ghsPy = $ghs['py'] ?? '';
- $num = $arr[$ghsId]['num'] ?? 0;
- $refundNum = $arr[$ghsId]['refundNum'] ?? 0;
- $amount = $arr[$ghsId]['amount'] ?? 0;
- $refundAmount = $arr[$ghsId]['refundAmount'] ?? 0;
- $lastAmount = bcsub($amount, $refundAmount, 2);
- $lastNum = bcsub($num, $refundNum, 2);
- $cg[] = [
- 'ghsId' => $ghsId,
- 'ghsName' => $ghsName,
- 'py' => $ghsPy,
- 'num' => $lastNum,
- 'amount' => $lastAmount,
- ];
- }
- $cg = arrayUtil::arraySort($cg, 'num');
- util::success(['list' => $cg]);
- }
- }
|