wzq 5 rokov pred
rodič
commit
cfc6db7bce

+ 20 - 0
app/Http/Controllers/MessageRuleController.php

@@ -66,4 +66,24 @@ class MessageRuleController extends Controller
         ];
         return $data;
     }
+
+    /**
+     * 创建消息
+     */
+    public function create(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'title' => 'required|string|max:20',
+            'notice_groups' => 'required|string|max:31',
+            'message_type' => ['required',Rule::in('star', 'system')],
+            'show_type' => ['required',Rule::in('only_show', 'user', 'post', 'activity', 'topic')],
+            'activity_url' => 'required_unless:type,only_show|string|max:64',
+            'cover' => 'required|url',
+            'send_time' => 'nullable|datetime'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->messageRuleRepository->create($request->all());
+    }
 }

+ 94 - 0
app/Repositories/MessageRuleRepository.php

@@ -43,4 +43,98 @@ class MessageRuleRepository
             ->orderBy('id','desc')
             ->paginate($perPage);
     }
+
+    /**
+     * 创建消息
+     */
+    public function create($request)
+    {
+        return 2223;
+        //验证小号
+        $userInfo = $this->getUserInfo($request['uid']);
+        if(!$userInfo || $userInfo['type'] != 1){
+            return Response::create([
+                'message'  => '所选小号信息有误',
+                'status_code'   => 500
+            ]);
+        }
+        //验证话题
+        $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
+        ];
+
+        $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);
+            }
+
+            DB::commit();
+            return Response::create();
+
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('发布内容:'.$exception->getMessage());
+            return Response::create([
+                'message'  => '发布失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
 }

+ 19 - 0
resources/lang/en/auth.php

@@ -0,0 +1,19 @@
+<?php
+
+return [
+
+    /*
+    |--------------------------------------------------------------------------
+    | Authentication Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used during authentication for various
+    | messages that we need to display to the user. You are free to modify
+    | these language lines according to your application's requirements.
+    |
+    */
+
+    'failed' => 'These credentials do not match our records.',
+    'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
+
+];

+ 19 - 0
resources/lang/en/pagination.php

@@ -0,0 +1,19 @@
+<?php
+
+return [
+
+    /*
+    |--------------------------------------------------------------------------
+    | Pagination Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used by the paginator library to build
+    | the simple pagination links. You are free to change them to anything
+    | you want to customize your views to better match your application.
+    |
+    */
+
+    'previous' => '&laquo; Previous',
+    'next' => 'Next &raquo;',
+
+];

+ 22 - 0
resources/lang/en/passwords.php

@@ -0,0 +1,22 @@
+<?php
+
+return [
+
+    /*
+    |--------------------------------------------------------------------------
+    | Password Reset Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are the default lines which match reasons
+    | that are given by the password broker for a password update attempt
+    | has failed, such as for an invalid token or invalid new password.
+    |
+    */
+
+    'password' => 'Passwords must be at least six characters and match the confirmation.',
+    'reset' => 'Your password has been reset!',
+    'sent' => 'We have e-mailed your password reset link!',
+    'token' => 'This password reset token is invalid.',
+    'user' => "We can't find a user with that e-mail address.",
+
+];

+ 146 - 0
resources/lang/en/validation.php

@@ -0,0 +1,146 @@
+<?php
+
+return [
+
+    /*
+    |--------------------------------------------------------------------------
+    | Validation Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines contain the default error messages used by
+    | the validator class. Some of these rules have multiple versions such
+    | as the size rules. Feel free to tweak each of these messages here.
+    |
+    */
+
+    'accepted'             => 'The :attribute must be accepted.',
+    'active_url'           => 'The :attribute is not a valid URL.',
+    'after'                => 'The :attribute must be a date after :date.',
+    'after_or_equal'       => 'The :attribute must be a date after or equal to :date.',
+    'alpha'                => 'The :attribute may only contain letters.',
+    'alpha_dash'           => 'The :attribute may only contain letters, numbers, dashes and underscores.',
+    'alpha_num'            => 'The :attribute may only contain letters and numbers.',
+    'array'                => 'The :attribute must be an array.',
+    'before'               => 'The :attribute must be a date before :date.',
+    'before_or_equal'      => 'The :attribute must be a date before or equal to :date.',
+    'between'              => [
+        'numeric' => 'The :attribute must be between :min and :max.',
+        'file'    => 'The :attribute must be between :min and :max kilobytes.',
+        'string'  => 'The :attribute must be between :min and :max characters.',
+        'array'   => 'The :attribute must have between :min and :max items.',
+    ],
+    'boolean'              => 'The :attribute field must be true or false.',
+    'confirmed'            => 'The :attribute confirmation does not match.',
+    'date'                 => 'The :attribute is not a valid date.',
+    'date_format'          => 'The :attribute does not match the format :format.',
+    'different'            => 'The :attribute and :other must be different.',
+    'digits'               => 'The :attribute must be :digits digits.',
+    'digits_between'       => 'The :attribute must be between :min and :max digits.',
+    'dimensions'           => 'The :attribute has invalid image dimensions.',
+    'distinct'             => 'The :attribute field has a duplicate value.',
+    'email'                => 'The :attribute must be a valid email address.',
+    'exists'               => 'The selected :attribute is invalid.',
+    'file'                 => 'The :attribute must be a file.',
+    'filled'               => 'The :attribute field must have a value.',
+    'gt'                   => [
+        'numeric' => 'The :attribute must be greater than :value.',
+        'file'    => 'The :attribute must be greater than :value kilobytes.',
+        'string'  => 'The :attribute must be greater than :value characters.',
+        'array'   => 'The :attribute must have more than :value items.',
+    ],
+    'gte'                  => [
+        'numeric' => 'The :attribute must be greater than or equal :value.',
+        'file'    => 'The :attribute must be greater than or equal :value kilobytes.',
+        'string'  => 'The :attribute must be greater than or equal :value characters.',
+        'array'   => 'The :attribute must have :value items or more.',
+    ],
+    'image'                => 'The :attribute must be an image.',
+    'in'                   => 'The selected :attribute is invalid.',
+    'in_array'             => 'The :attribute field does not exist in :other.',
+    'integer'              => 'The :attribute must be an integer.',
+    'ip'                   => 'The :attribute must be a valid IP address.',
+    'ipv4'                 => 'The :attribute must be a valid IPv4 address.',
+    'ipv6'                 => 'The :attribute must be a valid IPv6 address.',
+    'json'                 => 'The :attribute must be a valid JSON string.',
+    'lt'                   => [
+        'numeric' => 'The :attribute must be less than :value.',
+        'file'    => 'The :attribute must be less than :value kilobytes.',
+        'string'  => 'The :attribute must be less than :value characters.',
+        'array'   => 'The :attribute must have less than :value items.',
+    ],
+    'lte'                  => [
+        'numeric' => 'The :attribute must be less than or equal :value.',
+        'file'    => 'The :attribute must be less than or equal :value kilobytes.',
+        'string'  => 'The :attribute must be less than or equal :value characters.',
+        'array'   => 'The :attribute must not have more than :value items.',
+    ],
+    'max'                  => [
+        'numeric' => 'The :attribute may not be greater than :max.',
+        'file'    => 'The :attribute may not be greater than :max kilobytes.',
+        'string'  => 'The :attribute may not be greater than :max characters.',
+        'array'   => 'The :attribute may not have more than :max items.',
+    ],
+    'mimes'                => 'The :attribute must be a file of type: :values.',
+    'mimetypes'            => 'The :attribute must be a file of type: :values.',
+    'min'                  => [
+        'numeric' => 'The :attribute must be at least :min.',
+        'file'    => 'The :attribute must be at least :min kilobytes.',
+        'string'  => 'The :attribute must be at least :min characters.',
+        'array'   => 'The :attribute must have at least :min items.',
+    ],
+    'not_in'               => 'The selected :attribute is invalid.',
+    'not_regex'            => 'The :attribute format is invalid.',
+    'numeric'              => 'The :attribute must be a number.',
+    'present'              => 'The :attribute field must be present.',
+    'regex'                => 'The :attribute format is invalid.',
+    'required'             => 'The :attribute field is required.',
+    'required_if'          => 'The :attribute field is required when :other is :value.',
+    'required_unless'      => 'The :attribute field is required unless :other is in :values.',
+    'required_with'        => 'The :attribute field is required when :values is present.',
+    'required_with_all'    => 'The :attribute field is required when :values is present.',
+    'required_without'     => 'The :attribute field is required when :values is not present.',
+    'required_without_all' => 'The :attribute field is required when none of :values are present.',
+    'same'                 => 'The :attribute and :other must match.',
+    'size'                 => [
+        'numeric' => 'The :attribute must be :size.',
+        'file'    => 'The :attribute must be :size kilobytes.',
+        'string'  => 'The :attribute must be :size characters.',
+        'array'   => 'The :attribute must contain :size items.',
+    ],
+    'string'               => 'The :attribute must be a string.',
+    'timezone'             => 'The :attribute must be a valid zone.',
+    'unique'               => 'The :attribute has already been taken.',
+    'uploaded'             => 'The :attribute failed to upload.',
+    'url'                  => 'The :attribute format is invalid.',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Custom Validation Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | Here you may specify custom validation messages for attributes using the
+    | convention "attribute.rule" to name the lines. This makes it quick to
+    | specify a specific custom language line for a given attribute rule.
+    |
+    */
+
+    'custom' => [
+        'attribute-name' => [
+            'rule-name' => 'custom-message',
+        ],
+    ],
+
+    /*
+    |--------------------------------------------------------------------------
+    | Custom Validation Attributes
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used to swap attribute place-holders
+    | with something more reader friendly such as E-Mail Address instead
+    | of "email". This simply helps us make messages a little cleaner.
+    |
+    */
+
+    'attributes' => [],
+
+];

+ 17 - 0
resources/lang/zh-CN/auth.php

@@ -0,0 +1,17 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Authentication Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used during authentication for various
+    | messages that we need to display to the user. You are free to modify
+    | these language lines according to your application's requirements.
+    |
+    */
+
+    'failed' => '用户名或密码错误。',
+    'throttle' => '您的尝试登录次数过多,请 :seconds 秒后再试。',
+];

