| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- 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'])
- ->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}*");
- return parent::edit($data);
- }
- /**
- * 获取详情
- */
- public function getInfo($id = null)
- {
- if ($id === null) {
- $id = request()->input('id');
- }
- $info = MeetingModel::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','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])->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' => '删除成功'];
- }
- }
- }
|