作者 lyh

gx

... ... @@ -7,15 +7,14 @@ use App\Helper\Arr;
use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\Manage\ManageLogic;
use App\Models\ASide\Product\Product;
use App\Models\Blog\Blog;
use App\Models\Channel\Channel;
use App\Models\Channel\User;
use App\Models\Channel\Zone;
use App\Models\Devops\ServerConfig;
use App\Models\Inquiry\InquirySet;
use App\Models\Manage\Manage;
use App\Models\News\News;
use App\Models\Product\Product;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Payment;
... ... @@ -67,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' => Product::getNumByProjectId($item['id']),
'product_num' => (new Product($item['id']))->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';
//连接数据库
protected $connection = '';
const STATUS_DRAFT = 0;
const STATUS_ON = 1;
const STATUS_RECYCLE = 2;
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();
}
}
... ...
... ... @@ -2,10 +2,8 @@
namespace App\Models\Blog;
use App\Enums\Common\Code;
use App\Models\Base;
use App\Models\User\User;
use App\Services\ProjectServer;
class Blog extends Base
{
... ... @@ -17,10 +15,6 @@ class Blog extends Base
}
public static function getNumByProjectId($project_id){
$project = ProjectServer::useProject($project_id);
if(empty($project)){
return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);
}
return self::where('project_id', $project_id)->where('status', 1)->count();
}
}
... ...
... ... @@ -2,9 +2,7 @@
namespace App\Models\News;
use App\Enums\Common\Code;
use App\Models\Base;
use App\Services\ProjectServer;
class News extends Base
{
... ... @@ -13,10 +11,6 @@ class News extends Base
protected $connection = 'custom_mysql';
public static function getNumByProjectId($project_id){
$project = ProjectServer::useProject($project_id);
if(empty($project)){
return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);
}
return self::where('project_id', $project_id)->where('status', 1)->count();
}
}
... ...
... ... @@ -2,12 +2,10 @@
namespace App\Models\Product;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Models\Base;
use App\Models\RouteMap;
use App\Services\Facades\Upload;
use App\Services\ProjectServer;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
... ... @@ -154,10 +152,6 @@ class Product extends Base
// }
public static function getNumByProjectId($project_id){
$project = ProjectServer::useProject($project_id);
if(empty($project)){
return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);
}
return self::where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
}
... ...