1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- /**
- * @Name
- * @Description
- * @Author 刘学玺
- * @Date 2023/11/23 20:57
- */
- namespace App\Http\Services\Admin\Finance;
- use App\Http\Services\BaseService;
- use App\Models\Distributor;
- use App\Models\Menu;
- use App\Models\StatisticIncome;
- use Illuminate\Support\Facades\DB;
- class StatisticService extends BaseService
- {
- public function income($data)
- {
- $model = $this->queryCondition(StatisticIncome::query(), $data);
- if (!empty($data['province'])) {
- $model->where('province', $data['province']);
- }
- if (!empty($data['city'])) {
- $model->where('city', $data['city']);
- }
- $amountModel = clone $model;
- $model->select(['province', 'city', 'district']);
- $selectColumn = "SUM(order_count) as order_count,SUM(pay_price) as pay_price,SUM(artificer_income) as artificer_income,SUM(promotion_income) as promotion_income,SUM(total_income) as total_income,SUM(platform_income) as platform_income,SUM(agent_income) as agent_income,SUM(market_income) as market_income";
- $amountModel->selectRaw($selectColumn);
- if (!empty($data['type']) && $data['type'] !== '0') {
- // $model->selectRaw("SUM(order_count) as order_count,SUM(pay_price) as pay_price,SUM(artificer_income) as artificer_income,SUM(promotion_income) as promotion_income,SUM(total_income) as total_income,SUM(platform_income) as platform_income,SUM(agent_income) as agent_income,SUM(market_income) as market_income");
- $model->selectRaw($selectColumn);
- // 按月查询
- if ($data['type'] === '1') {
- $model->selectRaw("DATE_FORMAT(`time`, '%Y-%m') as month")
- ->groupBy(['province', 'city', 'district', 'month'])
- // ->latest('month');
- ->orderByDesc('month');
- if (!empty($data['month'])) {
- $where = [
- ['time', 'like', "%${data['month']}%"]
- ];
- // $model->where('time', 'like', "%${data['month']}%");
- $model->where($where);
- $amountModel->where($where);
- }
- }
- // 按年查询
- if ($data['type'] === '2') {
- $model->selectRaw("DATE_FORMAT(`time`, '%Y') as year")
- ->groupBy(['province', 'city', 'district', 'year'])
- // ->latest('year');
- ->orderByDesc('year');
- if (!empty($data['year'])) {
- $where = [
- ['time', 'like', "%${data['year']}%"]
- ];
- $model->where($where);
- $amountModel->where($where);
- // $model->where('time', 'like', "%${data['year']}%");
- }
- }
- } else {
- $model->selectRaw('time as date,order_count,pay_price,artificer_income,promotion_income,total_income,platform_income,agent_income,market_income')
- // ->latest('id');
- ->orderByDesc('date');
- if (!empty($data['date'])) {
- $where = [
- ['time', 'like', "%${data['date']}%"]
- ];
- $model->where($where);
- $amountModel->where($where);
- // $model->where('time', 'like', "%${data['date']}%");
- }
- }
- $amountData = $amountModel->first()->toArray();
- $list = $model->orderBy('province')
- ->orderBy('city')
- ->orderBy('district')
- ->paginate($data['pageSize'])
- ->toArray();
- return $this->apiSuccess('', [
- 'list' => $list['data'],
- 'total' => $list['total'],
- 'amountData' => $amountData
- ]);
- }
- }
|