LiveGoodsManage.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\store\controller;
  3. use library\Controller;
  4. use think\Db;
  5. /**
  6. * 直播商品添加
  7. * Class Goods
  8. * @package app\store\controller
  9. */
  10. class LiveGoodsManage extends Controller
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. protected $table = 'StoreLiveGoods';
  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. $this->cate_id = input('cate_id');
  31. $goods_cate = Db::table('store_live_cate')
  32. ->field('id,title')
  33. ->where('status',1)
  34. ->where('is_deleted',0)
  35. ->order('sort desc , id desc')
  36. ->select();
  37. $this->goods_cate = array_column($goods_cate,null,'id');
  38. $query = $this->_query($this->table)->where('is_deleted',0);
  39. if($this->cate_id) $query->where('cate_id',$this->cate_id );
  40. $query->like('name');
  41. $query->order('status desc , sort desc , id desc')->page();
  42. }
  43. /**
  44. * 数据列表处理
  45. * @auth true
  46. * @menu true
  47. * @param array $data
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. * @throws \think\exception\DbException
  51. */
  52. protected function _index_page_filter(&$data)
  53. {
  54. }
  55. /**
  56. * 添加商品
  57. * @auth true
  58. * @menu 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->goods_cate = Db::table('store_live_cate')
  69. ->field('id,title')
  70. ->where('status',1)
  71. ->where('is_deleted',0)
  72. ->order('sort desc , id desc')
  73. ->select();
  74. $this->_form($this->table, 'form');
  75. }
  76. /**
  77. * 编辑商品
  78. * @auth true
  79. * @menu true
  80. * @throws \think\Exception
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. * @throws \think\exception\PDOException
  85. */
  86. public function edit()
  87. {
  88. $this->title = '编辑商品';
  89. $this->goods_cate = Db::table('store_live_cate')
  90. ->field('id,title')
  91. ->where('status',1)
  92. ->where('is_deleted',0)
  93. ->order('sort desc , id desc')
  94. ->select();
  95. $this->_form($this->table, 'form');
  96. }
  97. /**
  98. * 禁用
  99. * @auth true
  100. * @menu true
  101. * @throws \think\Exception
  102. * @throws \think\exception\PDOException
  103. */
  104. public function forbidden()
  105. {
  106. $this->_save($this->table, ['status' => '0']);
  107. }
  108. /**
  109. * 启用
  110. * @auth true
  111. * @menu true
  112. * @throws \think\Exception
  113. * @throws \think\exception\PDOException
  114. */
  115. public function enable()
  116. {
  117. $this->_save($this->table, ['status' => 1]);
  118. }
  119. /**
  120. * 删除
  121. * @auth true
  122. * @menu true
  123. * @throws \think\Exception
  124. * @throws \think\exception\PDOException
  125. */
  126. public function del()
  127. {
  128. $this->_save($this->table, ['is_deleted' => 1]);
  129. }
  130. /**
  131. * 表单数据处理
  132. * @auth true
  133. * @menu true
  134. * @param array $data
  135. */
  136. protected function _form_filter(&$data)
  137. {
  138. $data['create_at'] = date('Y-m-d H:i:s');
  139. }
  140. }