Pic.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/8/13 0013
  6. * Time: 11:27
  7. */
  8. namespace app\common\model;
  9. use think\Model;
  10. class Pic extends Model
  11. {
  12. public function addPic($data)
  13. {
  14. return db('pic')->insertGetId($data);
  15. }
  16. public function editPic($condition, $data)
  17. {
  18. return db('pic')->where($condition)->update($data);
  19. }
  20. public function getPicList($condition, $page = '', $order = 'pic_id desc')
  21. {
  22. if ($page) {
  23. $res = db('pic')->where($condition)->order($order)->paginate($page, false, ['query' => request()->param()]);
  24. $this->page_info = $res;
  25. return $res->items();
  26. } else {
  27. return db('pic')->where($condition)->order($order)->select();
  28. }
  29. }
  30. public function delPic($condition, $attach_type)
  31. {
  32. switch ($attach_type) {
  33. case 'cases':
  34. $attach_type = ATTACH_CASES;
  35. break;
  36. case 'news':
  37. $attach_type = ATTACH_NEWS;
  38. break;
  39. case 'product':
  40. $attach_type = ATTACH_PRODUCT;
  41. default:
  42. break;
  43. }
  44. $casespic_list = $this->getpicList($condition);
  45. foreach ($casespic_list as $key => $casespic) {
  46. @unlink(BASE_UPLOAD_PATH . DS . $attach_type . DS . $casespic['pic_cover']);
  47. }
  48. return db('pic')->where($condition)->delete();
  49. }
  50. }