链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

  1. <?php
  2. namespace App\Models\v3;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Database\Eloquent\Model;
  6. class GoodsCategory extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_goods_category';
  11. protected $dateFormat = 'U';
  12. /* 查询记录数 limit */
  13. protected $perPage = 10;
  14. /**
  15. * 获取单个信息
  16. * @param int $id
  17. * @param string $field
  18. * @return string
  19. */
  20. public static function getInfo($id,$field = '*')
  21. {
  22. return self::select($field)->find($id);
  23. }
  24. /**
  25. * 获取二级分类数组
  26. * id为键,title为值
  27. * @return array
  28. */
  29. public static function getArray($where = [],$options = [])
  30. {
  31. $model = self::where('status',1)
  32. ->whereNull('deleted_at');
  33. if(count($where) > 0){
  34. $model->where($where);
  35. }
  36. $list = $model->pluck('id','title')->toArray();
  37. if(!empty($options)){
  38. $new = array_merge($options,$list);
  39. return array_flip($new);
  40. }else{
  41. return array_flip($list);
  42. }
  43. }
  44. }