Ad.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\supplier\controller\operate;
  3. use app\supplier\controller\Controller;
  4. use app\supplier\model\ad\Ad as AdModel;
  5. use app\supplier\model\ad\AdCategory as AdCategoryModel;
  6. /**
  7. * 广告控制器
  8. */
  9. class Ad extends Controller
  10. {
  11. /**
  12. * 广告数据
  13. */
  14. public function index()
  15. {
  16. $model = new AdModel;
  17. $list = $model->getList($this->postData(),$this->getSupplierId());
  18. return $this->renderSuccess('',compact('list'));
  19. }
  20. /**
  21. * 添加广告
  22. */
  23. public function add()
  24. {
  25. if($this->request->isGet()){
  26. return $this->renderSuccess('');
  27. }
  28. // 新增记录
  29. $model = new AdModel;
  30. $data = $this->postData();
  31. $data['shop_supplier_id'] = $this->getSupplierId();
  32. if ($model->add($data)) {
  33. return $this->renderSuccess('添加成功');
  34. }
  35. return $this->renderError($model->getError() ?: '添加失败');
  36. }
  37. /**
  38. * 广告详情
  39. */
  40. public function detail($ad_id)
  41. {
  42. // 广告详情
  43. $detail = AdModel::detail($ad_id);
  44. $catgory = AdCategoryModel::getAll();
  45. return $this->renderSuccess('',compact('detail','catgory'));
  46. }
  47. /**
  48. * 修改
  49. * @param $id
  50. * @return \think\response\Json
  51. */
  52. public function edit($ad_id)
  53. {
  54. if($this->request->isGet()){
  55. return $this->detail($ad_id);
  56. }
  57. $model = AdModel::detail($ad_id);
  58. // 更新记录
  59. if ($model->edit($this->postData())) {
  60. return $this->renderSuccess('更新成功');
  61. }
  62. return $this->renderError($model->getError() ?: '更新失败');
  63. }
  64. /**
  65. * 删除记录
  66. */
  67. public function delete($ad_id)
  68. {
  69. $model = AdModel::detail($ad_id);
  70. if ($model->remove($ad_id)) {
  71. return $this->renderSuccess('删除成功');
  72. }
  73. return $this->renderError($model->getError() ?:'删除失败');
  74. }
  75. }