作者 Your Name

Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev

... ... @@ -18,4 +18,5 @@ final class Common extends Enum
//端
const A='a';
const B='b';
const C='c';
}
... ...
<?php
namespace App\Exceptions;
use App\Enums\Common\Code;
use Exception;
use Throwable;
/**
* @notes: C端接口统一错误格式
* Class CsideGlobalException
* @package App\Exceptions
*/
class CsideGlobalException extends Exception
{
public function __construct($code = 0, $message = "", Throwable $previous = null)
{
$this->code = $code;
$this->message = $message;
if (empty($this->message)) {
$this->message = Code::fromValue($code)->description;
}
}
}
... ...
... ... @@ -72,6 +72,10 @@ class Handler extends ExceptionHandler
elseif($exception instanceof BsideGlobalException) {
LogUtils::error("BsideGlobalException", [], $exceptionMessage);
}
//C端错误
elseif($exception instanceof CsideGlobalException) {
LogUtils::error("CsideGlobalException", [], $exceptionMessage);
}
//验证错误(非手动抛出)
elseif ($exception instanceof ValidationException) {
LogUtils::error("参数验证失败", [], $exceptionMessage);
... ... @@ -110,6 +114,8 @@ class Handler extends ExceptionHandler
$code = $exception->getCode();
}elseif ($exception instanceof BsideGlobalException) {
$code = $exception->getCode();
}elseif ($exception instanceof CsideGlobalException) {
$code = $exception->getCode();
} elseif ($exception instanceof ValidationException) {
$code = Code::USER_PARAMS_ERROE();
$message = $code->description = Arr::first(Arr::first($exception->errors()));
... ...
<?php
namespace App\Helper;
use GuzzleHttp\Client;
/**
* @name: ayr_share社交绑定
*/
class AyrShare
{
public $path = 'https://app.ayrshare.com/api';
//api_key
public $api_key = 'G8GQW3X-XBTMGXW-QPDDZ9A-WE1Z5SB';
//系统设置
public $config = [
];
//profile_key
public $profile_key = "-----BEGIN RSA PRIVATE KEY-----
MIICWgIBAAKBgGFatMeBeaw7QJrqmylMLZlwuuO0FA/EZg5/g7Rrqu+FgpwvFkJq
9twEZJY+aIdDH8/RVrCZQGR/xUxKw9v4ows+sLwi4g41m8KRKDXUcJwQvSlwsHAi
h9hPGZxDsRK0Nv4pZ7XqGgh0Wb0VypX/+Q1dhX9BnXQmvEKayk8GQWQxAgMBAAEC
gYAFqOJNnudV7fPpja4LjpQwEW+sATIRYJeWTC9587ByUE6xicM/hTxouhCm82Xc
Rzi4OjFR/vbRYOQ1dTtBtIi18fdRrseQNyR/N2NZjw1X8n5aZcw5NVaa3d3YTQNa
uzjnYF5eYSOD4pNKKIDc35VHdmvGCV/JXwQKMTgu1+4AAQJBAL5jjN3kvMKFF8vG
DyYR8k+wPG9iXAdR0HjVNB3OzxKVW0MTwM32pJBXCmF1MOziL8WC48VHQL48hVRa
52xRqAECQQCC53rrrOPhPCLIb6kBfgqnxCojqlUK9paFL7NYTPtLYcOajY6+NiKT
CG1gaOwZh4r34HF7I59l/Ds98Z4nQDwxAkAC4/oIiGeBQIoK8vfZ6R3XreJNAp5J
EinrG7mN1kz4iEH5c7xSpDL9agTjU+cpQYneIs2Yeit2d+7CSBsJXvgBAkBDFsfU
yYLxCJT7DN8dOK/VU6AVL1Luj3qNP+k2tB2GgNBzAWHK8ou9t2/3HU8DtofuikUe
yx8Cccca9B4OF8nBAkAgIUZKGmVNFcGnFFo55vSJInNXFo4HCJ2o4DunBORVtQ/j
zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K
-----END RSA PRIVATE KEY-----";
//设置请求头
public $headers = [
'Authorization' => 'Bearer ',
'Content-Type' => 'application/json',
// 'Accept-Encoding' => 'deflate, gzip',
];
/**
* @name :参数构建
*/
public function __construct()
{
$this->headers['Authorization'] = $this->headers['Authorization'].$this->api_key;
}
/**
* @name :获取过去30天发布的历史记录(1-30)
* @author :lyh
* @method :get
* @time :2023/5/5 10:00
*/
public function get_analytics_links($to_day){
$last_days = (string)$to_day;
$url = $this->path.'/analytics/links?lastDays='.$last_days;
return $this->http_click('get',$url);
}
/**
* @name :(通过 Ayrshare 获取给定帖子的实时分析,例如点赞、印象、转推等)post_analytics
* @author :lyh
* @method :post
* @time :2023/5/5 11:56
*/
public function post_analytics($id){
$param = [
'id'=>$id,
'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
];
$url = $this->path.'/api/analytics/post';
return $this->http_click('post', $url, $param);
}
/**
* @name :(获取特定用户个人资料)analytics_post
* @author :lyh
* @method :post
* @time :2023/5/5 10:43
*/
public function post_analytics_social(){
$post_data = [
'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
];
$url = $this->path.'/api/analytics/social';
return $this->http_click('post',$url,$post_data);
}
/**
* @name :(设置自动计划)post_schedule_set
* @author :lyh
* @method :post
* @time :2023/5/5 13:58
*/
public function post_schedule_set($data){
$param = [
'schedule'=>["13:05Z", "20:14Z"],
'title'=>$data['title'],
];
$url = $this->path.'/api/auto-schedule/set';
return $this->http_click('post',$url,$param);
}
/**
* @name :(删除自动计划)delete_schedule
* @author :lyh
* @method :post
* @time :2023/5/5 14:04
*/
public function delete_schedule($data){
$param = [
'title'=>$data['title'],
];
$url = $this->path.'/api/auto-schedule/delete';
return $this->http_click('delete',$url,$param);
}
/**
* @name :(列出自动计划)get_schedule_list
* @author :lyh
* @method :post
* @time :2023/5/5 14:08
*/
public function get_schedule_list(){
$url = $this->path.'/api/auto-schedule/list';
return $this->http_click('get',$url);
}
/**
* @name :(发布到用户个人资料)post_user
* @author :lyh
* @method :post
* @time :2023/5/5 15:00
*/
public function post_user($data){
$param = [
'post'=>$data['post'],
'platforms'=>$data['platforms'],
'profileKey'=>$this->profile_key,
'mediaUrls'=>$data['mediaUrls']
];
$url = $this->path.'/api/post';
return $this->http_click('post',$url,$param);
}
/**
* @name :(创建子账户相关操作)post_create_profiles
* @author :lyh
* @method :post
* @time :2023/5/5 15:16
*/
public function post_create_profiles($data){
$param = [
'title'=>$data['title'],
];
$url = $this->path.'/profiles/profile';
return $this->http_click('post',$url,$param);
}
/**
* @name :(删除子账户相关操作)post_create_profiles
* @author :lyh
* @method :post
* @time :2023/5/5 15:16
*/
public function deleted_create_profiles($data){
$param = [
'title'=>$data['title'],
'profileKey'=>$this->profile_key,
];
$url = $this->path.'/profiles/profile';
return $this->http_click('delete',$url,$param);
}
public function put_update_profiles($data){
$param = [
'title'=>$data['title'],
'profileKey'=>$this->profile_key,
];
$url = $this->path.'/profiles/profile';
return $this->http_click('put',$url,$param);
}
/**
* @name :(获取有关用户社交资料的分析和人口统计,例如印象,视图和关注着)post_social
* @author :lyh
* @method :post
* @time :2023/5/5 10:37
*/
public function api_user(){
$post_data = [
'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
];
$url = $this->path.'/api/user';
return $this->http_click('post',$url,$post_data);
}
/**
* 发送http post,get,put,delete请求
* @param type $url
* @param type $post_data
*/
function http_click($method = 'post',$url, $param = [],$header = [])
{
if(!empty($param)){
$post_data['json'] = $param;
}
$post_data['headers'] = !empty($header) ? $header : $this->headers;
$client = new Client();
try {
$res = $client->request(strtoupper($method), $url, $post_data)->getBody()->getContents();
return $res;
} catch (\Exception $e) {
return json_encode(["status"=>"fail","message"=>$e->getMessage()]);
}
}
}
... ...
... ... @@ -7,6 +7,9 @@ use App\Models\User\UserLog as UserLogModel;
use App\Models\User\UserLogin as UserLoginModel;
use Illuminate\Support\Facades\Cache;
/**
* @name:
*/
class Common
{
/**
... ...
... ... @@ -4,6 +4,9 @@ namespace App\Helper;
use App\Models\WebSetting\WebSettingCountry;
/**
* @name:多语言国家设置
*/
class Country
{
public $tls_list = [
... ... @@ -681,6 +684,6 @@ class Country
}
$webCountry = new WebSettingCountry();
$webCountry->insert($data);
return;
return true;
}
}
... ...
... ... @@ -37,12 +37,14 @@ if(!function_exists('http_post')){
* @param type $url
* @param type $post_data
*/
function http_post($url, $post_data)
function http_post($url, $post_data,$header = [])
{
if(empty($header)){
$header = array(
"Accept: application/json",
"Content-Type:application/json;charset=utf-8",
);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
... ... @@ -69,10 +71,12 @@ if(!function_exists('http_get')){
* @param type $url
* @return type
*/
function http_get($url)
function http_get($url,$header = [])
{
$header[] = "content-type: application/x-www-form-urlencoded;
if(empty($header)){
$header[] = "content-type: application/json;
charset = UTF-8";
}
$ch1 = curl_init();
$timeout = 5;
curl_setopt($ch1, CURLOPT_URL, $url);
... ...
... ... @@ -39,12 +39,6 @@ class InquiryController extends BaseController
return $this->success(Arr::twoKeepKeys($data, ['id', 'name', 'email', 'phone', 'url', 'ip', 'ip_country', 'status', 'content', 'trans_content', 'created_at']));
}
public function save(InquiryRequest $request, InquiryLogic $logic)
{
$data = $logic->save($this->param);
return $this->success($data);
}
public function delete(Request $request, InquiryLogic $logic)
{
$request->validate([
... ...
... ... @@ -25,7 +25,7 @@ class NewsController extends BaseController
public function lists(NewsModel $news,NewsCategoryLogic $newsCategoryLogic){
$this->map['project_id'] = $this->user['project_id'];
$lists = $news->lists($this->map,$this->page,$this->row,$this->order,
['id','category_id','operator_id','status','created_at','updated_at','name','sort','url']);
['id','category_id','operator_id','status','created_at','updated_at','image','name','sort','url']);
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v = $newsCategoryLogic->get_category_name($v);
... ...
... ... @@ -25,7 +25,7 @@ class DescribeController extends BaseController
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'describe', 'status', 'created_at']);
$data = $logic->getList($map, $sort, ['id', 'title', 'text', 'status', 'created_at']);
return $this->success($data);
}
... ... @@ -36,7 +36,7 @@ class DescribeController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'describe', 'created_at']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'text', 'created_at']));
}
public function save(DescribeRequest $request, DescribeLogic $logic)
... ...
... ... @@ -43,7 +43,7 @@ class ProductController extends BaseController
$map[] = ['status', $this->param['status']];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_uid', 'created_at', 'updated_at']);
$data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']);
return $this->success($data);
}
... ... @@ -54,8 +54,8 @@ class ProductController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keywords', 'intro', 'content',
'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'status_text', 'created_uid', 'created_uid_text']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content',
'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text']));
}
public function save(ProductRequest $request, ProductLogic $logic)
... ...
... ... @@ -6,8 +6,6 @@ use App\Enums\Common\Code;
use App\Models\Image as ImageModel;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
... ... @@ -32,9 +30,9 @@ class ImageController
public $request = '';
public function __construct(Request $request)
public function __construct()
{
$this->request = $request;
$this->request = request();
$this->config = config('filesystems.disks.upload');
$this->path = $this->config['root'];
}
... ...
... ... @@ -11,6 +11,7 @@ use App\Http\Middleware\Bside\EnableCrossRequestMiddleware;
use App\Http\Middleware\Bside\ParamMiddleware as BsideParamMiddleware;
use App\Http\Middleware\Aside\LoginAuthMiddleware as AsideLoginAuthMiddleware;
use App\Http\Middleware\Bside\LoginAuthMiddleware as BsideLoginAuthMiddleware;
use App\Http\Middleware\Cside\ParamMiddleware as CsideParamMiddleware;
use App\Http\Middleware\PreventRepeatQuitCallMiddleware;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
... ... @@ -75,6 +76,11 @@ class Kernel extends HttpKernel
PreventRepeatQuitCallMiddleware::class,
//允许跨域请求
EnableCrossRequestMiddleware::class
],
//C端中间件组
'cside'=>[
//参数处理中间件--涉及-参数记录-参数加解密等
CsideParamMiddleware::class,
]
];
... ...
... ... @@ -2,13 +2,11 @@
namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Exceptions\BsideGlobalException;
use App\Helper\Common;
use App\Http\Controllers\ImageController;
use App\Http\Logic\Logic;
use App\Models\Image as ImageModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
/**
... ... @@ -25,6 +23,8 @@ class BaseLogic extends Logic
protected $user;
protected $side = Common::B;
public function __construct()
{
$this->request = request();
... ...
... ... @@ -32,15 +32,4 @@ class InquiryLogic extends BaseLogic
}
return $this->success($info->toArray());
}
public function save($param)
{
//todo 根据域名 判断 project_id
$param['ip_info'] = Arr::s2a($param['ip_info']);
$param['ip'] = $param['ip_info']['ip'] ?? '';
$param['ip_country'] = $param['ip_info']['country'] ?? '';
Logic::save($param);
}
}
... ...
... ... @@ -60,19 +60,19 @@ class NewsLogic extends BaseLogic
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s',time());
$this->param['updated_at'] = date('Y-m-d H:i:s',time());
DB::beginTransaction();
try {
// DB::beginTransaction();
// try {
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data;
}
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('添加失败');
}
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// $this->fail('添加失败');
// }
return $this->success();
}
... ...
... ... @@ -30,12 +30,7 @@ class ProductLogic extends BaseLogic
{
$data = parent::getList($map, $sort, $columns, $limit);
foreach ($data['list'] as &$v){
foreach ($v['category_id'] as $category_id){
$v['category_id_text'][] =(new CategoryLogic())->getCacheInfo($category_id)['title']??'';
}
$v['category_id_text'] = Arr::arrToSet($v['category_id_text'], 'trim');
$v['status_text'] = Product::statusMap()[$v['status']] ?? '';
$v['created_uid_text'] = (new UserLogic())->getCacheInfo($v['created_uid'])['name'] ?? '';
$v = $this->formatData($v);
}
return $this->success($data);
}
... ... @@ -43,13 +38,22 @@ class ProductLogic extends BaseLogic
public function getInfo($id)
{
$info = parent::getInfo($id);
$info = $this->formatData($info);
return $this->success($info);
}
public function formatData($info){
foreach ($info['category_id'] as $category_id) {
$info['category_id_text'][] = (new CategoryLogic())->getCacheInfo($category_id)['title'] ?? '';
}
foreach ($info['keyword_id'] as $keyword_id){
$info['keyword_id_text'][] =(new KeywordLogic())->getCacheInfo($keyword_id)['title']??'';
}
$info['category_id_text'] = Arr::arrToSet($info['category_id_text'], 'trim');
$info['keyword_id_text'] = Arr::arrToSet($info['keyword_id_text'], 'trim');
$info['status_text'] = Product::statusMap()[$info['status']] ?? '';
$info['created_uid_text'] = (new UserLogic())->getCacheInfo($info['created_uid'])['name'] ?? '';
return $this->success($info);
return $info;
}
public function save($param){
... ...
<?php
namespace App\Http\Logic\Cside;
use App\Enums\Common\Common;
use App\Exceptions\BsideGlobalException;
use App\Http\Logic\Logic;
/**
* @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
*/
class BaseLogic extends Logic
{
protected $requestAll;
protected $param;
protected $request;
protected $project;
protected $side = Common::C;
public function __construct()
{
$this->request = request();
$this->requestAll = request()->all();
$this->project = $this->request->get('project');
}
/**
* 列表
* @param array $map
* @param array $sort
* @param array $columns
* @param int $limit
* @return array
* @author zbj
* @date 2023/4/13
*/
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
$map[] = ['project_id' => $this->project['id']];
return parent::getList($map, $sort, $columns, $limit);
}
/**
* @param $id
* @return mixed
* @author zbj
* @date 2023/4/15
*/
public function getCacheInfo($id)
{
$info = parent::getCacheInfo($id);
if ($info && $info['project_id'] != $this->project['id']) {
$info = null;
}
return $info;
}
/**
* 保存
* @param $param
* @return array
* @throws BsideGlobalException
* @author zbj
* @date 2023/4/13
*/
public function save($param)
{
$param['project_id'] = $this->project['id'];
return parent::save($param);
}
/**
* 批量删除
* @param $ids
* @param array $map
* @return array
* @author zbj
* @date 2023/4/13
*/
public function delete($ids, $map = [])
{
$map[] = ['project_id' => $this->project['id']];
return parent::delete($ids, $map);
}
}
... ...
<?php
namespace App\Http\Logic\Cside;
use App\Helper\Arr;
use App\Models\Inquiry;
/**
* Class InquiryLogic
* @package App\Http\Logic\Bside
* @author zbj
* @date 2023/5/4
*/
class InquiryLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Inquiry();
}
public function save($param)
{
$param['ip_info'] = Arr::s2a($param['ip_info']);
$param['ip'] = $param['ip_info']['ip'] ?? '';
$param['ip_country'] = $param['ip_info']['country'] ?? '';
return parent::save($param);
}
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic;
use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Exceptions\CsideGlobalException;
use \App\Helper\Common as CommonHelper;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
... ... @@ -45,6 +46,9 @@ class Logic
if((request()->path()[0]) == Common::B){
throw new BsideGlobalException($code, $message);
}
if((request()->path()[0]) == Common::C){
throw new CsideGlobalException($code, $message);
}
throw new AsideGlobalException($code, $message);
}
... ...
<?php
namespace App\Http\Middleware\Cside;
use App\Enums\Common\Code;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Closure;
use Illuminate\Http\Request;
class ParamMiddleware
{
protected $param = [];
protected $project = [];
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
$this->param = $request->all();
$domain = $request->header('domain');
if(!isset($domain) || empty($domain)){
return response(['code'=>Code::USER_ERROR,'msg'=>'非法请求']);
}
$project = Project::getProjectByDomain($domain);
if(empty($project)){
return response(['code'=>Code::USER_ERROR,'msg'=>'非法请求']);
}
// 设置数据信息
// $project = ProjectServer::useProject($project['id']);
// if($project){
// return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);
// }
$request->attributes->add(['project' => $project]);
return $next($request);
}
}
... ...
... ... @@ -31,29 +31,14 @@ class ProjectRequest extends FormRequest
public function rules()
{
return [
// 'id' => 'required',
// 'title' => 'max:100',
// 'company' => 'max:100',
// 'lead_name' => 'max:20',
// 'mobile' => [new Mobile()],
// 'qq' => 'max:20',
// 'cooperate_date' => 'date_format:Y-m-d',
// 'province' => 'max:20',
// 'city' => 'max:20',
];
}
public function messages()
{
return [
'id.required' => 'ID不能为空',
'title.max' => '项目名称不能超过100个字符',
'company.max' => '公司名不能超过100个字符',
'lead_name.max' => '联系人不能超过20个字符',
'qq.max' => 'QQ号不能超过20个字符',
'cooperate_date.date_format' => '合作时间格式不正确',
'province.max' => '省份不能超过20个字符',
'city.max' => '城市不能超过20个字符',
];
}
... ...
... ... @@ -25,7 +25,7 @@ class NewsRequest extends FormRequest
{
return [
'name'=>'required|max:100',
'remark'=>'required|max:100',
'remark'=>'required|max:255',
'text'=>'required|min:10',
'category_id'=>'required',
];
... ...
... ... @@ -31,7 +31,7 @@ class DescribeRequest extends FormRequest
{
return [
'title'=>'required|max:50',
'describe'=>'required',
'text'=>'required',
];
}
... ... @@ -40,7 +40,7 @@ class DescribeRequest extends FormRequest
return [
'title.required' => '请输入描述名称',
'title.max' => '描述名称不能超过50个字符',
'seo_title.required' => '请输入描述内容',
'text.required' => '请输入描述内容',
];
}
... ...
... ... @@ -48,7 +48,7 @@ class ProductRequest extends FormRequest
}
}
}],
'attrs' => ['required', 'array', function ($attribute, $value, $fail) {
'attrs' => ['array', function ($attribute, $value, $fail) {
foreach ($value as $v) {
if (empty($v['key'])) {
$fail('产品属性名不能为空');
... ... @@ -59,11 +59,9 @@ class ProductRequest extends FormRequest
}
}],
'category_id' => 'required',
'keywords' => 'required',
'intro' => 'required|max:500',
'content' => 'required',
'describe' => 'required|array',
'seo_mate' => ['required', 'array', function ($attribute, $value, $fail) {
'seo_mate' => ['array', function ($attribute, $value, $fail) {
if(empty($value['title'])){
$fail('SEO标题不能为空');
}
... ... @@ -74,7 +72,7 @@ class ProductRequest extends FormRequest
$fail('SEO关键词不能为空');
}
}],
'related_product_id' => ['required', function ($attribute, $value, $fail) {
'related_product_id' => [function ($attribute, $value, $fail) {
$value = array_filter(Arr::splitFilterToArray($value), 'intval');
if(count($value) > 16){
$fail('关联产品不能超过16个');
... ...
<?php
namespace App\Http\Requests\Bside;
namespace App\Http\Requests\Cside;
use Illuminate\Foundation\Http\FormRequest;
/**
* Class InquiryRequest
* @package App\Http\Requests\Bside
* @package App\Http\Requests\Cside
* @author zbj
* @date 2023/5/4
*/
... ...
... ... @@ -85,12 +85,28 @@ class Product extends Base
return Arr::setToArr($value);
}
public function setKeywordsAttribute($value){
$this->attributes['keywords'] = Arr::arrToSet($value, 'trim');
public function setAttrIdAttribute($value){
$this->attributes['attr_id'] = Arr::arrToSet($value);
}
public function getKeywordsAttribute($value){
return Arr::setToArr($value, 'trim');
public function getAttrIdAttribute($value){
return Arr::setToArr($value);
}
public function setDescribeIdAttribute($value){
$this->attributes['describe_id'] = Arr::arrToSet($value);
}
public function getDescribeIdAttribute($value){
return Arr::setToArr($value);
}
public function setKeywordIdAttribute($value){
$this->attributes['keyword_id'] = Arr::arrToSet($value);
}
public function getKeywordIdAttribute($value){
return Arr::setToArr($value);
}
public function setRelatedProductIdAttribute($value){
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
use Illuminate\Support\Facades\Cache;
class DeployBuild extends Base
{
... ... @@ -19,4 +20,8 @@ class DeployBuild extends Base
return Arr::setToArr($value);
}
public static function clearCache($row){
$cache_key = 'project_' . $row->original['test_domain'];
Cache::forget($cache_key);
}
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
use Illuminate\Support\Facades\Cache;
class DeployOptimize extends Base
{
... ... @@ -19,4 +20,9 @@ class DeployOptimize extends Base
return Arr::s2a($value);
}
public static function clearCache($row){
$cache_key = 'project_' . $row->original['domain'];
Cache::forget($cache_key);
}
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
use App\Models\Devops\ServerConfig;
use Illuminate\Support\Facades\Cache;
class Project extends Base
{
... ... @@ -144,4 +145,30 @@ class Project extends Base
return Arr::s2a($value);
}
/**
* 根据域名获取项目信息
* @author zbj
* @date 2023/5/5
*/
public static function getProjectByDomain($domain){
$cache_key = 'project_'.$domain;
$data = Cache::get($cache_key);
if(!$data){
//是否测试域名
$project_id = DeployBuild::where('test_domain', $domain)->value('project_id');
//是否正式域名
if(!$project_id){
$project_id = DeployOptimize::where('domain', $domain)->value('project_id');
}
if(!$project_id){
return [];
}
$data = self::find($project_id);
if($data){
Cache::put($cache_key, $data);
}
}
return $data;
}
}
... ...
... ... @@ -40,6 +40,7 @@ class RouteServiceProvider extends ServiceProvider
//预定义两个端的API路由
$this->mapAsideRoute();
$this->mapBsideRoute();
$this->mapCsideRoute();
// 暂时无用
$this->routes(function () {
... ... @@ -74,6 +75,16 @@ class RouteServiceProvider extends ServiceProvider
->namespace($this->namespace . '\Bside')
->group(base_path('routes/bside.php'));
}
/**
*C端API路由
* @return void
*/
protected function mapCsideRoute(){
Route::middleware('cside')
->prefix('c')
->namespace($this->namespace . '\Cside')
->group(base_path('routes/cside.php'));
}
/**
* Configure the rate limiters for the application.
... ...
... ... @@ -60,6 +60,12 @@ return [
'via' => \App\Factory\LogFormatterFactory::class,
'prefix' => 'bside',
],
//自定义B端错误日志
'cside' => [
'driver' => 'custom',
'via' => \App\Factory\LogFormatterFactory::class,
'prefix' => 'cside',
],
'stack' => [
'driver' => 'stack',
... ...
<?php
/**
* C端用户路由文件
*/
use Illuminate\Support\Facades\Route;
//必须登录验证的路由组
Route::middleware([])->group(function () {
//添加询盘信息
Route::post('/inquiry/save', [\App\Http\Controllers\Cside\InquiryController::class, 'save'])->name('inquiry_save');
});
... ...