Album.php 7.5 KB

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