Goods.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 = 'release_commodity';
  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)->like('trade_name');
  44. $query->order('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 $k => &$v) {
  56. $data[$k]['service_category_id'] = Db::name('release_service_category')->where('id',$v['service_category_id'])->value('service_name');
  57. }
  58. }
  59. /**
  60. * 添加服务
  61. * @auth true
  62. * @throws \think\Exception
  63. * @throws \think\db\exception\DataNotFoundException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. * @throws \think\exception\DbException
  66. * @throws \think\exception\PDOException
  67. */
  68. public function add()
  69. {
  70. $this->title = '添加服务';
  71. if(input('reloaded') !=1) {
  72. echo "<script>
  73. location.href=location.href+'&reloaded=1';
  74. location.reload();
  75. </script>";
  76. }
  77. $this->isAddMode = '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->isAddMode = '0';
  93. $id = $this->request->get('id');
  94. $charging_standard = Db::name('release_commodity')->where('id',$id)->value('charging_standard');
  95. $charging_standard_arr = json_decode($charging_standard,true);
  96. $this->charging_standard_arr = $charging_standard_arr;
  97. $commodity_label = Db::name('release_commodity')->where('id',$id)->value('commodity_label');
  98. $this->commodity_label_arr = explode(',',$commodity_label);
  99. $this->_form($this->table, 'form');
  100. }
  101. /**
  102. * 表单数据处理
  103. * @param array $data
  104. * @throws \think\Exception
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\ModelNotFoundException
  107. * @throws \think\exception\DbException
  108. * @throws \think\exception\PDOException
  109. */
  110. protected function _form_filter(&$data)
  111. {
  112. if ($this->request->isGet()) {
  113. $this->service_category = Db::name('release_service_category')->where(['is_deleted' => '0', 'status' => '1'])->order('sort desc,id desc')->select();
  114. }else{
  115. if(isset($data['name'])){
  116. $charging_name_count = count($data['name']);
  117. $charging = [];
  118. for ($i= 0;$i < $charging_name_count;$i++) {
  119. $charging[$i]['name'] = $data['name'][$i]?$data['name'][$i] :'' ;
  120. $charging[$i]['price'] = $data['price'][$i]?$data['price'][$i] :'' ;
  121. }
  122. $data['charging_standard'] = json_encode($charging);
  123. $label_count = count($data['label']);
  124. $label = '';
  125. for ($i= 0;$i < $label_count;$i++) {
  126. if($i == 0){
  127. $label .= $data['label'][$i];
  128. }else{
  129. $label .= ','.$data['label'][$i];
  130. }
  131. }
  132. $data['commodity_label'] = $label;
  133. }
  134. }
  135. }
  136. /**
  137. * 表单结果处理
  138. * @param boolean $result
  139. */
  140. protected function _form_result($result)
  141. {
  142. if ($result && $this->request->isPost()) {
  143. $this->success('服务编辑成功!', $_SERVER['HTTP_REFERER'].'#/store/goods/index.html?spm=m-73-75-76');
  144. }
  145. }
  146. /**
  147. * 禁用服务
  148. * @auth true
  149. * @throws \think\Exception
  150. * @throws \think\exception\PDOException
  151. */
  152. public function forbid()
  153. {
  154. $this->_save($this->table, ['status' => '0']);
  155. }
  156. /**
  157. * 启用服务
  158. * @auth true
  159. * @throws \think\Exception
  160. * @throws \think\exception\PDOException
  161. */
  162. public function resume()
  163. {
  164. $this->_save($this->table, ['status' => '1']);
  165. }
  166. /**
  167. * 删除服务
  168. * @auth true
  169. * @throws \think\Exception
  170. * @throws \think\exception\PDOException
  171. */
  172. public function remove()
  173. {
  174. $this->_delete($this->table);
  175. }
  176. }