moshaorui hai 9 horas
pai
achega
17965335f1

+ 151 - 172
app/Distributor/Controllers/SmmPostController.php

@@ -41,6 +41,64 @@ class SmmPostController extends AdminDistController
             $form->title(admin_trans_label('local_materials'));
             $form->action('ssm-post');
             $form->disableListButton();
+
+            $form->radio('post_type',admin_trans_label('post_type'))
+                ->when([0], function ($step) {
+                    $step->textarea('image_message', '<span style="color:#bd4147;">*</span> '.admin_trans_label('post_message'))->rows(3)->placeholder(' ');
+                    $step->multipleImage('image_url', '<span style="color:#bd4147;">*</span> '.admin_trans_label('images'))
+                        ->retainable()//禁止删OSS图
+                        ->sortable() // 可拖动排序
+                        ->removable() // 可移除图片
+                        ->autoUpload() // 自动上传
+                        ->uniqueName()
+                        ->limit(4)
+                        ->accept('jpg,png')
+                        ->help('jpg,png (Max 3M)')
+                        ->maxSize(3072);
+                })
+                ->when([1], function ($step)  {
+                    $step->select('youtube_category','<span style="color:#bd4147;">*</span> '.admin_trans_label('youtube_category'))->setView('distributor.form_custom.select_hide')->options(SmmUserAccount::getYoutubeCategory())->default(22)->placeholder(' ');
+                    $step->text('yutube_title','<span style="color:#bd4147;">*</span> '.admin_trans_label('yutube_title'))->setView('distributor.form_custom.text_hide')->placeholder(' ');
+                    $step->textarea('video_message', '<span style="color:#bd4147;">*</span> '.admin_trans_label('post_message'))->rows(3)->placeholder(' ');
+                    $step->file('video_url','<span style="color:#bd4147;">*</span> '.admin_trans_label('video'))
+                        ->uniqueName()
+                        ->autoUpload()
+                        ->accept(config('admin.upload.oss_video.accept'))
+                        ->maxSize(20480)
+                        ->chunked()
+                        ->help('mp4 (Max 20M)')
+                        ->removable();
+                    //->chunked()
+                })
+                ->options([ 0=>admin_trans_label('graphic'), 1=>admin_trans_label('videos')])->default(0)->required();
+
+
+
+            //当前时间
+            $now = Carbon::now()->format('Y-m-d H:i:s');
+            $form->datetime('send_time', admin_trans_label('send_time'))->placeholder(' ')->default($now)->required();
+
+            $rootAccounts = SmmUserAccount::getUserAccounts();
+            $listBoxOptions = [];
+            foreach ($rootAccounts as $account) {
+                if (SmmPostLog::getPostQuota($account->getParent->name) > 0) {
+                    //限额大于0才显示
+                    $listBoxOptions[$account->id] = $account->name . ' ('.$account->getParent->name.')';
+                }
+            }
+
+            $form->checkbox('account_ids', admin_trans_label('accountsSelect'))->options($listBoxOptions)->required();
+
+            $form->disableViewButton();
+            $form->disableViewCheck();
+            $form->disableDeleteButton();
+            $form->disableEditingCheck();
+            $form->disableCreatingCheck();
+            $this->addJs();
+
+          //  $form->select('youtube_category')->setView('distributor.form_custom.select_hide')->options(SmmUserAccount::getYoutubeCategory())->default(22)->required();
+
+            /*
             $form->multipleSteps()
                 ->remember()
                 ->width('950px')
@@ -94,6 +152,7 @@ class SmmPostController extends AdminDistController
                     $this->stepLeaving($step,1);
                 });
             $this->addJs();
+            */
         });
     }
 
@@ -112,10 +171,21 @@ class SmmPostController extends AdminDistController
             // 上传图片或视频
             return $this->upload();
         }
