AdController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace business\controllers;
  3. use biz\ad\services\AdService;
  4. use Yii;
  5. use common\components\util;
  6. class AdController extends BaseController
  7. {
  8. //list,detail,create,update,delete
  9. protected $service = '\biz\ad\services\AdService';
  10. //protected $notAllowActions = ['delete']; // 设置方法过滤
  11. //广告列表
  12. public function actionList()
  13. {
  14. $get = Yii::$app->request->get();
  15. $type = isset($get['type']) ? $get['type'] : 0;
  16. $where = [];
  17. $where['merchantId'] = $this->merchantId;
  18. $where['type'] = $type;
  19. //parent::actionList('*', $where);
  20. $list = AdService::getAdList($where);
  21. util::success($list);
  22. }
  23. /*public function actionDetail()
  24. {
  25. $data = Yii::$app->request->get();
  26. if (isset($data['is_view']) && $data['is_view'] == 1) {
  27. $id = $data['id'];
  28. AdService::counters(['viewTimes' => 1], ['id' => $id]);
  29. }
  30. parent::actionDetail();
  31. }*/
  32. //添加广告
  33. public function actionAdd()
  34. {
  35. //$_POST['merchantId'] = $this->merchantId;
  36. //parent::actionAdd();
  37. $post = Yii::$app->request->post();
  38. $post['merchantId'] = $this->merchantId;
  39. $ad = AdService::addAd($post);
  40. $id = $ad['id'];
  41. $info = AdService::getDetail($id);
  42. util::success($info);
  43. }
  44. public function actionOrder()
  45. {
  46. $data = Yii::$app->request->post();
  47. $id = $data['firstAd'];
  48. $updateData = ['inTurn' => $data['secondOrder']];
  49. AdService::updateById($id, $updateData);
  50. $id = $data['secondAd'];
  51. $updateData = ['inTurn' => $data['firstOrder']];
  52. AdService::updateById($id, $updateData);
  53. $tempOrder = $data['firstOrder'];
  54. $data['firstOrder'] = $data['secondOrder'];
  55. $data['secondOrder'] = $tempOrder;
  56. util::success($data);
  57. }
  58. //广告点击
  59. public function actionClick()
  60. {
  61. $id = Yii::$app->request->get('id', 0);
  62. $info = AdService::getById($id);
  63. AdService::valid($info, $this->merchantId);
  64. AdService::clickAd($id);
  65. util::ok();
  66. }
  67. //更新广告
  68. public function actionUpdate()
  69. {
  70. $post = Yii::$app->request->post();
  71. $id = isset($post['id']) ? $post['id'] : 0;
  72. $info = AdService::getById($id);
  73. AdService::valid($info, $this->merchantId);
  74. AdService::updateAd($id, $post);
  75. util::ok('修改成功');
  76. }
  77. //删除广告
  78. public function actionDelete()
  79. {
  80. $id = Yii::$app->request->get('id', 0);
  81. $info = AdService::getById($id);
  82. AdService::valid($info, $this->merchantId);
  83. AdService::deleteById($id);
  84. util::ok('删除成功');
  85. }
  86. //上下架广告
  87. public function actionUpdateStatus()
  88. {
  89. $id = Yii::$app->request->get('id', 0);
  90. $status = Yii::$app->request->get('status', 1);
  91. $info = AdService::getById($id);
  92. AdService::valid($info, $this->merchantId);
  93. AdService::updateById($id,['status'=>$status]);
  94. util::ok('操作成功');
  95. }
  96. //广告详情
  97. public function actionDetail()
  98. {
  99. $id = Yii::$app->request->get('id', 0);
  100. $info = AdService::getDetail($id);
  101. util::success($info);
  102. }
  103. //广告排序
  104. public function actionSort()
  105. {
  106. $id = Yii::$app->request->get('id', 0);
  107. $inTurn = Yii::$app->request->get('inTurn', 0);
  108. $info = AdService::getById($id);
  109. AdService::valid($info, $this->merchantId);
  110. AdService::updateById($id, ['inTurn' => $inTurn]);
  111. util::ok('操作成功');
  112. }
  113. }