Product.php 1.2 KB
<?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();
    }

}