AdController.php 3.2 KB

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