| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371 |
- <?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;
- $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);
- }
- }
- }
- $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)],
- ];
- 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, 'payCodeIncome' => $payCodeIncome];
- }
- //按花材统计收入 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('查询时间不能超过三个月');
- }
- $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('查询时间不能超过三个月');
- }
- $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('查询时间不能超过三个月');
- }
- $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;
- }
- }
|