123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace App\Modules\OfficialAccount\Services;
- use App\Modules\OfficialAccount\Models\SmartPushMsgs;
- use Redis;
- class SmartPushMsgService
- {
- /**
- * 通过id获取自定义智能推送内容
- */
- static function smartPushMsgById($smartPushPrams)
- {
- return SmartPushMsgs::smartPushMsgsById($smartPushPrams['id']);
- }
- /**
- * 获取推送自定义智能推送内容消息列表
- */
- static function smartPushMsgBydistributionChannelId($smartPushPrams)
- {
- return SmartPushMsgs::smartPushMsgsBydistributionChannelId($smartPushPrams['distribution_channel_id']);
- }
-
- /**
- * 根据渠道和分类、性别获取推送自定义智能推送内容消息
- */
- static function smartPushByDistributionChannelIdAndCategorySex($smartPushPrams)
- {
-
- return SmartPushMsgs::smartPushByDistributionChannelIdAndCategorySex($smartPushPrams['distribution_channel_id'],$smartPushPrams['category_type'],$smartPushPrams['sex']);
-
- }
-
- /**
- * 根据渠道和分类、性别获取推送自定义智能推送内容消息
- */
- static function checkSexAllEdit($smartPushPrams)
- {
-
- return SmartPushMsgs::checkSexAllEdit($smartPushPrams['distribution_channel_id'],$smartPushPrams['category_type']);
-
- }
-
-
- /**
- * 更新状态
- */
- static function updateSmartPushMsgStatus($smartPushPrams)
- {
-
- return SmartPushMsgs::updateSmartPushMsgStatus($smartPushPrams['id'],$smartPushPrams['status']);
-
- }
- /**
- * 保存或修改自定义智能推送内容
- */
- static function addSmartPushMsg($smartPushMsgPrams)
- {
- try {
- \Log::info($smartPushMsgPrams);
- $smartPushMsg = SmartPushMsgs::smartPushByDistributionChannelIdAndCategorySex($smartPushMsgPrams['distribution_channel_id'],$smartPushMsgPrams['category_type'],$smartPushMsgPrams['sex']);
- \Log::info($smartPushMsg);
- if(empty($smartPushMsg)) {
- \Log::info('addSmartPushMsg_create');
- SmartPushMsgs::firstOrCreate($smartPushMsgPrams);
- return 1;
- }else{
- \Log::info('addSmartPushMsg_exist,channel_id:'.$smartPushMsgPrams['distribution_channel_id'].' category:'.$smartPushMsgPrams['category_type']);
- return 1;
- }
- } catch (\Exception $e) {
- \Log::info("addSmartPushMsg_ept:".$e);
-
- return 0;
- }
- }
-
- /**
- * 修改自定义智能推送内容
- */
- static function updateSmartPushMsg($smartPushMsgPrams)
- {
-
- try {
-
- $smartPushMsg = SmartPushMsgs::smartPushMsgsById($smartPushMsgPrams['id']);
- \Log::info('updateSmartPushMsg_origin');\Log::info($smartPushMsg);
- if(!empty($smartPushMsg)) {
- $smartPushMsg->name = $smartPushMsgPrams['name'];
- $smartPushMsg->category_type = $smartPushMsgPrams['category_type'];
- $smartPushMsg->content = $smartPushMsgPrams['content'];
- $smartPushMsg->sex = $smartPushMsgPrams['sex'];
- $smartPushMsg->description = $smartPushMsgPrams['description'];
- $smartPushMsg->book_name = $smartPushMsgPrams['book_name'];
- $smartPushMsg->chapter_name = $smartPushMsgPrams['chapter_name'];
- $smartPushMsg->distribution_channel_id = $smartPushMsgPrams['distribution_channel_id'];
- $smartPushMsg->status = $smartPushMsgPrams['status'];
- \Log::info('after_updateSmartPushMsg:');
- \Log::info($smartPushMsg);
- $smartPushMsg->save();
-
- return 1;
-
- }else{
- \Log::info('updateSmartPushMsg_not_exist');
- return 2;
-
- }
-
- } catch (\Exception $e) {
- \Log::info("updateSmartPushMsg_ept:".$e);
-
- return 0;
-
- }
-
- }
- }
|