| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace bizGhs\stat\classes;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizGhs\shop\models\ShopAdmin;
- use common\components\arrayUtil;
- use Yii;
- use bizGhs\base\classes\BaseClass;
- class StatYjClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\stat\models\StatYj';
- //业绩列表 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);
- }
- }
|