-        if (isset($post['ALL_STEPS']) && $post['ALL_STEPS'] == '1') {
+        //保存数据
+        if (isset($post['post_type'])) {
             if ($post['account_ids'] == [] || count($post['account_ids']) == 0 || $post['account_ids'] == '' || empty($post['account_ids'][0])) {
-                return Admin::json()->error('请选择社媒帐号');
+                return Admin::json()->error(admin_trans_label('choose_account'));
+            }
+            if (SmmUserAccount::findYoutubeAccount($post['account_ids'])->count() > 0) {
+                if (empty($post['yutube_title']) || empty($post['youtube_category'])) {
+                    return Admin::json()->error(admin_trans_label('input_yutube_fields'));
+                }
+                $charCount = mb_strlen($post['yutube_title'], 'UTF-8');
+                if ($charCount > 70) {
+                    return Admin::json()->error(admin_trans_label('yutube_title_limit'));
+                }
             }
+
             $post_type = $post['post_type'];
             if ($post_type == 0) {
                 $image_video_url = $post['image_url'];
@@ -124,30 +194,40 @@ class SmmPostController extends AdminDistController
                 $image_video_url = $post['video_url'];
                 $post['message'] = $post['video_message'];
             }
+            if (empty($post['message'])) {
+                return Admin::json()->error(admin_trans_label('fill_post_message'));
+            }
+            $messageCount = mb_strlen($post['message'], 'UTF-8');
+            if ($messageCount > 2000) {
+                return Admin::json()->error(admin_trans_label('post_message_limit'));
+            }
             if ($this->checkStoragePath($image_video_url) === false) {
-                return Admin::json()->error('请检查上传文件是否存在');
+                return Admin::json()->error(admin_trans_label('check_upload'));
             }
-            if ($post['send_type'] == 0) {
-                $send_time = Carbon::now();
-            } else {
-                // 從北京時間字符串創建 Carbon 對象
-                $sendTime = Carbon::createFromFormat('Y-m-d H:i:s', $post['send_time'], 'Asia/Shanghai');
-                // 轉換為 UTC 時間
-                $send_time = $sendTime->setTimezone('UTC');
-               // $send_time = Carbon::createFromFormat('Y-m-d H:i:s', $post['send_time'])->setTimezone('UTC');
+            if ($post['send_time'] == '' || $post['send_time'] == null) {
+                return Admin::json()->error(admin_trans_label('select_send_time'));
             }
+
+            // 從北京時間字符串創建 Carbon 對象
+            $sendTime = Carbon::createFromFormat('Y-m-d H:i:s', $post['send_time'], 'Asia/Shanghai');
+
+            // 轉換為 UTC 時間
+            $send_time = $sendTime->setTimezone('UTC');
+
             //保存数据
             SmmPost::create($post,$send_time,$image_video_url);
             // 生成发送记录
             $timer = new TimerSsmPost();
             $timer->createLog();
+
+            return Admin::json()->success(admin_trans_label('operation_successful'))->refresh();
             //最后一步
-            $data = [
-                'title'       => admin_trans_label('operation_successful'),
-                'description' => admin_trans_label('send_post_description'),
-                'continue_publishing' => admin_trans_label('continue_publishing'),
-            ];
-            return view('distributor.form_custom.completion-page', $data);
+//            $data = [
+//                'title'       => admin_trans_label('operation_successful'),
+//                'description' => admin_trans_label('send_post_description'),
+//                'continue_publishing' => admin_trans_label('continue_publishing'),
+//            ];
+           // return view('distributor.form_custom.completion-page', $data);
         }
     }
 
@@ -173,9 +253,6 @@ class SmmPostController extends AdminDistController
             //保存在本地
             $result = $disk->putFileAs($dir, $file, $newName);
 
-            //oss 保存
-//            $disk = $this->disk('oss');
-//            $result = $disk->putFileAs($dir, $file, $newName);
 
             return $result
                 ? $this->responseUploaded($result, $disk->url($result))
@@ -196,170 +273,72 @@ class SmmPostController extends AdminDistController
         return false;
     }
 
