| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\PledgeOrderModel;
- use App\Services\BaseService;
- /**
- * 质押订单管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Common
- */
- class PledgeOrderService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new PledgeOrderModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 获取列表
- * @param $params 参数
- * @param int $pageSize 分页大小:默认 15
- * @return array
- */
- public function getDataList($params, $pageSize = 10, $field = [])
- {
- $query = $this->getQuery($params);
- $list = $query->select($field ? $field : ['a.*', 'b.nickname','b.wallet_url'])
- ->orderBy('a.create_time','desc')
- ->orderBy('a.id','desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['create_time'] = datetime($item['create_time'],'Y-m-d H:i:s');
- if($item['user_type'] == 1){
- $item['uid'] = $item['user_id'];
- $item['account'] = isset($item['nickname'])&& $item['nickname']? $item['nickname'] : $item['user_id'];
- }
- }
- }
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- /**
- * 查询构造
- * @param $params
- * @return \Illuminate\Database\Eloquent\Builder
- */
- public function getQuery($params)
- {
- $where = ['a.mark' => 1];
- return $this->model->with(['member'])
- ->from('pledge_orders as a')
- ->leftJoin('member as b', function($join) {
- $join->on('b.id','=', 'a.user_id');
- })
- ->where($where)
- ->where(function ($query) use ($params) {
- $kw = isset($params['keyword']) ? trim($params['keyword']) : '';
- if ($kw) {
- $query->where('b.id', '=', $params['keyword'])
- ->orWhere('b.nickname', 'like', "%{$params['keyword']}%")
- ->orWhere('b.wallet_url', '=', trim($params['keyword']));
- }
- })
- ->where(function ($query) use($params){
- // 日期
- $date = isset($params['date']) ? $params['date'] : [];
- $start = isset($date[0])? $date[0] : '';
- $end = isset($date[1])? $date[1] : '';
- $end = $start>$end? '' : $end;
- if ($start) {
- $query->where('a.create_time','>=', strtotime($start));
- }
- if($end){
- $query->where('a.create_time','<=', strtotime($end));
- }
- $orderNo = isset($params['order_no'])? trim($params['order_no']) : '';
- if($orderNo){
- $query->where('a.order_no', 'like', "%{$orderNo}%");
- }
- $status = isset($params['status'])? $params['status'] : 0;
- if (is_array($status)) {
- $query->whereIn('a.status', $status);
- } else if($status){
- $query->where('a.status', $status);
- }
- });
- }
- /**
- * 统计
- * @param $params
- * @return array
- */
- public function count($params)
- {
- $query = $this->getQuery($params);
- $count = $query->count('a.id');
- $total = $query->sum('a.money');
- $profit = $query->sum('a.profit');
- return [
- 'count' => $count,
- 'total' => $total,
- 'profit' => $profit,
- ];
- }
- }
|