MeetingService.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\ActionLogModel;
  13. use App\Models\MeetingModel;
  14. use App\Services\BaseService;
  15. use App\Services\MpService;
  16. use App\Services\RedisService;
  17. /**
  18. * 会议管理-服务类
  19. * @author laravel开发员
  20. * @since 2020/11/11
  21. * @package App\Services\Common
  22. */
  23. class MeetingService extends BaseService
  24. {
  25. public static $instance = null;
  26. /**
  27. * 构造函数
  28. * @author laravel开发员
  29. * @since 2020/11/11
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new MeetingModel();
  34. }
  35. /**
  36. * 静态入口
  37. */
  38. public static function make()
  39. {
  40. if (!self::$instance) {
  41. self::$instance = new static();
  42. }
  43. return self::$instance;
  44. }
  45. /**
  46. * 获取数据列表
  47. * @param array $params 请求参数
  48. * @param int $pageSize 分页大小
  49. */
  50. public function getDataList($params, $pageSize = 15)
  51. {
  52. try {
  53. $query = $this->model->where('mark', 1);
  54. // 状态筛选
  55. if (isset($params['status']) && $params['status']) {
  56. $query->where('status', $params['status']);
  57. }
  58. // 关键词搜索
  59. if (isset($params['keyword']) && $params['keyword']) {
  60. $keyword = $params['keyword'];
  61. $query->where(function ($q) use ($keyword) {
  62. $q->where('title', 'like', '%' . $keyword . '%');
  63. });
  64. }
  65. $list = $query->with(['member','city','district'])
  66. ->withCount(['records'])
  67. ->orderBy('sort', 'desc')
  68. ->orderBy('id', 'desc')
  69. ->paginate($pageSize);
  70. $list = $list ? $list->toArray() : [];
  71. if ($list && isset($list['data'])) {
  72. foreach ($list['data'] as &$item) {
  73. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
  74. $info['qrcode'] = MpService::make()->getMiniQrcode('pagesSub/pages/meeting/books',$item['id']);
  75. $info['qrcode'] = $info['qrcode']? get_image_url($info['qrcode']):'';
  76. $city = isset($item['city'])?$item['city']:[];
  77. $district = isset($item['district'])?$item['district']:[];
  78. $cityName = isset($city['name'])?$city['name']:'';
  79. $districtName = isset($district['name'])?$district['name']:'';
  80. $item['area'] = $cityName.'/'.$districtName;
  81. }
  82. }
  83. return [
  84. 'msg' => '操作成功',
  85. 'code' => 0,
  86. 'data' => $list['data'] ?? [],
  87. 'count' => $list['total'] ?? 0,
  88. ];
  89. } catch (\Exception $e) {
  90. return [
  91. 'msg' => '查询失败: ' . $e->getMessage(),
  92. 'code' => 1,
  93. 'data' => [],
  94. 'count' => 0,
  95. ];
  96. }
  97. }
  98. /**
  99. * 添加会编辑会员
  100. * @return array
  101. * @since 2020/11/11
  102. * @author laravel开发员
  103. */
  104. public function edit()
  105. {
  106. // 请求参数
  107. $data = request()->all();
  108. $id = isset($data['id']) ? $data['id'] : 0;
  109. // 封面
  110. if (isset($data['thumb']) && $data['thumb']) {
  111. $data['thumb'] = get_image_path(trim($data['thumb']));
  112. }
  113. $areas = isset($data['areas'])?$data['areas']:[];
  114. // 省份
  115. $data['province_id'] = isset($areas[0])?$areas[0]:0;
  116. // 城市
  117. $data['city_id'] = isset($areas[1])?$areas[1]:0;
  118. // 县区
  119. $data['district_id'] = isset($areas[2])?$areas[2]:0;
  120. // 设置日志
  121. ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => '编辑会议信息', 'content' => json_encode($data, 256), 'module' => 'admin']);
  122. ActionLogModel::record();
  123. RedisService::keyDel("caches:meetings:count*");
  124. RedisService::keyDel("caches:meetings:info_{$id}*");
  125. return parent::edit($data);
  126. }
  127. /**
  128. * 获取详情
  129. */
  130. public function getInfo($id = null)
  131. {
  132. if ($id === null) {
  133. $id = request()->input('id');
  134. }
  135. $info = MeetingModel::where('id', $id)
  136. ->where('mark', 1)
  137. ->first();
  138. if (!$info) {
  139. return ['code' => 1, 'msg' => '会议不存在'];
  140. }
  141. $info = $info->toArray();
  142. $info['thumb'] = $info['thumb'] ? get_image_url($info['thumb']) : '';
  143. $info['create_time_text'] = date('Y-m-d H:i:s', (int)$info['create_time']);
  144. return [
  145. 'code' => 0,
  146. 'msg' => '获取成功',
  147. 'data' => $info
  148. ];
  149. }
  150. /**
  151. * 设置状态
  152. */
  153. public function status()
  154. {
  155. $params = request()->all();
  156. $id = $params['id'] ?? 0;
  157. $status = $params['status'] ?? 1;
  158. $info = MeetingModel::where('id', $id)
  159. ->where('mark', 1)
  160. ->first();
  161. if (!$info) {
  162. return ['code' => 1, 'msg' => '会议不存在'];
  163. }
  164. $info->status = $status;
  165. $info->update_time = time();
  166. $info->save();
  167. RedisService::clear("caches:meeting:info_{$id}");
  168. return ['code' => 0, 'msg' => '设置成功'];
  169. }
  170. /**
  171. * 删除
  172. * @return array
  173. */
  174. public function delete()
  175. {
  176. $id = request()->input('id');
  177. $this->model->where(['mark' => 0])->delete();
  178. if (is_array($id)) {
  179. // 批量删除
  180. $count = MeetingModel::whereIn('id', $id)
  181. ->where('mark', 1)
  182. ->update(['mark' => 0, 'update_time' => time()]);
  183. return ['code' => 0, 'msg' => "成功删除{$count}条记录"];
  184. } else {
  185. // 单个删除
  186. $info = MeetingModel::where('id', $id)
  187. ->where('mark', 1)
  188. ->first();
  189. if (!$info) {
  190. return ['code' => 1, 'msg' => '会议不存在'];
  191. }
  192. $info->mark = 0;
  193. $info->update_time = time();
  194. $info->save();
  195. RedisService::clear("caches:meeting:info_{$id}*");
  196. return ['code' => 0, 'msg' => '删除成功'];
  197. }
  198. }
  199. }