Goods.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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\approve\controller;
  15. use app\common\constant\CommonConstant;
  16. use app\common\constant\MaintainConstant;
  17. use library\Controller;
  18. /**
  19. * 商品
  20. */
  21. class Goods extends Controller
  22. {
  23. /**
  24. * 绑定数据表
  25. * @var string
  26. */
  27. protected $table = 'Goods';
  28. /**
  29. * 控制器初始化
  30. */
  31. protected function initialize()
  32. {
  33. $this->get_status_list = CommonConstant::get_status_list();
  34. }
  35. /**
  36. * 列表
  37. * @auth true
  38. * @menu true
  39. * @throws \think\Exception
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @throws \think\exception\DbException
  43. */
  44. public function index()
  45. {
  46. $status = input('status');
  47. $this->title = '商品列表';
  48. $query = $this->_query($this->table)
  49. ->field('is_deleted', true)
  50. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  51. ->when(array_key_exists($status, $this->get_status_list), function ($query) use ($status) {
  52. $query->where('status', $status);
  53. })
  54. ->like('goods_name')
  55. ->order('sort desc,id asc');
  56. $query->page();
  57. }
  58. /**
  59. * 列表数据处理
  60. * @param array $data
  61. * @throws \Exception
  62. */
  63. protected function _index_page_filter(&$data)
  64. {
  65. foreach ($data as &$value) {
  66. }
  67. }
  68. /**
  69. * 添加
  70. * @auth true
  71. * @throws \think\Exception
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. * @throws \think\exception\DbException
  75. * @throws \think\exception\PDOException
  76. */
  77. public function add()
  78. {
  79. $this->title = '添加';
  80. $this->_form($this->table, 'form');
  81. }
  82. /**
  83. * 编辑
  84. * @auth true
  85. * @throws \think\Exception
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. * @throws \think\exception\DbException
  89. * @throws \think\exception\PDOException
  90. */
  91. public function edit()
  92. {
  93. $this->title = '编辑';
  94. $this->_form($this->table, 'form');
  95. }
  96. /**
  97. * 表单处理
  98. * @param array $data
  99. * @throws \think\db\exception\DataNotFoundException
  100. * @throws \think\db\exception\ModelNotFoundException
  101. * @throws \think\exception\DbException
  102. */
  103. protected function _form_filter(&$data)
  104. {
  105. if ($this->request->isGet()) {
  106. }
  107. if ($this->request->isPost()) {
  108. }
  109. }
  110. /**
  111. * 删除
  112. * @auth true
  113. * @throws \think\Exception
  114. * @throws \think\exception\PDOException
  115. */
  116. public function remove()
  117. {
  118. $this->applyCsrfToken();
  119. $this->_delete($this->table);
  120. }
  121. /**
  122. * 启用
  123. * @auth true
  124. * @throws \think\Exception
  125. * @throws \think\exception\PDOException
  126. */
  127. public function resume()
  128. {
  129. $this->applyCsrfToken();
  130. $this->_save($this->table, ['status' => CommonConstant::STATUS_NORMAL]);
  131. }
  132. /**
  133. * 禁用
  134. * @auth true
  135. * @throws \think\Exception
  136. * @throws \think\exception\PDOException
  137. */
  138. public function forbid()
  139. {
  140. $this->applyCsrfToken();
  141. $this->_save($this->table, ['status' => CommonConstant::STATUS_FROZEN]);
  142. }
  143. }