Album.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Album extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 计算数量
  16. * @author csdeshang
  17. * @param array $condition 条件
  18. * @return int
  19. */
  20. public function getAlbumpicCount($condition)
  21. {
  22. $result = Db::name('albumpic')->where($condition)->count();
  23. return $result;
  24. }
  25. /**
  26. * 计算数量
  27. * @author csdeshang
  28. * @param array $condition 条件
  29. * @param string $table 表名
  30. * @return int
  31. */
  32. public function getCount($condition, $table = 'albumpic')
  33. {
  34. $result = Db::name($table)->where($condition)->count();
  35. return $result;
  36. }
  37. /**
  38. * 获取单条数据
  39. * @author csdeshang
  40. * @param array $condition 条件
  41. * @param string $table 表名
  42. * @return array 一维数组
  43. */
  44. public function getOne($condition, $table = 'albumpic')
  45. {
  46. $resule = Db::name($table)->where($condition)->find();
  47. return $resule;
  48. }
  49. /**
  50. * 分类列表
  51. * @author csdeshang
  52. * @param array $condition 查询条件
  53. * @param obj $pagesize 分页页数
  54. * @param str $order 排序
  55. * @return array 二维数组
  56. */
  57. public function getAlbumclassList($condition, $pagesize = '', $order = '')
  58. {
  59. $result = Db::name('albumclass')->where($condition)->order($order)->select()->toArray();
  60. return $result;
  61. }
  62. /**
  63. * 计算分类数量
  64. * @author csdeshang
  65. * @param int id 相册id
  66. * @return array 一维数组
  67. */
  68. public function getAlbumclassCount($id)
  69. {
  70. return Db::name('albumclass')->where('store_id', $id)->count();
  71. }
  72. /**
  73. * 验证相册
  74. * @author csdeshang
  75. * @param array $condition 条件
  76. * @return bool 布尔类型的返回结果
  77. */
  78. public function checkAlbum($condition)
  79. {
  80. /**
  81. * 验证是否为有默认相册
  82. */
  83. $result = Db::name('albumclass')->where($condition)->select()->toArray();
  84. if (!empty($result)) {
  85. unset($result);
  86. return true;
  87. }
  88. unset($result);
  89. return false;
  90. }
  91. /**
  92. * 图片列表
  93. * @author csdeshang
  94. * @param array $condition 查询条件
  95. * @param obj $pagesize 分页页数
  96. * @param obj $field 字段名
  97. * @param obj $order 排序
  98. * @return array 二维数组
  99. */
  100. public function getAlbumpicList($condition, $pagesize = '', $field = '*', $order = 'apic_id desc')
  101. {
  102. if ($pagesize) {
  103. $result = Db::name('albumpic')->where($condition)->field($field)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  104. $this->page_info = $result;
  105. return $result->items();
  106. } else {
  107. $result = Db::name('albumpic')->where($condition)->field($field)->order($order)->select()->toArray();
  108. return $result;
  109. }
  110. }
  111. /**
  112. * 添加相册分类
  113. * @author csdeshang
  114. * @param array $data 参数内容
  115. * @return bool
  116. */
  117. public function addAlbumclass($data)
  118. {
  119. return Db::name('albumclass')->insertGetId($data);
  120. }
  121. /**
  122. * 添加相册图片
  123. * @author csdeshang
  124. * @param array $data 参数内容
  125. * @return bool
  126. */
  127. public function addAlbumpic($data)
  128. {
  129. $result = Db::name('albumpic')->insertGetId($data);
  130. return $result;
  131. }
  132. /**
  133. * 更新相册分类
  134. * @author csdeshang
  135. * @param array $data 参数内容
  136. * @param int $id 相册id
  137. * @return bool
  138. */
  139. public function editAlbumclass($data, $id)
  140. {
  141. return Db::name('albumclass')->where('aclass_id', $id)->update($data);
  142. }
  143. /**
  144. * 更新相册图片
  145. * @author csdeshang
  146. * @param array $data 参数类容
  147. * @param int $condition 更新条件
  148. * @return bool
  149. */
  150. public function editAlbumpic($data, $condition)
  151. {
  152. $result = Db::name('albumpic')->where($condition)->update($data);
  153. return $result;
  154. }
  155. /**
  156. * 删除分类
  157. * @author csdeshang
  158. * @param type $condition
  159. * @return type
  160. */
  161. public function delAlbumclass($condition)
  162. {
  163. return Db::name('albumclass')->where($condition)->delete();
  164. }
  165. /**
  166. * 根据店铺id删除图片空间相关信息
  167. * @author csdeshang
  168. * @param int $id 店铺id
  169. * @return bool
  170. */
  171. public function delAlbum($id)
  172. {
  173. $id = intval($id);
  174. Db::name('albumclass')->where('store_id', $id)->delete();
  175. $pic_list = $this->getAlbumpicList(array("store_id" => $id), '', 'apic_cover,store_id,apic_uploadtime');
  176. $res = del_albumpic($pic_list);
  177. Db::name('albumpic')->where('store_id', $id)->delete();
  178. }
  179. /**
  180. * 删除图片
  181. * @author csdeshang
  182. * @param string $id 图片id
  183. * @param int $store_id 店铺id
  184. * @return bool
  185. */
  186. public function delAlbumpic($condition)
  187. {
  188. $pic_list = $this->getAlbumpicList($condition, '', 'apic_cover,store_id,apic_uploadtime');
  189. /**
  190. * 删除图片
  191. */
  192. $res = del_albumpic($pic_list);
  193. return Db::name('albumpic')->where($condition)->delete();
  194. }
  195. /**
  196. * 查询单条分类信息
  197. * @author csdeshang
  198. * @param int $condition 查询条件
  199. * @return array 一维数组
  200. */
  201. public function getOneAlbumclass($condition)
  202. {
  203. return Db::name('albumclass')->where($condition)->find();
  204. }
  205. /**
  206. * 根据id查询一张图片
  207. * @author csdeshang
  208. * @param int $condition 查询条件
  209. * @return array 一维数组
  210. */
  211. public function getOneAlbumpicById($condition)
  212. {
  213. return Db::name('albumpic')->where($condition)->find();
  214. }
  215. /**
  216. * 获取相册列表
  217. * @param type $condition
  218. * @param type $pagesize
  219. * @param type $field
  220. * @return type
  221. */
  222. public function getGoodsalbumList($condition, $pagesize, $field)
  223. {
  224. if ($pagesize) {
  225. $result = Db::name('albumclass')->alias('a')->where($condition)->join('store s', 'a.store_id=s.store_id', 'LEFT')->field($field)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  226. $this->page_info = $result;
  227. return $result->items();
  228. } else {
  229. return Db::name('albumclass')->alias('a')->where($condition)->join('store s', 'a.store_id=s.store_id', 'LEFT')->field($field)->select()->toArray();
  230. }
  231. }
  232. /**
  233. * 获取相册图片数列表
  234. * @param type $condition
  235. * @param type $field
  236. * @param type $group
  237. * @return type
  238. */
  239. public function getAlbumpicCountlist($condition, $field, $group)
  240. {
  241. return Db::name('albumpic')->field($field)->group($group)->where($condition)->select()->toArray();
  242. }
  243. }