AdController.php 2.6 KB

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