-    private function stepLeaving($step,$index=0)
+
+    public function addJs()
     {
-        $lang = config('app.locale');//当前语言
-        //JS 验证参数不能为空
-        if ($index == 0) {
-$step->leaving(<<<JS
-
-// 全局缓存对象,存储被移除的YouTube选项 {selectName: jQueryObject}
-function toggleYouTube(flag) {
-    var \$this = \$(this);
-
-    // 定义选择器
-    var youtubeSelector = 'option:contains("(YouTube)")';
-    var \$helper1 = \$('select[name="account_ids[]_helper1"]');
-    var \$helper2 = \$('select[name="account_ids[]_helper2"]');
-    var \$mainSelect = \$('select[name="account_ids[]"]');
-
-    // 初始化数据存储
-    if (!\$this.data('youtubeOptions')) {
-        \$this.data('youtubeOptions', {
-            helper1: \$helper1.find(youtubeSelector).clone(true),
-            helper2: \$helper2.find(youtubeSelector).clone(true),
-            main: \$mainSelect.find(youtubeSelector).clone(true),
-            positions: {  // 记录原始位置
-                helper1: \$helper1.find(youtubeSelector).index(),
-                helper2: \$helper2.find(youtubeSelector).index(),
-                main: \$mainSelect.find(youtubeSelector).index()
+        Admin::script(
+<<<JS
+     var hideYouTubeAccount = function(postType) {
+        // 查找所有 account_ids 的 checkbox
+        $('input[name="account_ids[]"]').each(function() {
+            var label = $(this).closest('.vs-checkbox-con').find('span').last().text();
+            // 检查是否包含 YouTube
+            if (label.includes('YouTube')) {
+                // 如果 post_type 值为 1(视频),显示 YouTube 选项;否则隐藏
+                if (postType === '1') {
+                    $(this).closest('.vs-checkbox-con').show();
+                    //
+                    const youtubeElements = ['#select_hide_youtube_category', '#text_hide_yutube_title'];
+                    youtubeElements.forEach(id => $(id).toggle(false));
+                } else {
+                    $(this).closest('.vs-checkbox-con').hide();
+                    // 可选择取消选中状态
+                    $(this).prop('checked', false);
+                }
             }
         });
-    }
-
-    // 通用移除函数
-    function removeYouTubeOptions(\$container) {
-        \$container.find(youtubeSelector).each(function() {
-            \$(this).detach(); // 使用 detach 保留事件和数据的引用
-        });
-    }
-
-    // 移除所有 YouTube 选项
-    removeYouTubeOptions(\$helper1);
-    removeYouTubeOptions(\$helper2);
-    removeYouTubeOptions(\$mainSelect);
-
-    // 还原逻辑
-    if (flag === false) {
-        var saved = \$this.data('youtubeOptions');
-
-        // 精确还原到原始位置
-        saved.helper1.insertAfter(
-            \$helper1.find('option').eq(saved.positions.helper1 - 1)
-        );
+     }
+     var changeCount = 0
+
+    $('input[name="post_type"]').on('change', function() {
+        changeCount++;
+        console.log(changeCount);
+        if (changeCount > 2) {
+            // 获取当前选中的 post_type 值
+            var postType = $(this).val();
+            hideYouTubeAccount(postType);
+        } else {
+            hideYouTubeAccount(0);
+        }
+    });
 
-        saved.helper2.insertAfter(
-            \$helper2.find('option').eq(saved.positions.helper2 - 1)
-        );
 
-        saved.main.insertAfter(
-            \$mainSelect.find('option').eq(saved.positions.main - 1)
-        );
-    }
-    //把选择账号全部向左移
-    $(".removeall ").click();
-    //隐藏youtube 分类
-    $('#select_hide_youtube_category').toggle(false);
-}
 
-function validateForm(formArray) {
-    lang = '{$lang}';
-    // 仅获取radio类型的post_type值
-    let postType = formArray.find(item =>
-        item.name === 'post_type' && item.type === 'radio'
-    )?.value;
-
-    // 仅获取radio类型的send_type值
-    let sendType = formArray.find(item =>
-        item.name === 'send_type' && item.type === 'radio'
-    )?.value;
-
-    // 验证post_type相关规则
-    if (postType === '0') {
-        const imageMessage = formArray.find(item => item.name === 'image_message')?.value;
-        const imageUrl = formArray.find(item => item.name === 'image_url')?.value;
-        if (!imageMessage || !imageUrl) {
-            if (lang === 'en') {
-                return 'Post message and images cannot be empty';
-            } else {
-                return '帖子留言和图片不能为空';
-            }
-        }
-        //隐藏youtube的帐号
-        toggleYouTube(true);
-    } else if (postType === '1') {
-        const videoMessage = formArray.find(item => item.name === 'video_message')?.value;
-        const videoUrl = formArray.find(item => item.name === 'video_url')?.value;
-        if (!videoMessage || !videoUrl) {
-            if (lang === 'en') {
-                return 'Post message and video cannot be empty';
-            } else {
-                return '帖子留言和视频不能为空';
-            }
-        }
-        toggleYouTube(false);
-    }
+    // 定义需要控制的表单元素ID
+    const youtubeElements = ['#select_hide_youtube_category', '#text_hide_yutube_title'];
 
-    // 验证send_type规则(仅处理radio类型的send_type)
-    if (sendType === '1') {
-        const sendTime = formArray.find(item => item.name === 'send_time')?.value;
-        if (!sendTime) {
-            if (lang === 'en') {
-                return 'Send time cannot be empty';
-            } else {
-                return '定时发送时间不能为空';
+    // 检查是否包含YouTube账号的函数
+    function checkYouTubeSelection() {
+        let hasYouTube = false;
+        // 遍历所有选中的复选框
+        $('input[name="account_ids[]"]:checked').each(function() {
+            // 获取父容器内的账号名称文本
+            const labelText = $(this).closest('.vs-checkbox-con').find('span:last').text().trim();
+            if (labelText.includes('YouTube')) {
+                hasYouTube = true;
+                return false; // 发现后提前终止循环
             }
-        }
-    }
-    return "";
-}
+        });
 
-var formArray = args.formArray;
-rs = validateForm(formArray);
-if (rs != "") {
-    Dcat.error(rs);
-    return false;
-}
-JS);
-        } else {
-$step->leaving(<<<JS
-var formArray = args.formArray;
-var lang = '{$lang}';
-//找account_ids
-let accountIds = formArray.find(item => item.name === 'account_ids[]')?.value;
-if (!accountIds || accountIds.length === 0) {
-    if (lang === 'en') {
-        Dcat.error('Please select accounts');
-    } else {
-        Dcat.error('请选择社媒帐号');
+        // 统一控制元素的显隐
+        youtubeElements.forEach(id => $(id).toggle(hasYouTube));
     }
-    return false;
-}
-
-JS);
-        }
 
-    }
+    // 绑定所有账号复选框的change事件
+    $('input[name="account_ids[]"]').change(checkYouTubeSelection);
 
-    public function addJs()
-    {
-        Admin::script(
-<<<JS
-function checkYouTubeOption(select) {
-    // 检查是否存在包含"YouTube"的option
-    var hasYouTube = select.find('option:contains("YouTube")').length > 0;
-    // 切换目标元素的显示状态
-    $('#select_hide_youtube_category').toggle(hasYouTube);
-}
-var select = $('select[name="account_ids\\[\\]_helper2"]');
-var select_lenght = select.children().length;
-let intervalId = setInterval(() => {
-    var select = $('select[name="account_ids\\[\\]_helper2"]');
-    // 处理变化的逻辑
-    if (select_lenght != select.children().length) {
-        checkYouTubeOption(select);
-    }
-}, 300);
+    // 初始化执行一次
+    checkYouTubeSelection();
 
 JS
         );

+ 2 - 1
app/Distributor/Repositories/SmmPost.php

@@ -21,7 +21,7 @@ class SmmPost extends EloquentRepository
     public static function create($post,$sendTime,$imageVideoUrl)
     {
         $model = new Model();
-        $model->send_type = $post['send_type'];
+    //    $model->send_type = $post['send_type'];
         $model->send_time = $sendTime;
         $model->message = $post['message'];
         $model->post_type = $post['post_type'];
@@ -31,6 +31,7 @@ class SmmPost extends EloquentRepository
         $model->dist_id = getDistributorId();
         $model->backup_field1 = json_encode([
             'youtube_category' => $post['youtube_category'],
+            'yutube_title' => $post['yutube_title'],
         ]);
         $model->save();
         return $model->id;

+ 11 - 0
app/Distributor/Repositories/SmmUserAccount.php

@@ -143,4 +143,15 @@ class SmmUserAccount extends EloquentRepository
         }
         return false;
     }
+
+     /*
+      * 查找用户IDS中有无YouTube的帐号
+      */
+    public static function findYoutubeAccount($ids)
+    {
+        $model = new Model();
+        $youTubeRs = $model->where('name', 'YouTube')->first();
+        $result = $model->where('parent_id', $youTubeRs->id)->whereIn('id', $ids)->get();
+        return $result;
+    }
 }

+ 11 - 0
lang/en/global.php

@@ -245,6 +245,17 @@ return [
         'operation_successful' => 'Operation successful',
         'send_post_description' => 'The system has generated the sending queue. Please check the logs for details.',
         'continue_publishing'   => 'Continue Publishing',
+        'post_type'             => 'Post Type',
+        'graphic'               => 'Graphic',
+        'yutube_title'          => 'Youtube Title',
+        'choose_account'    => 'Please select a social media account',
+        'fill_post_message'   => 'Please fill in the content of the post.',
+        'check_upload' => 'Please check if the uploaded file exists.',
+        'select_send_time' => 'Please select a delivery time',
+        'youtube_category' => 'Youtube Category',
+        'input_yutube_fields' => 'Please enter a YouTube title and category',
+        'yutube_title_limit' => 'The maximum length of the YouTube title is 70 characters',
+        'post_message_limit' => 'The maximum length of the post message is 2000 characters',
     ],
     'options' => [
         //

+ 13 - 1
lang/zh_CN/global.php

@@ -115,7 +115,7 @@ return [
         'title_en'              => '标题',
         'account_id'            => '账号ID',
         'expires_at'            => '过期时间',
-        'youtube_category'      => 'Youtube分类',
+        'youtube_category'      => 'Youtube 分类',
         'send_post'              => '发送帖子',
 
 
@@ -256,6 +256,18 @@ return [
         'operation_successful' => '操作成功',
         'send_post_description' => '系统已生成发送队列,详情请查看日志。',
         'continue_publishing'   => '继续发布',
+        'post_type'             => '帖子类型',
+        'graphic'               => '图文',
+        'yutube_title'          => 'Youtube 标题',
+        'choose_account'    => '请选择社媒帐号',
+        'fill_post_message'   => '请填写帖子内容',
+        'check_upload' => '请检查上传文件是否存在',
+        'select_send_time' => '请选择发送时间',
+        'youtube_category'      => 'Youtube 分类',
+        'input_yutube_fields'  => '请输入Youtube标题和分类',
+        'yutube_title_limit'   => 'Youtube标题长度不能超过70个字符',
+        'post_message_limit'    => '帖子内容长度不能超过2000个字符',
+
     ],
     'options' => [
         //

+ 26 - 0
resources/views/distributor/form_custom/text_hide.blade.php

@@ -0,0 +1,26 @@
+<div class="{{$viewClass['form-group']}}" style="display: none;" id="text_hide_{{ $name }}">
+
+    <div class="{{$viewClass['label']}} control-label">
+        <span>{!! $label !!}</span>
+    </div>
+
+    <div class="{{$viewClass['field']}}">
+
+        @include('admin::form.error')
+
+        <div class="input-group">
+
+            @if ($prepend)
+                <span class="input-group-prepend"><span class="input-group-text bg-white">{!! $prepend !!}</span></span>
+            @endif
+            <input {!! $attributes !!} />
+
+            @if ($append)
+                <span class="input-group-append">{!! $append !!}</span>
+            @endif
+        </div>
+
+        @include('admin::form.help-block')
+
+    </div>
+</div>