|
@@ -45,7 +45,7 @@ class MessageRuleRepository
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 创建消息
|
|
|
+ * 创建消息规则
|
|
|
*/
|
|
|
public function create($request)
|
|
|
{
|
|
@@ -63,81 +63,32 @@ class MessageRuleRepository
|
|
|
$noticeGroups = implode(',', array_unique($noticeGroups));
|
|
|
}
|
|
|
|
|
|
- return $noticeGroups;
|
|
|
- //验证话题
|
|
|
- $topicIds = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
|
|
|
- $topicCount = count($topicIds);
|
|
|
- if($topicCount == 0 || $topicCount > 5){
|
|
|
- return Response::create([
|
|
|
- 'message' => '所选话题必须1-5个',
|
|
|
- 'status_code' => 500
|
|
|
- ]);
|
|
|
- }
|
|
|
- $topicIds = implode(',', $topicIds);
|
|
|
|
|
|
$data = [
|
|
|
- 'uid' => $request['uid'],
|
|
|
- 'username' => $userInfo['username'],
|
|
|
- 'mobile' => $userInfo['mobile'],
|
|
|
- 'avatar' => $userInfo['avatar'],
|
|
|
- 'type' => $request['type'],
|
|
|
- 'img' => $request['img'],
|
|
|
- 'video' => $request['video']??'',
|
|
|
- 'topic_ids' => $topicIds,
|
|
|
- 'title' => $request['title']??'',
|
|
|
- 'content' => $request['content'],
|
|
|
- 'location' => $request['location']??'',
|
|
|
- 'is_suggest' => $request['is_suggest'],
|
|
|
- 'is_hide' => 0
|
|
|
+ 'title' => $request['title'],
|
|
|
+ 'notice_groups' => $noticeGroups,
|
|
|
+ 'message_type' => $request['message_type'],
|
|
|
+ 'activity_url' => $request['activity_url']??'',
|
|
|
+ 'cover' => $request['cover'],
|
|
|
+ 'message_status' => 0,
|
|
|
+ 'send_time' => isset($request['send_time']) && $request['send_time']? $request['send_time']:null,
|
|
|
+ 'activity_time' => $request['activity_time']??'',
|
|
|
+ 'sent_count' => 0,
|
|
|
+ 'open_count' => 0
|
|
|
];
|
|
|
|
|
|
- $date = date('Y-m-d H:i:s');
|
|
|
-
|
|
|
-
|
|
|
DB::beginTransaction();
|
|
|
try{
|
|
|
- $post = $this->post->create($data);
|
|
|
-
|
|
|
- $this->postData->create([
|
|
|
- 'post_id' => $post->id,
|
|
|
- 'pv' => 0,
|
|
|
- 'pv_real' => 0,
|
|
|
- 'dislike_count' => 0,
|
|
|
- 'praise_count' => 0,
|
|
|
- 'praise_real_count' => 0,
|
|
|
- 'share_count' => 0,
|
|
|
- 'share_real_count' => 0,
|
|
|
- 'comment_count' => 0,
|
|
|
- 'comment_real_count' => 0,
|
|
|
- 'collect_count' => 0,
|
|
|
- 'collect_real_count' => 0,
|
|
|
- 'available_bean' => $this->availableBean(),
|
|
|
- 'will_collect_bean' => rand(100, 200),
|
|
|
- 'collect_bean' => 0,
|
|
|
- 'weight' => 0
|
|
|
- ]);
|
|
|
-
|
|
|
- if(!empty($request['imgs']) && $request['type'] == 'image'){
|
|
|
- $imgData = [];
|
|
|
- foreach($request['imgs'] as $img){
|
|
|
- $imgData[] = [
|
|
|
- 'post_id' => $post->id,
|
|
|
- 'img' => $img,
|
|
|
- 'created_at' => $date,
|
|
|
- 'updated_at' => $date
|
|
|
- ];
|
|
|
- }
|
|
|
- $this->postImgs->insert($imgData);
|
|
|
- }
|
|
|
+ $this->messageRule->create($data);
|
|
|
|
|
|
DB::commit();
|
|
|
return Response::create();
|
|
|
|
|
|
}catch (QueryException $exception){
|
|
|
DB::rollBack();
|
|
|
- Log::debug('发布内容:'.$exception->getMessage());
|
|
|
+ Log::debug('创建消息规则:'.$exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '发布失败,请重试',
|
|
|
+ 'message' => '添加失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
'status_code' => 500
|
|
|
]);
|