MeetingService.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. // 设置日志
  114. ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => '编辑会议信息', 'content' => json_encode($data, 256), 'module' => 'admin']);
  115. ActionLogModel::record();
  116. RedisService::keyDel("caches:meetings:count*");
  117. RedisService::keyDel("caches:meetings:info_{$id}*");
  118. return parent::edit($data);
  119. }
  120. /**
  121. * 获取详情
  122. */
  123. public function getInfo($id = null)
  124. {
  125. if ($id === null) {
  126. $id = request()->input('id');
  127. }
  128. $info = MeetingModel::where('id', $id)
  129. ->where('mark', 1)
  130. ->first();
  131. if (!$info) {
  132. return ['code' => 1, 'msg' => '会议不存在'];
  133. }
  134. $info = $info->toArray();
  135. $info['thumb'] = $info['thumb'] ? get_image_url($info['thumb']) : '';
  136. $info['create_time_text'] = date('Y-m-d H:i:s', (int)$info['create_time']);
  137. return [
  138. 'code' => 0,
  139. 'msg' => '获取成功',
  140. 'data' => $info
  141. ];
  142. }
  143. /**
  144. * 设置状态
  145. */
  146. public function status()
  147. {
  148. $params = request()->all();
  149. $id = $params['id'] ?? 0;
  150. $status = $params['status'] ?? 1;
  151. $info = MeetingModel::where('id', $id)
  152. ->where('mark', 1)
  153. ->first();
  154. if (!$info) {
  155. return ['code' => 1, 'msg' => '会议不存在'];
  156. }
  157. $info->status = $status;
  158. $info->update_time = time();
  159. $info->save();
  160. RedisService::clear("caches:meeting:info_{$id}");
  161. return ['code' => 0, 'msg' => '设置成功'];
  162. }
  163. /**
  164. * 删除
  165. * @return array
  166. */
  167. public function delete()
  168. {
  169. $id = request()->input('id');
  170. $this->model->where(['mark' => 0])->delete();
  171. if (is_array($id)) {
  172. // 批量删除
  173. $count = MeetingModel::whereIn('id', $id)
  174. ->where('mark', 1)
  175. ->update(['mark' => 0, 'update_time' => time()]);
  176. return ['code' => 0, 'msg' => "成功删除{$count}条记录"];
  177. } else {
  178. // 单个删除
  179. $info = MeetingModel::where('id', $id)
  180. ->where('mark', 1)
  181. ->first();
  182. if (!$info) {
  183. return ['code' => 1, 'msg' => '会议不存在'];
  184. }
  185. $info->mark = 0;
  186. $info->update_time = time();
  187. $info->save();
  188. RedisService::clear("caches:meeting:info_{$id}*");
  189. return ['code' => 0, 'msg' => '删除成功'];
  190. }
  191. }
  192. }