album.model.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. /**
  3. * 相册管理
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class albumModel extends Model{
  11. public function __construct(){
  12. parent::__construct();
  13. }
  14. /**
  15. * 计算数量
  16. *
  17. * @param array $condition 条件
  18. * $param string $table 表名
  19. * @return int
  20. */
  21. public function getAlbumPicCount($condition) {
  22. $result = $this->table('album_pic')->where($condition)->count();
  23. return $result;
  24. }
  25. /**
  26. * 计算数量
  27. *
  28. * @param array $condition 条件
  29. * $param string $table 表名
  30. * @return int
  31. */
  32. public function getCount($condition, $table = 'album_pic') {
  33. $result = $this->table($table)->where($condition)->count();
  34. return $result;
  35. }
  36. /**
  37. * 获取单条数据
  38. *
  39. * @param array $condition 条件
  40. * @param string $table 表名
  41. * @return array 一维数组
  42. */
  43. public function getOne($condition, $table = 'album_pic') {
  44. $resule = $this->table($table)->where($condition)->find();
  45. return $resule;
  46. }
  47. /**
  48. * 分类列表
  49. *
  50. * @param array $condition 查询条件
  51. * @param obj $page 分页对象
  52. * @return array 二维数组
  53. */
  54. public function getClassList($condition,$page=''){
  55. $param = array();
  56. $param['table'] = 'album_class,album_pic';
  57. $param['field'] = 'album_class.*,count(album_pic.aclass_id) as count';
  58. $param['join_type'] = 'left join';
  59. $param['join_on'] = array('album_class.aclass_id = album_pic.aclass_id');
  60. $param['where'] = $this->getCondition($condition);
  61. $param['order'] = $condition['order'] ? $condition['order'] : 'album_class.aclass_sort desc';
  62. $param['group'] = 'album_class.aclass_id';
  63. return Db::select($param,$page);
  64. }
  65. /**
  66. * 计算分类数量
  67. *
  68. * @param int id
  69. * @return array 一维数组
  70. */
  71. public function countClass($id){
  72. $param = array();
  73. $param['table'] = 'album_class';
  74. $param['field'] = 'count(*) as count';
  75. $param['where'] = " and store_id = '$id'";
  76. $return = Db::select($param);
  77. return $return['0'];
  78. }
  79. /**
  80. * 验证相册
  81. *
  82. * @param array $param 参数内容
  83. * @return bool 布尔类型的返回结果
  84. */
  85. public function checkAlbum($condition) {
  86. /**
  87. * 验证是否为当前合作伙伴
  88. */
  89. $check_array = self::getClassList($condition,'');
  90. if (!empty($check_array)){
  91. unset($check_array);
  92. return true;
  93. }
  94. unset($check_array);
  95. return false;
  96. }
  97. /**
  98. * 图片列表
  99. *
  100. * @param array $condition 查询条件
  101. * @param obj $page 分页对象
  102. * @return array 二维数组
  103. */
  104. public function getPicList($condition, $page='', $field='*'){
  105. $param = array();
  106. $param['table'] = 'album_pic';
  107. $param['where'] = $this->getCondition($condition);
  108. $param['order'] = $condition['order'] ? $condition['order'] : 'apic_id desc';
  109. $param['field'] = $field;
  110. return Db::select($param,$page);
  111. }
  112. /**
  113. * 添加相册分类
  114. *
  115. * @param array $input
  116. * @return bool
  117. */
  118. public function addClass($input){
  119. if(is_array($input) && !empty($input)){
  120. return Db::insert('album_class',$input);
  121. }else{
  122. return false;
  123. }
  124. }
  125. /**
  126. * 添加相册图片
  127. *
  128. * @param array $input
  129. * @return bool
  130. */
  131. public function addPic($input) {
  132. $result = $this->table('album_pic')->insert($input);
  133. return $result;
  134. }
  135. /**
  136. * 更新相册分类
  137. *
  138. * @param array $input
  139. * @param int $id
  140. * @return bool
  141. */
  142. public function updateClass($input,$id){
  143. if(is_array($input) && !empty($input)){
  144. return Db::update('album_class',$input," aclass_id='$id' ");
  145. }else{
  146. return false;
  147. }
  148. }
  149. /**
  150. * 更新相册图片
  151. *
  152. * @param array $input
  153. * @param int $id
  154. * @return bool
  155. */
  156. public function updatePic($input,$condition){
  157. if(is_array($input) && !empty($input)){
  158. return Db::update('album_pic',$input,$this->getCondition($condition));
  159. }else{
  160. return false;
  161. }
  162. }
  163. /**
  164. * 删除分类
  165. *
  166. * @param string $id
  167. * @return bool
  168. */
  169. public function delClass($id){
  170. if(!empty($id)) {
  171. return Db::delete('album_class'," aclass_id ='".$id."' ");
  172. }else{
  173. return false;
  174. }
  175. }
  176. /**
  177. * 根据店铺id删除图片空间相关信息
  178. *
  179. * @param int $id
  180. * @return bool
  181. */
  182. public function delAlbum($id){
  183. $id = intval($id);
  184. Db::delete('album_class'," store_id= ".$id);
  185. $pic_list = $this->getPicList(array(" store_id= ".$id),'','apic_cover');
  186. if(!empty($pic_list) && is_array($pic_list)){
  187. $image_ext = explode(',', GOODS_IMAGES_EXT);
  188. foreach($pic_list as $v){
  189. foreach ($image_ext as $ext) {
  190. $file = str_ireplace('.', $ext . '.', $v['apic_cover']);
  191. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_GOODS.DS.$id.DS.$file);
  192. }
  193. }
  194. }
  195. Db::delete('album_pic'," store_id= ".$id);
  196. }
  197. /**
  198. * 删除图片
  199. *
  200. * @param string $id
  201. * @param int $store_id
  202. * @return bool
  203. */
  204. public function delPic($id, $store_id){
  205. $pic_list = $this->getPicList(array('in_apic_id'=>$id),'','apic_cover');
  206. /**
  207. * 删除图片
  208. */
  209. if(!empty($pic_list) && is_array($pic_list)){
  210. $image_ext = explode(',', GOODS_IMAGES_EXT);
  211. foreach($pic_list as $v){
  212. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_GOODS.DS.$store_id.DS.$v['apic_cover']);
  213. foreach ($image_ext as $ext) {
  214. $file = str_ireplace('.', $ext . '.', $v['apic_cover']);
  215. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_GOODS.DS.$store_id.DS.$file);
  216. }
  217. }
  218. }
  219. if(!empty($id)) {
  220. return Db::delete('album_pic','apic_id in('.$id.')');
  221. }else{
  222. return false;
  223. }
  224. }
  225. /**
  226. * 查询单条分类信息
  227. *
  228. * @param int $id 活动id
  229. * @return array 一维数组
  230. */
  231. public function getOneClass($param){
  232. if(is_array($param) && !empty($param)) {
  233. return Db::getRow(array_merge(array('table'=>'album_class'),$param));
  234. }else{
  235. return false;
  236. }
  237. }
  238. /**
  239. * 根据id查询一张图片
  240. *
  241. * @param int $id 活动id
  242. * @return array 一维数组
  243. */
  244. public function getOnePicById($param){
  245. if(is_array($param) && !empty($param)) {
  246. return Db::getRow(array_merge(array('table'=>'album_pic'),$param));
  247. }else{
  248. return false;
  249. }
  250. }
  251. /**
  252. * 构造查询条件
  253. *
  254. * @param array $condition 条件数组
  255. * @return $condition_sql
  256. */
  257. private function getCondition($condition){
  258. $condition_sql = '';
  259. if($condition['apic_id'] != '') {
  260. $condition_sql .= " and apic_id= '{$condition['apic_id']}'";
  261. }
  262. if($condition['apic_name'] != '') {
  263. $condition_sql .= " and apic_name='".$condition['apic_name']."'";
  264. }
  265. if($condition['apic_tag'] != '') {
  266. $condition_sql .= " and apic_tag like '%".$condition['apic_tag']."%'";
  267. }
  268. if($condition['aclass_id'] != '') {
  269. $condition_sql .= " and aclass_id= '{$condition['aclass_id']}'";
  270. }
  271. if($condition['album_aclass.store_id'] != '') {
  272. $condition_sql .= " and `album_class`.store_id = '{$condition['album_aclass.store_id']}'";
  273. }
  274. if($condition['album_aclass.aclass_id'] != '') {
  275. $condition_sql .= " and `album_class`.aclass_id= '{$condition['album_aclass.aclass_id']}'";
  276. }
  277. if($condition['album_pic.store_id'] != '') {
  278. $condition_sql .= " and `album_pic`.store_id= '{$condition['album_pic.store_id']}'";
  279. }
  280. if($condition['album_pic.apic_id'] != '') {
  281. $condition_sql .= " and `album_pic`.apic_id= '{$condition['album_pic.apic_id']}'";
  282. }
  283. if($condition['store_id'] != '') {
  284. $condition_sql .= " and store_id= '{$condition['store_id']}'";
  285. }
  286. if($condition['aclass_name'] != '') {
  287. $condition_sql .= " and aclass_name='".$condition['aclass_name']."'";
  288. }
  289. if($condition['in_apic_id'] != '') {
  290. $condition_sql .= " and apic_id in (".$condition['in_apic_id'].")";
  291. }
  292. if($condition['gt_apic_id'] != '') {
  293. $condition_sql .= " and apic_id > '{$condition['gt_apic_id']}'";
  294. }
  295. if($condition['like_cover'] != '') {
  296. $condition_sql .= " and apic_cover like '%".$condition['like_cover']."%'";
  297. }
  298. if($condition['is_default'] != '') {
  299. $condition_sql .= " and is_default= '{$condition['is_default']}'";
  300. }
  301. if($condition['album_class.un_aclass_id'] != '') {
  302. $condition_sql .= " and `album_class`.aclass_id <> '{$condition['album_class.un_aclass_id']}'";
  303. }
  304. return $condition_sql;
  305. }
  306. }
  307. ?>