123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace app\admin\model;
- use support\Db;
- use support\Model;
- /**
- * 角色模型
- * Class Users
- * @package app\admin\model
- */
- class PackageGoods extends Model
- {
- const GOODS_PUT_SHELVES = '1';
- const GOODS_LOWER_SHELF = '2';
- const GOODS_STATUS = [
- self::GOODS_PUT_SHELVES => '上架',
- self::GOODS_LOWER_SHELF => '下架'
- ];
- /**
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'package_goods';
- public $timestamps = false;
- /**
- * Notes:获取产品列表
- * @param string $keywords
- * @param int $page
- * @param int $limit
- * @return array
- * User: QJF
- * Date: 2022/9/20
- */
- public static function getPackageGoodsList(int $page, int $limit, $keywords)
- {
- $model = new PackageGoods();
- if($limit == 1000){
- $model = $model->where('goods_status',1);
- }
- $list = $model->select('*')
- ->with('Category')
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('goods_name', 'like', '%' . $keywords . '%');
- })
- ->orderBy('goods_update_time','DESC')
- ->forPage($page, $limit)
- ->get();
- $count = $model->when($keywords != '', function ($query) use ($keywords){
- $query->where('goods_name', $keywords);
- })
- ->count();
- return [$list, $count];
- }
- //测试
- public static function getProductList(int $page, int $limit, string $keywords)
- {
- $list = static::select(['intelligence_products.*','intelligence_category.category_name'])
- ->where(['product_del'=>0])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('product_name', $keywords);
- })
- ->leftJoin('intelligence_category', 'category_id', '=', 'intelligence_products.product__category_id')
- ->orderBy('product_create_time','DESC')
- ->forPage($page, $limit)
- ->get();
- $count = static::where(['product_del'=>0])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('product_name', $keywords);
- })
- ->count();
- return [$list, $count];
- }
- public function Category(){
- return $this->belongsTo(PackageGoodsCategory::class,'goods_category_id','category_id');
- }
- public function getGoodsCreateTimeAttribute($value)
- {
- return date('Y-m-d H:i:s', $value);
- }
- public function getGoodsUpdateTimeAttribute($value)
- {
- return date('Y-m-d H:i:s', $value);
- }
- /**
- * Notes:获取套餐包包含所有产品
- * @param array $goods_ids
- * @return array
- * User: yym
- * Date: 2022/9/22
- */
- public static function getPackageGoodsListNew(array $goods_ids)
- {
- return static::where(['goods_status' => static::GOODS_PUT_SHELVES])
- ->whereIn('goods_id', $goods_ids)
- ->get()
- ->toArray();
- }
- }
|