Browse Source

社媒对facebook

moshaorui 5 days ago
parent
commit
17029616cd

+ 157 - 0
app/Distributor/Controllers/SmmPostController.php

@@ -0,0 +1,157 @@
+<?php
+
+namespace App\Distributor\Controllers;
+
+use App\Admin\Repositories\BaseProductImage;
+use App\Distributor\Repositories\SmmPost;
+use App\Distributor\Repositories\SmmUserAccount;
+use Carbon\Carbon;
+use Dcat\Admin\Form;
+use Dcat\Admin\Grid;
+use Dcat\Admin\Grid\Model;
+use Dcat\Admin\Show;
+use Dcat\Admin\Http\Controllers\AdminController;
+use Dcat\Admin\Layout\Content;
+use Dcat\Admin\Admin;
+use Dcat\Admin\FormStep\Form as StepForm;
+use Dcat\Admin\Traits\HasUploadedFile;
+use Dcat\Admin\Widgets\Alert;
+
+class SmmPostController extends AdminDistController
+{
+    use HasUploadedFile;
+
+    /**
+     * page index
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('发报帖子')
+            ->body($this->form());
+    }
+
+    protected function form()
+    {
+        return Form::make(new SmmPost(), function (Form $form) {
+            $form->title('本地素材发布');
+            $form->action('ssm-post');
+            $form->disableListButton();
+            $form->multipleSteps()
+                ->remember(false)
+                ->width('950px')
+                ->add('选择本地媒体', function ($step) {
+                    $step->radio('send_type',admin_trans_label('send_type'))
+                        ->when([1], function ($step) {
+                            $step->datetime('send_time', admin_trans_label('send_time'))->required();
+                        })
+                        ->options([ 0=>admin_trans_label('immediate'), 1=>admin_trans_label('timing')])->required()->default(0);
+                            $step->text('message', admin_trans_label('post_title'))->required()->maxLength(20);
+                            $step->radio('media_type',admin_trans_label('media_type'))
+                        ->when([0], function ($step) {
+                            $step->multipleImage('image_url', admin_trans_label('images'))
+                                ->disk('local')
+                                ->retainable()//禁止删OSS图
+                                ->sortable() // 可拖动排序
+                                ->removable() // 可移除图片
+                                ->autoUpload() // 自动上传
+                                ->uniqueName()
+                                ->limit(config('admin.upload.oss_image.limit'))
+                                ->accept(config('admin.upload.oss_image.accept'))
+                                ->maxSize(config('admin.upload.oss_image.max_size'))
+                                ->required()
+                                ->saving(function ($reslut) {
+                                    return json_encode($reslut);
+                                });
+                        })
+                        ->when([1], function ($step)  {
+                            $step->file('video_url')
+                                ->disk('local') // 使用本地存储
+                                ->uniqueName()
+                                ->autoUpload()
+                                ->required()
+                                ->accept(config('admin.upload.oss_video.accept'))
+                                ->maxSize(config('admin.upload.oss_video.max_size'))
+                                ->chunkSize(1024)
+                                ->required()
+                                ->saving(function ($reslut) {
+                                    return json_encode($reslut);
+                                });
+                        })
+                        ->options([ 0=>admin_trans_label('images'), 1=>admin_trans_label('videos')])->required()->default(0);
+                })
+                ->add('选择传单社媒平台', function ($step) {
+                    $rootAccounts = SmmUserAccount::getUserAccounts();
+                    $listBoxOptions = [];
+                    foreach ($rootAccounts as $account) {
+                        $listBoxOptions[$account->id] = $account->name . ' ('.$account->getParent->name.')';
+                    }
+                    $step->listbox('account_ids', admin_trans_label('accountsSelect'))->required()->options($listBoxOptions);
+                });
+        });
+    }
+
+    /*
+     * 保存数据
+     */
+    public function store() {
+        $post = $_POST;
+        if (isset($post['upload_column']) && $post['upload_column'] == 'image_url') {
+            // 上传图片或视频
+            return $this->upload();
+        }
+        if (isset($post['ALL_STEPS']) && $post['ALL_STEPS'] == '1') {
+            $media_type = $post['media_type'];
+            if ($media_type == 0) {
+                $image_video_url = $post['image_url'];
+            } else {
+                $image_video_url = $post['video_url'];
+            }
+            if ($this->checkStoragePath($image_video_url) === false) {
+                return '发送失败,请检查上传文件是否存在';
+            }
+            if ($post['send_type'] == 0) {
+                $send_time = Carbon::now();
+            } else {
+                //转换时间格式
+                $send_time = Carbon::createFromFormat('Y-m-d H:i:s', $post['send_time']);
+            }
+            //保存数据
+            SmmPost::create($post,$send_time,$image_video_url);
+            //最后一步
+            $data = [
+                'title'       => '操作成功',
+                'description' => '系统已生成发送队列,详情请查看日志。',
+            ];
+            return view('distributor.form_custom.completion-page', $data);
+        }
+    }
+
+
+    /**
+     * 上传图片到本地
+     */
+    public function upload() {
+        $disk = $this->disk('local');
+        // 获取上传的文件
+        $file = $this->file();
+        $dir = 'ssm/'.getDistributorId();
+        $newName = md5(uniqid() . mt_rand()) .'.'.$file->getClientOriginalExtension();
+        $result = $disk->putFileAs($dir, $file, $newName);
+        return $result
+            ? $this->responseUploaded($result, $disk->url($result))
+            : $this->responseErrorMessage(admin_trans_label('upload_failed'));
+    }
+
+
+    /*
+     * 判断路径是否正确
+     */
+    public function checkStoragePath ($filePath) {
+        $storagePath = 'ssm/'.getDistributorId();
+        if (strpos($filePath, $storagePath) === 0) {
+            return true;
+        }
+        return false;
+    }
+}

