EmailTemplateModel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\admin\model;
  3. use think\Db;
  4. use think\Model;
  5. class EmailTemplateModel extends Model
  6. {
  7. protected $name = 'email_template';
  8. public function getByWhere($map,$od, $Nowpage, $limits)
  9. {
  10. $res = $this
  11. ->where($map)
  12. ->page($Nowpage, $limits)
  13. ->order($od)
  14. ->select();
  15. return $res;
  16. }
  17. /**
  18. * [getOneMenu 根据菜单id获取一条信息]
  19. * @author
  20. */
  21. public function getInfo($id)
  22. {
  23. return $this->where('id', $id)->find();
  24. }
  25. /*
  26. * 页面总数
  27. */
  28. public function getCount($map){
  29. return $this->alias('a')
  30. ->where($map)
  31. ->count();
  32. }
  33. public function edit($param)
  34. {
  35. $param['update_time']=time();
  36. $res=$this->allowField(true)->save($param, ['id' => $param['id']]);
  37. if($res){
  38. return ['code' => 200, 'data' => '', 'msg' => '编辑成功'];
  39. }else{
  40. return ['code' => 100, 'data' => '', 'msg' =>'编辑失败'];
  41. }
  42. }
  43. public function add($param)
  44. {
  45. $data['spread_id']=session('uid');
  46. $data['create_time']=time();
  47. $data['theme']=$param['theme'];
  48. $data['type']=isset($param['type'])?$param['type']:1;
  49. $data['content']=$param['content'];
  50. if (isset($param['form'])) {
  51. $data['form'] = $param['form'];
  52. }
  53. if (isset($param['to'])) {
  54. $data['to'] = $param['to'];
  55. }
  56. $res=Db::table('think_email_template')->insertGetId($data);
  57. if($res){
  58. return ['code' => 200, 'data' => '', 'msg' => '添加成功','id'=>$res];
  59. }else{
  60. return ['code' => 100, 'data' => '', 'msg' =>'添加失败'];
  61. }
  62. }
  63. /**
  64. * batchDelUser 批量删除管理员
  65. * @param $param
  66. * @return array
  67. */
  68. public function del($param){
  69. try{
  70. Db::name('email_template')->where('id','=',$param)->update(['is_deleted'=>time()]);
  71. return ['code' => 200, 'data' => '', 'msg' => '批量删除成功'];
  72. }catch( \Exception $e){
  73. return ['code' => 100, 'data' => '', 'msg' => '批量删除失败'];
  74. }
  75. }
  76. /**
  77. * batchDelUser 批量删除管理员
  78. * @param $param
  79. * @return array
  80. */
  81. public function batchDel($param){
  82. try{
  83. Db::name('email_template')->where('id','in',$param)->update(['is_deleted'=>time()]);
  84. return ['code' => 200, 'data' => '', 'msg' => '批量删除成功'];
  85. }catch( \Exception $e){
  86. return ['code' => 100, 'data' => '', 'msg' => '批量删除失败'];
  87. }
  88. }
  89. }