Recommend.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\admin\controller;
  3. use app\model\web\Recommend as RecommendModel;
  4. use app\model\goods\Goods;
  5. class Recommend extends BaseAdmin
  6. {
  7. /**
  8. * @return array|mixed
  9. * index
  10. */
  11. public function index(){
  12. if (request()->isAjax()) {
  13. $page = input('page', 1);
  14. $limit = input('page_size', PAGE_LIST_ROWS);
  15. $condition = [];
  16. $goods_name = input('goods_name','');
  17. if($goods_name){
  18. $condition[] = ['goods_name','like','%'.$goods_name.'%'];
  19. }
  20. $notice = new RecommendModel();
  21. $list = $notice->getRecommendPageList($condition, $page, $limit);
  22. return $list;
  23. }
  24. return $this->fetch('recommend/index');
  25. }
  26. public function add(){
  27. $goods_model = new Goods();
  28. if (request()->isAjax()) {
  29. $data = [
  30. 'goods_id' => input('goods_id', ''),
  31. 'create_time' => time(),
  32. ];
  33. if(!empty($data['goods_id'])){
  34. $goods = $goods_model->getGoodsInfo([['goods_id','=',$data['goods_id']]],'goods_name,goods_image');
  35. $goods_image = explode(',',$goods['data']['goods_image']);
  36. $data['goods_name']=$goods['data']['goods_name'];
  37. $data['goods_image']=$goods_image[0];
  38. }
  39. $notice = new RecommendModel();
  40. $res = $notice->add_recommend($data);
  41. return $res;
  42. } else {
  43. $goods_arr = $goods_model->getGoodsList(['goods_state'=>1,'verify_state'=>1,'is_delete'=>0],'goods_id,goods_name');
  44. $this->assign('goods_arr',$goods_arr['data']);
  45. return $this->fetch('recommend/add');
  46. }
  47. }
  48. /**
  49. * 公告删除
  50. * @return string[]|mixed[]
  51. */
  52. public function deleteRecommend()
  53. {
  54. if (request()->isAjax()) {
  55. $id = input('id', '');
  56. $notice = new RecommendModel();
  57. $res = $notice->delete_recommend([ [ 'id', 'in', $id ] ]);
  58. return $res;
  59. }
  60. }
  61. }