44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
| <?php
 | |
| declare (strict_types=1);
 | |
| 
 | |
| namespace app\model;
 | |
| 
 | |
| /**
 | |
|  * @author canny
 | |
|  * @date 2024/2/23 16:51
 | |
|  **/
 | |
| class Product extends BaseModel
 | |
| {
 | |
|     use SearcherTrait;
 | |
| 
 | |
|     const PRODUCT_TYPE_BAO_YUE = 2;
 | |
|     const PRODUCT_TYPE_NORMAL = 1;
 | |
|     public function searchNameAttr($query, $value, $data)
 | |
|     {
 | |
|         if (!empty($value)) {
 | |
|             $query->whereLike('name', "%" . $value . "%");
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 根据商品id 获取商品信息
 | |
|      * @param int $productId
 | |
|      * @param string $field
 | |
|      * @return Product|array|mixed|\think\Model
 | |
|      */
 | |
|     public static function getById(int $productId, string $field = '*')
 | |
|     {
 | |
|         return self::where('id', $productId)->field($field)->findOrEmpty();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * 根据supplier_product_id获取商品信息
 | |
|      * @param int $productId
 | |
|      * @param string $field
 | |
|      * @return Product|array|mixed|\think\Model
 | |
|      */
 | |
|     public static function getBySupplierProductId(int $productId, string $field = '*')
 | |
|     {
 | |
|         return self::where('supplier_product_id', $productId)->field($field)->findOrEmpty();
 | |
|     }
 | |
| } |