category.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. Doo::loadCore('db/DooModel');
  3. /**
  4. * Created by PhpStorm.
  5. * User: ellisran
  6. * Date: 2016/9/22
  7. * Time: 16:20
  8. */
  9. class Category extends DooModel {
  10. public $cateid;
  11. public $catename;
  12. public $parentid;
  13. public $itemid;
  14. public $_table = 'fc_category';
  15. public $_primarykey = 'cateid';
  16. public $_fields = array('cateid', 'catename', 'parentid', 'itemid');
  17. public function __construct() {
  18. parent::setupModel(__CLASS__);
  19. }
  20. public function getAlllist($itemid = 0) {
  21. return $this->find(array('select' => 'cateid,catename', 'where' => 'itemid='.$itemid, 'asArray' => TRUE));
  22. }
  23. public function getparentlist($itemid = 0) {
  24. return $this->find(array('select' => 'cateid,catename', 'where' => 'parentid=0 and itemid='.$itemid, 'asArray' => TRUE));
  25. }
  26. public function getRowbylimit($limit,$itemid = 0) {
  27. return $this->find(array('where' => 'itemid='.$itemid, 'desc' => 'cateid', 'limit' => $limit, 'asArray' => TRUE));
  28. }
  29. public function getnamebyid($id) {
  30. $cate = $this->getOne(array('select' => 'catename', 'where' => 'cateid='.$id, 'asArray' => TRUE));
  31. return $cate['catename'];
  32. }
  33. public function getchildbyparent($parentid) {
  34. return $this->find(array('select' => 'cateid', 'where' => 'parentid='.$parentid, 'asArray' => TRUE));
  35. }
  36. public function hadChild($parentid) {
  37. $total = $this->count(array('where' => 'parentid='.$parentid, 'asArray' => TRUE));
  38. if($total == 0){
  39. return 0;
  40. }else{
  41. return 1;
  42. }
  43. }
  44. public function getChildList($parentid) {
  45. return $this->find(array('select' => 'cateid,catename','where' => 'parentid='.$parentid, 'asArray' => TRUE));
  46. }
  47. }