// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\CapitalLogModel; use App\Services\BaseService; /** * 资产交易明细-服务类 * Class CapitalLogService * @package App\Services\Common */ class CapitalLogService extends BaseService { // 静态对象 protected static $instance = null; /** * 构造函数 * @since 2020/11/10 * CapitalLogService constructor. */ public function __construct() { $this->model = new CapitalLogModel(); } /** * 静态入口 * @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 = 15) { $where = ['a.mark' => 1]; $type = isset($params['type'])? $params['type'] : 1; $changeType = isset($params['change_type'])? $params['change_type'] : 1; $userId = isset($params['user_id'])? $params['user_id'] : 0; if($type>0){ $where['a.type'] = $type; } if($changeType>0){ $where['a.change_type'] = $changeType; } if($userId>0){ $where['a.user_id'] = $userId; } $list = $this->model->from('capital_logs as a') ->leftJoin('member as m', 'm.id', '=', 'a.user_id') ->where($where) ->where(function ($query) use($params){ $keyword = isset($params['keyword'])? $params['keyword'] : ''; if($keyword){ $query->where('a.order_no','like',"%{$keyword}%"); } // 日期 $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)); } }) ->select(['a.*', 'm.username']) ->orderBy('a.create_time','desc') ->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list? $list->toArray() :[]; if($list){ foreach($list['data'] as &$item){ $item['time_text'] = $item['create_time']? datetime(strtotime($item['create_time']), 'm-d H:i'):''; } } return [ 'pageSize'=> $pageSize, 'total'=>isset($list['total'])? $list['total'] : 0, 'list'=> isset($list['data'])? $list['data'] : [] ]; } }