| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\ArticleConsultRecordsModel;
- use App\Services\BaseService;
- /**
- * 行业咨询记录管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Common
- */
- class ArticleConsultRecordService extends BaseService
- {
- public static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new ArticleConsultRecordsModel();
- }
- /**
- * 静态入口
- */
- 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 = ['a.mark' => 1];
- $status = isset($params['status']) ? $params['status'] : 0;
- if ($status > 0) {
- $where['a.status'] = $status;
- }
- $userId = isset($params['user_id']) ? $params['user_id'] : 0;
- if ($userId > 0) {
- $where['a.user_id'] = $userId;
- }
- $sourceId = isset($params['source_id']) ? $params['source_id'] : 0;
- if ($sourceId > 0) {
- $where['a.source_id'] = $sourceId;
- }
- $query = $this->model->with(['member','article'])->from('article_consult_records as a')
- ->leftJoin('member as b','b.id','=','a.user_id')
- ->where($where)
- ->where(function ($query) use ($params) {
- $keyword = isset($params['keyword']) ? $params['keyword'] : '';
- if ($keyword) {
- $query->where('a.realname', 'like', "%{$keyword}%")
- ->orWhere('a.mobile', 'like', "%{$keyword}%");
- }
- })
- ->where(function ($query) use ($params) {
- $date =isset($params['date'])?$params['date']:[];
- $start = $date[0] ?? '';
- $end = $date[1] ?? '';
- if ($start) {
- $query->where('a.create_time', '>=', strtotime($start));
- }
- if ($end && $start < $end) {
- $query->where('a.create_time', '<=', strtotime($end));
- }else if ($end && $start == $end) {
- $query->where('a.create_time', '<', strtotime($end)+86400);
- }
- })
- ->select(['a.*']);
- $query->orderBy('a.id', 'desc');
- $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
- }
- }
- return [
- 'msg' => '操作成功',
- 'code' => 0,
- 'data' => isset($list['data']) ? $list['data'] : [],
- 'count' => isset($list['total']) ? $list['total'] : 0,
- ];
- }
- /**
- * 删除
- * @return array
- */
- public function delete()
- {
- $this->model->where(['mark'=>0])->where('update_time','<', time() - 600)->delete();
- return parent::delete(); // TODO: Change the autogenerated stub
- }
- /**
- * 处理状态
- * @param int $adminId
- * @return array
- */
- public function status($adminId=0)
- {
- return parent::status($adminId); // TODO: Change the autogenerated stub
- }
- }
|