+ 4 - 4
app/Distributor/Controllers/SmmUserAccountController.php

@@ -13,7 +13,7 @@ use Dcat\Admin\Layout\Content;
 use Dcat\Admin\Admin;
 use Illuminate\Http\Request;
 
-class SmmUserAccountController extends AdminController
+class SmmUserAccountController extends AdminDistController
 {
     /**
      * page index
@@ -35,7 +35,7 @@ class SmmUserAccountController extends AdminController
     {
         return Grid::make(new SmmUserAccount(), function (Grid $grid) {
             $grid->column('id')->sortable();
-            $grid->column('title')->tree();
+            $grid->column('name')->tree();
             $grid->column('access_token');
             $grid->column('created_at');
             $grid->column('updated_at')->sortable();
@@ -63,7 +63,7 @@ class SmmUserAccountController extends AdminController
             $grid->disableCreateButton();
             $grid->disableEditButton();
             $grid->disableViewButton();
-            $grid->model()->whereIn('dist_id', [0,getDistributorId()])->orderBy('title', 'asc')->orderBy('id', 'desc');
+            $grid->model()->whereIn('dist_id', [0,getDistributorId()])->orderBy('name', 'asc')->orderBy('id', 'desc');
         });
     }
 
@@ -76,7 +76,7 @@ class SmmUserAccountController extends AdminController
         try {
             $ssmService = new SmmService($mediaName);
             $result = $ssmService->loginCallback($request);
-            dd($result);
+           // dd($result);
             if ($result['status']) {
                 $accessToken = $result['data']['access_token'];
                 $userName = $result['data']['user_name'];

+ 34 - 0
app/Distributor/Repositories/SmmPost.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Distributor\Repositories;
+
+use App\Models\SmmPost as Model;
+use Dcat\Admin\Repositories\EloquentRepository;
+
+class SmmPost extends EloquentRepository
+{
+    /**
+     * Model.
+     *
+     * @var string
+     */
+    protected $eloquentClass = Model::class;
+
+
+    /*
+     * 插入数据
+     */
+    public static function create($post,$sendTime,$imageVideoUrl)
+    {
+        $model = new Model();
+        $model->send_type = $post['send_type'];
+        $model->send_time = $sendTime;
+        $model->message = $post['message'];
+        $model->media_type = $post['media_type'];
+        $model->account_ids = implode(',',$post['account_ids']);
+        $model->image_video_url = $imageVideoUrl;
+        $model->status = 0;
+        $model->save();
+        return $model->id;
+    }
+}

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

@@ -43,4 +43,27 @@ class SmmUserAccount extends EloquentRepository
         return $model->insert($data);
     }
 
+
+    /*
+     * 查出dist_id=0和parent_id=0的账号
+     */
+    public static function getRootAccounts()
+    {
+        $model = new Model();
+        $accounts = $model->where('dist_id', 0)->where('parent_id', 0)->get();
+        return $accounts;
+    }
+
+
+    /*
+     * 查找所有用户账号
+     */
+    public static function getUserAccounts()
+    {
+        $model = new Model();
+        $accounts = $model->where('dist_id','>', 0)->where('parent_id','>',0)->orderBy('parent_id', 'asc')->get();
+        return $accounts;
+    }
+
+
 }

