作者 lyh

gx

... ... @@ -66,7 +66,7 @@ class ProjectLogic extends BaseLogic
'domain' => $item['deploy_optimize']['domain'] ?? 0,
'created_at' => date('Y年m月d日', strtotime($item['created_at'])),
'autologin_code' => $this->getAutoLoginCode($item['id']),
'product_num' => (new Product($item['id']))->getNumByProjectId($item['id']),
'product_num' => (new Product())->getNumByProjectId($item['id']),
'keyword_num' => $item['deploy_build']['keyword_num'] ?? 0,
'article_num' => Blog::getNumByProjectId($item['id']) + News::getNumByProjectId($item['id']),
'task_finish_num' => Task::getNumByProjectId($item['id'], Task::STATUS_DOWN),
... ...
<?php
namespace App\Models\Product;
use App\Helper\Arr;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
class Attr extends Base
{
use SoftDeletes;
protected $appends = ['attr_num'];
//设置关联表名
protected $table = 'gl_product_attr';
//连接数据库
protected $connection = 'custom_mysql';
public function setAttrsAttribute($value)
{
$this->attributes['attrs'] = Arr::a2s($value);
}
public function getAttrsAttribute($value)
{
return Arr::s2a($value);
}
public function getAttrNumAttribute()
{
return count($this->attrs);
}
}
<?php
namespace App\Models\Product;
use App\Models\Base;
use App\Models\RouteMap;
use App\Services\Facades\Upload;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @method static get()
* @method static where(string $string, int $int)
*/
class Category extends Base
{
use SoftDeletes;
//设置关联表名
protected $table = 'gl_product_category';
//连接数据库
protected $connection = 'custom_mysql';
const STATUS_ACTIVE = 1;
/**
* 子分类
* @var array
*/
protected $child_ids_arr = [];
protected $appends = ['route'];
public function getRouteAttribute(){
return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_CATE, $this->id, $this->project_id);
}
/**
* 获取指定分类的所有子分类IDS(包括自己)
* @param $id
* @return array
* @author zbj
* @date 2023/4/28
*/
public function getChildIdsArr($id)
{
$this->child_ids_arr = [$id];
return $this->getChildrenIdArr($id);
}
/**
* 递归获取指定分类的所有子孙
* @param $id
* @return array
* @author zbj
* @date 2023/4/28
*/
protected function getChildrenIdArr($id)
{
$list = parent::where("pid", $id)->pluck('pid', 'id');
if ($list) {
foreach ($list as $id => $pid) {
$this->child_ids_arr[] = $id;
$this->getChildrenIdArr($id);
}
}
return $this->child_ids_arr;
}
}
<?php
namespace App\Models\Product;
use App\Helper\Arr;
use App\Models\Base;
class CategoryRelated extends Base
{
//设置关联表名
protected $table = 'gl_product_category_related';
//连接数据库
protected $connection = 'custom_mysql';
const CREATED_AT = null;
const UPDATED_AT = null;
/**
* 关联产品分类
* @param $product_id
* @param $cate_ids
* @author zbj
* @date 2023/4/21
*/
public static function saveRelated($product_id, $cate_ids)
{
if(!is_array($cate_ids)){
$cate_ids = array_filter(Arr::splitFilterToArray($cate_ids), 'intval');
}
//先删除
self::where('product_id', $product_id)->delete();
//批量保存
$data = [];
foreach ($cate_ids as $cate_id){
$data[] = [
'product_id' => $product_id,
'cate_id' => $cate_id
];
}
self::insert($data);
}
}
<?php
namespace App\Models\Product;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
class Describe extends Base
{
use SoftDeletes;
//设置关联表名
protected $table = 'gl_product_describe';
//连接数据库
protected $connection = 'custom_mysql';
}
<?php
namespace App\Models\Product;
use App\Models\Base;
use App\Models\RouteMap;
use Illuminate\Database\Eloquent\SoftDeletes;
class Keyword extends Base
{
use SoftDeletes;
//设置关联表名
protected $table = 'gl_product_keyword';
protected $appends = ['route'];
//连接数据库
protected $connection = 'custom_mysql';
public function getRouteAttribute(){
return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $this->id, $this->project_id);
}
}
<?php
namespace App\Models\Product;
use App\Helper\Arr;
use App\Models\Base;
class KeywordRelated extends Base
{
//设置关联表名
protected $table = 'gl_product_keyword_related';
const CREATED_AT = null;
const UPDATED_AT = null;
//连接数据库
protected $connection = 'custom_mysql';
/**
* 关联产品关键词
* @param $product_id
* @param $keyword_ids
* @author zbj
* @date 2023/5/4
*/
public static function saveRelated($product_id, $keyword_ids)
{
if(!is_array($keyword_ids)){
$keyword_ids = array_filter(Arr::splitFilterToArray($keyword_ids), 'intval');
}
//先删除
self::where('product_id', $product_id)->delete();
//批量保存
$data = [];
foreach ($keyword_ids as $keyword_id){
$data[] = [
'product_id' => $product_id,
'keyword_id' => $keyword_id
];
}
self::insert($data);
}
}
<?php
namespace App\Models\ASide\Product;
use App\Enums\Common\Code;
use App\Models\Base;
use App\Services\ProjectServer;
/**
* @method static get()
*/
class Product extends Base
{
//设置关联表名
protected $table = 'gl_product';
const STATUS_DRAFT = 0;
const STATUS_ON = 1;
const STATUS_RECYCLE = 2;
protected $connection;
public function __construct($project_id)
{
$project = ProjectServer::useProject($project_id);
if(empty($project)){
return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);
}
$this->connection = 'custom_mysql';
}
public static function statusMap(){
return [
self::STATUS_DRAFT => '草稿',
self::STATUS_ON => '已发布',
self::STATUS_RECYCLE => '回收站',
];
}
/**
* @var 获取产品类型
*/
public $productType = [
1=>'一般产品',
2=>'推荐产品',
3=>'热销产品'
];
public static function getNumByProjectId($project_id){
return self::where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
}
}
... ... @@ -213,4 +213,6 @@ class Base extends Model
});
return $query;
}
}
... ...
... ... @@ -9,7 +9,7 @@ class Blog extends Base
{
protected $table = 'gl_blog';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
public function user(){
return $this->hasMany(User::class,'operator_id','id');
}
... ...
... ... @@ -8,7 +8,7 @@ class News extends Base
{
protected $table = 'gl_news';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
public static function getNumByProjectId($project_id){
return self::where('project_id', $project_id)->where('status', 1)->count();
... ...
... ... @@ -12,5 +12,5 @@ class NewsCategory extends Base
{
protected $table = 'gl_news_category';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
}
... ...
... ... @@ -8,5 +8,5 @@ class NewsLabel extends Base
{
protected $table = 'gl_news_label';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
}
... ...
... ... @@ -15,7 +15,7 @@ class Attr extends Base
//设置关联表名
protected $table = 'gl_product_attr';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
public function setAttrsAttribute($value)
{
... ...
... ... @@ -19,7 +19,7 @@ class Category extends Base
//设置关联表名
protected $table = 'gl_product_category';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
const STATUS_ACTIVE = 1;
... ...
... ... @@ -12,7 +12,7 @@ class CategoryRelated extends Base
//设置关联表名
protected $table = 'gl_product_category_related';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
const CREATED_AT = null;
const UPDATED_AT = null;
... ...
... ... @@ -12,6 +12,6 @@ class Describe extends Base
//设置关联表名
protected $table = 'gl_product_describe';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
}
... ...
... ... @@ -16,7 +16,7 @@ class Keyword extends Base
protected $appends = ['route'];
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
public function getRouteAttribute(){
return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $this->id, $this->project_id);
}
... ...
... ... @@ -16,7 +16,7 @@ class KeywordRelated extends Base
const UPDATED_AT = null;
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
/**
* 关联产品关键词
* @param $product_id
... ...
... ... @@ -18,7 +18,7 @@ class Product extends Base
//设置关联表名
protected $table = 'gl_product';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
const STATUS_DRAFT = 0;
const STATUS_ON = 1;
const STATUS_RECYCLE = 2;
... ...