作者 Your Name

gx

<?php
namespace App\Http\Controllers\Aside;
use App\Models\Template\AHeadFoot;
/**
* 模板
* @author:dc
* @time 2023/5/4 17:10
* Class TemplateController
* @package App\Http\Controllers\Aside
*/
class TemplateController extends BaseController
{
/**
* 列表
* @author:dc
* @time 2023/5/4 17:10
*/
public function index(){
$data = AHeadFoot::all();
$lists = [];
// 以名字为单位区分
foreach ($data as $datum){
if(empty($lists[$datum['name']])) $lists[$datum['name']] = [];
$lists[$datum['name']]['name'] = $datum['name'];
$lists[$datum['name']]['default'] = $datum['is_default'];
$lists[$datum['name']]['sort'] = $datum['sort'];
$lists[$datum['name']]['status'] = $datum['status'];
$lists[$datum['name']]['created_at'] = $datum['created_at'];
// $lists[$datum['name']]['tags'] = $datum['tags'];
$lists[$datum['name']][$datum['type']==AHeadFoot::TYPE_HEADER?'header':'footer'] = $datum['html'];
}
return $this->success($lists);
}
/**
* 编辑
* @author:dc
* @time 2023/5/4 16:19
*/
public function edit(){
}
/**
* 新增
* @author:dc
* @time 2023/5/5 9:30
*/
public function insert(){
}
private function save($name = ''){
}
/**
* 删除
* @author:dc
* @time 2023/5/4 17:10
*/
public function delete(){
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\AyrShare;
use App\Enums\Common\Code;
use App\Helper\AyrShare as AyrShareHelper;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\AyrShare\AyrReleaseLogic;
use App\Http\Logic\Bside\AyrShare\AyrShareLogic;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Support\Facades\DB;
/**
* @name:社交发布
*/
class AyrReleaseController extends BaseController
{
/**
* @name :(获取当前用户已绑定的社交链接)info
* @author :lyh
* @method :post
* @time :2023/5/9 16:00
*/
public function info(AyrShareLogic $ayrShareLogic){
$info = $ayrShareLogic->ayr_share_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :(发布社交)send_post
* @author :lyh
* @method :post
* @time :2023/5/9 9:36
*/
public function send_post(AyrReleaseLogic $ayrReleaseLogic,AyrShareLogic $ayrShareLogic){
DB::beginTransaction();
try {
//获取发送账号详情
$share_info = $ayrShareLogic->ayr_share_info();
$data = [
'image'=>explode(',',$this->param['image']),
'file'=>explode(',',$this->param['file'])
];
//参数处理
$image_file = $this->_extents($data);
$this->param['mediaUrls'] = $image_file;
//统一生成链接
$param = [
'post'=>$this->param['content'],
'platforms'=>$this->param['platforms'],
'mediaUrls'=>$this->param['mediaUrls'],//参数处理
];
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
$res = $ayrShareHelper->post_send_msg($param,$share_info['profile_key']);
$this->response('success',Code::SUCCESS,$res);
//保存数据库
$ayrReleaseLogic->release_add();
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->response('error',Code::USER_ERROR);
}
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\BNav;
/**
* 导航栏目 b端编辑 c端显示
* @author:dc
* @time 2023/5/8 16:31
* Class NavController
* @package App\Http\Controllers\Bside
*/
class NavController extends BaseController
{
/**
* 验证规则
* @var array[]
*/
private $verify = [
'role' => [
'pid' => ['required','integer','gte:0'],
'name' => ['required','max:100'],
'location' => ['required','in:header,footer'],
'url' => ['required','max:200'],
'status' => ['required','in:0,1'],
'target' => ['required','in:0,1'],
'sort' => ['required','integer','gte:0']
],
'message' => [
'pid.required' => '上级选择错误',
'pid.gte' => '上级选择错误',
'pid.integer' => '上级选择错误',
'name.required' => '名称必须',
'name.max' => '名称不能超过100个字符',
'location.required' => '位置选择错误',
'location.in' => '位置选择错误',
'url.required' => '链接必须',
'url.max' => '链接不能超过200个字符',
'status.required' => '状态选择错误',
'status.in' => '状态必须是显示/隐藏',
'target.required' => '打开方式必须',
'target.in' => '打开方式选择错误',
'sort.required' => '排序必须',
'sort.integer' => '排序必须是一个数字',
'sort.gte' => '排序必须大于等于0',
],
'attr' => [
]
];
/**
* 列表数据
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/8 16:37
*/
public function index(){
$isTree = $this->param['tree']??false;
// 显示位置
$location = $this->param['location']??'';
$lists = BNav::_all($this->user['project_id'],$location)->toArray();
if($isTree){
$lists = list_to_tree($lists);
}
return $this->success($lists);
}
/**
* 创建导航栏
* @author:dc
* @time 2023/5/8 16:39
*/
public function create(){
return $this->save();
}
/**
* 修改
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/8 17:06
*/
public function update(){
$this->verify['role']['id'] = ['required','integer','gt:0'];
$this->verify['message']['id.gt'] = $this->verify['message']['id.integer'] = $this->verify['message']['id.required'] = '编辑导航数据不存在';
return $this->save();
}
/**
* 新增修改
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/8 17:06
*/
private function save(){
$data = $this->validate(request() ,$this->verify['role'],$this->verify['message']);
if($data['pid']){
// 验证是否存在上级
$all = BNav::_all($this->user['project_id'],$data['location']);
if(!$all->where('id',$data['pid'])->count()){
return $this->response('上级栏目不存在','B_NAV_PID_NOTFOUND');
}
// 上级不允许是自己的下级
if(!empty($data['id'])){
$all = list_to_tree($all->toArray(),$data['id']);
$all = tree_to_list($all);
if(in_array($data['pid'],array_column($all,'id'))){
return $this->response('上级栏目不允许为本身的下级','B_NAV_PID_IS_CHILD');
}
}
}
// 保存
$id = BNav::_save($this->user['project_id'],$data,$data['id']??0);
if($id===-1){
return $this->response('导航菜单不存在','B_NAV_NOTFOUND');
}
return $this->success(BNav::_find($this->user['project_id'],$id,true));
}
/**
* 删除数据
* @return \Illuminate\Http\JsonResponse
* @author:dc
* @time 2023/5/9 9:20
*/
public function delete(){
$id = $this->param['id']??0;
$data = BNav::_find($this->user['project_id'],$id);
if(empty($data)){
return $this->response('导航菜单不存在','B_NAV_NOTFOUND');
}
if(BNav::isChild($data['id'],$this->user['project_id'])){
return $this->response('存在下级无法删除','B_NAV_DELETE_CHILD');
}
if($data->delete()){
return $this->response('删除成功',Code::SUCCESS);
}
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Models\Template\AHeadFoot;
use App\Models\Template\BCustom;
use App\Models\Template\BHeadFoot;
use App\Models\Template\BTemplate;
use Illuminate\Support\Facades\DB;
/**
* 自定义 页面
* @author:dc
* @time 2023/5/4 15:59
* Class TemplateController
* @package App\Http\Controllers\Bside
*/
class TemplateController extends BaseController
{
/**
* 头部底部的 html
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author:dc
* @time 2023/5/4 16:15
*/
public function index(){
$data = BTemplate::_get($this->user['project_id']);
// todo::这里要进行html的替换
return $this->success($data);
}
/**
* 读取编辑的html
* @author:dc
* @time 2023/5/4 16:19
*/
public function edit_html(){
$data = BHeadFoot::_get($this->user['project_id']);
if(!$data){
$data = AHeadFoot::_bDefault();
}
return $this->success([
'header' => $data[BHeadFoot::TYPE_HEADER]??'',
'footer' => $data[BHeadFoot::TYPE_FOOTER]??'',
]);
}
/**
* 保存
* @author:dc
* @time 2023/5/4 17:42
*/
public function edit_save(){
$header = $this->param['header']??'';
$footer = $this->param['footer']??'';
if(!$header && !$footer){
throw new BsideGlobalException('B01024','不能为空');
}
DB::beginTransaction();
try {
if($header){
BHeadFoot::_save($this->user['project_id'],BHeadFoot::TYPE_HEADER,$header);
}
if($footer){
BHeadFoot::_save($this->user['project_id'],BHeadFoot::TYPE_FOOTER,$footer);
}
}catch (\Throwable $e){
DB::rollBack();
throw new BsideGlobalException('B01024','保存失败');
}
DB::commit();
$this->success([]);
}
/**
* 获取系统的模板
* @author:dc
* @time 2023/5/4 16:21
*/
public function system_all_html(){
$data = AHeadFoot::_ball();
$lists = [];
// 以名字为单位区分
foreach ($data as $datum){
if(empty($lists[$datum['name']])) $lists[$datum['name']] = [];
$lists[$datum['name']]['name'] = $datum['name'];
$lists[$datum['name']]['default'] = $datum['is_default'];
$lists[$datum['name']][$datum['type']==AHeadFoot::TYPE_HEADER?'header':'footer'] = $datum['html'];
}
return $this->success(array_values($lists));
}
/**
* 自定义 列表
* @author:dc
* @time 2023/5/4 17:13
*/
public function custom(){
$data = BCustom::_all($this->user['project_id']);
return $this->success($data->toArray());
}
public function custom_create(){
}
public function custom_edit($id){
}
public function custom_delete($id){
}
}
... ...
<?php
namespace App\Http\Logic\Bside\AyrShare;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\AyrShare\AyrRelease;
class AyrReleaseLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new AyrRelease();
$this->param = $this->requestAll;
}
/**
* @name :()release_info
* @author :lyh
* @method :post
* @time :2023/5/9 16:27
*/
public function release_info(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
}
return $this->success($info);
}
/**
* @name :(发布社交写入数据库)release_add
* @author :lyh
* @method :post
* @time :2023/5/9 9:38
*/
public function release_add(){
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(上传第三方平台)0ayr_release_add
* @author :lyh
* @method :post
* @time :2023/5/9 10:02
*/
public function ayr_release_add($param){
$param = [
'post'=>$this->param['content'],
'platforms'=>$this->param['platforms'],
'mediaUrls'=>$this->param['mediaUrls'],
];
return $this->success($param);
}
/**
* @name :(发布到推特)post_twitter
* @author :lyh
* @method :post
* @time :2023/5/9 13:42
*/
public function post_twitter($param){
$param['post'] = '描述';
$param['platforms'] = ['twitter'];
$param['twitterOptions'] = [
'thread'=> true,
'threadNumber'=> true,
'mediaUrls'=>[
//图片地址
],
];
return $this->success($param);
}
/**
* @name :(发布到youtube)post_facebook
* @author :lyh
* @method :post
* @time :2023/5/9 10:05
*/
public function post_facebook(){
$param['post'] = '视频描述';
$param['platforms'] = ['facebook'];
$param['faceBookOptions'] = [
'reels'=> true,
'title'=>'Super title for the Reel'
];
return $this->success($param);
}
/**
* @name :(发布到fbg,)post_youtube
* @author :lyh
* @method :post
* @time :2023/5/9 10:22
* @TODO::只能发布一张图片和一张视频
*/
public function post_gmb(){
$param['post'] = '描述';
$param['platforms'] = ['gmb'];
$param['mediaUrls'] = [];//图片链接
$param['gmbOptions'] = [
//视屏设置
'isPhotoVideo' => true,
'category'=> 'cate',//分类
];
return $this->success($param);
}
/**
* @name :(发布到instagram)post_google
* @author :lyh
* @method :post
* @time :2023/5/9 11:54
*/
public function post_instagram(){
$param['post'] = '视频描述';
$param['platforms'] = ['instagram'];
$param['faceBookOptions'] = [
'reels'=> true,
'title'=>'Super title for the Reel'
];
return $this->success();
}
/**
* @name :(领英)post_linkedin
* @author :lyh
* @method :post
* @time :2023/5/9 11:56
*/
public function post_linkedin(){
return $this->success();
}
/**
* @name :(红迪网)post_reddit
* @author :lyh
* @method :post
* @time :2023/5/9 13:40
*/
public function post_reddit(){
return $this->success();
}
/**
* @name :(抖音)post_tiktok
* @author :lyh
* @method :post
* @time :2023/5/9 13:44
*/
public function post_tiktok(){
}
}
... ...
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* b端控制, c端显示的导航
* @author:dc
* @time 2023/5/8 16:14
* Class BNav
* @package App\Models
*/
class BNav extends Base
{
protected $table = 'gl_bside_nav';
use SoftDeletes;
public $hidden = ['deleted_at','project_id'];
/**
* 显示
*/
const STATUS_ACTIVE = 1;
/**
* 隐藏
*/
const STATUS_DISABLED = 0;
/**
* 创建或者新增导航栏
* @param int $project_id
* @param array $data
* @param int $id
* @return int
* @author:dc
* @time 2023/5/8 16:24
*/
public static function _save(int $project_id, array $data, int $id = 0):int {
if($id){
$model = static::where('id',$id)->where('project_id', $project_id)->first();
if(!$model){
return -1;
}
}else{
$model = new static();
$model->project_id = $project_id;
}
$model->pid = $data['pid'];
$model->name = $data['name'];
$model->location = $data['location'];
$model->url = $data['url'];
$model->status = $data['status'];
$model->target = $data['target'];
$model->sort = $data['sort'];
$model->save();
return $model->id;
}
/**
* 删除
* @param int $project_id
* @param int $id
* @return mixed
* @author:dc
* @time 2023/5/8 16:27
*/
public static function _del(int $project_id, int $id){
return static::where(['project_id'=>$project_id,'id'=>$id])->delete();
}
/**
* 查询当前项目下的所有栏目信息
* @param int $project_id
* @return mixed
* @author:dc
* @time 2023/5/8 16:29
*/
public static function _all(int $project_id, string $location = null)
{
return static::where(function ($query) use ($project_id,$location){
// 那个公司
$query->where('project_id',$project_id);
// 显示位置
$location && $query->where('location',$location);
})
->orderBy('sort')
->get();
}
/**
* 查询一条数据
* @param int $project_id
* @param int $id
* @return mixed
* @author:dc
* @time 2023/5/8 17:04
*/
public static function _find(int $project_id, int $id, $array = false)
{
$data = static::where(['id'=>$id,'project_id'=>$project_id])->first();
if($data){
return $array ? $data->toArray() : $data;
}
return [];
}
/**
* 是否存在
* @param int $project_id
* @param int $id
* @return mixed
* @author:dc
* @time 2023/5/8 17:24
*/
public static function _check(int $project_id, int $id)
{
return static::where(['id'=>$id,'project_id'=>$project_id])->count();
}
/**
* 是否有下级
* @param int $id
* @param int $project_id
* @return mixed
* @author:dc
* @time 2023/5/9 9:23
*/
public static function isChild(int $id,int $project_id=0)
{
return static::where(['pid'=>$id,'project_id'=>$project_id])->limit(1)->count();
}
}
... ...
<?php
namespace App\Models\Template;
/**
* 头部底部
* @author:dc
* @time 2023/5/4 15:52
* Class AHeadFoot
* @package App\Models\Template
*/
class AHeadFoot extends \App\Models\Base{
protected $table = 'gl_aside_template_header_footer';
// 分开存 头底 为了方便后期可能会 改版为 随意搭配 头底部
const TYPE_HEADER = 'H';
const TYPE_FOOTER = 'F';
const STATUS_ACTIVE = 1;
const STATUS_DISABLED = 0;
const IS_DEFAULT = 1;
/**
* b 端 查询
* @return mixed
* @author:dc
* @time 2023/5/4 16:24
*/
public static function _ball(){
return static::where('status',static::STATUS_ACTIVE)->orderBy('sort')->get(['id','name','type','html','is_default']);
}
/**
* b 端 读取默认的一个头部底部
* @return mixed
* @author:dc
* @time 2023/5/4 16:51
*/
public static function _bDefault(){
return static::where(['status'=>static::STATUS_ACTIVE,'is_default'=>static::IS_DEFAULT])
->get(['type','html'])
->pluck('html','type')
->toArray();
}
}
... ...
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 自定义 页面
* @author:dc
* @time 2023/5/4 17:18
* Class BCustom
* @package App\Models\Template
*/
class BCustom extends \App\Models\Base{
protected $table = 'gl_bside_template_custom';
use SoftDeletes;
const STATUS_ACTIVE = 1;
const STATUS_DISABLED = 0;
/**
* 读取列表
* @param $project_id
* @return mixed
* @author:dc
* @time 2023/5/4 17:22
*/
public static function _all($project_id){
return static::where([
'project_id' => $project_id
])->paginate(20);
}
}
... ...
<?php
namespace App\Models\Template;
/**
* 自定义 界面
* @author:dc
* @time 2023/5/8 13:52
* Class BTemplate
* @package App\Models\Template
*/
class BTemplate extends \App\Models\Base{
protected $table = 'gl_bside_template_html';
/**
* @param $project_id
* @return mixed
* @author:dc
* @time 2023/5/4 16:13
*/
public static function _get($project_id){
return static::where(['project_id'=>$project_id])->get(['html','type'])->pluck('html','type')->toArray();
}
public static function _all($project_id){
return static::where(['project_id'=>$project_id])->get();
}
/**
* 保存
* @param $project_id
* @param $type
* @param $html
* @author:dc
* @time 2023/5/4 17:50
*/
public static function _save($project_id,$type,$html){
$data = static::where(['project_id'=>$project_id,'type'=>$type])->first();
if(!$data){
$data = new static();
$data->project_id = $project_id;
$data->type = $type;
}
$data->html = $html;
$data->save();
return $data->id;
}
}
... ...