+ 17 - 0
resources/lang/zh-CN/pagination.php

@@ -0,0 +1,17 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Pagination Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used by the paginator library to build
+    | the simple pagination links. You are free to change them to anything
+    | you want to customize your views to better match your application.
+    |
+    */
+
+    'previous' => '&laquo; 上一页',
+    'next' => '下一页 &raquo;',
+];

+ 20 - 0
resources/lang/zh-CN/passwords.php

@@ -0,0 +1,20 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Password Reminder Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are the default lines which match reasons
+    | that are given by the password broker for a password update attempt
+    | has failed, such as for an invalid token or invalid new password.
+    |
+    */
+
+    'password' => '密码至少是六位字符并且匹配。',
+    'reset' => '密码重置成功!',
+    'sent' => '密码重置邮件已发送!',
+    'token' => '密码重置令牌无效。',
+    'user' => '找不到该邮箱对应的用户。',
+];

+ 112 - 0
resources/lang/zh-CN/validation.php

@@ -0,0 +1,112 @@
+<?php
+
+return [
+    /*
+    |--------------------------------------------------------------------------
+    | Validation Language Lines
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines contain the default error messages used by
+    | the validator class. Some of these rules have multiple versions such
+    | as the size rules. Feel free to tweak each of these messages.
+    |
+    */
+
+    'accepted' => ':attribute 必须接受。',
+    'active_url' => ':attribute 不是一个有效的网址。',
+    'after' => ':attribute 必须要晚于 :date。',
+    'after_or_equal' => ':attribute 必须要等于 :date 或更晚。',
+    'alpha' => ':attribute 只能由字母组成。',
+    'alpha_dash' => ':attribute 只能由字母、数字和斜杠组成。',
+    'alpha_num' => ':attribute 只能由字母和数字组成。',
+    'array' => ':attribute 必须是一个数组。',
+    'before' => ':attribute 必须要早于 :date。',
+    'before_or_equal' => ':attribute 必须要等于 :date 或更早。',
+    'between' => [
+        'numeric' => ':attribute 必须介于 :min - :max 之间。',
+        'file' => ':attribute 必须介于 :min - :max kb 之间。',
+        'string' => ':attribute 必须介于 :min - :max 个字符之间。',
+        'array' => ':attribute 必须只有 :min - :max 个单元。',
+    ],
+    'boolean' => ':attribute 必须为布尔值。',
+    'confirmed' => ':attribute 两次输入不一致。',
+    'date' => ':attribute 不是一个有效的日期。',
+    'date_format' => ':attribute 的格式必须为 :format。',
+    'different' => ':attribute 和 :other 必须不同。',
+    'digits' => ':attribute 必须是 :digits 位的数字。',
+    'digits_between' => ':attribute 必须是介于 :min 和 :max 位的数字。',
+    'dimensions' => ':attribute 图片尺寸不正确。',
+    'distinct' => ':attribute 已经存在。',
+    'email' => ':attribute 不是一个合法的邮箱。',
+    'exists' => ':attribute 不存在。',
+    'file' => ':attribute 必须是文件。',
+    'filled' => ':attribute 不能为空。',
+    'image' => ':attribute 必须是图片。',
+    'in' => '已选的属性 :attribute 非法。',
+    'in_array' => ':attribute 没有在 :other 中。',
+    'integer' => ':attribute 必须是整数。',
+    'ip' => ':attribute 必须是有效的 IP 地址。',
+    'ipv4' => ':attribute 必须是有效的 IPv4 地址。',
+    'ipv6' => ':attribute 必须是有效的 IPv6 地址。',
+    'json' => ':attribute 必须是正确的 JSON 格式。',
+    'max' => [
+        'numeric' => ':attribute 不能大于 :max。',
+        'file' => ':attribute 不能大于 :max kb。',
+        'string' => ':attribute 不能大于 :max 个字符。',
+        'array' => ':attribute 最多只有 :max 个单元。',
+    ],
+    'mimes' => ':attribute 必须是一个 :values 类型的文件。',
+    'mimetypes' => ':attribute 必须是一个 :values 类型的文件。',
+    'min' => [
+        'numeric' => ':attribute 必须大于等于 :min。',
+        'file' => ':attribute 大小不能小于 :min kb。',
+        'string' => ':attribute 至少为 :min 个字符。',
+        'array' => ':attribute 至少有 :min 个单元。',
+    ],
+    'not_in' => '已选的属性 :attribute 非法。',
+    'numeric' => ':attribute 必须是一个数字。',
+    'present' => ':attribute 必须存在。',
+    'regex' => ':attribute 格式不正确。',
+    'required' => ':attribute 不能为空。',
+    'required_if' => '当 :other 为 :value 时 :attribute 不能为空。',
+    'required_unless' => '当 :other 不为 :value 时 :attribute 不能为空。',
+    'required_with' => '当 :values 存在时 :attribute 不能为空。',
+    'required_with_all' => '当 :values 存在时 :attribute 不能为空。',
+    'required_without' => '当 :values 不存在时 :attribute 不能为空。',
+    'required_without_all' => '当 :values 都不存在时 :attribute 不能为空。',
+    'same' => ':attribute 和 :other 必须相同。',
+    'size' => [
+        'numeric' => ':attribute 大小必须为 :size。',
+        'file' => ':attribute 大小必须为 :size kb。',
+        'string' => ':attribute 必须是 :size 个字符。',
+        'array' => ':attribute 必须为 :size 个单元。',
+    ],
+    'string' => ':attribute 必须是一个字符串。',
+    'timezone' => ':attribute 必须是一个合法的时区值。',
+    'unique' => ':attribute 已经存在。',
+    'uploaded' => ':attribute 上传失败。',
+    'url' => ':attribute 格式不正确。',
+
+
+    /*
+    |--------------------------------------------------------------------------
+    | Custom Validation Attributes
+    |--------------------------------------------------------------------------
+    |
+    | The following language lines are used to swap attribute place-holders
+    | with something more reader friendly such as E-Mail Address instead
+    | of 'email'. This simply helps us make messages a little cleaner.
+    |
+    */
+
+    'attributes' => [
+        'title' => '标题',
+        'notice_groups' => '通知群体',
+        'message_type' => '消息类型',
+        'show_type' => '展示类型',
+        'activity_url' => '活动链接',
+        'cover' => '封面图',
+        'send_time' => '发送时间',
+    ],
+
+];

+ 2 - 0
routes/api.php

@@ -58,6 +58,8 @@ $api->version('v1', [
 
         //消息规则列表
         $api->get('message', 'MessageRuleController@index');
+        //创建消息规则
+        $api->post('message', 'MessageRuleController@create');
 
     });
     //配置文件