// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\ActionLogModel; use App\Models\MeetingModel; use App\Models\StoreModel; use App\Models\SupervisorsModel; use App\Services\BaseService; use App\Services\MpService; use App\Services\RedisService; /** * 会议管理-服务类 * @author laravel开发员 * @since 2020/11/11 * @package App\Services\Common */ class MeetingService extends BaseService { public static $instance = null; /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 */ public function __construct() { $this->model = new MeetingModel(); } /** * 静态入口 */ public static function make() { if (!self::$instance) { self::$instance = new static(); } return self::$instance; } /** * 获取数据列表 * @param array $params 请求参数 * @param int $pageSize 分页大小 */ public function getDataList($params, $pageSize = 15) { try { $query = $this->model->where('mark', 1); // 状态筛选 if (isset($params['status']) && $params['status']) { $query->where('status', $params['status']); } // 关键词搜索 if (isset($params['keyword']) && $params['keyword']) { $keyword = $params['keyword']; $query->where(function ($q) use ($keyword) { $q->where('title', 'like', '%' . $keyword . '%'); }); } $list = $query->with(['member','city','district','company']) ->withCount(['records']) ->orderBy('sort', 'desc') ->orderBy('id', 'desc') ->paginate($pageSize); $list = $list ? $list->toArray() : []; if ($list && isset($list['data'])) { foreach ($list['data'] as &$item) { $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : ''; $city = isset($item['city'])?$item['city']:[]; $district = isset($item['district'])?$item['district']:[]; $cityName = isset($city['name'])?$city['name']:''; $districtName = isset($district['name'])?$district['name']:''; $item['area'] = $cityName.'/'.$districtName; if($item['store_ids']){ $item['stores'] = StoreModel::whereIn('id', $item['store_ids']) ->select(['id','nickname','mobile']) ->get(); } $item['supervisors'] = []; if($item['supervisor_ids']){ $item['supervisors'] = SupervisorsModel::whereIn('id', $item['supervisor_ids']) ->select(['id','name','mobile']) ->get(); } } } return [ 'msg' => '操作成功', 'code' => 0, 'data' => $list['data'] ?? [], 'count' => $list['total'] ?? 0, ]; } catch (\Exception $e) { return [ 'msg' => '查询失败: ' . $e->getMessage(), 'code' => 1, 'data' => [], 'count' => 0, ]; } } /** * 添加会编辑会员 * @return array * @since 2020/11/11 * @author laravel开发员 */ public function edit() { // 请求参数 $data = request()->all(); $id = isset($data['id']) ? $data['id'] : 0; // 封面 if (isset($data['thumb']) && $data['thumb']) { $data['thumb'] = get_image_path(trim($data['thumb'])); } $areas = isset($data['areas'])?$data['areas']:[]; // 省份 $data['province_id'] = isset($areas[0])?$areas[0]:0; // 城市 $data['city_id'] = isset($areas[1])?$areas[1]:0; // 县区 $data['district_id'] = isset($areas[2])?$areas[2]:0; // 签到关联订单有效天数 $data['order_day'] = isset($data['order_day']) && $data['order_day']>1? intval($data['order_day']) : 1; $data['store_ids'] = $data['store_ids']? implode(',',$data['store_ids']).',' : ''; $data['supervisor_ids'] = $data['supervisor_ids']? implode(',',$data['supervisor_ids']).',' : ''; // 设置日志 ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => '编辑会议信息', 'content' => json_encode($data, 256), 'module' => 'admin']); ActionLogModel::record(); RedisService::keyDel("caches:meetings:count*"); RedisService::keyDel("caches:meetings:info_{$id}*"); unset($data['company']); return parent::edit($data); } /** * 获取详情 */ public function getInfo($id = null) { if ($id === null) { $id = request()->input('id'); } $info = MeetingModel::with(['company'])->where('id', $id) ->where('mark', 1) ->first(); if (!$info) { return ['code' => 1, 'msg' => '会议不存在']; } $info = $info->toArray(); $info['thumb'] = $info['thumb'] ? get_image_url($info['thumb']) : ''; $info['qrcode'] = MpService::make()->getMiniQrcode('pagesSub/pages/meeting/books','meet&id='.$info['id']); $info['qrcode'] = $info['qrcode']? get_image_url($info['qrcode']):''; return [ 'code' => 0, 'msg' => '获取成功', 'data' => $info ]; } /** * 设置状态 */ public function status() { $params = request()->all(); $id = $params['id'] ?? 0; $status = $params['status'] ?? 1; $info = MeetingModel::where('id', $id) ->where('mark', 1) ->first(); if (!$info) { return ['code' => 1, 'msg' => '会议不存在']; } $info->status = $status; $info->update_time = time(); $info->save(); RedisService::clear("caches:meeting:info_{$id}"); return ['code' => 0, 'msg' => '设置成功']; } /** * 删除 * @return array */ public function delete() { $id = request()->input('id'); $this->model->where(['mark'=>0])->where('update_time','<', time() - 600)->delete(); if (is_array($id)) { // 批量删除 $count = MeetingModel::whereIn('id', $id) ->where('mark', 1) ->update(['mark' => 0, 'update_time' => time()]); return ['code' => 0, 'msg' => "成功删除{$count}条记录"]; } else { // 单个删除 $info = MeetingModel::where('id', $id) ->where('mark', 1) ->first(); if (!$info) { return ['code' => 1, 'msg' => '会议不存在']; } $info->mark = 0; $info->update_time = time(); $info->save(); RedisService::clear("caches:meeting:info_{$id}*"); return ['code' => 0, 'msg' => '删除成功']; } } }