MeetingService.php 6.5 KB

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