| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\AccountLogModel;
- use App\Services\BaseService;
- use Illuminate\Support\Facades\DB;
- /**
- * 交易管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class AccountLogService
- * @package App\Services\Common
- */
- class AccountLogService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * AccountService constructor.
- */
- public function __construct()
- {
- $this->model = new AccountLogModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['mark' => 1];
- $status = isset($params['status'])? $params['status'] : 0;
- $type = isset($params['type'])? $params['type'] : 0;
- $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
- $userType = isset($params['user_type'])? $params['user_type'] : 0;
- $userId = isset($params['user_id'])? $params['user_id'] : 0;
- $merchId = isset($params['merch_id'])? $params['merch_id'] : 0;
- if($status>0){
- $where['status'] = $status;
- }else{
- $where['status'] = 1;
- }
- if($type>0){
- $where['type'] = $type;
- }
- if($coinType>0){
- $where['coin_type'] = $coinType;
- }
- if($userId>0 && $merchId<=0){
- $where['user_id'] = $userId;
- }
- if($merchId>0){
- $where['merch_id'] = $merchId;
- }
- $year = isset($params['year']) && $params['year']? $params['year'] : '';
- $month = isset($params['month']) && $params['month']? $params['month'] : '';
- $date = $year&&$month? "{$year}-{$month}" : '';
- $date = $date? $date : date('Y');
- if(!$table = $this->model->getTable($year)){
- return false;
- }
- $model = DB::table($table)->where($where)->where(function($query) use($userType,$year,$month){
- if($userType>0){
- $query->whereIn('user_type', [0, $userType]);
- }
- $date = $year&&$month? "{$year}-{$month}" : '';
- $date = $date? $date : date('Y-m');
- if($month){
- $query->where('date', 'like', "{$date}%");
- }else{
- $query->where('date', 'like', "{$year}%");
- }
- });
- // 统计
- $countModel = clone $model;
- $countModel1 = clone $model;
- $counts = [
- 'expend'=> moneyFormat(abs($countModel->where('money','<', 0)->sum('money')), 2),
- 'income'=> moneyFormat($countModel1->where('money','>', 0)->sum('money'), 2),
- ];
- $list = $model->select(['*'])
- ->orderBy('create_time','desc')
- ->orderBy('id','desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list? $list->toArray() :[];
- if($list){
- foreach($list['data'] as &$item){
- $item->time_text = $item->create_time? dateFormat($item->create_time,'m月d日 H:i') : date('Y年m月');
- $item->create_time = $item->create_time? datetime($item->create_time,'Y-m-d H.i.s') : '';
- $titles = ['','服务消费','商城消费','佣金结算','平台调整','余额充值','余额转账','退款','聊天付费','简历付费','代理佣金','账户余额提现','商户余额提现'];
- $item->remark = $item->remark? $item->remark : (isset($titles[$item->remark])? $titles[$item->remark]:'其他');
- }
- unset($item);
- }
- return [
- 'pageSize'=> $pageSize,
- 'counts'=> $counts,
- 'date'=> $date,
- 'total'=>isset($list['total'])? $list['total'] : 0,
- 'list'=> isset($list['data'])? $list['data'] : []
- ];
- }
- /**
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getCounts($params, $pageSize = 15)
- {
- $where = ['mark' => 1];
- $status = isset($params['status'])? $params['status'] : 0;
- $type = isset($params['type'])? $params['type'] : 0;
- $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
- $countType = isset($params['count_type'])? $params['count_type'] : 0;
- $userId = isset($params['user_id'])? $params['user_id'] : 0;
- $merchId = isset($params['merch_id'])? $params['merch_id'] : 0;
- if($status>0){
- $where['status'] = $status;
- }else{
- $where['status'] = 1;
- }
- if($type>0){
- $where['type'] = $type;
- }
- if($coinType>0){
- $where['coin_type'] = $coinType;
- }
- if($userId>0 && $merchId<=0){
- $where['user_id'] = $userId;
- }
- if($merchId>0){
- $where['merch_id'] = $merchId;
- }
- $year = isset($params['year']) && $params['year']? $params['year'] : '';
- $month = isset($params['month']) && $params['month']? $params['month'] : '';
- $types = [1=>'服务消费',2=>'商城消费',3=>'佣金结算',4=>'平台调整',5=>'余额充值',6=>'余额转账',7=>'退款',8=>'聊天付费',9=>'简历付费',11=>'账户余额提现',99=>'其他'];
- if(!$table = $this->model->getTable($year)){
- return false;
- }
- $userType = isset($params['user_type'])? $params['user_type'] : 0;
- $model = new AccountLogModel($table);
- $model = $model->where($where)->where(function($query) use($userType,$countType,$year,$month){
- if($userType>0){
- $query->whereIn('user_type', [0, $userType]);
- }
- if($countType == 1){
- $query->where('money', '<', 0);
- }else{
- $query->where('money', '>', 0);
- }
- $date = $year&&$month? "{$year}-{$month}" : '';
- $date = $date? $date : date('Y-m');
- if($month){
- $query->where('date', 'like', "{$date}%");
- }else{
- $query->where('date', 'like', "{$year}%");
- }
- });
- $model1 = clone $model;
- $total = abs(moneyFormat($model->sum('money'),2));
- $count = $model1->count('id');
- $list = [];
- $sums = $model1->select(['type',DB::raw('sum(money) as total')])
- ->groupBy('type')
- ->get()->keyBy('type');
- $sums = $sums? $sums->toArray() : [];
- foreach ($types as $k => $name){
- $sum = isset($sums[$k]['total'])? abs(moneyFormat($sums[$k]['total'],2)) : 0;
- if($sum>0){
- $list[] = [
- 'id'=> $k,
- 'name'=> $name,
- 'total'=> $sum,
- 'rate'=> round($sum/$total*100,2),
- ];
- }
- }
- return [
- 'counts'=> ['total'=> $total,'count'=> $count],
- 'list'=> $list,
- ];
- }
- }
|