Goods.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\store\controller;
  15. use library\Controller;
  16. use library\tools\Data;
  17. use think\Db;
  18. /**
  19. * 新闻管理
  20. * Class Goods
  21. * @package app\store\controller
  22. */
  23. class Goods extends Controller
  24. {
  25. /**
  26. * 指定数据表
  27. * @var string
  28. */
  29. protected $table = 'StoreGoods';
  30. /**
  31. * 新闻管理
  32. * @auth true
  33. * @menu true
  34. * @throws \think\Exception
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. * @throws \think\exception\PDOException
  39. */
  40. public function index()
  41. {
  42. $this->title = '新闻管理';
  43. $query = $this->_query($this->table)->equal('status,cate_id')->like('title');
  44. $query->where(['is_deleted' => '0'])->order(['is_top'=>'desc','sort'=>'desc','id'=>'desc'])->page();
  45. }
  46. /**
  47. * 数据列表处理
  48. * @param array $data
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. */
  53. protected function _index_page_filter(&$data)
  54. {
  55. foreach ($data as &$vo) {
  56. $vo['cate_name'] = Db::name('store_goods_cate')->where('id',$vo['cate_id'])->value('title');
  57. $media_info = Db::name('store_media')->field('logo,title')->where('id',$vo['media_id'])->find();
  58. $vo['media_logo'] = $media_info['logo'];
  59. $vo['media_title'] = $media_info['title'];
  60. }
  61. $this->cate_arr = Db::name('store_goods_cate')->field('id,title')->where('status',1)->where('is_deleted',0)->select();
  62. }
  63. /**
  64. * 添加新闻
  65. * @auth true
  66. * @throws \think\Exception
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. * @throws \think\exception\PDOException
  71. */
  72. public function add()
  73. {
  74. $this->title = '添加新闻信息';
  75. $this->cate_arr = Db::name('store_goods_cate')->field('id,title')->where('status',1)->where('is_deleted',0)->select();
  76. $this->media_arr = Db::name('store_media')->field('id,title')->where('status',1)->where('is_deleted',0)->select();
  77. $this->is_top = array('0'=>'不置顶','1'=>'置顶');
  78. $this->_form($this->table, 'form');
  79. }
  80. /**
  81. * 编辑新闻
  82. * @auth true
  83. * @throws \think\Exception
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. * @throws \think\exception\DbException
  87. * @throws \think\exception\PDOException
  88. */
  89. public function edit()
  90. {
  91. $this->title = '编辑新闻信息';
  92. $this->_form($this->table, 'form');
  93. }
  94. /**
  95. * 表单数据处理
  96. * @param array $data
  97. * @throws \think\Exception
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. * @throws \think\exception\DbException
  101. * @throws \think\exception\PDOException
  102. */
  103. protected function _form_filter(&$data)
  104. {
  105. // 生成活动ID
  106. if ($this->request->isGet()) {
  107. $this->cate_arr = Db::name('store_goods_cate')->field('id,title')->where('status',1)->where('is_deleted',0)->select();
  108. $this->media_arr = Db::name('store_media')->field('id,title')->where('status',1)->where('is_deleted',0)->select();
  109. $this->is_top = array('0'=>'不置顶','1'=>'置顶');
  110. } elseif ($this->request->isPost()) {
  111. if (empty($data['image'])) $this->error('展示图片不能为空,请上传图片');
  112. $data['user_id'] = $data['media_id'];
  113. }
  114. }
  115. /**
  116. * 表单结果处理
  117. * @param boolean $result
  118. */
  119. protected function _form_result($result)
  120. {
  121. if ($result && $this->request->isPost()) {
  122. $this->success('活动编辑成功!', 'javascript:history.back()');
  123. }
  124. }
  125. /**
  126. * 禁用新闻
  127. * @auth true
  128. * @throws \think\Exception
  129. * @throws \think\exception\PDOException
  130. */
  131. public function forbid()
  132. {
  133. $this->_save($this->table, ['status' => '0']);
  134. }
  135. /**
  136. * 启用新闻
  137. * @auth true
  138. * @throws \think\Exception
  139. * @throws \think\exception\PDOException
  140. */
  141. public function resume()
  142. {
  143. $this->_save($this->table, ['status' => '1']);
  144. }
  145. /**
  146. * 删除新闻
  147. * @auth true
  148. * @throws \think\Exception
  149. * @throws \think\exception\PDOException
  150. */
  151. public function remove()
  152. {
  153. $this->_delete($this->table);
  154. }
  155. }