123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\admin\model;
- use support\Db;
- use support\Model;
- /**
- * 地块模型
- * Class Users
- * @package app\admin\model
- */
- class HomeGoods extends Model
- {
- const ROLE_STATUS = 1;
- const IS_DEL_YES = 1;
- const IS_DEL_NO = 0;
- const GOODS_IS_SHOW = [
- self::IS_DEL_YES => '已删除',
- self::IS_DEL_NO => '未删除'
- ];
- /**
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'home_goods';
- public $timestamps = false;
- /**
- * Notes:获取居家项目列表
- * @return array
- * User: YCP
- * Date: 2022/10/31
- */
- public static function getGoodsList(int $page,int $limit,string $keywords,$category_id)
- {
- $list = static::select('*')
- ->where(['goods_is_del'=>static::IS_DEL_NO])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('goods_name', 'like', '%' . $keywords . '%');
- })
- ->when($category_id != '', function ($query) use ($category_id){
- $query->where('goods_category_id',$category_id);
- })
- ->orderBy('goods_weigh','DESC')
- ->forPage($page, $limit)
- ->get();
- $count = static::where(['goods_is_del'=>static::IS_DEL_NO])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('goods_name', 'like', '%' . $keywords . '%');
- })
- ->when($category_id != '', function ($query) use ($category_id){
- $query->where('goods_category_id',$category_id);
- })
- ->count();
- return [$list, $count];
- }
- //时间格式
- public function getGoodsCreateTimeAttribute($value)
- {
- if($value == 0 || $value == ''){
- return 0;
- }else{
- return date('Y-m-d H:i:s', $value);
- }
- }
- //时间格式
- public function getGoodsUpdateTimeAttribute($value)
- {
- if($value == 0 || $value == ''){
- return 0;
- }else{
- return date('Y-m-d H:i:s', $value);
- }
- }
-
- }
|