Category.php 985 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\api\model\service;
  3. use think\Model;
  4. class Category extends Model
  5. {
  6. // 表名
  7. protected $name = 'service_category';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. /**
  14. * 获取分类列表
  15. * @param $ids
  16. * @return string
  17. */
  18. public function getCategoryList($ids)
  19. {
  20. if(!$ids)
  21. {
  22. return '';
  23. }
  24. $idArr = explode(',',$ids);
  25. $list = [];
  26. foreach ($idArr as $val)
  27. {
  28. $name = $this->where(['id'=>$val])->value('name');
  29. if($name)
  30. {
  31. $list[] = $name;
  32. }
  33. }
  34. return implode(',',$list);
  35. }
  36. public static function getName($id)
  37. {
  38. return self::where(['id'=>$id])->value('name');
  39. }
  40. }