News.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\system;
  4. use app\Request;
  5. use library\basic\BaseModel;
  6. use library\services\UtilService;
  7. use library\utils\Arr;
  8. use think\db\exception\DbException;
  9. use think\Model;
  10. class News extends BaseModel{
  11. private $_data;
  12. /**
  13. * 保存数据
  14. * @param type $post
  15. * @return boolean
  16. */
  17. public function newsSave($post){
  18. if(!empty($post['id'])) {
  19. $this->where('id',$post['id'])->save($post);
  20. return true;
  21. } else {
  22. unset($post['id']);
  23. $post["time"] = time();
  24. $bool = $this->insert($post);
  25. return $bool;
  26. }
  27. }
  28. /**
  29. * 删除数据
  30. * @param type $id
  31. * @return boolean
  32. */
  33. public function newsDel($id){
  34. $this->where("id",$id)->delete();
  35. return true;
  36. }
  37. /**
  38. * 设置显示状态
  39. * @param $id
  40. * @param $status
  41. */
  42. public function newsShowSet($id,$status) {
  43. self::beginTrans();
  44. try{
  45. $this->where('id', $id)->save(['is_show'=>$status]);
  46. self::commitTrans();
  47. return true;
  48. }catch (DbException $db) {
  49. self::rollbackTrans();
  50. return false;
  51. }
  52. }
  53. }