HomeGoods.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 地块模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class HomeGoods extends Model
  11. {
  12. const ROLE_STATUS = 1;
  13. const IS_DEL_YES = 1;
  14. const IS_DEL_NO = 0;
  15. const GOODS_IS_SHOW = [
  16. self::IS_DEL_YES => '已删除',
  17. self::IS_DEL_NO => '未删除'
  18. ];
  19. /**
  20. * The table associated with the model.
  21. *
  22. * @var string
  23. */
  24. protected $table = 'home_goods';
  25. public $timestamps = false;
  26. /**
  27. * Notes:获取居家项目列表
  28. * @return array
  29. * User: YCP
  30. * Date: 2022/10/31
  31. */
  32. public static function getGoodsList(int $page,int $limit,string $keywords,$category_id)
  33. {
  34. $list = static::select('*')
  35. ->where(['goods_is_del'=>static::IS_DEL_NO])
  36. ->when($keywords != '', function ($query) use ($keywords){
  37. $query->where('goods_name', 'like', '%' . $keywords . '%');
  38. })
  39. ->when($category_id != '', function ($query) use ($category_id){
  40. $query->where('goods_category_id',$category_id);
  41. })
  42. ->orderBy('goods_weigh','DESC')
  43. ->forPage($page, $limit)
  44. ->get();
  45. $count = static::where(['goods_is_del'=>static::IS_DEL_NO])
  46. ->when($keywords != '', function ($query) use ($keywords){
  47. $query->where('goods_name', 'like', '%' . $keywords . '%');
  48. })
  49. ->when($category_id != '', function ($query) use ($category_id){
  50. $query->where('goods_category_id',$category_id);
  51. })
  52. ->count();
  53. return [$list, $count];
  54. }
  55. //时间格式
  56. public function getGoodsCreateTimeAttribute($value)
  57. {
  58. if($value == 0 || $value == ''){
  59. return 0;
  60. }else{
  61. return date('Y-m-d H:i:s', $value);
  62. }
  63. }
  64. //时间格式
  65. public function getGoodsUpdateTimeAttribute($value)
  66. {
  67. if($value == 0 || $value == ''){
  68. return 0;
  69. }else{
  70. return date('Y-m-d H:i:s', $value);
  71. }
  72. }
  73. }