Condition.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 GoodsCate
  21. * @package app\store\controller
  22. */
  23. class Condition extends Controller
  24. {
  25. /**
  26. * 绑定数据表
  27. * @var string
  28. */
  29. protected $table = 'store_goods_condition';
  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. $goods_id = input('goods_id');
  44. if(empty($goods_id)){
  45. $this->error('非法操作');
  46. }
  47. $this->app->session->set('goods_id', $goods_id);
  48. $query = $this->_query($this->table)->like('title');
  49. $query->where(['goods_id'=>$goods_id])->order('sort desc,id desc')->page();
  50. }
  51. /**需求列表处理
  52. * @param array $data
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. */
  57. protected function _index_page_filter(array &$data)
  58. {
  59. foreach ($data as &$vo) {
  60. if($vo['images']){
  61. $vo['images'] = image_path($vo['images']);
  62. }
  63. }
  64. }
  65. /**
  66. * 表单数据处理
  67. * @param array $data
  68. * @throws \think\Exception
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. * @throws \think\exception\DbException
  72. * @throws \think\exception\PDOException
  73. */
  74. protected function _form_filter(&$data)
  75. {
  76. // 生成活动ID
  77. if ($this->request->isGet()) {
  78. } elseif ($this->request->isPost()) {
  79. if (empty($data['images'])) $this->error('情形图片不能为空,请上传图片');
  80. $data['goods_id'] = $this->app->session->get('goods_id');
  81. }
  82. }
  83. /**
  84. * 添加适用情形
  85. * @auth true
  86. * @throws \think\Exception
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. * @throws \think\exception\DbException
  90. * @throws \think\exception\PDOException
  91. */
  92. public function add()
  93. {
  94. $this->title = '添加适用情形';
  95. $this->isAddMode = '1';
  96. $this->_form($this->table, 'form');
  97. }
  98. /**
  99. * 编辑适用情形
  100. * @auth true
  101. * @throws \think\Exception
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\ModelNotFoundException
  104. * @throws \think\exception\DbException
  105. * @throws \think\exception\PDOException
  106. */
  107. public function edit()
  108. {
  109. $this->title = '编辑适用情形';
  110. $this->isAddMode = '0';
  111. $this->_form($this->table, 'form');
  112. }
  113. /**
  114. * 表单结果处理
  115. * @param boolean $result
  116. */
  117. protected function _form_result($result)
  118. {
  119. if ($result && $this->request->isPost()) {
  120. $this->success('编辑成功!', 'javascript:history.back()');
  121. }
  122. }
  123. /**
  124. * 禁用适用情形
  125. * @auth true
  126. * @throws \think\Exception
  127. * @throws \think\exception\PDOException
  128. */
  129. public function forbid()
  130. {
  131. $this->_save($this->table, ['status' => '0']);
  132. }
  133. /**
  134. * 启用适用情形
  135. * @auth true
  136. * @throws \think\Exception
  137. * @throws \think\exception\PDOException
  138. */
  139. public function resume()
  140. {
  141. $this->_save($this->table, ['status' => '1']);
  142. }
  143. /**
  144. * 删除适用情形
  145. * @auth true
  146. * @throws \think\Exception
  147. * @throws \think\exception\PDOException
  148. */
  149. public function remove()
  150. {
  151. $this->_delete($this->table);
  152. }
  153. }