MeetingService.php 7.6 KB

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