flea_upload.model.php 4.9 KB

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