Specifica.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\store\controller;
  3. use library\Controller;
  4. use think\Db;
  5. /**
  6. * 商品规格
  7. * Class Specifica
  8. * @package app\store\controller
  9. */
  10. class Specifica extends Controller
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. protected $table = 'StoreGoodsSpecifica';
  17. /**
  18. * 商品列表
  19. * @auth true
  20. * @menu true
  21. * @throws \think\Exception
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. * @throws \think\exception\PDOException
  26. */
  27. public function index()
  28. {
  29. $this->title = '规格管理';
  30. $query = $this->_query($this->table)->where('is_deleted',0)->like('title');
  31. $query->dateBetween('create_at')->order('sort desc , id desc')->page();
  32. }
  33. /**
  34. * 数据列表处理
  35. * @auth true
  36. * @menu true
  37. * @param array $data
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. protected function _index_page_filter(&$data)
  43. {
  44. foreach ($data as $k=>&$v){
  45. if($v['detail']) $v['detail'] = implode(',',json_decode($v['detail'],true));
  46. }
  47. }
  48. /**
  49. * 添加规格
  50. * @auth true
  51. * @menu true
  52. * @throws \think\Exception
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. * @throws \think\exception\PDOException
  57. */
  58. public function add()
  59. {
  60. $this->title = '添加规格';
  61. $this->_form($this->table, 'form');
  62. }
  63. /**
  64. * 编辑规格
  65. * @auth true
  66. * @menu true
  67. * @throws \think\Exception
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. * @throws \think\exception\DbException
  71. * @throws \think\exception\PDOException
  72. */
  73. public function edit()
  74. {
  75. $this->title = '编辑规格';
  76. $this->_form($this->table, 'form');
  77. }
  78. /**
  79. * 删除规格
  80. * @auth true
  81. * @menu true
  82. * @throws \think\Exception
  83. * @throws \think\exception\PDOException
  84. */
  85. public function del()
  86. {
  87. $this->_save($this->table, ['is_deleted' => '1']);
  88. }
  89. /**
  90. * 表单数据处理
  91. * @auth true
  92. * @menu true
  93. * @param array $data
  94. */
  95. protected function _form_filter(&$data)
  96. {
  97. if ($this->request->isPost()) {
  98. $data['spe_info'];
  99. $spe_info = [];
  100. foreach ($data['spe_info'] as $v) {
  101. if($v) $spe_info[] = $v;
  102. }
  103. $data['detail'] = empty($spe_info)? '': json_encode($spe_info);
  104. }else{
  105. if(isset($data['id']) && $data['detail']) $data['detail'] =json_decode( $data['detail'],true);
  106. }
  107. }
  108. }