| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace bizGhs\stat\classes;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizGhs\shop\models\ShopAdmin;
- use common\components\arrayUtil;
- use common\components\dateUtil;
- use Yii;
- use bizGhs\base\classes\BaseClass;
- class StatYjClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\stat\models\StatYj';
- 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';
- $arr = [];
- //批发开单
- $where = ['mainId' => $mainId];
- $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $ghsOrderList = OrderClass::getAllByCondition($where, null, '*');
- if (!empty($ghsOrderList)) {
- foreach ($ghsOrderList as $ghsKey => $ghsOrder) {
- $shopAdminId = $ghsOrder['shopAdminId'] ?? 0;
- $shopAdminName = $ghsOrder['shopAdminName'] ?? '';
- $actPrice = $ghsOrder['actPrice'] ?? 0;
- $arr[$shopAdminId]['id'] = $shopAdminId;
- $arr[$shopAdminId]['name'] = $shopAdminName;
- if (isset($arr[$shopAdminId]['pfAmount']) == false) {
- $arr[$shopAdminId]['pfAmount'] = 0;
- $arr[$shopAdminId]['pfNum'] = 0;
- }
- if (isset($arr[$shopAdminId]['amount']) == false) {
- $arr[$shopAdminId]['amount'] = 0;
- $arr[$shopAdminId]['num'] = 0;
- }
- $arr[$shopAdminId]['pfAmount'] = bcadd($arr[$shopAdminId]['pfAmount'], $actPrice, 2);
- $arr[$shopAdminId]['pfNum'] = bcadd($arr[$shopAdminId]['pfNum'], 1);
- $arr[$shopAdminId]['num'] = bcadd($arr[$shopAdminId]['num'], 1);
- $arr[$shopAdminId]['amount'] = bcadd($arr[$shopAdminId]['amount'], $actPrice, 2);
- }
- }
- $hdWhere = ['mainId' => $mainId];
- $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $hdOrderList = \bizHd\order\classes\OrderClass::getAllByCondition($hdWhere, null, '*');
- if (!empty($hdOrderList)) {
- foreach ($hdOrderList as $hdKey => $hdOrder) {
- $shopAdminId = $hdOrder['shopAdminId'] ?? 0;
- $shopAdminName = $hdOrder['shopAdminName'] ?? '';
- $actPrice = $hdOrder['actPrice'] ?? 0;
- $arr[$shopAdminId]['id'] = $shopAdminId;
- $arr[$shopAdminId]['name'] = $shopAdminName;
- if (isset($arr[$shopAdminId]['lsAmount']) == false) {
- $arr[$shopAdminId]['lsAmount'] = 0;
- $arr[$shopAdminId]['lsNum'] = 0;
- }
- if (isset($arr[$shopAdminId]['amount']) == false) {
- $arr[$shopAdminId]['amount'] = 0;
- $arr[$shopAdminId]['num'] = 0;
- }
- $arr[$shopAdminId]['lsAmount'] = bcadd($arr[$shopAdminId]['lsAmount'], $actPrice, 2);
- $arr[$shopAdminId]['lsNum'] = bcadd($arr[$shopAdminId]['lsNum'], 1);
- $arr[$shopAdminId]['num'] = bcadd($arr[$shopAdminId]['num'], 1);
- $arr[$shopAdminId]['amount'] = bcadd($arr[$shopAdminId]['amount'], $actPrice, 2);
- }
- }
- if (!empty($arr)) {
- $ids = array_keys($arr);
- $staffList = ShopAdminClass::getByIds($ids, null, 'id');
- foreach ($arr as $shopAdminId => $val) {
- $name = $staffList[$shopAdminId]['name'] ?? '商城';
- $arr[$shopAdminId]['name'] = $name;
- }
- }
- return array_values($arr);
- }
- //业绩列表 ssh 2021.3.15
- public static function getYjList($where)
- {
- $data = self::getList('*', $where, 'addTime DESC');
- $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
- if (empty($list)) {
- return $data;
- }
- $arr = [];
- foreach ($data['list'] as $key => $val) {
- $shopAdminId = $val['shopAdminId'];
- if (isset($arr[$shopAdminId]) == false) {
- $arr[$shopAdminId] = ['amount' => 0, 'num' => 0];
- }
- $arr[$shopAdminId]['amount'] = bcadd($val['amount'], $arr[$shopAdminId]['amount'], 2);
- $arr[$shopAdminId]['num'] = bcadd($val['num'], $arr[$shopAdminId]['num']);
- }
- $ids = array_keys($arr);
- $admin = ShopAdminClass::getByIds($ids);
- $show = [];
- foreach ($admin as $key => $val) {
- $adminId = $val['id'];
- $name = $val['name'] ?? '';
- $amount = $arr[$adminId]['amount'] ?? 0.00;
- $num = $arr[$adminId]['num'] ?? 0;
- $show[] = [
- 'name' => $name,
- 'amount' => $amount,
- 'num' => $num,
- 'id' => $val['id'],
- ];
- }
- //排序
- $show = arrayUtil::arraySort($show, 'amount');
- return ['list' => $show];
- }
- //增加业绩 ssh 2021.3.20
- public static function addYj($main, $shop, $shopAdminId, $amount, $date = null)
- {
- $sjId = $shop->sjId ?? 0;
- $mainId = $main->id ?? 0;
- $date = isset($date) ? $date : date("Ymd");
- $stat = self::getByCondition(['shopAdminId' => $shopAdminId, 'mainId' => $mainId, 'sjId' => $sjId, 'time' => $date], true);
- if (empty($stat)) {
- $stat = self::add(['sjId' => $sjId, 'shopAdminId' => $shopAdminId, 'mainId' => $mainId, 'time' => $date], true);
- }
- $stat->num += 1;
- $stat->totalNum += 1;
- $stat->amount = bcadd($amount, $stat->amount, 2);
- $stat->totalAmount = bcadd($amount, $stat->totalAmount, 2);
- $stat->save();
- StatYjMonthClass::addYj($main, $shop, $shopAdminId, $amount);
- }
- }
|