Mail.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. class Mail extends Model{
  5. protected $autoWriteTimestamp = 'datetime'; // 开启自动写入时间戳字段
  6. protected $createTime = 'create_time'; // 创建时间
  7. protected $updateTime = ''; // 每次更新时间
  8. public function initialize(){
  9. parent::initialize();
  10. }
  11. /**
  12. * 获取数据信息
  13. * @param int $page 页码
  14. * @param array $where 查询条件
  15. */
  16. public function getInfo($page = 0, $where = array()){
  17. return $this->db()
  18. ->where($where)
  19. ->page($page, config('paginate.list_rows'))
  20. ->select();
  21. }
  22. /**
  23. * 获取分页信息
  24. * @param array $where 查询条件
  25. */
  26. public function getPage($where = array()){
  27. $query = getPaginatiorQuery();
  28. $total = $this->db()->where($where)->count();
  29. // 查询条件
  30. $config = ['query'=>$query];
  31. $paginate = $this->db()->where($where)->paginate(config('paginate.list_rows'), $total, $config);
  32. return $paginate->render();
  33. }
  34. /**
  35. * 根据id找到对象
  36. * @param int $id
  37. */
  38. public function getMailById($id){
  39. return $this->db()->where(['id'=>$id])->find();
  40. }
  41. /**
  42. * 添加和更新的方法
  43. */
  44. public function addAndSave(){
  45. $data = request()->post();
  46. return $this->allowField(true)->isUpdate(isset($data['id']) && $data['id']?true:false)->save($data);
  47. }
  48. /**
  49. * 没有发送的邮件
  50. * @return number|string
  51. */
  52. public function notSendMail(){
  53. return $this->db()->where(['is_send'=>0])->count();
  54. }
  55. }