作者 lyh

gx

@@ -6,7 +6,9 @@ use App\Helper\Arr; @@ -6,7 +6,9 @@ use App\Helper\Arr;
6 use App\Models\Base; 6 use App\Models\Base;
7 use App\Models\RouteMap; 7 use App\Models\RouteMap;
8 use App\Services\Facades\Upload; 8 use App\Services\Facades\Upload;
  9 +use App\Services\ProjectServer;
9 use Illuminate\Database\Eloquent\SoftDeletes; 10 use Illuminate\Database\Eloquent\SoftDeletes;
  11 +use Illuminate\Support\Facades\DB;
10 12
11 /** 13 /**
12 * @method static get() 14 * @method static get()
@@ -18,7 +20,7 @@ class Product extends Base @@ -18,7 +20,7 @@ class Product extends Base
18 //设置关联表名 20 //设置关联表名
19 protected $table = 'gl_product'; 21 protected $table = 'gl_product';
20 //连接数据库 22 //连接数据库
21 -// protected $connection = 'custom_mysql'; 23 + protected $connection = 'custom_mysql';
22 const STATUS_DRAFT = 0; 24 const STATUS_DRAFT = 0;
23 const STATUS_ON = 1; 25 const STATUS_ON = 1;
24 const STATUS_RECYCLE = 2; 26 const STATUS_RECYCLE = 2;
@@ -152,6 +154,8 @@ class Product extends Base @@ -152,6 +154,8 @@ class Product extends Base
152 // } 154 // }
153 155
154 public static function getNumByProjectId($project_id){ 156 public static function getNumByProjectId($project_id){
  157 + $project = ProjectServer::useProject($project_id);
  158 + DB::connection('custom_mysql')->reconnect(); // 连接到目标数据库
155 return self::where('project_id', $project_id)->where('status', self::STATUS_ON)->count(); 159 return self::where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
156 } 160 }
157 161