SignPoster.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\user;
  12. use app\admin\model\user\SignPoster as SignPosterModel;
  13. use app\admin\controller\AuthController;
  14. use service\JsonService as Json;
  15. use service\FormBuilder as Form;
  16. use think\Url;
  17. use think\Request;
  18. use service\UploadService as Upload;
  19. /**
  20. * 会员管理控制器
  21. * Class User
  22. * @package app\admin\controller\user
  23. */
  24. class SignPoster extends AuthController
  25. {
  26. public function index()
  27. {
  28. return $this->fetch();
  29. }
  30. public function getSignPosterList()
  31. {
  32. $where = parent::getMore([
  33. ['page', 1],
  34. ['limit', 20],
  35. ]);
  36. return Json::successlayui(SignPosterModel::getSignPosterList($where));
  37. }
  38. /**
  39. * 添加签到海报
  40. * @param $id
  41. * @return mixed|\think\response\Json|void
  42. */
  43. public function create()
  44. {
  45. $f = array();
  46. $f[] = Form::dateTime('sign_time', '签到时间');
  47. $f[] =Form::frameImageOne('poster', '签到海报(690*590px)', Url::build('admin/widget.images/index', array('fodder' => 'poster')))->icon('image')->width('100%')->height('500px');
  48. $f[] =Form::input('sign_talk', '签到语录');
  49. $f[] = Form::number('sort', '排序')->col(12);
  50. $form = Form::make_post_form('新增海报', $f, Url::build('save'),2);
  51. $this->assign(compact('form'));
  52. return $this->fetch('public/form-builder');
  53. }
  54. public function save(Request $request)
  55. {
  56. $data = parent::postMore([
  57. ['sign_time', ''],
  58. ['poster', []],
  59. ['sign_talk', ''],
  60. ['sort', 0],
  61. ], $request);
  62. if(!$data['sign_time']) return Json::fail('请选择时间');
  63. if(count($data['poster'])<1) return Json::fail('请上传海报');
  64. $data['add_time'] = time();
  65. $data['poster']=$data['poster'][0];
  66. $data['sign_time']=strtotime($data['sign_time']);
  67. $res=SignPosterModel::set($data);
  68. if ($res)
  69. return Json::successful('添加成功');
  70. else
  71. return Json::fail('添加失败');
  72. }
  73. /**
  74. * 编辑签到海报
  75. * @param $id
  76. * @return mixed|\think\response\Json|void
  77. */
  78. public function edit($id)
  79. {
  80. if (!$id) return $this->failed('数据不存在');
  81. $poster = SignPosterModel::get($id);
  82. if (!$poster) return Json::fail('数据不存在!');
  83. $f = array();
  84. $f[] = Form::dateTime('sign_time', '签到时间',date('Y-m-d H:i:s',$poster->getData('sign_time')));
  85. $f[] =Form::frameImageOne('poster', '签到海报(690*590px)', Url::build('admin/widget.images/index', array('fodder' => 'poster')),$poster->getData('poster'))->icon('image')->width('100%')->height('500px');
  86. $f[] =Form::input('sign_talk', '签到语录', $poster->getData('sign_talk'));
  87. $f[] = Form::number('sort', '排序',$poster->getData('sort'))->col(12);
  88. $form = Form::make_post_form('修改海报', $f, Url::build('update',compact('id')),2);
  89. $this->assign(compact('form'));
  90. return $this->fetch('public/form-builder');
  91. }
  92. public function update(Request $request,$id)
  93. {
  94. $data = parent::postMore([
  95. ['sign_time', ''],
  96. ['poster', []],
  97. ['sign_talk', ''],
  98. ['sort', 0],
  99. ], $request);
  100. if(!$data['sign_time']) return Json::fail('请选择时间');
  101. if(count($data['poster'])<1) return Json::fail('请上传海报');
  102. $data['poster']=$data['poster'][0];
  103. $data['sign_time']=strtotime($data['sign_time']);
  104. $res=SignPosterModel::edit($data,$id);
  105. if ($res)
  106. return Json::successful('修改成功');
  107. else
  108. return Json::fail('修改失败');
  109. }
  110. public function delete($id = '')
  111. {
  112. if ($id == '') return Json::fail('缺少参数');
  113. $poster = SignPosterModel::get($id);
  114. if (!$poster) return Json::fail('数据不存在');
  115. if (SignPosterModel::del($id))
  116. return Json::successful('删除成功');
  117. else
  118. return Json::fail('删除失败');
  119. }
  120. }