mb_ad.model.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * 手机端广告
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class mb_adModel extends Model{
  11. public function __construct(){
  12. parent::__construct('mb_ad');
  13. }
  14. /**
  15. * 列表
  16. *
  17. * @param array $condition 查询条件
  18. * @param int $page 分页数
  19. * @param string $order 排序
  20. * @param string $field 字段
  21. * @return array
  22. */
  23. public function getMbAdList($condition, $page = null, $order = 'link_id asc', $field = '*'){
  24. $link_list = $this->field($field)->where($condition)->page($page)->order($order)->select();
  25. //整理图片链接
  26. if (is_array($link_list)){
  27. foreach ($link_list as $k => $v){
  28. if (!empty($v['link_pic'])){
  29. $link_list[$k]['link_pic_url'] = UPLOAD_SITE_URL.'/'.ATTACH_MOBILE.'/ad'.'/'.$v['link_pic'];
  30. }
  31. }
  32. }
  33. return $link_list;
  34. }
  35. /**
  36. * 取单个内容
  37. *
  38. * @param int $id ID
  39. * @return array 数组类型的返回结果
  40. */
  41. public function getMbAdInfoByID($id){
  42. if (intval($id) > 0){
  43. $condition = array('link_id' => $id);
  44. $result = $this->where($condition)->find();
  45. return $result;
  46. }else {
  47. return false;
  48. }
  49. }
  50. /**
  51. * 取单个内容
  52. *
  53. * @param int $id ID
  54. * @return array 数组类型的返回结果
  55. */
  56. public function getMbAdCount(){
  57. return Db::getCount('mb_ad');
  58. }
  59. /**
  60. * 新增
  61. *
  62. * @param array $param 参数内容
  63. * @return bool 布尔类型的返回结果
  64. */
  65. public function addMbAd($param){
  66. return $this->insert($param);
  67. }
  68. /**
  69. * 更新信息
  70. *
  71. * @param array $param 更新数据
  72. * @param array $condition 条件
  73. * @return bool 布尔类型的返回结果
  74. */
  75. public function editMbAd($param, $condition){
  76. return $this->where($condition)->update($param);
  77. }
  78. /**
  79. * 删除
  80. *
  81. * @param int $id 记录ID
  82. * @return bool 布尔类型的返回结果
  83. */
  84. public function delMbAd($id){
  85. if (intval($id) > 0){
  86. //删除图片
  87. $tmp = $this->getMbAdInfoByID($id);
  88. if (!empty($tmp['link_pic'])){
  89. @unlink(BASE_ROOT_PATH.DS.DIR_UPLOAD.DS.ATTACH_MOBILE.'/ad/'.$tmp['link_pic']);
  90. }
  91. $condition = array('link_id' => $id);
  92. return $this->where($condition)->delete();
  93. } else {
  94. return false;
  95. }
  96. }
  97. }