Album.php 7.4 KB

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