+ 2 - 0
app/Distributor/routes.php

@@ -78,6 +78,8 @@ Route::group([
     $router->get('site-album/{id}', 'SiteAlbumController@show');
     //社媒账号管理
     $router->get('ssm-user-account', 'SmmUserAccountController@index');
+    //社媒传单管理
+    $router->resource('ssm-post', 'SmmPostController');
 
 });
 

+ 14 - 0
app/Models/SmmPost.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+
+use Illuminate\Database\Eloquent\Model;
+
+class SmmPost extends Model
+{
+	use HasDateTimeFormatter;
+    protected $table = 'smm_post';
+    
+}

+ 7 - 0
app/Models/SmmUserAccount.php

@@ -14,6 +14,13 @@ class SmmUserAccount extends Model
 
     protected $table = 'smm_user_account';
 
+    protected $titleColumn = 'name';
 
+    protected $parentColumn = 'parent_id';
+
+    public function getParent()
+    {
+        return $this->hasOne(SmmUserAccount::class,'id','parent_id');
+    }
 
 }

+ 6 - 0
config/distributor.php

@@ -286,6 +286,12 @@ return [
             'max_size' => 500, // 上传文件大小限制,单位kB
             'limit' => 20, // 上传文件数量限制
         ],
+
+        'oss_video' => [
+            'accept' => 'mp4',//允许上传的文件类型
+            'max_size' => 300000, // 上传文件大小限制,单位kB
+            'limit' => 50, // 上传文件数量限制
+        ],
     ],
 
     /*

+ 7 - 0
lang/en/global.php

@@ -209,6 +209,13 @@ return [
         'distributor_name'      => 'Distributor Name',
         'product_audit'         => 'Product Audit',
         'add_platform_account' => 'Add Platform Account',
+        'post_title'            => 'Post Title',
+        'media_type'            => 'Media Type',
+        'accountsSelect'        => 'Accounts Select',
+        'send_time'              => 'Send Time',
+        'send_type'             => 'Send Type',
+        'timing'                => 'Timing',
+        'immediate'             => 'Immediate',
     ],
     'options' => [
         //

+ 7 - 0
lang/zh_CN/global.php

@@ -218,6 +218,13 @@ return [
         'audit_success'      => '审核成功',
         'product_audit'      => '产品审核',
         'add_platform_account' => '添加平台账号',
+        'post_title'            => '帖子标题',
+        'media_type'            => '媒体类型',
+        'accountsSelect'        => '选择账号',
+        'send_time'              => '发送时间',
+        'immediate'              => '立即',
+        'timing'                 => '定时',
+        'send_type'             => '发送类型',
 
     ],
     'options' => [

+ 3 - 0
lang/zh_CN/menu.php

@@ -55,5 +55,8 @@ return [
         'banner'  =>'轮播图',
         'promotional_materials'  =>'宣传资料',
         'product_audit'  =>'产品审核',
+        'flyer_management'  =>'传单管理',
+        'account_management'=>'账户管理',
+        'post_sending'  =>'帖子发送',
     ],
 ];

+ 40 - 0
resources/views/distributor/form_custom/completion-page.blade.php

@@ -0,0 +1,40 @@
+<style>
+    .dcat-done-step {
+        max-width: 560px;
+        margin: 0 auto;
+        padding: 24px 0 8px;
+    }
+    .dcat-done-step .st-icon {
+        color: {{ Dcat\Admin\Admin::color()->success() }};
+        font-size: 72px;
+        text-align:center;
+    }
+    .dcat-done-step .st-content {
+        text-align:center;
+    }
+    .dcat-done-step .st-title {
+        font-size: 24px;
+    }
+    .dcat-done-step .st-desc {
+        color: rgba(0,0,0,.5);
+        font-size: 14px;
+        line-height: 1.6;
+    }
+    .dcat-done-step .st-btn {
+        margin: 30px 0 10px;
+    }
+</style>
+<div style="margin: 0 auto">
+    <div class="st-icon">
+        <svg viewBox="64 64 896 896" focusable="false" class="" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 0 1-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path></svg>
+    </div>
+
+    <div class="st-content">
+        <div class="st-title">
+            {{ $title }}
+        </div>
+        <div class="st-desc" style="margin-top: 10px">
+            {{ $description }}
+        </div>
+    </div>
+</div>