作者 lyh

gx

@@ -7,15 +7,14 @@ use App\Helper\Arr; @@ -7,15 +7,14 @@ use App\Helper\Arr;
7 use App\Helper\FormGlobalsoApi; 7 use App\Helper\FormGlobalsoApi;
8 use App\Http\Logic\Aside\BaseLogic; 8 use App\Http\Logic\Aside\BaseLogic;
9 use App\Http\Logic\Aside\Manage\ManageLogic; 9 use App\Http\Logic\Aside\Manage\ManageLogic;
  10 +use App\Models\ASide\Product\Product;
10 use App\Models\Blog\Blog; 11 use App\Models\Blog\Blog;
11 use App\Models\Channel\Channel; 12 use App\Models\Channel\Channel;
12 use App\Models\Channel\User; 13 use App\Models\Channel\User;
13 use App\Models\Channel\Zone; 14 use App\Models\Channel\Zone;
14 use App\Models\Devops\ServerConfig; 15 use App\Models\Devops\ServerConfig;
15 use App\Models\Inquiry\InquirySet; 16 use App\Models\Inquiry\InquirySet;
16 -use App\Models\Manage\Manage;  
17 use App\Models\News\News; 17 use App\Models\News\News;
18 -use App\Models\Product\Product;  
19 use App\Models\Project\DeployBuild; 18 use App\Models\Project\DeployBuild;
20 use App\Models\Project\DeployOptimize; 19 use App\Models\Project\DeployOptimize;
21 use App\Models\Project\Payment; 20 use App\Models\Project\Payment;
@@ -67,7 +66,7 @@ class ProjectLogic extends BaseLogic @@ -67,7 +66,7 @@ class ProjectLogic extends BaseLogic
67 'domain' => $item['deploy_optimize']['domain'] ?? 0, 66 'domain' => $item['deploy_optimize']['domain'] ?? 0,
68 'created_at' => date('Y年m月d日', strtotime($item['created_at'])), 67 'created_at' => date('Y年m月d日', strtotime($item['created_at'])),
69 'autologin_code' => $this->getAutoLoginCode($item['id']), 68 'autologin_code' => $this->getAutoLoginCode($item['id']),
70 - 'product_num' => Product::getNumByProjectId($item['id']), 69 + 'product_num' => (new Product($item['id']))->getNumByProjectId($item['id']),
71 'keyword_num' => $item['deploy_build']['keyword_num'] ?? 0, 70 'keyword_num' => $item['deploy_build']['keyword_num'] ?? 0,
72 'article_num' => Blog::getNumByProjectId($item['id']) + News::getNumByProjectId($item['id']), 71 'article_num' => Blog::getNumByProjectId($item['id']) + News::getNumByProjectId($item['id']),
73 'task_finish_num' => Task::getNumByProjectId($item['id'], Task::STATUS_DOWN), 72 'task_finish_num' => Task::getNumByProjectId($item['id'], Task::STATUS_DOWN),
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Models\Base;
  7 +use Illuminate\Database\Eloquent\SoftDeletes;
  8 +
  9 +class Attr extends Base
  10 +{
  11 + use SoftDeletes;
  12 +
  13 + protected $appends = ['attr_num'];
  14 +
  15 + //设置关联表名
  16 + protected $table = 'gl_product_attr';
  17 + //连接数据库
  18 + protected $connection = 'custom_mysql';
  19 +
  20 + public function setAttrsAttribute($value)
  21 + {
  22 + $this->attributes['attrs'] = Arr::a2s($value);
  23 + }
  24 +
  25 + public function getAttrsAttribute($value)
  26 + {
  27 + return Arr::s2a($value);
  28 + }
  29 +
  30 + public function getAttrNumAttribute()
  31 + {
  32 + return count($this->attrs);
  33 + }
  34 +
  35 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +
  6 +use App\Models\Base;
  7 +use App\Models\RouteMap;
  8 +use App\Services\Facades\Upload;
  9 +use Illuminate\Database\Eloquent\SoftDeletes;
  10 +
  11 +/**
  12 + * @method static get()
  13 + * @method static where(string $string, int $int)
  14 + */
  15 +class Category extends Base
  16 +{
  17 + use SoftDeletes;
  18 +
  19 + //设置关联表名
  20 + protected $table = 'gl_product_category';
  21 + //连接数据库
  22 + protected $connection = 'custom_mysql';
  23 +
  24 + const STATUS_ACTIVE = 1;
  25 +
  26 + /**
  27 + * 子分类
  28 + * @var array
  29 + */
  30 + protected $child_ids_arr = [];
  31 +
  32 +
  33 + protected $appends = ['route'];
  34 +
  35 + public function getRouteAttribute(){
  36 + return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_CATE, $this->id, $this->project_id);
  37 + }
  38 +
  39 +
  40 + /**
  41 + * 获取指定分类的所有子分类IDS(包括自己)
  42 + * @param $id
  43 + * @return array
  44 + * @author zbj
  45 + * @date 2023/4/28
  46 + */
  47 + public function getChildIdsArr($id)
  48 + {
  49 + $this->child_ids_arr = [$id];
  50 + return $this->getChildrenIdArr($id);
  51 + }
  52 +
  53 + /**
  54 + * 递归获取指定分类的所有子孙
  55 + * @param $id
  56 + * @return array
  57 + * @author zbj
  58 + * @date 2023/4/28
  59 + */
  60 + protected function getChildrenIdArr($id)
  61 + {
  62 + $list = parent::where("pid", $id)->pluck('pid', 'id');
  63 + if ($list) {
  64 + foreach ($list as $id => $pid) {
  65 + $this->child_ids_arr[] = $id;
  66 + $this->getChildrenIdArr($id);
  67 + }
  68 + }
  69 + return $this->child_ids_arr;
  70 + }
  71 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +
  6 +use App\Helper\Arr;
  7 +use App\Models\Base;
  8 +
  9 +class CategoryRelated extends Base
  10 +{
  11 +
  12 + //设置关联表名
  13 + protected $table = 'gl_product_category_related';
  14 + //连接数据库
  15 + protected $connection = 'custom_mysql';
  16 +
  17 + const CREATED_AT = null;
  18 + const UPDATED_AT = null;
  19 +
  20 +
  21 + /**
  22 + * 关联产品分类
  23 + * @param $product_id
  24 + * @param $cate_ids
  25 + * @author zbj
  26 + * @date 2023/4/21
  27 + */
  28 + public static function saveRelated($product_id, $cate_ids)
  29 + {
  30 + if(!is_array($cate_ids)){
  31 + $cate_ids = array_filter(Arr::splitFilterToArray($cate_ids), 'intval');
  32 + }
  33 + //先删除
  34 + self::where('product_id', $product_id)->delete();
  35 +
  36 + //批量保存
  37 + $data = [];
  38 + foreach ($cate_ids as $cate_id){
  39 + $data[] = [
  40 + 'product_id' => $product_id,
  41 + 'cate_id' => $cate_id
  42 + ];
  43 + }
  44 + self::insert($data);
  45 + }
  46 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +
  8 +class Describe extends Base
  9 +{
  10 + use SoftDeletes;
  11 +
  12 + //设置关联表名
  13 + protected $table = 'gl_product_describe';
  14 + //连接数据库
  15 + protected $connection = 'custom_mysql';
  16 +
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Models\Base;
  6 +use App\Models\RouteMap;
  7 +use Illuminate\Database\Eloquent\SoftDeletes;
  8 +
  9 +class Keyword extends Base
  10 +{
  11 + use SoftDeletes;
  12 +
  13 + //设置关联表名
  14 + protected $table = 'gl_product_keyword';
  15 +
  16 + protected $appends = ['route'];
  17 +
  18 + //连接数据库
  19 + protected $connection = 'custom_mysql';
  20 + public function getRouteAttribute(){
  21 + return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $this->id, $this->project_id);
  22 + }
  23 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +
  6 +use App\Helper\Arr;
  7 +use App\Models\Base;
  8 +
  9 +class KeywordRelated extends Base
  10 +{
  11 +
  12 + //设置关联表名
  13 + protected $table = 'gl_product_keyword_related';
  14 +
  15 + const CREATED_AT = null;
  16 + const UPDATED_AT = null;
  17 +
  18 + //连接数据库
  19 + protected $connection = 'custom_mysql';
  20 + /**
  21 + * 关联产品关键词
  22 + * @param $product_id
  23 + * @param $keyword_ids
  24 + * @author zbj
  25 + * @date 2023/5/4
  26 + */
  27 + public static function saveRelated($product_id, $keyword_ids)
  28 + {
  29 + if(!is_array($keyword_ids)){
  30 + $keyword_ids = array_filter(Arr::splitFilterToArray($keyword_ids), 'intval');
  31 + }
  32 + //先删除
  33 + self::where('product_id', $product_id)->delete();
  34 +
  35 + //批量保存
  36 + $data = [];
  37 + foreach ($keyword_ids as $keyword_id){
  38 + $data[] = [
  39 + 'product_id' => $product_id,
  40 + 'keyword_id' => $keyword_id
  41 + ];
  42 + }
  43 + self::insert($data);
  44 + }
  45 +}
  1 +<?php
  2 +
  3 +namespace App\Models\ASide\Product;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Base;
  7 +use App\Services\ProjectServer;
  8 +
  9 +/**
  10 + * @method static get()
  11 + */
  12 +class Product extends Base
  13 +{
  14 + //设置关联表名
  15 + protected $table = 'gl_product';
  16 + //连接数据库
  17 + protected $connection = '';
  18 + const STATUS_DRAFT = 0;
  19 + const STATUS_ON = 1;
  20 + const STATUS_RECYCLE = 2;
  21 +
  22 + public function __construct($project_id)
  23 + {
  24 + // 设置数据信息
  25 + $project = ProjectServer::useProject($project_id);
  26 + if(empty($project)){
  27 + return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);
  28 + }
  29 + $this->connection = 'custom_mysql';
  30 + }
  31 +
  32 + public static function statusMap(){
  33 + return [
  34 + self::STATUS_DRAFT => '草稿',
  35 + self::STATUS_ON => '已发布',
  36 + self::STATUS_RECYCLE => '回收站',
  37 + ];
  38 + }
  39 +
  40 + /**
  41 + * @var 获取产品类型
  42 + */
  43 + public $productType = [
  44 + 1=>'一般产品',
  45 + 2=>'推荐产品',
  46 + 3=>'热销产品'
  47 + ];
  48 +
  49 + public static function getNumByProjectId($project_id){
  50 + return self::where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
  51 + }
  52 +
  53 +}
@@ -2,10 +2,8 @@ @@ -2,10 +2,8 @@
2 2
3 namespace App\Models\Blog; 3 namespace App\Models\Blog;
4 4
5 -use App\Enums\Common\Code;  
6 use App\Models\Base; 5 use App\Models\Base;
7 use App\Models\User\User; 6 use App\Models\User\User;
8 -use App\Services\ProjectServer;  
9 7
10 class Blog extends Base 8 class Blog extends Base
11 { 9 {
@@ -17,10 +15,6 @@ class Blog extends Base @@ -17,10 +15,6 @@ class Blog extends Base
17 } 15 }
18 16
19 public static function getNumByProjectId($project_id){ 17 public static function getNumByProjectId($project_id){
20 - $project = ProjectServer::useProject($project_id);  
21 - if(empty($project)){  
22 - return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);  
23 - }  
24 return self::where('project_id', $project_id)->where('status', 1)->count(); 18 return self::where('project_id', $project_id)->where('status', 1)->count();
25 } 19 }
26 } 20 }
@@ -2,9 +2,7 @@ @@ -2,9 +2,7 @@
2 2
3 namespace App\Models\News; 3 namespace App\Models\News;
4 4
5 -use App\Enums\Common\Code;  
6 use App\Models\Base; 5 use App\Models\Base;
7 -use App\Services\ProjectServer;  
8 6
9 class News extends Base 7 class News extends Base
10 { 8 {
@@ -13,10 +11,6 @@ class News extends Base @@ -13,10 +11,6 @@ class News extends Base
13 protected $connection = 'custom_mysql'; 11 protected $connection = 'custom_mysql';
14 12
15 public static function getNumByProjectId($project_id){ 13 public static function getNumByProjectId($project_id){
16 - $project = ProjectServer::useProject($project_id);  
17 - if(empty($project)){  
18 - return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);  
19 - }  
20 return self::where('project_id', $project_id)->where('status', 1)->count(); 14 return self::where('project_id', $project_id)->where('status', 1)->count();
21 } 15 }
22 } 16 }
@@ -2,12 +2,10 @@ @@ -2,12 +2,10 @@
2 2
3 namespace App\Models\Product; 3 namespace App\Models\Product;
4 4
5 -use App\Enums\Common\Code;  
6 use App\Helper\Arr; 5 use App\Helper\Arr;
7 use App\Models\Base; 6 use App\Models\Base;
8 use App\Models\RouteMap; 7 use App\Models\RouteMap;
9 use App\Services\Facades\Upload; 8 use App\Services\Facades\Upload;
10 -use App\Services\ProjectServer;  
11 use Illuminate\Database\Eloquent\SoftDeletes; 9 use Illuminate\Database\Eloquent\SoftDeletes;
12 10
13 /** 11 /**
@@ -154,10 +152,6 @@ class Product extends Base @@ -154,10 +152,6 @@ class Product extends Base
154 // } 152 // }
155 153
156 public static function getNumByProjectId($project_id){ 154 public static function getNumByProjectId($project_id){
157 - $project = ProjectServer::useProject($project_id);  
158 - if(empty($project)){  
159 - return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);  
160 - }  
161 return self::where('project_id', $project_id)->where('status', self::STATUS_ON)->count(); 155 return self::where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
162 } 156 }
163 157