WechatKeywordMsgService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace App\Modules\OfficialAccount\Services;
  3. use App\Modules\OfficialAccount\Models\WechatKeywordMsgs;
  4. use Redis;
  5. class WechatKeywordMsgService
  6. {
  7. /**
  8. * 通过id获取关键字
  9. */
  10. static function wechatKeywordMsgById($wechatKeywordPrams)
  11. {
  12. return WechatKeywordMsgs::wechatKeywordMsgsById($wechatKeywordPrams['id']);
  13. }
  14. /**
  15. * 获取推送关键字消息列表
  16. */
  17. static function wechatKeywordMsgBydistributionChannelId($wechatKeywordPrams)
  18. {
  19. return WechatKeywordMsgs::wechatKeywordMsgsBydistributionChannelId($wechatKeywordPrams['distribution_channel_id']);
  20. }
  21. /**
  22. * 更新状态
  23. */
  24. static function updateWechatKeywordMsgStatus($wechatKeywordPrams)
  25. {
  26. return WechatKeywordMsgs::updateWechatKeywordMsgStatus($wechatKeywordPrams['id'],$wechatKeywordPrams['distribution_channel_id'],$wechatKeywordPrams['status']);
  27. }
  28. /**
  29. * 增加关键字
  30. */
  31. static function addWechatKeywordMsg($wechatKeywordMsgPrams)
  32. {
  33. try {
  34. \Log::info($wechatKeywordMsgPrams);
  35. $wechatKeywordMsg = WechatKeywordMsgs::wechatKeywordByDistributionChannelIdAndKeyword($wechatKeywordMsgPrams['distribution_channel_id'],$wechatKeywordMsgPrams['keyword'],1);
  36. if(empty($wechatKeywordMsg)) {
  37. \Log::info('addWechatKeywordMsg_create');
  38. WechatKeywordMsgs::firstOrCreate($wechatKeywordMsgPrams);
  39. return 1;
  40. }else{
  41. \Log::info('addWechatKeywordMsg_exist');
  42. return 2;
  43. }
  44. } catch (\Exception $e) {
  45. \Log::info("addWechatKeywordMsg_ept:".$e);
  46. return 0;
  47. }
  48. }
  49. /**
  50. * 修改关键字
  51. */
  52. static function updateWechatKeywordMsg($wechatKeywordMsgPrams)
  53. {
  54. try {
  55. $wechatKeywordMsg = WechatKeywordMsgs::wechatKeywordMsgsById($wechatKeywordMsgPrams['id']);
  56. \Log::info('updateWechatKeywordMsg_origin');\Log::info($wechatKeywordMsg);
  57. if(!empty($wechatKeywordMsg)) {
  58. $wechatKeywordMsg->appids = $wechatKeywordMsgPrams['appids'];
  59. $wechatKeywordMsg->bid = $wechatKeywordMsgPrams['bid'];
  60. $wechatKeywordMsg->cid = $wechatKeywordMsgPrams['cid'];
  61. $wechatKeywordMsg->book_name = $wechatKeywordMsgPrams['book_name'];
  62. $wechatKeywordMsg->chapter_name = $wechatKeywordMsgPrams['chapter_name'];
  63. $wechatKeywordMsg->send_title = $wechatKeywordMsgPrams['send_title'];
  64. $wechatKeywordMsg->send_cover = $wechatKeywordMsgPrams['send_cover'];
  65. $wechatKeywordMsg->keyword = $wechatKeywordMsgPrams['keyword'];
  66. $wechatKeywordMsg->link_type = $wechatKeywordMsgPrams['link_type'];
  67. $wechatKeywordMsg->link = $wechatKeywordMsgPrams['link'];
  68. $wechatKeywordMsg->desc = $wechatKeywordMsgPrams['desc'];
  69. $wechatKeywordMsg->mode = $wechatKeywordMsgPrams['mode'];
  70. $wechatKeywordMsg->content = $wechatKeywordMsgPrams['content'];
  71. \Log::info('after_update:');
  72. \Log::info($wechatKeywordMsg);
  73. $wechatKeywordMsg->save();
  74. return 1;
  75. }else{
  76. \Log::info('updateWechatKeywordMsg_not_exist');
  77. return 2;
  78. }
  79. } catch (\Exception $e) {
  80. \Log::info("updateWechatKeywordMsg_ept:".$e);
  81. return 0;
  82. }
  83. }
  84. }