MeetingService.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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','company'])
  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. unset($data['company']);
  141. return parent::edit($data);
  142. }
  143. /**
  144. * 获取详情
  145. */
  146. public function getInfo($id = null)
  147. {
  148. if ($id === null) {
  149. $id = request()->input('id');
  150. }
  151. $info = MeetingModel::with(['company'])->where('id', $id)
  152. ->where('mark', 1)
  153. ->first();
  154. if (!$info) {
  155. return ['code' => 1, 'msg' => '会议不存在'];
  156. }
  157. $info = $info->toArray();
  158. $info['thumb'] = $info['thumb'] ? get_image_url($info['thumb']) : '';
  159. $info['qrcode'] = MpService::make()->getMiniQrcode('pagesSub/pages/meeting/books','meet&id='.$info['id']);
  160. $info['qrcode'] = $info['qrcode']? get_image_url($info['qrcode']):'';
  161. return [
  162. 'code' => 0,
  163. 'msg' => '获取成功',
  164. 'data' => $info
  165. ];
  166. }
  167. /**
  168. * 设置状态
  169. */
  170. public function status()
  171. {
  172. $params = request()->all();
  173. $id = $params['id'] ?? 0;
  174. $status = $params['status'] ?? 1;
  175. $info = MeetingModel::where('id', $id)
  176. ->where('mark', 1)
  177. ->first();
  178. if (!$info) {
  179. return ['code' => 1, 'msg' => '会议不存在'];
  180. }
  181. $info->status = $status;
  182. $info->update_time = time();
  183. $info->save();
  184. RedisService::clear("caches:meeting:info_{$id}");
  185. return ['code' => 0, 'msg' => '设置成功'];
  186. }
  187. /**
  188. * 删除
  189. * @return array
  190. */
  191. public function delete()
  192. {
  193. $id = request()->input('id');
  194. $this->model->where(['mark'=>0])->where('update_time','<', time() - 600)->delete();
  195. if (is_array($id)) {
  196. // 批量删除
  197. $count = MeetingModel::whereIn('id', $id)
  198. ->where('mark', 1)
  199. ->update(['mark' => 0, 'update_time' => time()]);
  200. return ['code' => 0, 'msg' => "成功删除{$count}条记录"];
  201. } else {
  202. // 单个删除
  203. $info = MeetingModel::where('id', $id)
  204. ->where('mark', 1)
  205. ->first();
  206. if (!$info) {
  207. return ['code' => 1, 'msg' => '会议不存在'];
  208. }
  209. $info->mark = 0;
  210. $info->update_time = time();
  211. $info->save();
  212. RedisService::clear("caches:meeting:info_{$id}*");
  213. return ['code' => 0, 'msg' => '删除成功'];
  214. }
  215. }
  216. }