| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378 |
- <?php
- namespace bizGhs\stat\classes;
- use biz\stat\classes\StatCgClass;
- use biz\stat\classes\StatStockInClass;
- use biz\stat\classes\StatStockOutClass;
- use bizGhs\cg\classes\CgRefundClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\expend\classes\ExpendClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\order\classes\OrderItemClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\order\classes\PurchaseOrderItemClass;
- use bizGhs\order\classes\RefundOrderClass;
- use bizGhs\order\classes\StockWastageOrderClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\staff\classes\SalaryClass;
- use bizHd\goods\classes\PlantCgClass;
- use bizHd\order\classes\OrderClass as HdOrderClass;
- use bizGhs\order\classes\OrderClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\refund\classes\HdRefundClass;
- use common\components\arrayUtil;
- use common\components\dateUtil;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\util;
- use Yii;
- use bizGhs\base\classes\BaseClass;
- class StatSaleClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\stat\models\StatSale';
- public static function wastage($mainId)
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $mainId;
- $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'];
- $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['addTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $list = StockWastageOrderClass::getAllByCondition($where, null, '*');
- $totalPrice = 0;
- if (!empty($list)) {
- foreach ($list as $order) {
- $price = $order['price'] ?? 0;
- $totalPrice = bcadd($totalPrice, $price, 2);
- }
- }
- $totalPrice = floatval($totalPrice);
- return ['totalPrice' => $totalPrice];
- }
- //结账跟踪 ssh 20230503
- public static function OrderClear($mainId)
- {
- $get = Yii::$app->request->get();
- $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
- $timeStyle = $get['timeStyle'] ?? 0;
- if (isset($get['searchTime']) && !empty($get['searchTime'])) {
- $searchTime = $get['searchTime'];
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $start = $period['startTime'];
- $end = $period['endTime'];
- $currentStartDate = date('Y-m-d', strtotime($start));
- $currentEndDate = date('Y-m-d', strtotime($end));
- $currentStartTime = $currentStartDate . ' 00:00:00';
- $currentEndTime = $currentEndDate . ' 23:59:59';
- if ($timeStyle == 0) {
- $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- } else {
- $where['clearTime'] = ['between', [$currentStartTime, $currentEndTime]];
- }
- } else {
- $payTime = 'today';
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($payTime, $startTime, $endTime, true);
- $start = $period['startTime'];
- $end = $period['endTime'];
- $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['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- }
- $customId = $get['customId'] ?? 0;
- if (!empty($customId)) {
- $where['customId'] = $customId;
- }
- $unClear = $get['unClear'] ?? 0;
- if ($unClear == 1) {
- $where['clearId'] = 0;
- $where['remainDebtPrice>'] = 0;
- }
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- return ['list' => $ghsOrderList];
- }
- //客户下单榜 ssh 20230502
- public static function statCustomCg($mainId)
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $mainId;
- $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'];
- $where['time'] = ['between', [$start, $end]];
- $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, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
- $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, 'id,name,py', 'id');
- $arr = [];
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- $totalAmount = 0;
- $totalNum = 0;
- if (!empty($ghsOrderList)) {
- foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
- $actPrice = $ghsOrder['actPrice'] ?? 0;
- $orderPrice = $ghsOrder['orderPrice'] ?? 0;
- $tkPrice = $ghsOrder['tkPrice'] ?? 0;
- $customId = $ghsOrder['customId'] ?? 0;
- $status = $ghsOrder['status'] ?? 0;
- $book = $ghsOrder['book'] ?? 0;
- if ($status == 1 || $status == 5) {
- continue;
- }
- if ($book == 1 && $status == 2) {
- continue;
- }
- $customName = $customList[$customId]['name'] ?? '';
- $py = $customList[$customId]['py'] ?? '';
- $totalNum++;
- $totalAmount = bcadd($totalAmount, $actPrice, 2);
- if (isset($arr[$customId])) {
- $arr[$customId]['num']++;
- $arr[$customId]['amount'] = bcadd($arr[$customId]['amount'], $actPrice, 2);
- $arr[$customId]['orderPrice'] = bcadd($arr[$customId]['orderPrice'], $orderPrice, 2);
- $arr[$customId]['tkPrice'] = bcadd($arr[$customId]['tkPrice'], $tkPrice, 2);
- } else {
- $arr[$customId] = [
- 'customId' => $customId,
- 'customName' => $customName,
- 'py' => $py,
- 'num' => 1,
- 'amount' => $actPrice,
- 'levelName' => '',
- 'orderPrice' => $orderPrice,
- 'tkPrice' => $tkPrice,
- ];
- }
- }
- $arr = arrayUtil::arraySort($arr, 'amount');
- }
- $totalAmount = floatval($totalAmount);
- return ['list' => $arr, 'totalAmount' => $totalAmount, 'totalNum' => $totalNum];
- }
- public static function profile($mainId)
- {
- //收入:批发开单、零售开单(含门店、美团和微信客服)、出库
- //支出:采购、调拨入库、批发退款、零售退款、店租、水电、伙食
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $mainId;
- $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'];
- $where['time'] = ['between', [$start, $end]];
- $currentStartDate = date('Y-m-d', strtotime($start));
- $currentEndDate = date('Y-m-d', strtotime($end));
- $currentStartTime = $currentStartDate . ' 00:00:00';
- $currentEndTime = $currentEndDate . ' 23:59:59';
- //出库
- $stockOut = StatStockOutClass::getSum($where);
- //采购入库
- $cgWhere = ['mainId' => $mainId, 'status' => 4];
- $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
- $cg = 0;
- if (!empty($cgList)) {
- foreach ($cgList as $cgKey => $cgItem) {
- $actPrice = $cgItem['actPrice'] ?? 0;
- $paidPrice = $cgItem['paidPrice'] ?? 0;
- if ($actPrice <= 0) {
- // 如果$actPrice=0,表示这个采购单已经全部退款,不需要再统计成本,本来$paidPrice要同步清零,但没有,这个问题由徐州邂逅花坊马总,提出的需求发现
- $cg = bcadd($cg, 0, 2);
- } else {
- $total = bcadd($actPrice, $paidPrice, 2);
- //物流费用不算成本。意思是说,长短途运费+提货费+本地运费,这四项和打包费一起,参与到平摊花材运费成本的计算,但那四项不参与总的采购成本登记,因为,有另外地方会独立登记运费成本。
- //$paidPrice 字段说明,此字段表示收货方已付款金额,包括 $localCharge本地运费、 $pickCharge提货费、 $shortCharge短途运费(到付时算,如果不是到付,不算在$paidPrice里)、$longCharge长途运费(到付时算,如果不是到付,不算在$paidPrice里)
- //请搜索关键词 cg_item_cost ,有多处相似情况要考虑
- if (isset($cgItem['isCost']) && $cgItem['isCost'] == 0) {
- $shortCharge = $cgItem['shortCharge'] ?? 0;
- $longCharge = $cgItem['longCharge'] ?? 0;
- $pickCharge = $cgItem['pickCharge'] ?? 0;
- $localCharge = $cgItem['localCharge'] ?? 0;
- $a1 = bcadd($shortCharge, $longCharge, 2);
- $a2 = bcadd($pickCharge, $localCharge, 2);
- $a = bcadd($a1, $a2, 2);
- //注意下面是减号 bcsub
- $total = bcsub($total, $a, 2);
- }
- $cg = bcadd($cg, $total, 2);
- }
- }
- }
- $cg = floatval($cg);
- $lsCgWhere = ['mainId' => $mainId, 'status' => 4, 'belongCost' => 1];
- $lsCgWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $lsCgList = PurchaseClass::getAllByCondition($lsCgWhere, null, '*');
- $lsCgAmount = 0;
- if (!empty($lsCgList)) {
- foreach ($lsCgList as $lsCgItem) {
- $actPrice = $lsCgItem['actPrice'] ?? 0;
- $lsCgAmount = bcadd($lsCgAmount, $actPrice, 2);
- }
- }
- $lsCgAmount = floatval($lsCgAmount);
- $lzWhere = ['mainId' => $mainId, 'status' => 3];
- $lzWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $lzCgList = PlantCgClass::getAllByCondition($lzWhere, null, '*');
- $lzCgAmount = 0;
- if (!empty($lzCgList)) {
- foreach ($lzCgList as $lzInfo) {
- $actPrice = $lzInfo['actPrice'] ?? 0;
- $lzCgAmount = bcadd($actPrice, $lzCgAmount, 2);
- }
- }
- $lzCgAmount = floatval($lzCgAmount);
- //调拨入库
- $stockIn = StatStockInClass::getSum($where);
- $totalOrderNum = 0;
- //批发开单
- $pfIncome = 0;
- $pfSendCost = 0;
- $pfPack = 0;
- $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
- $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- if (!empty($ghsOrderList)) {
- foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
- $actPrice = $ghsOrder['actPrice'] ?? 0;
- $sendCost = $ghsOrder['sendCost'] ?? 0;
- $refundSendCost = $ghsOrder['refundSendCost'] ?? 0;
- $remainSendCost = bcsub($sendCost, $refundSendCost, 2);
- $packCost = $ghsOrder['packCost'] ?? 0;
- $refundPackCost = $ghsOrder['refundPackCost'] ?? 0;
- $remainPackCost = bcsub($packCost, $refundPackCost, 2);
- $pfIncome = bcadd($pfIncome, $actPrice, 2);
- $pfSendCost = bcadd($pfSendCost, $remainSendCost, 2);
- $pfPack = bcadd($pfPack, $remainPackCost, 2);
- $totalOrderNum++;
- }
- }
- //零售开单
- $payCodeIncome = 0;
- $lsAfterSale = 0;
- $lsGiveBalance = 0;
- $lsIncome = 0;
- $lsSendCost = 0;
- $lsServiceFee = 0;
- $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
- $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
- foreach ($hdOrderList as $hdKey => $hdOrder) {
- $actPrice = $hdOrder['mainPay'] ?? 0;
- $onlinePay = $hdOrder['onlinePay'] ?? 1;
- $repeat = $hdOrder['repeat'] ?? 0;
- $forward = $hdOrder['forward'] ?? 0;
- if ($hdOrder['tkPrice'] && $hdOrder['tkPrice'] > 0) {
- $actPrice = bcsub($actPrice, $hdOrder['tkPrice'], 2);
- }
- if ($forward == 1) {
- //零售售后付款
- $lsAfterSale = bcadd($lsAfterSale, $actPrice, 2);
- } else {
- $cash = $hdOrder['cash'] ?? 0;
- $serviceFee = $hdOrder['serviceFee'] ?? 0;
- $sendCost = $hdOrder['sendCost'] ?? 0;
- $lsIncome = bcadd($actPrice, $lsIncome, 2);
- $lsIncome = bcadd($lsIncome, $cash, 2);
- //如果$actPrice<=0,则退款取消先不计算成本
- if ($actPrice > 0) {
- $lsSendCost = bcadd($lsSendCost, $sendCost, 2);
- $lsServiceFee = bcadd($lsServiceFee, $serviceFee, 2);
- }
- $totalOrderNum++;
- if ($onlinePay == 2 && floatval($cash) <= 0 && $repeat == 1) {
- $payCodeIncome = bcadd($payCodeIncome, $actPrice, 2);
- $payCodeIncome = floatval($payCodeIncome);
- }
- $giveBalance = $hdOrder['giveBalance'] ?? 0;
- $giveBalanceTk = $hdOrder['giveBalanceTk'] ?? 0;
- $remainGiveBalance = bcsub($giveBalance, $giveBalanceTk, 2);
- $lsGiveBalance = bcadd($lsGiveBalance, $remainGiveBalance, 2);
- }
- }
- $condition = ['mainId' => $mainId, 'addTime' => ['between', [$currentStartTime, $currentEndTime]],];
- $salary = 0;
- $salaryList = SalaryClass::getAllByCondition($condition, null, '*', null, true);
- if (!empty($salaryList)) {
- foreach ($salaryList as $item) {
- $salary = bcadd($salary, $item->amount, 2);
- }
- }
- $condition = [
- 'mainId' => $mainId,
- 'payTime' => ['between', [$currentStartTime, $currentEndTime]],
- 'delStatus' => 0,
- ];
- $expendList = ExpendClass::getAllByCondition($condition, null, '*', null, true);
- $expendTypeMap = dict::getDict('expendTypeMap');
- $expendAmount = [];
- if (!empty($expendList)) {
- foreach ($expendList as $item) {
- $type = $item->type ?? 0;
- $amount = $item->amount ?? 0;
- $name = $expendTypeMap[$type] ?? '暂无';
- if (!isset($expendAmount[$type]['amount'])) {
- $expendAmount[$type]['amount'] = 0;
- }
- $expendAmount[$type]['name'] = $name;
- $expendAmount[$type]['amount'] = floatval(bcadd($expendAmount[$type]['amount'], $amount, 2));
- }
- }
- $income = [
- ['name' => '批发', 'id' => 'pf', 'amount' => floatval($pfIncome)],
- ['name' => '零售', 'id' => 'ls', 'amount' => floatval($lsIncome)],
- ['name' => '调拨出库', 'id' => 'allot', 'amount' => floatval($stockOut)],
- ];
- $expend = [
- ['name' => '批发运费', 'id' => 'pfSendCost', 'amount' => floatval($pfSendCost)],
- ['name' => '批发包装费', 'id' => 'pfSendCost', 'amount' => floatval($pfPack)],
- ['name' => '零售运费', 'id' => 'lsSendCost', 'amount' => floatval($lsSendCost)],
- ['name' => '零售售后付款', 'id' => 'lsSendCost', 'amount' => floatval($lsAfterSale)],
- ['name' => '美团手续费', 'id' => 'mtFee', 'amount' => floatval($lsServiceFee)],
- ['name' => '花材采购', 'id' => 'cg', 'amount' => floatval($cg)],
- ['name' => '绿植资材采购', 'id' => 'cg', 'amount' => floatval($lzCgAmount)],
- ['name' => '零售花材采购', 'id' => 'cg', 'amount' => floatval($lsCgAmount)],
- ['name' => '调拨入库', 'id' => 'allot', 'amount' => floatval($stockIn)],
- ['name' => '员工工资', 'id' => 'salary', 'amount' => floatval($salary)],
- ['name' => '收款码收入', 'id' => 'salary', 'amount' => floatval($payCodeIncome)],
- ['name' => '零售充值赠送', 'id' => 'salary', 'amount' => floatval($lsGiveBalance)],
- ];
- if (!empty($expendAmount)) {
- foreach ($expendAmount as $it) {
- $expend[] = $it;
- }
- }
- $balance = 0;
- foreach ($income as $it) {
- $amount = $it['amount'] ?? 0;
- $balance = bcadd($amount, $balance, 2);
- }
- foreach ($expend as $it) {
- $amount = $it['amount'] ?? 0;
- $balance = bcsub($balance, $amount, 2);
- }
- return ['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'totalOrderNum' => $totalOrderNum];
- }
- //按花材统计收入 ssh 20231111
- public static function incomeOutItem($mainId)
- {
- $get = Yii::$app->request->get();
- $export = $get['export'] ?? 0;
- $where = [];
- $where['mainId'] = $mainId;
- $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'];
- $where['time'] = ['between', [$start, $end]];
- $currentStartDate = date('Y-m-d', strtotime($start));
- $currentEndDate = date('Y-m-d', strtotime($end));
- $currentStartTime = $currentStartDate . ' 00:00:00';
- $currentEndTime = $currentEndDate . ' 23:59:59';
- $s = strtotime($currentStartTime);
- $e = strtotime($currentEndTime);
- $p = bcsub($e, $s);
- $xx = bcmul(86400, 90);
- if ($p > $xx) {
- util::fail('查询时间不能超过三个月,编号666');
- }
- $productList = ProductClass::getAllByCondition(['mainId' => $mainId], null, 'id,name', 'id');
- if (empty($productList)) {
- util::fail('没有找到花材');
- }
- $arr = [];
- //打包费和运费
- $packFreight = 0;
- $onlyRefundCg = 0;
- $onlyRefund = 0;
- $totalDiscountAmount = 0;
- $totalLabourCost = 0;
- //采购入库
- $tbCgIncome = [];
- $tbCgIncomeStaff = [];
- $cgWhere = ['mainId' => $mainId, 'status' => 4];
- $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
- if (!empty($cgList)) {
- foreach ($cgList as $cgKey => $cgItem) {
- $packingCharge = $cgItem['packingCharge'] ?? 0;
- $shortCharge = $cgItem['shortCharge'] ?? 0;
- $longCharge = $cgItem['longCharge'] ?? 0;
- $pickCharge = $cgItem['pickCharge'] ?? 0;
- $localCharge = $cgItem['localCharge'] ?? 0;
- $packFreight = bcadd($packFreight, $packingCharge, 2);
- $packFreight = bcadd($packFreight, $shortCharge, 2);
- $packFreight = bcadd($packFreight, $longCharge, 2);
- $packFreight = bcadd($packFreight, $pickCharge, 2);
- $packFreight = bcadd($packFreight, $localCharge, 2);
- $tkPrice = $cgItem['tkPrice'] ?? 0;
- $orderSn = $cgItem['orderSn'] ?? '';
- $cgItemInfoList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($cgItemInfoList)) {
- foreach ($cgItemInfoList as $cgData) {
- $itemNum = $cgData->itemNum ?? 0;
- $productId = $cgData->productId ?? 0;
- $refundNum = $cgData->refundNum ?? 0;
- $remainNum = bcsub($itemNum, $refundNum);
- $bigPrice = $cgData->bigPrice ?? 0;
- $amount = bcmul($remainNum, $bigPrice, 2);
- $itemName = $productList[$productId]['name'] ?? '已删除';
- $arr[$productId]['name'] = $itemName;
- $arr[$productId]['id'] = $productId;
- if (isset($arr[$productId]['expend'])) {
- $arr[$productId]['expend'] = bcadd($amount, $arr[$productId]['expend'], 2);
- $arr[$productId]['outNum'] = bcadd($arr[$productId]['outNum'], $remainNum, 2);
- } else {
- $arr[$productId]['expend'] = $amount;
- $arr[$productId]['outNum'] = $remainNum;
- $arr[$productId]['inNum'] = 0;
- $arr[$productId]['income'] = 0;
- }
- }
- if ($tkPrice > 0) {
- $cgRefundOrderList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
- if (!empty($cgRefundOrderList)) {
- foreach ($cgRefundOrderList as $cgRefundOrder) {
- if ($cgRefundOrder->refundType == 2) {
- $onlyRefundCg = bcadd($cgRefundOrder->refundPrice, $onlyRefundCg, 2);
- }
- }
- }
- }
- }
- }
- }
- //批发开单
- $pfIncome = 0;
- $tbSaleIncome = [];
- $tbSaleIncomeStaff = [];
- $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
- $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- if (!empty($ghsOrderList)) {
- foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
- $book = $ghsOrder['book'] ?? 0;
- $status = $ghsOrder['status'] ?? 0;
- if ($book == 1 && $status == 2) {
- //预订单待发货的不算收入
- continue;
- }
- if ($status == 0 || $status == 5) {
- continue;
- }
- $shopAdminId = $ghsOrder['shopAdminId'] ?? 0;
- $shopAdminName = $ghsOrder['shopAdminName'] ?? '';
- $orderSn = $ghsOrder['orderSn'] ?? '';
- $actPrice = $ghsOrder['actPrice'] ?? 0;
- $tkPrice = $ghsOrder['tkPrice'] ?? 0;
- $pfIncome = bcadd($pfIncome, $actPrice, 2);
- $labourCost = $ghsOrder['labourCost'] ?? 0;
- $discountAmount = $ghsOrder['discountAmount'] ?? 0;
- $totalLabourCost = bcadd($labourCost, $totalLabourCost, 2);
- $totalDiscountAmount = bcadd($totalDiscountAmount, $discountAmount, 2);
- $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $orderItem) {
- $refundNum = $orderItem->refundNum ?? 0;
- $name = $orderItem->name ?? '';
- $productId = $orderItem->productId ?? 0;
- $num = $orderItem->xhNum ?? 0;
- $remainNum = bcsub($num, $refundNum);
- $xhUnitPrice = $orderItem->xhUnitPrice ?? 0;
- $amount = bcmul($remainNum, $xhUnitPrice, 2);
- $itemName = $productList[$productId]['name'] ?? '已删除';
- $arr[$productId]['name'] = $itemName;
- $arr[$productId]['id'] = $productId;
- if (isset($arr[$productId]['income'])) {
- $arr[$productId]['income'] = bcadd($amount, $arr[$productId]['income'], 2);
- $arr[$productId]['inNum'] = bcadd($arr[$productId]['inNum'], $remainNum, 2);
- } else {
- $arr[$productId]['expend'] = 0;
- $arr[$productId]['outNum'] = 0;
- $arr[$productId]['inNum'] = $remainNum;
- $arr[$productId]['income'] = $amount;
- }
- //单独统计
- $belongCost = $orderItem->belongCost ?? 0;
- if ($belongCost == 1) {
- if (isset($tbSaleIncome[$productId])) {
- $tbSaleIncome[$productId]['num'] = bcadd($tbSaleIncome[$productId]['num'], $remainNum);
- $tbSaleIncome[$productId]['price'] = bcadd($tbSaleIncome[$productId]['price'], $amount, 2);
- } else {
- $tbSaleIncome[$productId] = ['name' => $name, 'num' => $remainNum, 'price' => $amount];
- }
- if (isset($tbSaleIncomeStaff[$productId]) && isset($tbSaleIncomeStaff[$productId][$shopAdminId])) {
- $tbSaleIncomeStaff[$productId][$shopAdminId]['num'] = bcadd($tbSaleIncomeStaff[$productId][$shopAdminId]['num'], $remainNum);
- $tbSaleIncomeStaff[$productId][$shopAdminId]['price'] = bcadd($tbSaleIncomeStaff[$productId][$shopAdminId]['price'], $amount, 2);
- } else {
- $tbSaleIncomeStaff[$productId][$shopAdminId] = ['name' => $name, 'num' => $remainNum, 'price' => $amount, 'staffName' => $shopAdminName];
- }
- }
- }
- if ($tkPrice > 0) {
- $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
- if (!empty($refundList)) {
- foreach ($refundList as $refund) {
- if ($refund->refundType == 1) {
- //退货退款前面已经考虑,这里不再处理 OK
- } else {
- $onlyRefund = bcadd($onlyRefund, $refund->refundPrice, 2);
- }
- }
- }
- }
- }
- }
- }
- //零售开单
- $lsIncome = 0;
- $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
- $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
- foreach ($hdOrderList as $hdKey => $hdOrder) {
- $actPrice = $hdOrder['mainPay'] ?? 0;
- $cash = $hdOrder['cash'] ?? 0;
- $lsIncome = bcadd($actPrice, $lsIncome, 2);
- $lsIncome = bcadd($lsIncome, $cash, 2);
- $orderSn = $hdOrder['orderSn'] ?? '';
- $tkPrice = $hdOrder['tkPrice'] ?? 0;
- $orderItemList = \bizHd\order\classes\OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $orderItem) {
- $unitPrice = $orderItem->unitPrice ?? 0;
- $refundNum = $orderItem->refundNum ?? 0;
- $num = $orderItem->num ?? 0;
- $productId = $orderItem->itemId ?? 0;
- $remainNum = bcsub($num, $refundNum);
- $amount = bcmul($remainNum, $unitPrice, 2);
- $itemName = $productList[$productId]['name'] ?? '已删除';
- $arr[$productId]['name'] = $itemName;
- $arr[$productId]['id'] = $productId;
- if (isset($arr[$productId]['income'])) {
- $arr[$productId]['income'] = bcadd($amount, $arr[$productId]['income'], 2);
- $arr[$productId]['inNum'] = bcadd($arr[$productId]['inNum'], $remainNum, 2);
- } else {
- $arr[$productId]['expend'] = 0;
- $arr[$productId]['outNum'] = 0;
- $arr[$productId]['inNum'] = $remainNum;
- $arr[$productId]['income'] = $amount;
- }
- }
- if ($tkPrice > 0) {
- $refundList = HdRefundClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($refundList)) {
- foreach ($refundList as $refund) {
- if ($refund->refundType == 2) {
- $onlyRefund = bcadd($onlyRefund, $refund->refundPrice, 2);
- }
- }
- }
- }
- }
- }
- $totalIncome = 0;
- $totalExpend = 0;
- if (!empty($arr)) {
- foreach ($arr as $key => $val) {
- $income = $val['income'] ?? 0;
- $income = floatval($income);
- $totalIncome = bcadd($totalIncome, $income, 2);
- $expend = $val['expend'] ?? 0;
- $expend = floatval($expend);
- $totalExpend = bcadd($totalExpend, $expend, 2);
- $profit = bcsub($income, $expend, 2);
- $arr[$key]['profit'] = floatval($profit);
- $arr[$key]['income'] = floatval($income);
- $arr[$key]['expend'] = floatval($expend);
- }
- }
- //总成本算上物流打包等费用
- $totalExpend = bcadd($totalExpend, $packFreight, 2);
- //总收入算上采购仅退款
- $totalIncome = bcadd($totalIncome, $onlyRefundCg, 2);
- //总收入加上人工费
- $totalIncome = bcadd($totalIncome, $totalLabourCost, 2);
- //总收入减掉优惠金额
- $totalIncome = bcsub($totalIncome, $totalDiscountAmount, 2);
- //总成本算上销售仅退款
- $totalExpend = bcadd($totalExpend, $onlyRefund, 2);
- $totalProfit = bcsub($totalIncome, $totalExpend, 2);
- $totalIncome = floatval($totalIncome);
- $totalExpend = floatval($totalExpend);
- $totalProfit = floatval($totalProfit);
- $arr = array_values($arr);
- $arr = arrayUtil::arraySort($arr, 'profit');
- if ($export == 1) {
- $statData = [
- ['id' => 0, 'name' => '物流打包费', 'income' => 0, 'expend' => $packFreight, 'profit' => -$packFreight, 'inNum' => 0, 'outNum' => 0],
- ['id' => 0, 'name' => '采购仅退款', 'income' => $onlyRefundCg, 'expend' => 0, 'profit' => $onlyRefundCg, 'inNum' => 0, 'outNum' => 0],
- ['id' => 0, 'name' => '销售仅退款', 'income' => 0, 'expend' => $onlyRefund, 'profit' => -$onlyRefund, 'inNum' => 0, 'outNum' => 0],
- ['id' => 0, 'name' => '附加人工费', 'income' => $totalLabourCost, 'expend' => 0, 'profit' => $totalLabourCost, 'inNum' => 0, 'outNum' => 0],
- ['id' => 0, 'name' => '优惠金额', 'income' => -$totalDiscountAmount, 'expend' => 0, 'profit' => -$totalDiscountAmount, 'inNum' => 0, 'outNum' => 0],
- ['id' => 0, 'name' => '【汇总金额】', 'income' => $totalIncome, 'expend' => $totalExpend, 'profit' => $totalProfit, 'inNum' => 0, 'outNum' => 0],
- ];
- $list = array_merge($arr, $statData);
- self::exportIncomeOutItem($list, $mainId);
- }
- util::success(['list' => $arr, 'packFreight' => $packFreight, 'onlyRefundCg' => $onlyRefundCg, 'onlyRefund' => $onlyRefund,
- 'totalIncome' => $totalIncome,
- 'totalExpend' => $totalExpend,
- 'totalProfit' => $totalProfit,
- 'tbSaleIncome' => $tbSaleIncome,
- 'tbCgIncome' => $tbCgIncome,
- 'tbCgIncomeStaff' => $tbCgIncomeStaff,
- 'tbSaleIncomeStaff' => $tbSaleIncomeStaff,
- 'totalLabourCost' => $totalLabourCost,
- 'totalDiscountAmount' => $totalDiscountAmount,
- ]);
- }
- //按分类统计收入 ssh 20231111
- public static function classProfile($mainId)
- {
- $get = Yii::$app->request->get();
- $export = $get['export'] ?? 0;
- $where = [];
- $where['mainId'] = $mainId;
- $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'];
- $where['time'] = ['between', [$start, $end]];
- $currentStartDate = date('Y-m-d', strtotime($start));
- $currentEndDate = date('Y-m-d', strtotime($end));
- $currentStartTime = $currentStartDate . ' 00:00:00';
- $currentEndTime = $currentEndDate . ' 23:59:59';
- $s = strtotime($currentStartTime);
- $e = strtotime($currentEndTime);
- $p = bcsub($e, $s);
- $xx = bcmul(86400, 90);
- if ($p > $xx) {
- util::fail('查询时间不能超过三个月,编号780');
- }
- $classList = ItemClassClass::getAllByCondition(['mainId' => $mainId], null, 'id,name', 'id');
- if (empty($classList)) {
- util::fail('没有找到花材');
- }
- $arr = [];
- //打包费和运费
- $packFreight = 0;
- $onlyRefundCg = 0;
- $onlyRefund = 0;
- $totalDiscountAmount = 0;
- $totalLabourCost = 0;
- //采购入库
- $tbCgIncome = [];
- $tbCgIncomeStaff = [];
- $cgWhere = ['mainId' => $mainId, 'status' => 4];
- $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
- if (!empty($cgList)) {
- foreach ($cgList as $cgKey => $cgItem) {
- $packingCharge = $cgItem['packingCharge'] ?? 0;
- $shortCharge = $cgItem['shortCharge'] ?? 0;
- $longCharge = $cgItem['longCharge'] ?? 0;
- $pickCharge = $cgItem['pickCharge'] ?? 0;
- $localCharge = $cgItem['localCharge'] ?? 0;
- $cgStaffId = $cgItem['cgStaffId'] ?? 0;
- $cgStaffName = $cgItem['cgStaffName'] ?? '';
- $actPrice = $cgItem['actPrice'] ?? 0;
- if ($actPrice <= 0) {
- continue;
- }
- $packFreight = bcadd($packFreight, $packingCharge, 2);
- $packFreight = bcadd($packFreight, $shortCharge, 2);
- $packFreight = bcadd($packFreight, $longCharge, 2);
- $packFreight = bcadd($packFreight, $pickCharge, 2);
- $packFreight = bcadd($packFreight, $localCharge, 2);
- $tkPrice = $cgItem['tkPrice'] ?? 0;
- $orderSn = $cgItem['orderSn'] ?? '';
- $cgItemInfoList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($cgItemInfoList)) {
- foreach ($cgItemInfoList as $cgData) {
- $itemNum = $cgData->itemNum ?? 0;
- $productId = $cgData->productId ?? 0;
- $name = $cgData->name ?? '';
- $refundNum = $cgData->refundNum ?? 0;
- $remainNum = bcsub($itemNum, $refundNum);
- $bigPrice = $cgData->bigPrice ?? 0;
- $amount = bcmul($remainNum, $bigPrice, 2);
- $classId = $cgData->classId;
- $className = $classList[$classId]['name'] ?? '已删除';
- if ($className == '运费') {
- //noticeUtil::push("{$cgData->orderSn}运费项", '15280215347');
- }
- $arr[$classId]['className'] = $className;
- $arr[$classId]['classId'] = $classId;
- if (isset($arr[$classId]['expend'])) {
- $arr[$classId]['expend'] = bcadd($amount, $arr[$classId]['expend'], 2);
- $arr[$classId]['cgNum'] = bcadd($arr[$classId]['cgNum'], $remainNum);
- } else {
- $arr[$classId]['expend'] = $amount;
- $arr[$classId]['income'] = 0;
- $arr[$classId]['cgNum'] = $remainNum;
- $arr[$classId]['saleNum'] = 0;
- }
- //单独统计
- $belongCost = $cgData->belongCost ?? 0;
- if ($belongCost == 1) {
- if (isset($tbCgIncome[$productId])) {
- $tbCgIncome[$productId]['num'] = bcadd($tbCgIncome[$productId]['num'], $remainNum);
- $tbCgIncome[$productId]['price'] = bcadd($tbCgIncome[$productId]['price'], $amount, 2);
- } else {
- $tbCgIncome[$productId] = ['num' => $remainNum, 'name' => $name, 'price' => $amount];
- }
- if (isset($tbCgIncomeStaff[$productId]) && isset($tbCgIncomeStaff[$productId][$cgStaffId])) {
- $tbCgIncomeStaff[$productId][$cgStaffId]['num'] = bcadd($tbCgIncomeStaff[$productId][$cgStaffId]['num'], $remainNum);
- $tbCgIncomeStaff[$productId][$cgStaffId]['price'] = bcadd($tbCgIncomeStaff[$productId][$cgStaffId]['price'], $amount, 2);
- } else {
- $tbCgIncomeStaff[$productId][$cgStaffId] = ['num' => $remainNum, 'name' => $name, 'price' => $amount, 'staffName' => $cgStaffName,];
- }
- }
- }
- if ($tkPrice > 0) {
- $cgRefundOrderList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
- if (!empty($cgRefundOrderList)) {
- foreach ($cgRefundOrderList as $cgRefundOrder) {
- if ($cgRefundOrder->refundType == 2) {
- $onlyRefundCg = bcadd($cgRefundOrder->refundPrice, $onlyRefundCg, 2);
- }
- }
- }
- }
- }
- }
- }
- //批发开单
- $pfIncome = 0;
- $tbSaleIncome = [];
- $tbSaleIncomeStaff = [];
- $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
- $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- if (!empty($ghsOrderList)) {
- foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
- $book = $ghsOrder['book'] ?? 0;
- $status = $ghsOrder['status'] ?? 0;
- if ($book == 1 && $status == 2) {
- //预订单待发货的不算收入
- continue;
- }
- if ($status == 0 || $status == 5) {
- continue;
- }
- $shopAdminId = $ghsOrder['shopAdminId'] ?? 0;
- $shopAdminName = $ghsOrder['shopAdminName'] ?? '';
- $orderSn = $ghsOrder['orderSn'] ?? '';
- $actPrice = $ghsOrder['actPrice'] ?? 0;
- if ($actPrice <= 0) {
- continue;
- }
- $tkPrice = $ghsOrder['tkPrice'] ?? 0;
- $pfIncome = bcadd($pfIncome, $actPrice, 2);
- $labourCost = $ghsOrder['labourCost'] ?? 0;
- $discountAmount = $ghsOrder['discountAmount'] ?? 0;
- $totalLabourCost = bcadd($labourCost, $totalLabourCost, 2);
- $totalDiscountAmount = bcadd($totalDiscountAmount, $discountAmount, 2);
- $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $orderItem) {
- $refundNum = $orderItem->refundNum ?? 0;
- $name = $orderItem->name ?? '';
- $productId = $orderItem->productId ?? 0;
- $num = $orderItem->xhNum ?? 0;
- $remainNum = bcsub($num, $refundNum);
- $classId = $orderItem->classId ?? 0;
- $className = $classList[$classId]['name'] ?? '已删除';
- $xhUnitPrice = $orderItem->xhUnitPrice ?? 0;
- $amount = bcmul($remainNum, $xhUnitPrice, 2);
- $arr[$classId]['className'] = $className;
- $arr[$classId]['classId'] = $classId;
- if (isset($arr[$classId]['income'])) {
- $arr[$classId]['income'] = bcadd($amount, $arr[$classId]['income'], 2);
- $arr[$classId]['saleNum'] = bcadd($arr[$classId]['saleNum'], $remainNum);
- } else {
- $arr[$classId]['expend'] = 0;
- $arr[$classId]['income'] = $amount;
- $arr[$classId]['saleNum'] = $remainNum;
- $arr[$classId]['cgNum'] = 0;
- }
- //单独统计
- $belongCost = $orderItem->belongCost ?? 0;
- if ($belongCost == 1) {
- if (isset($tbSaleIncome[$productId])) {
- $tbSaleIncome[$productId]['num'] = bcadd($tbSaleIncome[$productId]['num'], $remainNum);
- $tbSaleIncome[$productId]['price'] = bcadd($tbSaleIncome[$productId]['price'], $amount, 2);
- } else {
- $tbSaleIncome[$productId] = ['name' => $name, 'num' => $remainNum, 'price' => $amount];
- }
- if (isset($tbSaleIncomeStaff[$productId]) && isset($tbSaleIncomeStaff[$productId][$shopAdminId])) {
- $tbSaleIncomeStaff[$productId][$shopAdminId]['num'] = bcadd($tbSaleIncomeStaff[$productId][$shopAdminId]['num'], $remainNum);
- $tbSaleIncomeStaff[$productId][$shopAdminId]['price'] = bcadd($tbSaleIncomeStaff[$productId][$shopAdminId]['price'], $amount, 2);
- } else {
- $tbSaleIncomeStaff[$productId][$shopAdminId] = ['name' => $name, 'num' => $remainNum, 'price' => $amount, 'staffName' => $shopAdminName];
- }
- }
- }
- if ($tkPrice > 0) {
- $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
- if (!empty($refundList)) {
- foreach ($refundList as $refund) {
- if ($refund->refundType == 1) {
- //退货退款前面已经考虑,这里不再处理 OK
- } else {
- $onlyRefund = bcadd($onlyRefund, $refund->refundPrice, 2);
- }
- }
- }
- }
- }
- }
- }
- //零售开单
- $lsIncome = 0;
- $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]];
- $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
- foreach ($hdOrderList as $hdKey => $hdOrder) {
- $actPrice = $hdOrder['mainPay'] ?? 0;
- $cash = $hdOrder['cash'] ?? 0;
- if ($actPrice <= 0 && $cash <= 0) {
- continue;
- }
- $lsIncome = bcadd($actPrice, $lsIncome, 2);
- $lsIncome = bcadd($lsIncome, $cash, 2);
- $orderSn = $hdOrder['orderSn'] ?? '';
- $tkPrice = $hdOrder['tkPrice'] ?? 0;
- $orderItemList = \bizHd\order\classes\OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $orderItem) {
- $classId = $orderItem->classId ?? 0;
- $unitPrice = $orderItem->unitPrice ?? 0;
- $refundNum = $orderItem->refundNum ?? 0;
- $num = $orderItem->num ?? 0;
- $productId = $orderItem->itemId ?? 0;
- $name = $orderItem->name ?? '';
- $remainNum = bcsub($num, $refundNum);
- $amount = bcmul($remainNum, $unitPrice, 2);
- $className = $classList[$classId]['name'] ?? '已删除';
- $arr[$classId]['className'] = $className;
- $arr[$classId]['classId'] = $classId;
- if (isset($arr[$classId]['income'])) {
- $arr[$classId]['income'] = bcadd($amount, $arr[$classId]['income'], 2);
- $arr[$classId]['saleNum'] = bcadd($arr[$classId]['saleNum'], $remainNum);
- } else {
- $arr[$classId]['expend'] = 0;
- $arr[$classId]['income'] = $amount;
- $arr[$classId]['saleNum'] = $remainNum;
- $arr[$classId]['cgNum'] = 0;
- }
- $belongCost = $orderItem->belongCost ?? 0;
- if ($belongCost == 1) {
- if (isset($tbSaleIncome[$productId])) {
- $tbSaleIncome[$productId]['num'] = bcadd($tbSaleIncome[$productId]['num'], $remainNum);
- $tbSaleIncome[$productId]['price'] = bcadd($tbSaleIncome[$productId]['price'], $amount, 2);
- } else {
- $tbSaleIncome[$productId] = ['name' => $name, 'num' => $remainNum, 'price' => $amount];
- }
- }
- }
- if ($tkPrice > 0) {
- $refundList = HdRefundClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($refundList)) {
- foreach ($refundList as $refund) {
- if ($refund->refundType == 2) {
- $onlyRefund = bcadd($onlyRefund, $refund->refundPrice, 2);
- }
- }
- }
- }
- }
- }
- $totalIncome = 0;
- $totalExpend = 0;
- if (!empty($arr)) {
- foreach ($arr as $key => $val) {
- $income = $val['income'] ?? 0;
- $income = floatval($income);
- $totalIncome = bcadd($totalIncome, $income, 2);
- $expend = $val['expend'] ?? 0;
- $expend = floatval($expend);
- $totalExpend = bcadd($totalExpend, $expend, 2);
- $profit = bcsub($income, $expend, 2);
- $arr[$key]['profit'] = floatval($profit);
- $arr[$key]['income'] = floatval($income);
- $arr[$key]['expend'] = floatval($expend);
- }
- }
- //总成本算上物流打包等费用
- $totalExpend = bcadd($totalExpend, $packFreight, 2);
- //总收入算上采购仅退款
- $totalIncome = bcadd($totalIncome, $onlyRefundCg, 2);
- //总收入加上人工费
- $totalIncome = bcadd($totalIncome, $totalLabourCost, 2);
- //总收入减掉优惠金额
- $totalIncome = bcsub($totalIncome, $totalDiscountAmount, 2);
- //总成本算上销售仅退款
- $totalExpend = bcadd($totalExpend, $onlyRefund, 2);
- $totalProfit = bcsub($totalIncome, $totalExpend, 2);
- $totalIncome = floatval($totalIncome);
- $totalExpend = floatval($totalExpend);
- $totalProfit = floatval($totalProfit);
- $arr = array_values($arr);
- $arr = arrayUtil::arraySort($arr, 'profit');
- if ($export == 1) {
- $statData = [
- ['classId' => 0, 'className' => '物流打包费', 'income' => 0, 'expend' => $packFreight, 'profit' => -$packFreight, 'saleNum' => 0, 'cgNum' => 0],
- ['classId' => 0, 'className' => '采购仅退款', 'income' => $onlyRefundCg, 'expend' => 0, 'profit' => $onlyRefundCg, 'saleNum' => 0, 'cgNum' => 0],
- ['classId' => 0, 'className' => '销售仅退款', 'income' => 0, 'expend' => $onlyRefund, 'profit' => -$onlyRefund, 'saleNum' => 0, 'cgNum' => 0],
- ['classId' => 0, 'className' => '附加人工费', 'income' => $totalLabourCost, 'expend' => 0, 'profit' => $totalLabourCost, 'saleNum' => 0, 'cgNum' => 0],
- ['classId' => 0, 'className' => '优惠金额', 'income' => -$totalDiscountAmount, 'expend' => 0, 'profit' => -$totalDiscountAmount, 'saleNum' => 0, 'cgNum' => 0],
- ['classId' => 0, 'className' => '【汇总金额】', 'income' => $totalIncome, 'expend' => $totalExpend, 'profit' => $totalProfit, 'saleNum' => 0, 'cgNum' => 0],
- ];
- $list = array_merge($arr, $statData);
- self::exportIncomeClass($list, $mainId);
- }
- util::success(['list' => $arr, 'packFreight' => $packFreight, 'onlyRefundCg' => $onlyRefundCg, 'onlyRefund' => $onlyRefund,
- 'totalIncome' => $totalIncome,
- 'totalExpend' => $totalExpend,
- 'totalProfit' => $totalProfit,
- 'tbSaleIncome' => $tbSaleIncome,
- 'tbCgIncome' => $tbCgIncome,
- 'tbCgIncomeStaff' => $tbCgIncomeStaff,
- 'tbSaleIncomeStaff' => $tbSaleIncomeStaff,
- 'totalLabourCost' => $totalLabourCost,
- 'totalDiscountAmount' => $totalDiscountAmount,
- ]);
- }
- public static function exportIncomeOutItem($list, $mainId)
- {
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel.php');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Document")
- ->setSubject("Office 2007 XLSX Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("file");
- $ghsTitle = '供货商';
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', '名称');
- $objPHPExcel->getActiveSheet()->setCellValue('B1', '销售收入');
- $objPHPExcel->getActiveSheet()->setCellValue('C1', '销售数量');
- $objPHPExcel->getActiveSheet()->setCellValue('D1', '采购成本');
- $objPHPExcel->getActiveSheet()->setCellValue('E1', '采购数量');
- $objPHPExcel->getActiveSheet()->setCellValue('F1', '利润');
- //设置宽度
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- //加粗
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $baseRow = 2;
- foreach ($list as $key => $custom) {
- $i = $baseRow + $key;
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['name']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['income']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['inNum']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['expend']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['outNum']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $custom['profit']);
- //居左
- $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- }
- $fileName = '收支花材-' . date("m-d");
- $objPHPExcel->getActiveSheet()->setTitle($fileName);
- $objPHPExcel->setActiveSheetIndex(0);
- $dir = './priceTable/' . $mainId;
- if (file_exists($dir) == false) {
- mkdir($dir, 0777, true);
- }
- $date = $fileName;
- $file = $date . '.xls';
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- if (file_exists($dir . '/' . $file)) {
- unlink($dir . '/' . $file);
- }
- $objWriter->save($dir . '/' . $file);
- $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $file]);
- }
- public static function exportIncomeClass($list, $mainId)
- {
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel.php');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Document")
- ->setSubject("Office 2007 XLSX Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("file");
- $ghsTitle = '供货商';
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', '名称');
- $objPHPExcel->getActiveSheet()->setCellValue('B1', '销售数量');
- $objPHPExcel->getActiveSheet()->setCellValue('C1', '销售收入');
- $objPHPExcel->getActiveSheet()->setCellValue('D1', '采购数量');
- $objPHPExcel->getActiveSheet()->setCellValue('E1', '采购成本');
- $objPHPExcel->getActiveSheet()->setCellValue('F1', '利润');
- //设置宽度
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
- //加粗
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $baseRow = 2;
- foreach ($list as $key => $custom) {
- $i = $baseRow + $key;
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['className']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['saleNum']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['income']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['cgNum']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['expend']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $custom['profit']);
- //居左
- $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- }
- $fileName = '收支分类-' . time();
- $objPHPExcel->getActiveSheet()->setTitle($fileName);
- $objPHPExcel->setActiveSheetIndex(0);
- $dir = './priceTable/' . $mainId;
- if (file_exists($dir) == false) {
- mkdir($dir, 0777, true);
- }
- $date = $fileName;
- $file = $date . '.xls';
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- if (file_exists($dir . '/' . $file)) {
- unlink($dir . '/' . $file);
- }
- $objWriter->save($dir . '/' . $file);
- $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $file]);
- }
- public static function exportItemSale($list, $mainId)
- {
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel.php');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Document")
- ->setSubject("Office 2007 XLSX Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("file");
- $ghsTitle = '供货商';
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', '名称');
- $objPHPExcel->getActiveSheet()->setCellValue('B1', '总数量');
- $objPHPExcel->getActiveSheet()->setCellValue('C1', '总金额');
- $objPHPExcel->getActiveSheet()->setCellValue('D1', '毛利');
- $objPHPExcel->getActiveSheet()->setCellValue('E1', '毛利率');
- //设置宽度
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
- //加粗
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $baseRow = 2;
- foreach ($list as $key => $custom) {
- $i = $baseRow + $key;
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['name']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['num']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['amount']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['gross']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['mll'] . '%');
- //居左
- $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- }
- $fileName = '花材销量-' . date("m-d");
- $objPHPExcel->getActiveSheet()->setTitle($fileName);
- $objPHPExcel->setActiveSheetIndex(0);
- $dir = './priceTable/' . $mainId;
- if (file_exists($dir) == false) {
- mkdir($dir, 0777, true);
- }
- $date = $fileName;
- $file = $date . '.xls';
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- if (file_exists($dir . '/' . $file)) {
- unlink($dir . '/' . $file);
- }
- $objWriter->save($dir . '/' . $file);
- $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $file]);
- }
- public static function send($mainId)
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $mainId;
- $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'];
- $where['time'] = ['between', [$start, $end]];
- $currentStartDate = date('Y-m-d', strtotime($start));
- $currentEndDate = date('Y-m-d', strtotime($end));
- $currentStartTime = $currentStartDate . ' 00:00:00';
- $currentEndTime = $currentEndDate . ' 23:59:59';
- $s = strtotime($currentStartTime);
- $e = strtotime($currentEndTime);
- $p = bcsub($e, $s);
- $xx = bcmul(86400, 90);
- if ($p > $xx) {
- util::fail('查询时间不能超过三个月,编号699');
- }
- $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
- $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- $arr = [];
- if (!empty($ghsOrderList)) {
- foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
- $book = $ghsOrder['book'] ?? 0;
- $status = $ghsOrder['status'] ?? 0;
- if ($book == 1 && $status == 2) {
- //预订单待发货的不算收入
- continue;
- }
- if ($status == 0 || $status == 5) {
- continue;
- }
- $orderSn = $ghsOrder['orderSn'] ?? '';
- $actPrice = $ghsOrder['actPrice'] ?? 0;
- if ($actPrice <= 0) {
- continue;
- }
- $sendStaffId = $ghsOrder['sendStaffId'] ?? 0;
- $sendStaffName = isset($ghsOrder['sendStaffName']) && !empty($ghsOrder['sendStaffName']) ? $ghsOrder['sendStaffName'] : '未记名';
- if (isset($arr[$sendStaffId])) {
- $arr[$sendStaffId]['orderNum'] = bcadd($arr[$sendStaffId]['orderNum'], 1);
- $arr[$sendStaffId]['amount'] = bcadd($arr[$sendStaffId]['amount'], $actPrice, 2);
- } else {
- $arr[$sendStaffId] = ['staffName' => $sendStaffName, 'orderNum' => 1, 'itemNum' => 0, 'amount' => $actPrice, 'staffId' => $sendStaffId];
- }
- $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $orderItem) {
- $refundNum = $orderItem->refundNum ?? 0;
- $num = $orderItem->xhNum ?? 0;
- $remainNum = bcsub($num, $refundNum);
- $arr[$sendStaffId]['itemNum'] = bcadd($arr[$sendStaffId]['itemNum'], $remainNum);
- }
- }
- }
- }
- if (!empty($arr)) {
- $arr = array_values($arr);
- }
- return $arr;
- }
- }
|