ExchangeGoods.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 ExchangeGoods 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')->like('name');
  44. $query->where(['is_deleted' => '0'])->order('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. }
  56. /**
  57. * 添加商品信息
  58. * @auth true
  59. * @throws \think\Exception
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @throws \think\exception\DbException
  63. * @throws \think\exception\PDOException
  64. */
  65. public function add()
  66. {
  67. $this->title = '添加商品信息';
  68. $this->isAddMode = '1';
  69. $this->_form($this->table, 'form');
  70. }
  71. /**
  72. * 编辑商品信息
  73. * @auth true
  74. * @throws \think\Exception
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. * @throws \think\exception\DbException
  78. * @throws \think\exception\PDOException
  79. */
  80. public function edit()
  81. {
  82. $this->title = '编辑商品信息';
  83. $this->isAddMode = '0';
  84. $this->_form($this->table, 'form');
  85. }
  86. /**
  87. * 表单数据处理
  88. * @param array $data
  89. * @throws \think\Exception
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. * @throws \think\exception\PDOException
  94. */
  95. protected function _form_filter(&$data)
  96. {
  97. if ($this->request->isGet()) {
  98. } elseif ($this->request->isPost()) {
  99. if (empty($data['logo'])) $this->error('商品LOGO不能为空,请上传图片');
  100. }
  101. }
  102. /**
  103. * 表单结果处理
  104. * @param boolean $result
  105. */
  106. protected function _form_result($result)
  107. {
  108. if ($result && $this->request->isPost()) {
  109. $this->success('商品编辑成功!', 'javascript:history.back()');
  110. }
  111. }
  112. /**
  113. * 禁用商品信息
  114. * @auth true
  115. * @throws \think\Exception
  116. * @throws \think\exception\PDOException
  117. */
  118. public function forbid()
  119. {
  120. $this->_save($this->table, ['status' => '0']);
  121. }
  122. /**
  123. * 启用商品信息
  124. * @auth true
  125. * @throws \think\Exception
  126. * @throws \think\exception\PDOException
  127. */
  128. public function resume()
  129. {
  130. $this->_save($this->table, ['status' => '1']);
  131. }
  132. /**
  133. * 删除商品信息
  134. * @auth true
  135. * @throws \think\Exception
  136. * @throws \think\exception\PDOException
  137. */
  138. public function remove()
  139. {
  140. $this->_delete($this->table);
  141. }
  142. }