upload.model.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * 上传文件模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class uploadModel
  11. {
  12. /**
  13. * 列表
  14. *
  15. * @param array $condition 检索条件
  16. * @return array 数组结构的返回结果
  17. */
  18. public function getUploadList($condition,$field='*'){
  19. $condition_str = $this->_condition($condition);
  20. $param = array();
  21. $param['table'] = 'upload';
  22. $param['field'] = $field;
  23. $param['where'] = $condition_str;
  24. $param['order'] = 'upload_id asc';
  25. $result = Db::select($param);
  26. return $result;
  27. }
  28. /**
  29. * 构造检索条件
  30. *
  31. * @param int $id 记录ID
  32. * @return string 字符串类型的返回结果
  33. */
  34. private function _condition($condition)
  35. {
  36. $condition_str = '';
  37. if ($condition['upload_type'] != ''){
  38. $condition_str .= " and upload_type = '". $condition['upload_type'] ."'";
  39. }
  40. if ($condition['item_id'] != ''){
  41. $condition_str .= " and item_id = '". $condition['item_id'] ."'";
  42. }
  43. if ($condition['file_name'] != '') {
  44. $condition_str .= " and file_name = '".$condition['file_name']."'";
  45. }
  46. if (isset($condition['upload_type_in'])){
  47. if ($condition['upload_type_in'] == ''){
  48. $condition_str .= " and upload_type in('')";
  49. }else{
  50. $condition_str .= " and upload_type in({$condition['upload_type_in']})";
  51. }
  52. }
  53. if (isset($condition['item_id_in'])){
  54. if ($condition['item_id_in'] == ''){
  55. $condition_str .= " and item_id in('')";
  56. }else{
  57. $condition_str .= " and item_id in({$condition['item_id_in']})";
  58. }
  59. }
  60. if (isset($condition['upload_id_in'])){
  61. if ($condition['upload_id_in'] == ''){
  62. $condition_str .= " and upload_id in('')";
  63. }else{
  64. $condition_str .= " and upload_id in({$condition['upload_id_in']})";
  65. }
  66. }
  67. if ($condition['upload_time_lt'] != ''){
  68. $condition_str .= " and upload_time < '". $condition['upload_time_lt'] ."'";
  69. }
  70. return $condition_str;
  71. }
  72. /**
  73. * 取单个内容
  74. *
  75. * @param int $id 分类ID
  76. * @return array 数组类型的返回结果
  77. */
  78. public function getOneUpload($id){
  79. if (intval($id) > 0){
  80. $param = array();
  81. $param['table'] = 'upload';
  82. $param['field'] = 'upload_id';
  83. $param['value'] = intval($id);
  84. $result = Db::getRow($param);
  85. return $result;
  86. }else {
  87. return false;
  88. }
  89. }
  90. /**
  91. * 新增
  92. *
  93. * @param array $param 参数内容
  94. * @return bool 布尔类型的返回结果
  95. */
  96. public function add($param){
  97. if (empty($param)){
  98. return false;
  99. }
  100. if (is_array($param)){
  101. $result = Db::insert('upload',$param);
  102. return $result;
  103. }else {
  104. return false;
  105. }
  106. }
  107. /**
  108. * 更新信息
  109. *
  110. * @param array $param 更新数据
  111. * @return bool 布尔类型的返回结果
  112. */
  113. public function update($param){
  114. if (empty($param)){
  115. return false;
  116. }
  117. if (is_array($param)){
  118. $tmp = array();
  119. foreach ($param as $k => $v){
  120. $tmp[$k] = $v;
  121. }
  122. $where = " upload_id = '". $param['upload_id'] ."'";
  123. $result = Db::update('upload',$tmp,$where);
  124. return $result;
  125. }else {
  126. return false;
  127. }
  128. }
  129. /**
  130. * 更新信息
  131. *
  132. * @param array $param 更新数据
  133. * @param array $conditionarr 条件数组
  134. * @return bool 布尔类型的返回结果
  135. */
  136. public function updatebywhere($param,$conditionarr){
  137. if (empty($param)){
  138. return false;
  139. }
  140. if (is_array($param)){
  141. //条件
  142. $condition_str = $this->_condition($conditionarr);
  143. //更新信息
  144. $tmp = array();
  145. foreach ($param as $k => $v){
  146. $tmp[$k] = $v;
  147. }
  148. $result = Db::update('upload',$tmp,$condition_str);
  149. return $result;
  150. }else {
  151. return false;
  152. }
  153. }
  154. /**
  155. * 删除分类
  156. *
  157. * @param int $id 记录ID
  158. * @return bool 布尔类型的返回结果
  159. */
  160. public function del($id){
  161. if (intval($id) > 0){
  162. $where = " upload_id = '". intval($id) ."'";
  163. $result = Db::delete('upload',$where);
  164. return $result;
  165. }else {
  166. return false;
  167. }
  168. }
  169. /**
  170. * 删除上传图片信息
  171. * @param mixed $id 删除上传图片记录编号
  172. */
  173. public function dropUploadById($id){
  174. if(empty($id)) {
  175. return false;
  176. }
  177. $condition_str = ' 1=1 ';
  178. if (is_array($id) && count($id)>0){
  179. $idStr = implode(',',$id);
  180. $condition_str .= " and upload_id in({$idStr}) ";
  181. }else {
  182. $condition_str .= " and upload_id = '{$id}' ";
  183. }
  184. $result = Db::delete('upload',$condition_str);
  185. return $result;
  186. }
  187. /**
  188. * 删除图片信息,根据where
  189. *
  190. * @param int $id 店铺id
  191. * @param array $conditionarr 条件数组
  192. * @return bool 布尔类型的返回结果
  193. */
  194. public function delByWhere($conditionarr){
  195. if(is_array($conditionarr)){
  196. $condition_str = $this->_condition($conditionarr);
  197. $result = Db::delete('upload',$condition_str);
  198. return $result;
  199. }else{
  200. return false;
  201. }
  202. }
  203. }