MeetingService.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ywl
  5. * Date: 2017/4/14
  6. * Time: 11:38
  7. */
  8. namespace App\Web\Services;
  9. use App\Common\Facades\ComSmsFacade;
  10. use App\Common\Facades\UserCenterFacade;
  11. use App\Exceptions\ApiException;
  12. use App\Services\CommonUserBaseService;
  13. use App\Web\Facades\WebFacade;
  14. use App\Web\Models\MeetingModel;
  15. use App\Web\Models\MeetingSpeechScheduleModel;
  16. use App\Web\Models\MeetingTagModel;
  17. use App\Web\Models\MeetingTagRelationModel;
  18. use App\Web\Models\MeetingTypeModel;
  19. use App\Web\Models\MeetingTypeRelationModel;
  20. use Illuminate\Support\Facades\Cache;
  21. use Illuminate\Http\Request;
  22. use Illuminate\Support\Facades\DB;
  23. use Illuminate\Support\Facades\Log;
  24. use Illuminate\Support\Facades\Mail;
  25. class MeetingService extends CommonUserBaseService
  26. {
  27. protected $cache = true;
  28. protected $cacheBucket = 'Meeting:';
  29. protected $meetingTypeModel;
  30. protected $meetingTypeRelationModel;
  31. protected $meetingTagModel;
  32. protected $meetingTagRelationModel;
  33. protected $meetingSpeechScheduleModel;
  34. /**
  35. * MeetingService construct
  36. * @param MeetingModel $model
  37. * @param MeetingTypeModel $meetingTypeModel
  38. * @param MeetingTagRelationModel $meetingTagRelationModel
  39. * @param MeetingTagModel $meetingTagModel
  40. * @param MeetingTypeRelationModel $meetingTypeRelationModel
  41. * @param MeetingSpeechScheduleModel $meetingSpeechScheduleModel
  42. * */
  43. public function __construct(MeetingModel $model,
  44. MeetingTypeModel $meetingTypeModel,
  45. MeetingTagRelationModel $meetingTagRelationModel,
  46. MeetingTagModel $meetingTagModel,
  47. MeetingTypeRelationModel $meetingTypeRelationModel,
  48. MeetingSpeechScheduleModel $meetingSpeechScheduleModel
  49. )
  50. {
  51. $this->model = $model;
  52. $this->meetingTypeModel = $meetingTypeModel;
  53. $this->meetingTypeRelationModel = $meetingTypeRelationModel;
  54. $this->meetingTagModel = $meetingTagModel;
  55. $this->meetingTagRelationModel = $meetingTagRelationModel;
  56. $this->meetingSpeechScheduleModel = $meetingSpeechScheduleModel;
  57. }
  58. /**
  59. * 获取产品类型列表
  60. * */
  61. public function getMeetingTypeList($params)
  62. {
  63. $retData = $this->meetingTypeModel->getMeetingTypeList($params);
  64. if (!empty($retData['data'])) {
  65. $typeIds = array_column($retData['data'], 'id');
  66. $meetingCounts = $this->meetingTypeRelationModel->getMeetingTypeCount($typeIds);
  67. foreach ($retData['data'] as &$meetingItem) {
  68. $meetingItem['meeting_count'] = $meetingCounts[$meetingItem['id']] ?? 0;
  69. $meetingItem['expand_content'] = empty($meetingItem['expand_content']) ? [] : json_decode($meetingItem['expand_content'], true);
  70. $meetingItem['expand_array'] = $this->transformArrayToKeyValue($meetingItem['expand_content']);
  71. }
  72. }
  73. return $retData;
  74. }
  75. public function transformArrayToKeyValue($array)
  76. {
  77. $result = [];
  78. foreach ($array as $item) {
  79. if (isset($item['key']) && isset($item['value'])) {
  80. $result[$item['key']] = $item['value'];
  81. }
  82. }
  83. return $result;
  84. }
  85. /**
  86. * 产品类型保存
  87. * */
  88. public function saveMeetingType($params)
  89. {
  90. $saveData = [];
  91. $nowTime = nowTime();
  92. $saveData['update_time'] = $nowTime;
  93. $userId = $this->getAuthUserId();
  94. if (!empty($params['seo_data'])) {
  95. $urlaUnique = WebFacade::checkUrlaUnique($params['seo_data']['urla'], $params['seo_id']);
  96. if (!$urlaUnique) {
  97. throw new ApiException(10019, ['name' => $params['seo_data']['urla']]);
  98. }
  99. }
  100. if (!empty($params['id'])) {
  101. $saveData['id'] = $params['id'];
  102. if (isset($params['type_name'])) {
  103. $nameUnique = $this->meetingTypeModel->checkTypeNameUnique($params['type_name'], $params['id']);
  104. if (!$nameUnique) {
  105. throw new ApiException(10018, ['name' => $params['type_name']]);
  106. }
  107. $saveData['type_name'] = $params['type_name'];
  108. }
  109. if (isset($params['status'])) {
  110. $saveData['status'] = $params['status'];
  111. }
  112. if (isset($params['sort'])) {
  113. $saveData['sort'] = $params['sort'];
  114. }
  115. if (isset($params['expand_content'])) {
  116. $saveData['expand_content'] = !empty($params['expand_content']) ? json_encode($params['expand_content']) : '';
  117. }
  118. } else {
  119. $nameUnique = $this->meetingTypeModel->checkTypeNameUnique($params['type_name']);
  120. if (!$nameUnique) {
  121. throw new ApiException(10018, ['name' => $params['type_name']]);
  122. }
  123. $saveData['user_id'] = $userId;
  124. $saveData['type_name'] = $params['type_name'];
  125. $saveData['expand_content'] = !empty($params['expand_content']) ? json_encode($params['expand_content']) : '';
  126. $saveData['sort'] = empty($params['sort']) ? 0 : $params['sort'];
  127. $saveData['create_time'] = $nowTime;
  128. }
  129. $id = $this->meetingTypeModel->saveTypeData($saveData);
  130. if (!empty($id) && isset($params['seo_data'])) {
  131. $seoParams = [
  132. 'relation_table' => WebService::RELATION_TABLE_MEETING_TYPE,
  133. 'relation_id' => $id,
  134. 'urla' => $params['seo_data']['urla'],
  135. 'seo_title' => $params['seo_data']['seo_title'],
  136. 'seo_keyword' => $params['seo_data']['seo_keyword'],
  137. 'seo_describe' => $params['seo_data']['seo_describe']
  138. ];
  139. if (empty($params['seo_id'])) {
  140. $seoParams['user_id'] = $userId;
  141. $urlaId = WebFacade::saveSeoData($seoParams);
  142. $this->meetingTypeModel->newInstance()->where('id', '=', $id)->update(['seo_id' => $urlaId]);
  143. } else {
  144. $seoParams['id'] = $params['seo_id'];
  145. $urlaId = WebFacade::saveSeoData($seoParams);
  146. }
  147. if (!empty($saveData['status']) && $saveData['status'] == 2) {
  148. //移除对应seo
  149. $delSeoParams = [];
  150. $delSeoParams['relation_table'] = WebService::RELATION_TABLE_MEETING_TYPE;
  151. $delSeoParams['relation_id'] = $id;
  152. $ret = WebFacade::delSeoByRelation($delSeoParams);
  153. }
  154. }
  155. //更新所有页面缓存
  156. WebFacade::clearPageCache('urla:');
  157. return $id;
  158. }
  159. /**
  160. * 保存产品类型关系
  161. * */
  162. public function typeRelationSave($params)
  163. {
  164. $userId = $this->getAuthUserId();
  165. $ret = $this->meetingTypeRelationModel->typeRelationSave($params, $userId);
  166. //更新所有页面缓存
  167. WebFacade::clearPageCache('urla:');
  168. return $ret;
  169. }
  170. /**
  171. * 根据产品类型 保存产品关系
  172. * */
  173. public function addRelationByTypeId($typeId, $meetingIds)
  174. {
  175. $userId = $this->getAuthUserId();
  176. $ret = $this->meetingTypeRelationModel->addByTypeId($typeId, $meetingIds, $userId);
  177. //更新所有页面缓存
  178. WebFacade::clearPageCache('urla:');
  179. return $ret;
  180. }
  181. /**
  182. * 根据类型id及产品id 删除关联关系
  183. * */
  184. public function delTypeRelation($typeId, $meetingId)
  185. {
  186. $ret = $this->meetingTypeRelationModel->delTypeRelation($typeId, $meetingId);
  187. //更新所有页面缓存
  188. WebFacade::clearPageCache('urla:');
  189. return $ret;
  190. }
  191. /**
  192. * 获取产品标签列表
  193. * */
  194. public function getMeetingTagList($params)
  195. {
  196. $retData = $this->meetingTagModel->getMeetingTagList($params);
  197. if (!empty($retData['data'])) {
  198. $tagIds = array_column($retData['data'], 'id');
  199. $meetingCounts = $this->meetingTagRelationModel->getMeetingTagCount($tagIds);
  200. foreach ($retData['data'] as &$meetingItem) {
  201. $meetingItem['meeting_count'] = $meetingCounts[$meetingItem['id']] ?? 0;
  202. }
  203. }
  204. return $retData;
  205. }
  206. /**
  207. * 产品标签保存
  208. * */
  209. public function saveMeetingTag($params)
  210. {
  211. $saveData = [];
  212. $nowTime = nowTime();
  213. $saveData['update_time'] = $nowTime;
  214. $userId = $this->getAuthUserId();
  215. // if (!empty($params['seo_data'])) {
  216. // $urlaUnique = WebFacade::checkUrlaUnique($params['seo_data']['urla'], $params['seo_id']);
  217. // if (!$urlaUnique) {
  218. // throw new ApiException(10019, ['name' => $params['seo_data']['urla']]);
  219. // }
  220. // }
  221. if (!empty($params['id'])) {
  222. $saveData['id'] = $params['id'];
  223. if (isset($params['tag_name'])) {
  224. $nameUnique = $this->meetingTagModel->checkTagNameUnique($params['tag_name'], $params['id']);
  225. if (!$nameUnique) {
  226. throw new ApiException(10018, ['name' => $params['tag_name']]);
  227. }
  228. $saveData['tag_name'] = $params['tag_name'];
  229. }
  230. if (isset($params['status'])) {
  231. $saveData['status'] = $params['status'];
  232. }
  233. if (isset($params['sort'])) {
  234. $saveData['sort'] = $params['sort'];
  235. }
  236. if (isset($params['is_hot'])) {
  237. $saveData['is_hot'] = $params['is_hot'];
  238. }
  239. // if(isset($params['type'])){
  240. // $saveData['type']=empty($params['type'])?0:$params['type'];
  241. // }
  242. } else {
  243. $nameUnique = $this->meetingTagModel->checkTagNameUnique($params['tag_name']);
  244. if (!$nameUnique) {
  245. throw new ApiException(10018, ['name' => $params['tag_name']]);
  246. }
  247. $saveData['user_id'] = $userId;
  248. $saveData['tag_name'] = $params['tag_name'];
  249. // $saveData['type']=empty($params['type'])?0:$params['type'];
  250. $saveData['sort'] = empty($params['sort']) ? 0 : $params['sort'];
  251. $saveData['create_time'] = $nowTime;
  252. }
  253. $id = $this->meetingTagModel->saveTagData($saveData);
  254. // if (!empty($id) && isset($params['seo_data'])) {
  255. // $seoParams = [
  256. // 'relation_table' => WebService::RELATION_TABLE_MEETING_TAG,
  257. // 'relation_id' => $id,
  258. // 'urla' => $params['seo_data']['urla'],
  259. // 'seo_title' => $params['seo_data']['seo_title'],
  260. // 'seo_keyword' => $params['seo_data']['seo_keyword'],
  261. // 'seo_describe' => $params['seo_data']['seo_describe']
  262. // ];
  263. //
  264. // if (empty($params['seo_id'])) {
  265. // $seoParams['user_id'] = $userId;
  266. // $urlaId = WebFacade::saveSeoData($seoParams);
  267. // $this->meetingTagModel->newInstance()->where('id','=',$id)->update(['seo_id' => $urlaId]);
  268. // } else {
  269. // $seoParams['id'] = $params['seo_id'];
  270. // $urlaId = WebFacade::saveSeoData($seoParams);
  271. // }
  272. // }
  273. return $id;
  274. }
  275. /**
  276. * 保存产品标签关系
  277. * */
  278. public function tagRelationSave($params)
  279. {
  280. $userId = $this->getAuthUserId();
  281. $ret = $this->meetingTagRelationModel->tagRelationSave($params, $userId);
  282. //更新所有页面缓存
  283. WebFacade::clearPageCache('urla:');
  284. return $ret;
  285. }
  286. /**
  287. * 根据产品标签 保存产品关系
  288. * */
  289. public function addRelationByTagId($tagId, $meetingIds)
  290. {
  291. $userId = $this->getAuthUserId();
  292. $ret = $this->meetingTagRelationModel->addByTagId($tagId, $meetingIds, $userId);
  293. //更新所有页面缓存
  294. WebFacade::clearPageCache('urla:');
  295. return $ret;
  296. }
  297. /**
  298. * 根据标签id及产品id 删除关联关系
  299. * */
  300. public function delTagRelation($tagId, $meetingId)
  301. {
  302. $ret = $this->meetingTagRelationModel->delTagRelation($tagId, $meetingId);
  303. //更新所有页面缓存
  304. WebFacade::clearPageCache('urla:');
  305. return $ret;
  306. }
  307. /**
  308. * 保存产品数据
  309. * */
  310. public function saveMeeting($params)
  311. {
  312. $saveData = $this->buildMeetingData($params);
  313. $userId = $this->getAuthUserId();
  314. $typeIds = empty($params['type_ids']) ? [] : $params['type_ids'];
  315. $tagIds = empty($params['tag_ids']) ? [] : $params['tag_ids'];
  316. $seoData = empty($params['seo_data']) ? [] : $params['seo_data'];
  317. $urlaId = empty($saveData['seo_id']) ? 0 : $saveData['seo_id'];
  318. if (!empty($seoData)) {
  319. $urlaUnique = WebFacade::checkUrlaUnique($seoData['urla'], $urlaId);
  320. if (!$urlaUnique) {
  321. throw new ApiException(10019, ['name' => $seoData['urla']]);
  322. }
  323. }
  324. $id = $this->model->saveMeetingData($saveData);
  325. if (!empty($id)) {
  326. if (isset($params['seo_data'])) {
  327. $seoParams = [];
  328. $seoParams['relation_table'] = WebService::RELATION_TABLE_MEETING;
  329. $seoParams['relation_id'] = $id;
  330. $seoParams['urla'] = $seoData['urla'];
  331. $seoParams['seo_title'] = $seoData['seo_title'];
  332. $seoParams['seo_keyword'] = $seoData['seo_keyword'];
  333. $seoParams['seo_describe'] = $seoData['seo_describe'];
  334. if (empty($urlaId)) {
  335. $seoParams['user_id'] = $userId;
  336. $urlaId = WebFacade::saveSeoData($seoParams);
  337. $this->model->newInstance()->where('id', '=', $id)->update(['seo_id' => $urlaId]);
  338. } else {
  339. $seoParams['id'] = $urlaId;
  340. $urlaId = WebFacade::saveSeoData($seoParams);
  341. }
  342. }
  343. if (isset($params['type_ids'])) {
  344. $meetingTypeParams = [];
  345. $meetingTypeParams['meeting_id'] = $id;
  346. $meetingTypeParams['type_ids'] = $typeIds;
  347. $this->meetingTypeRelationModel->typeRelationSave($meetingTypeParams, $userId);
  348. }
  349. if (isset($params['tag_ids'])) {
  350. $meetingTagParams = [];
  351. $meetingTagParams['meeting_id'] = $id;
  352. $meetingTagParams['tag_ids'] = $tagIds;
  353. $this->meetingTagRelationModel->tagRelationSave($meetingTagParams, $userId);
  354. }
  355. // 获取是否需要修改排序数据
  356. if (isset($saveData['sort'])) {
  357. $getData = $this->model->selectRaw('id')
  358. ->where('sort', '=', $saveData['sort'])
  359. ->where('id', '<>', $id)->first();
  360. if (!empty($getData['id'])) {
  361. $this->model->where('sort', '>=', $saveData['sort'])
  362. ->where('id', '<>', $id)
  363. ->update(['sort' => DB::raw('sort + 1')]);
  364. }
  365. }
  366. if (!empty($params['id']) && !empty($params['virtual_view'])) {
  367. $this->updatePv($params['id'], $params['virtual_view']);
  368. }
  369. if (isset($params['speech_schedule'])) {
  370. $this->meetingSpeechScheduleModel->saveSpeechScheduleData($id, $params['speech_schedule'], $userId);
  371. }
  372. if (!empty($saveData['status']) && $saveData['status'] == 2) {
  373. //移除对应seo
  374. $delSeoParams = [];
  375. $delSeoParams['relation_table'] = WebService::RELATION_TABLE_MEETING;
  376. $delSeoParams['relation_id'] = $id;
  377. $ret = WebFacade::delSeoByRelation($delSeoParams);
  378. }
  379. }
  380. //更新所有页面缓存
  381. WebFacade::clearPageCache('urla:');
  382. return $id;
  383. }
  384. /**
  385. * 构建产品保存数据
  386. * */
  387. private function buildMeetingData($params)
  388. {
  389. $saveData = [];
  390. $userId = $this->getAuthUserId();
  391. $nowTime = nowTime();
  392. $saveData['update_time'] = $nowTime;
  393. if (!empty($params['id'])) {
  394. $saveData['id'] = $params['id'];
  395. if (isset($params['seo_id'])) {
  396. $saveData['seo_id'] = $params['seo_id'];
  397. }
  398. if (isset($params['pub_date'])) {
  399. $saveData['pub_date'] = empty($params['pub_date']) ? null : $params['pub_date'];;
  400. }
  401. if (isset($params['title'])) {
  402. $nameUnique = $this->model->checkNameUnique($params['title'], $params['id']);
  403. if (!$nameUnique) {
  404. throw new ApiException(10018, ['name' => $params['title']]);
  405. }
  406. $saveData['title'] = empty($params['title']) ? '' : $params['title'];
  407. }
  408. if (isset($params['description'])) {
  409. $saveData['description'] = empty($params['description']) ? '' : $params['description'];
  410. }
  411. if (isset($params['content'])) {
  412. $saveData['content'] = empty($params['content']) ? '' : $params['content'];
  413. }
  414. if (isset($params['start_date'])) {
  415. $saveData['start_date'] = empty($params['start_date']) ? '' : $params['start_date'];
  416. }
  417. if (isset($params['end_date'])) {
  418. $saveData['end_date'] = empty($params['end_date']) ? '' : $params['end_date'];
  419. }
  420. if (!empty($params['start_date']) && !empty($params['end_date'])) {
  421. $startDate = strtotime($params['start_date']);
  422. $endDate = strtotime($params['end_date']);
  423. if (!$startDate > $endDate) {
  424. throw new ApiException(10022);
  425. }
  426. }
  427. if (isset($params['image_url'])) {
  428. $saveData['image_url'] = empty($params['image_url']) ? '' : $params['image_url'];
  429. }
  430. if (isset($params['image_alt'])) {
  431. $saveData['image_alt'] = empty($params['image_alt']) ? '' : $params['image_alt'];
  432. }
  433. if (isset($params['main_image'])) {
  434. $saveData['main_image'] = empty($params['main_image']) ? '' : $params['main_image'];
  435. }
  436. if (isset($params['main_image_alt'])) {
  437. $saveData['main_image_alt'] = empty($params['main_image_alt']) ? '' : $params['main_image_alt'];
  438. }
  439. if (isset($params['sub_image_urls'])) {
  440. $saveData['sub_image_urls'] = empty($params['sub_image_urls']) ? '' : json_encode($params['sub_image_urls']);
  441. }
  442. if (isset($params['country'])) {
  443. $saveData['country'] = empty($params['country']) ? '' : $params['country'];
  444. }
  445. if (isset($params['address'])) {
  446. $saveData['address'] = empty($params['address']) ? '' : $params['address'];
  447. }
  448. if (isset($params['download_url'])) {
  449. $saveData['download_url'] = empty($params['download_url']) ? '' : json_encode($params['download_url']);
  450. }
  451. if (isset($params['video_path'])) {
  452. $saveData['video_path'] = empty($params['video_path']) ? '' : $params['video_path'];
  453. }
  454. if (isset($params['video_image_url'])) {
  455. $saveData['video_image_url'] = empty($params['video_image_url']) ? '' : $params['video_image_url'];
  456. }
  457. if (isset($params['video_type'])) {
  458. $saveData['video_type'] = empty($params['video_type']) ? 0 : $params['video_type'];
  459. }
  460. if (isset($params['video_desc'])) {
  461. $saveData['video_desc'] = empty($params['video_desc']) ? '' : $params['video_desc'];
  462. }
  463. if (isset($params['is_top'])) {
  464. $saveData['is_top'] = empty($params['is_top']) ? 0 : $params['is_top'];
  465. }
  466. if (isset($params['status'])) {
  467. $saveData['status'] = $params['status'];
  468. }
  469. if (isset($params['meeting_host'])) {
  470. $saveData['meeting_host'] = empty($params['meeting_host']) ? '' : $params['meeting_host'];
  471. }
  472. if (isset($params['page_route'])) {
  473. $saveData['page_route'] = empty($params['page_route']) ? '' : $params['page_route'];
  474. }
  475. if (isset($params['expand_content'])) {
  476. $saveData['expand_content'] = empty($params['expand_content']) ? '' : json_encode($params['expand_content']);
  477. }
  478. } else {
  479. $nameUnique = $this->model->checkNameUnique($params['title']);
  480. if (!$nameUnique) {
  481. throw new ApiException(10018, ['name' => $params['title']]);
  482. }
  483. if (empty($params['title'])) {
  484. throw new ApiException(11002);
  485. }
  486. if (isset($params['status'])) {
  487. $saveData['status'] = $params['status'];
  488. }
  489. $saveData['user_id'] = $userId;
  490. $saveData['pub_date'] = empty($params['pub_date']) ? null : $params['pub_date'];
  491. $saveData['title'] = empty($params['title']) ? '' : $params['title'];
  492. $saveData['content'] = empty($params['content']) ? '' : $params['content'];
  493. $saveData['description'] = empty($params['description']) ? '' : $params['description'];
  494. $saveData['start_date'] = empty($params['start_date']) ? '' : $params['start_date'];
  495. $saveData['end_date'] = empty($params['end_date']) ? '' : $params['end_date'];
  496. if (!empty($params['start_date']) && !empty($params['end_date'])) {
  497. $startDate = strtotime($params['start_date']);
  498. $endDate = strtotime($params['end_date']);
  499. if (!$startDate > $endDate) {
  500. throw new ApiException(10022);
  501. }
  502. }
  503. $saveData['image_url'] = empty($params['image_url']) ? '' : $params['image_url'];
  504. $saveData['image_alt'] = empty($params['image_alt']) ? '' : $params['image_alt'];
  505. $saveData['main_image'] = empty($params['main_image']) ? '' : $params['main_image'];
  506. $saveData['main_image_alt'] = empty($params['main_image_alt']) ? '' : $params['main_image_alt'];
  507. $saveData['sub_image_urls'] = empty($params['sub_image_urls']) ? '' : json_encode($params['sub_image_urls']);
  508. $saveData['download_url'] = empty($params['download_url']) ? '' : json_encode($params['download_url']);
  509. $saveData['country'] = empty($params['country']) ? '' : $params['country'];
  510. $saveData['address'] = empty($params['address']) ? '' : $params['address'];
  511. $saveData['virtual_view'] = empty($params['virtual_view']) ? 0 : $params['virtual_view'];
  512. $saveData['total_view'] = $saveData['virtual_view'];
  513. $saveData['video_path'] = empty($params['video_path']) ? '' : $params['video_path'];
  514. $saveData['video_image_url'] = empty($params['video_image_url']) ? '' : $params['video_image_url'];
  515. $saveData['video_type'] = empty($params['video_type']) ? 0 : $params['video_type'];
  516. $saveData['video_desc'] = empty($params['video_desc']) ? '' : $params['video_desc'];
  517. $saveData['is_top'] = empty($params['is_top']) ? 0 : $params['is_top'];
  518. $saveData['sort'] = empty($params['sort']) ? 0 : $params['sort'];
  519. $saveData['is_recommend'] = empty($params['is_recommend']) ? 0 : $params['is_recommend'];
  520. $saveData['meeting_host'] = empty($params['meeting_host']) ? '' : $params['meeting_host'];
  521. $saveData['page_route'] = empty($params['page_route']) ? '' : $params['page_route'];
  522. $saveData['expand_content'] = empty($params['expand_content']) ? '' : json_encode($params['expand_content']);
  523. $saveData['create_time'] = $nowTime;
  524. $saveData['update_time'] = $nowTime;
  525. }
  526. return $saveData;
  527. }
  528. public function updatePv($id, $newVirtualView)
  529. {
  530. $virtualView = $this->getFieldById('virtual_view', $id);
  531. $value = $newVirtualView - $virtualView;
  532. $ret = $this->model->where('id', '=', $id)->increment('total_view', $value);
  533. $ret = $this->model->where('id', '=', $id)->increment('virtual_view', $value);
  534. WebFacade::clearPageCache('urla:');
  535. return $ret;
  536. }
  537. /**
  538. * 构造虚拟阅读量
  539. * */
  540. public function meetingUvFactory()
  541. {
  542. $page = 1;
  543. $total = 0;
  544. do {
  545. $where = [];
  546. $where['page_size'] = 500;
  547. $where['page'] = $page;
  548. $where['status'] = 0;
  549. $where['lt_total_view'] = 1000;
  550. $meetingData = $this->model->getMeetingList($where, 'a.id,a.virtual_view,a.total_view');
  551. if (!empty($meetingData) && !empty($meetingData['data'])) {
  552. $total = $meetingData['total'];
  553. $data = $meetingData['data'];
  554. $updateUvStr = '';
  555. // 规则:小于1千数随记增加 150以内位数
  556. foreach ($data as $item) {
  557. $value = 0;
  558. if ($item['total_view'] < 1000) {
  559. $value = mt_rand(0, 150);
  560. }
  561. /* if($item['total_view']<1000){
  562. $value= mt_rand(0, 150);
  563. }else if($item['total_view']<5000){
  564. $value= mt_rand(0, 99);
  565. }else{
  566. $value= mt_rand(0, 9);
  567. }*/
  568. $this->upMeetingPv($item['id'], $value);
  569. }
  570. }
  571. $page++;
  572. } while ($total > ($page * 500));
  573. WebFacade::clearPageCache('urla:');
  574. }
  575. /**
  576. * 更新产品浏览量
  577. * */
  578. public function upMeetingPv($meetingId, $value = 1)
  579. {
  580. if ($value > 1) {
  581. $ret = $this->model->where('id', '=', $meetingId)->increment('total_view', $value);
  582. $ret = $this->model->where('id', '=', $meetingId)->increment('virtual_view', $value);
  583. } else {
  584. $totalView = $this->getFieldById('total_view', $meetingId);
  585. $value = (($value * -1) > $totalView) ? ($totalView * -1) : $value;
  586. $ret = $this->model->where('id', '=', $meetingId)->increment('total_view', $value);
  587. }
  588. return $ret;
  589. }
  590. /**
  591. * 产品推荐设置
  592. * */
  593. public function recommendSet($params)
  594. {
  595. $id = empty($params['id']) ? 0 : $params['id'];
  596. $isRecommend = empty($params['is_recommend']) ? 0 : $params['is_recommend'];
  597. $ret = $this->model->where('id', '=', $id)
  598. ->update(['is_recommend' => $isRecommend, 'update_time' => nowTime()]);
  599. //更新所有页面缓存
  600. WebFacade::clearPageCache('urla:');
  601. return $id;
  602. }
  603. /**
  604. * 产品列表
  605. * */
  606. public function getMeetingList($params)
  607. {
  608. $ret = $this->model->getMeetingList($params);
  609. $pageListData = empty($ret['data']) ? [] : $ret['data'];
  610. if (!empty($pageListData)) {
  611. $ids = array_column($pageListData, 'seo_id');
  612. $seoList = [];
  613. if (!empty($ids)) {
  614. $seoList = WebFacade:: getSeoListByIds($ids);
  615. if (!empty($seoList)) {
  616. $seoList = mapByKey($seoList, 'id');
  617. }
  618. }
  619. foreach ($pageListData as &$pageItem) {
  620. $pageItem['seo_data'] = empty($seoList[$pageItem['seo_id']]) ? [] : $seoList[$pageItem['seo_id']];
  621. $pageItem['expand_content'] = empty($pageItem['expand_content']) ? [] : json_decode($pageItem['expand_content'], true);
  622. }
  623. }
  624. $ret['data'] = $pageListData;
  625. return $ret;
  626. }
  627. /**
  628. * 获取产品详情
  629. * */
  630. public function getMeetingInfo($params)
  631. {
  632. $meetingInfo = $this->model->getMeetingInfo($params);
  633. if (!empty($meetingInfo)) {
  634. if (!empty($meetingInfo['seo_id'])) {
  635. $meetingInfo['seo_data'] = WebFacade::getSeoInfo(['id' => $meetingInfo['seo_id']]);
  636. } else {
  637. $meetingInfo['seo_data'] = [
  638. 'seo_describe' => '',
  639. 'seo_keyword' => '',
  640. 'seo_title' => '',
  641. 'urla' => ''
  642. ];
  643. }
  644. $meetingInfo['spec'] = empty($meetingInfo['spec']) ? [] : json_decode($meetingInfo['spec'], true);
  645. $meetingInfo['type_ids'] = $this->meetingTypeRelationModel->getTypeIds($meetingInfo['id']);
  646. $meetingInfo['tag_ids'] = $this->meetingTagRelationModel->getTagIds($meetingInfo['id']);
  647. $meetingInfo['expand_content'] = empty($meetingInfo['expand_content']) ? [] : json_decode($meetingInfo['expand_content'], true);
  648. /*if (!empty($meetingInfo['expand_content'])) {
  649. $meetingInfo['expand_content'] = mapByKey($meetingInfo['expand_content'],'key');
  650. }*/
  651. if (!empty($meetingInfo['download_url'])) {
  652. $meetingInfo['download_url'] = json_decode($meetingInfo['download_url'], true);
  653. } else {
  654. $meetingInfo['download_url'] = [];
  655. }
  656. if (!empty($meetingInfo['sub_image_urls'])) {
  657. $meetingInfo['sub_image_urls'] = json_decode($meetingInfo['sub_image_urls'], true);
  658. } else {
  659. $meetingInfo['sub_image_urls'] = [];
  660. }
  661. $meetingInfo['speech_schedule'] = $this->meetingSpeechScheduleModel->getSpeechScheduleByMeetingId($meetingInfo['id']);
  662. foreach ($meetingInfo['speech_schedule'] as $key => $speech_item) {
  663. $meetingInfo['speech_schedule'][$key]['expand_content'] = json_decode($speech_item['expand_content'], true);
  664. }
  665. }
  666. return $meetingInfo;
  667. }
  668. /**
  669. * 获取产品分类未关联的产品
  670. * */
  671. public function getUnrelatedMeetingByTypeIds($params)
  672. {
  673. $ret = $this->model->getUnrelatedMeetingByTypeIds($params);
  674. return $ret;
  675. }
  676. /**
  677. * 获取产品标签未关联的产品
  678. * */
  679. public function getUnrelatedMeetingByTagIds($params)
  680. {
  681. $ret = $this->model->getUnrelatedMeetingByTagIds($params);
  682. return $ret;
  683. }
  684. /**
  685. * 获取产品详情渲染数据
  686. * */
  687. public function getMeetingRenderData($params)
  688. {
  689. $meetingInfo = $this->model->getMeetingInfo($params);
  690. if (!empty($meetingInfo)) {
  691. $newestTypeAndTagData = $this->getTypeAndTagDataByMeetingId([$meetingInfo['id']]);
  692. if (!empty($newestTypeAndTagData[$meetingInfo['id']]['type_items'])) {
  693. $meetingInfo['type_items'] = $newestTypeAndTagData[$meetingInfo['id']]['type_items'];
  694. } else {
  695. $meetingInfo['type_items'] = [];
  696. }
  697. if (!empty($newestTypeAndTagData[$meetingInfo['id']]['tag_items'])) {
  698. $meetingInfo['tag_items'] = $newestTypeAndTagData[$meetingInfo['id']]['tag_items'];
  699. } else {
  700. $meetingInfo['tag_items'] = [];
  701. }
  702. if (!empty($meetingInfo['download_url'])) {
  703. $meetingInfo['download_url'] = json_decode($meetingInfo['download_url'], true);
  704. } else {
  705. $meetingInfo['download_url'] = [];
  706. }
  707. if (!empty($meetingInfo['sub_image_urls'])) {
  708. $meetingInfo['sub_image_urls'] = json_decode($meetingInfo['sub_image_urls'], true);
  709. } else {
  710. $meetingInfo['sub_image_urls'] = [];
  711. }
  712. $meetingInfo['seo_data'] = WebFacade::getSeoInfo(['id' => $meetingInfo['seo_id']]);
  713. $meetingInfo['speech_schedule'] = $this->meetingSpeechScheduleModel->getSpeechScheduleByMeetingId($meetingInfo['id']);
  714. $meetingInfo['expand_content'] = empty($meetingInfo['expand_content']) ? [] : json_decode($meetingInfo['expand_content'], true);
  715. /*//初始化会议自定义字段
  716. if (!empty($meetingInfo['expand_content'])) {
  717. $meetingInfo['expand_content'] = mapByKey($meetingInfo['expand_content'],'key');
  718. }*/
  719. //初始化会议日程自定义字段
  720. if (!empty($meetingInfo['speech_schedule'])) {
  721. foreach ($meetingInfo['speech_schedule'] as $speech_schedule_key => $speech_schedule_item) {
  722. if (!empty($speech_schedule_item['expand_content'])) {
  723. $speech_schedule_item['expand_content'] = empty($speech_schedule_item['expand_content']) ? [] : json_decode($speech_schedule_item['expand_content'], true);
  724. // $meetingInfo['speech_schedule'][$speech_schedule_key]['expand_content'] = mapByKey($speech_schedule_item['expand_content'],'key');
  725. $meetingInfo['speech_schedule'][$speech_schedule_key]['expand_content'] = $speech_schedule_item['expand_content'];
  726. }
  727. }
  728. }
  729. }
  730. return $meetingInfo;
  731. }
  732. /**
  733. * 根据产品id获取产品类型及产品标签数据
  734. * */
  735. public function getTypeAndTagDataByMeetingId($newestMeetingIds)
  736. {
  737. $resultData = [];
  738. $newestTypeData = $this->meetingTypeRelationModel->getTypeListByMeetingIds($newestMeetingIds);
  739. foreach ($newestTypeData as $typeItem) {
  740. $resultData[$typeItem['meeting_id']]['type_items'][] = $typeItem;
  741. }
  742. $newestTagData = $this->meetingTagRelationModel->getTagListByMeetingIds($newestMeetingIds);
  743. foreach ($newestTagData as $tagItem) {
  744. $resultData[$tagItem['meeting_id']]['tag_items'][] = $tagItem;
  745. }
  746. return $resultData;
  747. }
  748. /**
  749. * 获取产品列表页渲染数据
  750. * */
  751. public function getMeetingRecentlyData($params = [])
  752. {
  753. // 获取举办地点
  754. $data = [
  755. 'country' => [],//国家
  756. ];
  757. $data['country'] = $this->model->getLocalCountryList();
  758. return $data;
  759. }
  760. /**
  761. * 获取类型详情
  762. * */
  763. public function getMeetingTypeRenderInfo($params = [])
  764. {
  765. $typeWhere = [];
  766. $typeWhere['status'] = 0;
  767. $typeWhere['id'] = empty($params['id']) ? 0 : $params['id'];
  768. $typeInfo = $this->meetingTypeModel->getMeetingTypeInfo($typeWhere);
  769. return $typeInfo;
  770. }
  771. /**
  772. * 获取标签详情
  773. * */
  774. public function getMeetingTagRenderInfo($params = [])
  775. {
  776. $tagWhere = [];
  777. $tagWhere['status'] = 0;
  778. $tagWhere['id'] = empty($params['tag_id']) ? 0 : $params['tag_id'];
  779. $tagInfo = $this->meetingTagModel->getMeetingTagInfo($tagWhere);
  780. return $tagInfo;
  781. }
  782. /**
  783. * 获取相关商品
  784. * */
  785. public function getRelevanceList($params)
  786. {
  787. $newestListParams = [];
  788. $newestListParams['page_size'] = empty($params['relevance_page_size']) ? 5 : $params['relevance_page_size'];
  789. $newestListParams['sort']['is_top'] = 1;
  790. $newestListParams['sort']['pub_date'] = 1;
  791. $newestListParams['type_ids'] = empty($params['type_ids']) ? [] : $params['type_ids'];
  792. $newestList = $this->getPublishMeetingList($newestListParams);
  793. return $newestList;
  794. }
  795. /**
  796. * 获取已发布的连接
  797. * */
  798. public function getPublishMeetingList($params, $fields = '')
  799. {
  800. if (empty($fields)) {
  801. $fields = 'a.sort,a.id,a.pub_date,a.title,a.description,a.image_url,a.image_alt,a.expand_content,a.country,' .
  802. 'a.is_top,a.is_recommend,a.download_url,a.total_view,a.meeting_host,a.start_date,a.end_date,b.urla,a.address';
  803. }
  804. $ids = [];
  805. if (!empty($params['type_ids'])) {
  806. $typeMeetingList = $this->getMeetingByTypeIds(['type_id' => $params['type_ids'], 'page_size' => 99999]);
  807. if (!empty($typeMeetingList['data'])) {
  808. $ids = array_column($typeMeetingList['data'], 'id');
  809. }
  810. }
  811. if (!empty($params['tag_ids'])) {
  812. $tagMeetingList = $this->getMeetingByTagIds(['tag_id' => $params['tag_ids'], 'page_size' => 99999]);
  813. if (!empty($tagMeetingList['data'])) {
  814. $tagReIds = array_column($tagMeetingList['data'], 'id');
  815. if (!empty($tagReIds) && !empty($params['type_ids'])) {
  816. $ids = array_intersect($ids, $tagReIds);
  817. } else {
  818. $ids = $tagReIds;
  819. }
  820. }
  821. }
  822. if (!empty($ids)) {
  823. $params['ids'] = $ids;
  824. }
  825. $meetingList = $this->model->getPublishMeetingList($params, $fields);
  826. $meetingListData = $meetingList['data'];
  827. $meetingIds = array_column($meetingListData, 'id');
  828. if ($meetingIds) {
  829. $newestTypeAndTagData = $this->getTypeAndTagDataByMeetingId($meetingIds);
  830. foreach ($meetingListData as &$meetingItem) {
  831. if (!empty($newestTypeAndTagData[$meetingItem['id']]['type_items'])) {
  832. $meetingItem['type_items'] = $newestTypeAndTagData[$meetingItem['id']]['type_items'];
  833. } else {
  834. $meetingItem['type_items'] = [];
  835. }
  836. if (!empty($newestTypeAndTagData[$meetingItem['id']]['tag_items'])) {
  837. $meetingItem['tag_items'] = $newestTypeAndTagData[$meetingItem['id']]['tag_items'];
  838. } else {
  839. $meetingItem['tag_items'] = [];
  840. }
  841. $meetingItem['expand_content'] = empty($meetingItem['expand_content']) ? [] : json_decode($meetingItem['expand_content'], true);
  842. $meetingItem['expand_content'] = mapByKey($meetingItem['expand_content'], 'key');
  843. }
  844. $meetingList['data'] = $meetingListData;
  845. }
  846. return $meetingList;
  847. }
  848. /**
  849. * 根据类型id 获取产品列表
  850. * */
  851. public function getMeetingByTypeIds($params)
  852. {
  853. $retData = $this->meetingTypeRelationModel->getMeetingByTypeIds($params);
  854. return $retData;
  855. }
  856. /**
  857. * 根据标签id 获取产品列表
  858. * */
  859. public function getMeetingByTagIds($params)
  860. {
  861. $retData = $this->meetingTagRelationModel->getMeetingByTagIds($params);
  862. return $retData;
  863. }
  864. /**
  865. * 热门产品列表
  866. * */
  867. public function getHotList($params)
  868. {
  869. $hotListParams = [];
  870. $hotListParams['page_size'] = empty($params['hot_news_size']) ? 4 : $params['hot_news_size'];
  871. $hotListParams['sort']['is_hot'] = 1;
  872. $hotListParams['sort']['pub_date'] = 1;
  873. $hotList = $this->getPublishMeetingList($hotListParams);
  874. return $hotList;
  875. }
  876. /**
  877. * 推荐产品列表
  878. * */
  879. public function getRecommendList($params)
  880. {
  881. $recommendListParams = [];
  882. $recommendListParams['page_size'] = empty($params['recommend_news_size']) ? 4 : $params['recommend_news_size'];
  883. $recommendListParams['sort']['is_recommend'] = 1;
  884. $recommendListParams['sort']['pub_date'] = 1;
  885. $recommendList = $this->getPublishMeetingList($recommendListParams);
  886. return $recommendList;
  887. }
  888. /**
  889. * 根据类型id获取产品
  890. * */
  891. public function getPublishMeetingListByTypeId($params)
  892. {
  893. $fields = 'a.id,a.pub_date,a.title,a.description,a.image_url,a.image_alt,a.is_top,a.is_recommend,a.download_url,a.total_view,b.type_id,c.urla';
  894. $ret = $this->model->getPublishMeetingListByTypeId($params, $fields);
  895. $meetingData = empty($ret['data']) ? [] : $ret['data'];
  896. if (!empty($meetingData)) {
  897. $newestMeetingIds = array_column($meetingData, 'id');
  898. $newestTypeAndTagData = $this->getTypeAndTagDataByMeetingId($newestMeetingIds);
  899. foreach ($meetingData as &$meetingItem) {
  900. if (!empty($newestTypeAndTagData[$meetingItem['id']]['type_items'])) {
  901. $meetingItem['type_items'] = $newestTypeAndTagData[$meetingItem['id']]['type_items'];
  902. } else {
  903. $meetingItem['type_items'] = [];
  904. }
  905. if (!empty($newestTypeAndTagData[$meetingItem['id']]['tag_items'])) {
  906. $meetingItem['tag_items'] = $newestTypeAndTagData[$meetingItem['id']]['tag_items'];
  907. } else {
  908. $meetingItem['tag_items'] = [];
  909. }
  910. }
  911. $ret['data'] = $meetingData;
  912. }
  913. return $ret;
  914. }
  915. /**
  916. * 根据标签id获取产品
  917. * */
  918. public function getPublishMeetingListByTagId($params)
  919. {
  920. $fields = 'a.id,a.pub_date,a.title,a.description,a.image_url,a.image_alt,a.is_top,a.is_recommend,a.download_url,a.total_view,b.tag_id,c.urla';
  921. $ret = $this->model->getPublishMeetingListByTagId($params, $fields);
  922. $meetingData = empty($ret['data']) ? [] : $ret['data'];
  923. if (!empty($meetingData)) {
  924. $newestMeetingIds = array_column($meetingData, 'id');
  925. $newestTypeAndTagData = $this->getTypeAndTagDataByMeetingId($newestMeetingIds);
  926. foreach ($meetingData as &$meetingItem) {
  927. if (!empty($newestTypeAndTagData[$meetingItem['id']]['type_items'])) {
  928. $meetingItem['type_items'] = $newestTypeAndTagData[$meetingItem['id']]['type_items'];
  929. } else {
  930. $meetingItem['type_items'] = [];
  931. }
  932. if (!empty($newestTypeAndTagData[$meetingItem['id']]['tag_items'])) {
  933. $meetingItem['tag_items'] = $newestTypeAndTagData[$meetingItem['id']]['tag_items'];
  934. } else {
  935. $meetingItem['tag_items'] = [];
  936. }
  937. }
  938. $ret['data'] = $meetingData;
  939. }
  940. return $ret;
  941. }
  942. /**
  943. * 搜索获取已发布的产品
  944. * */
  945. public function getSearchMeetingList($params)
  946. {
  947. if (empty($fields)) {
  948. $fields = 'a.id,a.title,b.urla';
  949. }
  950. $meetingList = $this->model->getPublishMeetingList($params, $fields);
  951. return $meetingList;
  952. }
  953. /**
  954. * 新闻排序
  955. */
  956. public function changeMeetingSort($meetingId, $sort)
  957. {
  958. $data = [];
  959. $getData = $this->findOneById($meetingId, 'id,sort');
  960. if ($sort == 0) { // 置顶
  961. $sortData = $this->findOneBy([
  962. 'sort' => $sort,
  963. 'id' => ['<>', $meetingId]
  964. ], 'id');
  965. if (empty($sortData['id'])) {
  966. throw new ApiException(1004, ['msg' => '当前已经是最高一行']);
  967. }
  968. if ($getData['sort'] == 0) {
  969. $this->incrementBy([
  970. 'id' => ['<>', $meetingId],
  971. ], 'sort');
  972. } else {
  973. $this->incrementBy([
  974. 'id' => ['<', $meetingId],
  975. ], 'sort');
  976. }
  977. $upData['sort'] = $sort;
  978. } elseif ($sort == '-1') { // 上移
  979. $upSortData = $this->model->where('sort', '<', $getData['sort'])
  980. ->orderBy('sort', 'desc')->first();
  981. if (empty($upSortData)) {
  982. throw new ApiException(1004, ['msg' => '当前已经是最高一行']);
  983. } else {
  984. $upData = $upSortData->toArray();
  985. }
  986. } elseif ($sort == '+1') { // 下移
  987. $downSortData = $this->model->where('sort', '>', $getData['sort'])
  988. ->orderBy('sort', 'asc')->first();
  989. if (empty($downSortData)) {
  990. throw new ApiException(1004, ['msg' => '当前已经是最后一行']);
  991. } else {
  992. $upData = $downSortData->toArray();
  993. }
  994. }
  995. $data['sort'] = $upData['sort'];
  996. $this->updateBy([
  997. 'sort' => $data['sort']
  998. ], [
  999. 'sort' => $getData['sort']
  1000. ]);
  1001. $is_top = 0;
  1002. if ($data['sort'] == 0) {
  1003. $is_top = 1;
  1004. }
  1005. $rst = $this->update($meetingId, [
  1006. 'sort' => $data['sort'],
  1007. 'is_top' => $is_top
  1008. ]);
  1009. //更新所有页面缓存
  1010. WebFacade::clearPageCache('urla:');
  1011. return $rst;
  1012. }
  1013. /**
  1014. * 展会、会议下一项
  1015. * */
  1016. public function getNextMeetingItem($id)
  1017. {
  1018. $meeting = $this->model->getNextItem($id);
  1019. return $meeting;
  1020. }
  1021. /**
  1022. * 展会、会议上一项
  1023. * */
  1024. public function getPrevMeetingItem($id)
  1025. {
  1026. $meeting = $this->model->getPrevItem($id);
  1027. return $meeting;
  1028. }
  1029. /**
  1030. * 批量修改类型
  1031. * @param $params
  1032. * @return true
  1033. */
  1034. public function typePluralEdit($params)
  1035. {
  1036. $userId = $this->getAuthUserId();
  1037. $ret = 1;
  1038. foreach ($params['ids'] as $v) {
  1039. $ret = $this->meetingTypeRelationModel->addByMeetingId($v, $params['type_ids'], $userId);
  1040. }
  1041. return $ret;
  1042. }
  1043. /**
  1044. * 批量修改标签
  1045. * @param $params
  1046. * @return true
  1047. */
  1048. public function tagPluralEdit($params)
  1049. {
  1050. $userId = $this->getAuthUserId();
  1051. $ret = 1;
  1052. foreach ($params['ids'] as $v) {
  1053. $ret = $this->meetingTagRelationModel->addByMeetingId($v, $params['tag_ids'], $userId);
  1054. }
  1055. return $ret;
  1056. }
  1057. public function batchDelete($params)
  1058. {
  1059. $ids = $params['ids'];
  1060. $rst = $this->model->whereIn('id', $ids)->update(['status' => 2]);
  1061. //删除处理
  1062. if ($rst) {
  1063. $this->meetingTypeRelationModel->deleteByMeetingId($ids);
  1064. $this->meetingTagRelationModel->deleteByMeetingId($ids);
  1065. }
  1066. return $rst;
  1067. }
  1068. public function batchStatus($params)
  1069. {
  1070. $ids = $params['ids'];
  1071. $status = $params['status'];
  1072. $rst = $this->model->whereIn('id', $ids)->update(['status' => $status]);
  1073. return $rst;
  1074. }
  1075. /**
  1076. * 获取全球展会列表筛选项
  1077. * @param $tagId
  1078. * @param $part
  1079. * @return array
  1080. */
  1081. public function getGlobalFilter($tagId = 1, $part = 0)
  1082. {
  1083. $typeData = $this->model->getTypesWithTagId($tagId);
  1084. $timelineData = [];
  1085. $nowYear = date('Y');
  1086. $nowMonth = date('m');
  1087. if ($part == 1) {
  1088. $nextYear = $nowYear;
  1089. $nextMonth = $nowMonth + 1;
  1090. if ($nextMonth > 12) {
  1091. $nextYear = $nextYear + 1;
  1092. $nextMonth = 1;
  1093. }
  1094. } else {
  1095. $nextYear = $nowYear - 2;
  1096. $nextMonth = 1;
  1097. }
  1098. $timelineData[] = $this->generateYearAndMonthOptions($nextYear, $nextMonth);
  1099. $nextYear = $nextYear + 1;
  1100. $nextMonth = 1;
  1101. $timelineData[] = $this->generateYearAndMonthOptions($nextYear, $nextMonth);
  1102. if ($part != 1) {
  1103. $nextYear = $nextYear + 1;
  1104. $nextMonth = $nowMonth;
  1105. $timelineData[] = $this->generateYearAndMonthOptions($nextYear, $nextMonth, true);
  1106. }
  1107. $areaData = $this->model->getAreaDataWithTagId($tagId);
  1108. return [
  1109. 'type_data' => $typeData,
  1110. 'area_data' => $areaData,
  1111. 'timeline_data' => $timelineData
  1112. ];
  1113. }
  1114. private function generateYearAndMonthOptions($nextYear, $nextMonth, $isPast = false)
  1115. {
  1116. $arr = ['text' => $nextYear];
  1117. $children = [];
  1118. if ($isPast) {
  1119. if ($nextMonth >= 4) {
  1120. $children[] = [
  1121. 'id' => $nextYear . '-1 ' . $nextYear . '-3',
  1122. 'text' => '1-3'
  1123. ];
  1124. }
  1125. if ($nextMonth >= 7) {
  1126. $children[] = [
  1127. 'id' => $nextYear . '-4 ' . $nextYear . '-6',
  1128. 'text' => '4-6'
  1129. ];
  1130. }
  1131. if ($nextMonth >= 10) {
  1132. $children[] = [
  1133. 'id' => $nextYear . '-7 ' . $nextYear . '-9',
  1134. 'text' => '7-9'
  1135. ];
  1136. }
  1137. } else {
  1138. if ($nextMonth <= 3) {
  1139. $children[] = [
  1140. 'id' => $nextYear . '-1 ' . $nextYear . '-3',
  1141. 'text' => '1-3'
  1142. ];
  1143. }
  1144. if ($nextMonth <= 6) {
  1145. $children[] = [
  1146. 'id' => $nextYear . '-4 ' . $nextYear . '-6',
  1147. 'text' => '4-6'
  1148. ];
  1149. }
  1150. if ($nextMonth <= 9) {
  1151. $children[] = [
  1152. 'id' => $nextYear . '-7 ' . $nextYear . '-9',
  1153. 'text' => '7-9'
  1154. ];
  1155. }
  1156. $children[] = [
  1157. 'id' => $nextYear . '-10 ' . $nextYear . '-12',
  1158. 'text' => '10-12'
  1159. ];
  1160. }
  1161. $arr['children'] = $children;
  1162. return $arr;
  1163. }
  1164. }