// +---------------------------------------------------------------------- namespace App\Services\Api; use App\Models\AccountLogModel; use App\Models\BalanceLogModel; use App\Services\BaseService; use Illuminate\Support\Facades\DB; /** * 余额日志管理-服务类 * @author laravel开发员 * @since 2020/11/11 * Class BalanceLogService * @package App\Services\Common */ class BalanceLogService extends BaseService { /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 * BalanceLogService constructor. */ public function __construct() { $this->model = new BalanceLogModel(); } /** * 静态入口 * @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; $userType = isset($params['user_type'])? $params['user_type'] : 0; $coinType = isset($params['coin_type'])? $params['coin_type'] : 0; $userId = isset($params['user_id'])? $params['user_id'] : 0; if($status>0){ $where['status'] = $status; } if($type>0){ $where['type'] = $type; } if($userId>0){ $where['user_id'] = $userId; } if($coinType>0){ $where['coin_type'] = $coinType; } $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'); $model = $this->model->with(['payment'])->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 = [ 'wait'=> moneyFormat($countModel->where(['status'=>1])->sum('money'), 2), 'checked'=> moneyFormat($countModel1->where(['status'=>2])->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') : ''; $item['pay_at'] = $item['pay_at'] && $item['pay_at'] !='0000-00-00 00:00:00'? $item['pay_at'] : $item['create_time']; $item['payment'] = isset($item['payment'])? $item['payment'] : []; $item['pay_img'] = $item['pay_img']? get_image_url($item['pay_img']) : ''; if($item['payment'] && isset($item['payment']['qrcode'])){ $item['payment']['qrcode'] = get_image_url($item['payment']['qrcode']); } if($item['payment'] && isset($item['payment']['bank_card'])){ $item['payment']['bank_card_text'] = format_bank_card($item['payment']['bank_card']); } } unset($item); } return [ 'pageSize'=> $pageSize, 'counts'=> $counts, 'date'=> $date, 'total'=>isset($list['total'])? $list['total'] : 0, 'list'=> isset($list['data'])? $list['data'] : [] ]; } }