| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace bizGhs\stat\classes;
- use biz\stat\classes\StatCgClass;
- use biz\stat\classes\StatStockInClass;
- use biz\stat\classes\StatStockOutClass;
- use bizGhs\expend\classes\ExpendClass;
- use bizGhs\staff\classes\SalaryClass;
- use bizHd\order\classes\OrderClass as HdOrderClass;
- use bizGhs\order\classes\OrderClass;
- use common\components\dateUtil;
- use common\components\dict;
- use Yii;
- use bizGhs\base\classes\BaseClass;
- class StatSaleClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\stat\models\StatSale';
- public static function profile($mainId)
- {
- //收入:批发开单、零售开单(含门店、美团和微信客服)、出库
- //支出:采购、调拨入库、批发退款、零售退款、店租、水电、伙食
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $mainId;
- $searchTime = 'today';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- //出库
- $stockOut = StatStockOutClass::getSum($where);
- //采购入库
- $cg = StatCgClass::getSum($where);
- //调拨入库
- $stockIn = StatStockInClass::getSum($where);
- $totalOrderNum = 0;
- $todayDate = date('Y-m-d');
- $todayStartTime = $todayDate . ' 00:00:00';
- $todayEndTime = $todayDate . ' 23:59:59';
- //批发开单
- $pfIncome = 0;
- $pfSendCost = 0;
- $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]];
- $where['payTime'] = ['between', [$todayStartTime, $todayEndTime]];
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- if (!empty($ghsOrderList)) {
- foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
- $actPrice = $ghsOrder['actPrice'] ?? 0;
- $sendCost = $ghsOrder['sendCost'] ?? 0;
- $pfIncome = bcadd($pfIncome, $actPrice, 2);
- $pfSendCost = bcadd($pfSendCost, $sendCost, 2);
- $totalOrderNum++;
- }
- }
- //零售开单
- $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', [$todayStartTime, $todayEndTime]];
- $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
- foreach ($hdOrderList as $hdKey => $hdOrder) {
- $actPrice = $hdOrder['actPrice'] ?? 0;
- $serviceFee = $hdOrder['serviceFee'] ?? 0;
- $sendCost = $hdOrder['sendCost'] ?? 0;
- $lsIncome = bcadd($actPrice, $lsIncome, 2);
- $lsSendCost = bcadd($lsSendCost, $sendCost, 2);
- $lsServiceFee = bcadd($lsServiceFee, $serviceFee, 2);
- $totalOrderNum++;
- }
- $condition = ['mainId' => $mainId, 'addTime' => ['between', [$todayStartTime, $todayEndTime]],];
- $salary = 0;
- $salaryList = SalaryClass::getAllByCondition($condition, null, '*', null, true);
- if (!empty($salaryList)) {
- foreach ($salaryList as $item) {
- $salary = bcadd($salary, $item->amount, 2);
- }
- }
- $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']) == false) {
- $expendAmount[$type]['amount'] = 0;
- }
- $expendAmount[$type]['name'] = $name;
- $expendAmount[$type]['amount'] = floatval(bcadd($expendAmount[$type]['amount'], $amount, 2));
- }
- }
- $income = [
- ['name' => '批发销售', 'amount' => floatval($pfIncome)],
- ['name' => '零售销售', 'amount' => floatval($lsIncome)],
- ['name' => '调拨出库', 'amount' => floatval($stockOut)],
- ];
- $expend = [
- ['name' => '批发运费', 'amount' => floatval($pfSendCost)],
- ['name' => '零售运费', 'amount' => floatval($lsSendCost)],
- ['name' => '美团手续费', 'amount' => floatval($lsServiceFee)],
- ['name' => '采购', 'amount' => floatval($cg)],
- ['name' => '调拨入库', 'amount' => floatval($stockIn)],
- ['name' => '员工工资', '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];
- }
- }
|