cms_special.model.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * cms专题模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class cms_specialModel extends Model{
  11. const SPECIAL_TYPE_CMS = 1;
  12. const SPECIAL_TYPE_SHOP = 2;
  13. private $special_type_array = array(
  14. self::SPECIAL_TYPE_CMS => '资讯',
  15. self::SPECIAL_TYPE_SHOP => '商城',
  16. );
  17. public function __construct(){
  18. parent::__construct('cms_special');
  19. }
  20. /**
  21. * 读取列表
  22. * @param array $condition
  23. *
  24. */
  25. public function getList($condition, $page=null, $order='', $field='*', $limit=''){
  26. $list = $this->field($field)->where($condition)->page($page)->order($order)->limit($limit)->select();
  27. foreach ($list as $key => $value) {
  28. $list[$key]['special_type_text'] = $this->special_type_array[$value['special_type']];
  29. if($value['special_type'] == self::SPECIAL_TYPE_SHOP) {
  30. $list[$key]['special_link'] = getShopSpecialUrl($value['special_id']);
  31. } else {
  32. $list[$key]['special_link'] = getCMSSpecialUrl($value['special_id']);
  33. }
  34. }
  35. return $list;
  36. }
  37. public function getCMSList($condition, $page=null, $order='', $field='*', $limit=''){
  38. $condition['special_type'] = self::SPECIAL_TYPE_CMS;
  39. return $this->getList($condition, $page=null, $order='', $field='*', $limit='');
  40. }
  41. public function getShopList($condition, $page=null, $order='', $field='*', $limit=''){
  42. $condition['special_type'] = self::SPECIAL_TYPE_SHOP;
  43. return $this->getList($condition, $page=null, $order='', $field='*', $limit='');
  44. }
  45. /**
  46. * 读取单条记录
  47. * @param array $condition
  48. *
  49. */
  50. public function getOne($condition,$order=''){
  51. $result = $this->where($condition)->order($order)->find();
  52. return $result;
  53. }
  54. /**
  55. * 获取类型列表
  56. */
  57. public function getSpecialTypeArray() {
  58. return $this->special_type_array;
  59. }
  60. /*
  61. * 判断是否存在
  62. * @param array $condition
  63. *
  64. */
  65. public function isExist($condition) {
  66. $result = $this->getOne($condition);
  67. if(empty($result)) {
  68. return FALSE;
  69. }
  70. else {
  71. return TRUE;
  72. }
  73. }
  74. /*
  75. * 增加
  76. * @param array $param
  77. * @return bool
  78. */
  79. public function save($param){
  80. return $this->insert($param);
  81. }
  82. /*
  83. * 更新
  84. * @param array $update
  85. * @param array $condition
  86. * @return bool
  87. */
  88. public function modify($update, $condition){
  89. return $this->where($condition)->update($update);
  90. }
  91. /*
  92. * 删除
  93. * @param array $condition
  94. * @return bool
  95. */
  96. public function drop($condition){
  97. return $this->where($condition)->delete();
  98. }
  99. }