cms_picture.model.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * cms文章模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class cms_pictureModel extends Model{
  11. public function __construct(){
  12. parent::__construct('cms_picture');
  13. }
  14. /**
  15. * 读取列表
  16. * @param array $condition
  17. *
  18. */
  19. public function getList($condition, $page=null, $order='', $field='*', $limit=''){
  20. $result = $this->table('cms_picture')->field($field)->where($condition)->page($page)->order($order)->limit($limit)->select();
  21. return $result;
  22. }
  23. /**
  24. * 画报数量
  25. * @param array $condition
  26. * @return int
  27. */
  28. public function getCmsPictureCount($condition) {
  29. return $this->where($condition)->count();
  30. }
  31. /**
  32. * 根据tag编号查询
  33. */
  34. public function getListByTagID($condition, $page=null, $order='', $field='*', $limit=''){
  35. $condition['relation_type'] = 2;
  36. $on = 'cms_picture.picture_id= cms_tag_relation.relation_object_id';
  37. $result = $this->table('cms_picture,cms_tag_relation')->field($field)->join('left')->on($on)->where($condition)->page($page)->order($order)->limit($limit)->select();
  38. $this->cls();
  39. return $result;
  40. }
  41. /**
  42. * 读取单条记录
  43. * @param array $condition
  44. *
  45. */
  46. public function getOne($condition,$order=''){
  47. $result = $this->table('cms_picture')->where($condition)->order($order)->find();
  48. return $result;
  49. }
  50. /*
  51. * 判断是否存在
  52. * @param array $condition
  53. *
  54. */
  55. public function isExist($condition) {
  56. $result = $this->table('cms_picture')->getOne($condition);
  57. if(empty($result)) {
  58. return FALSE;
  59. }
  60. else {
  61. return TRUE;
  62. }
  63. }
  64. /*
  65. * 增加
  66. * @param array $param
  67. * @return bool
  68. */
  69. public function save($param){
  70. return $this->table('cms_picture')->insert($param);
  71. }
  72. /*
  73. * 更新
  74. * @param array $update
  75. * @param array $condition
  76. * @return bool
  77. */
  78. public function modify($update, $condition){
  79. return $this->table('cms_picture')->where($condition)->update($update);
  80. }
  81. /*
  82. * 删除
  83. * @param array $condition
  84. * @return bool
  85. */
  86. public function drop($condition){
  87. $this->drop_picture_image($condition);
  88. return $this->table('cms_picture')->where($condition)->delete();
  89. }
  90. /**
  91. * 删除图片
  92. */
  93. private function drop_picture_image($condition) {
  94. $model_picture_image = Model('cms_picture_image');
  95. $picture_list = self::getList($condition);
  96. $picture_ids = '';
  97. if(!empty($picture_list) && is_array($picture_list)) {
  98. //删除画报图片文件
  99. foreach($picture_list as $picture) {
  100. $picture_ids .= $picture['picture_id'].',';
  101. $picture_image_list = $model_picture_image->getList(array('image_picture_id'=>$picture['picture_id']), NULL);
  102. if(!empty($picture_image_list)) {
  103. foreach ($picture_image_list as $value) {
  104. list($base_name, $ext) = explode('.',$value['image_name']);
  105. $image = BASE_UPLOAD_PATH.DS.ATTACH_CMS.DS.'article'.DS.$picture['picture_attachment_path'].DS.$value['image_name'];
  106. $image_list = BASE_UPLOAD_PATH.DS.ATTACH_CMS.DS.'article'.DS.$picture['picture_attachment_path'].DS.$base_name.'_list.'.$ext;
  107. $image_max = BASE_UPLOAD_PATH.DS.ATTACH_CMS.DS.'article'.DS.$picture['picture_attachment_path'].DS.$base_name.'_max.'.$ext;
  108. if(is_file($image)) {
  109. unlink($image);
  110. }
  111. if(is_file($image_list)) {
  112. unlink($image_list);
  113. }
  114. if(is_file($image_max)) {
  115. unlink($image_max);
  116. }
  117. }
  118. }
  119. }
  120. //删除画报图片记录
  121. $model_picture_image->drop(array('image_picture_id'=>array('in', trim($picture_ids, ','))));
  122. }
  123. }
  124. }