SmartPushMsgService.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace App\Modules\OfficialAccount\Services;
  3. use App\Modules\OfficialAccount\Models\SmartPushMsgs;
  4. use Redis;
  5. class SmartPushMsgService
  6. {
  7. /**
  8. * 通过id获取自定义智能推送内容
  9. */
  10. static function smartPushMsgById($smartPushPrams)
  11. {
  12. return SmartPushMsgs::smartPushMsgsById($smartPushPrams['id']);
  13. }
  14. /**
  15. * 获取推送自定义智能推送内容消息列表
  16. */
  17. static function smartPushMsgBydistributionChannelId($smartPushPrams)
  18. {
  19. return SmartPushMsgs::smartPushMsgsBydistributionChannelId($smartPushPrams['distribution_channel_id']);
  20. }
  21. /**
  22. * 根据渠道和分类、性别获取推送自定义智能推送内容消息
  23. */
  24. static function smartPushByDistributionChannelIdAndCategorySex($smartPushPrams)
  25. {
  26. return SmartPushMsgs::smartPushByDistributionChannelIdAndCategorySex($smartPushPrams['distribution_channel_id'],$smartPushPrams['category_type'],$smartPushPrams['sex']);
  27. }
  28. /**
  29. * 根据渠道和分类、性别获取推送自定义智能推送内容消息
  30. */
  31. static function checkSexAllEdit($smartPushPrams)
  32. {
  33. return SmartPushMsgs::checkSexAllEdit($smartPushPrams['distribution_channel_id'],$smartPushPrams['category_type']);
  34. }
  35. /**
  36. * 更新状态
  37. */
  38. static function updateSmartPushMsgStatus($smartPushPrams)
  39. {
  40. return SmartPushMsgs::updateSmartPushMsgStatus($smartPushPrams['id'],$smartPushPrams['status']);
  41. }
  42. /**
  43. * 保存或修改自定义智能推送内容
  44. */
  45. static function addSmartPushMsg($smartPushMsgPrams)
  46. {
  47. try {
  48. \Log::info($smartPushMsgPrams);
  49. $smartPushMsg = SmartPushMsgs::smartPushByDistributionChannelIdAndCategorySex($smartPushMsgPrams['distribution_channel_id'],$smartPushMsgPrams['category_type'],$smartPushMsgPrams['sex']);
  50. \Log::info($smartPushMsg);
  51. if(empty($smartPushMsg)) {
  52. \Log::info('addSmartPushMsg_create');
  53. SmartPushMsgs::firstOrCreate($smartPushMsgPrams);
  54. return 1;
  55. }else{
  56. \Log::info('addSmartPushMsg_exist,channel_id:'.$smartPushMsgPrams['distribution_channel_id'].' category:'.$smartPushMsgPrams['category_type']);
  57. return 1;
  58. }
  59. } catch (\Exception $e) {
  60. \Log::info("addSmartPushMsg_ept:".$e);
  61. return 0;
  62. }
  63. }
  64. /**
  65. * 修改自定义智能推送内容
  66. */
  67. static function updateSmartPushMsg($smartPushMsgPrams)
  68. {
  69. try {
  70. $smartPushMsg = SmartPushMsgs::smartPushMsgsById($smartPushMsgPrams['id']);
  71. \Log::info('updateSmartPushMsg_origin');\Log::info($smartPushMsg);
  72. if(!empty($smartPushMsg)) {
  73. $smartPushMsg->name = $smartPushMsgPrams['name'];
  74. $smartPushMsg->category_type = $smartPushMsgPrams['category_type'];
  75. $smartPushMsg->content = $smartPushMsgPrams['content'];
  76. $smartPushMsg->sex = $smartPushMsgPrams['sex'];
  77. $smartPushMsg->description = $smartPushMsgPrams['description'];
  78. $smartPushMsg->book_name = $smartPushMsgPrams['book_name'];
  79. $smartPushMsg->chapter_name = $smartPushMsgPrams['chapter_name'];
  80. $smartPushMsg->distribution_channel_id = $smartPushMsgPrams['distribution_channel_id'];
  81. $smartPushMsg->status = $smartPushMsgPrams['status'];
  82. \Log::info('after_updateSmartPushMsg:');
  83. \Log::info($smartPushMsg);
  84. $smartPushMsg->save();
  85. return 1;
  86. }else{
  87. \Log::info('updateSmartPushMsg_not_exist');
  88. return 2;
  89. }
  90. } catch (\Exception $e) {
  91. \Log::info("updateSmartPushMsg_ept:".$e);
  92. return 0;
  93. }
  94. }
  95. }