| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace ghs\controllers;
- use biz\stat\classes\StatKhCgClass;
- use bizGhs\custom\classes\CustomClass;
- use common\components\arrayUtil;
- use common\components\dateUtil;
- use Yii;
- use common\components\util;
- class StatKhCgController extends BaseController
- {
- //客户采购列表 ssh 20211017
- public function actionProfile()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['shopId'] = $this->shopId;
- if (isset($get['shopId']) && !empty($get['shopId'])) {
- $where['shopId'] = $get['shopId'];
- }
- $searchTime = $get['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']]];
- }
- $list = StatKhCgClass::getAllByCondition($where, null, '*');
- $customIds = [];
- $arr = [];
- if (!empty($list)) {
- foreach ($list as $ke => $item) {
- $customId = $item['customId'] ?? 0;
- $num = $item['num'] ?? 0;
- $refundNum = $item['refundNum'] ?? 0;
- $amount = $item['amount'] ?? 0;
- $refundAmount = $item['refundAmount'] ?? 0;
- $customIds[$customId] = 1;
- if (isset($arr[$customId]['num'])) {
- $arr[$customId]['num'] = bcadd($arr[$customId]['num'], $num, 2);
- } else {
- $arr[$customId]['num'] = $num;
- }
- if (isset($arr[$customId]['refundNum'])) {
- $arr[$customId]['refundNum'] = bcadd($arr[$customId]['refundNum'], $refundNum, 2);
- } else {
- $arr[$customId]['refundNum'] = $refundNum;
- }
- if (isset($arr[$customId]['amount'])) {
- $arr[$customId]['amount'] = bcadd($arr[$customId]['amount'], $amount, 2);
- } else {
- $arr[$customId]['amount'] = $amount;
- }
- if (isset($arr[$customId]['refundAmount'])) {
- $arr[$customId]['refundAmount'] = bcadd($arr[$customId]['refundAmount'], $refundAmount, 2);
- } else {
- $arr[$customId]['refundAmount'] = $refundAmount;
- }
- }
- }
- $customIds = array_keys($customIds);
- $customData = CustomClass::getByIds($customIds);
- $map = CustomClass::$levelMap;
- $cg = [];
- foreach ($customData as $custom) {
- $customId = $custom['id'] ?? 0;
- $customName = $custom['name'] ?? '';
- $customPy = $custom['py'] ?? '';
- $num = $arr[$customId]['num'] ?? 0;
- $refundNum = $arr[$customId]['refundNum'] ?? 0;
- $amount = $arr[$customId]['amount'] ?? 0;
- $refundAmount = $arr[$customId]['refundAmount'] ?? 0;
- $lastAmount = bcsub($amount, $refundAmount, 2);
- $lastNum = bcsub($num, $refundNum, 2);
- $level = $custom['level'] ?? 0;
- $levelName = $map[$level] ?? '';
- $cg[] = [
- 'customId' => $customId,
- 'customName' => $customName,
- 'py' => $customPy,
- 'num' => $lastNum,
- 'amount' => $lastAmount,
- 'levelName' => $levelName,
- ];
- }
- $cg = arrayUtil::arraySort($cg, 'num');
- util::success(['list' => $cg]);
- }
- }
|