AdvertController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Validator\AdvertValidator;
  4. use App\Services\Common\AdvertOrderService;
  5. use App\Services\Common\AdvertService;
  6. use App\Services\Common\CoinLogService;
  7. /**
  8. * 挂单广告
  9. * Class AdvertController
  10. * @package App\Http\Controllers\Admin
  11. */
  12. class AdvertController extends Backend
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. $this->service = new AdvertService();
  18. }
  19. /**
  20. * 获取挂单广告列表
  21. * @return array|mixed
  22. */
  23. public function index()
  24. {
  25. $pageSize = request()->post('limit', 15);
  26. $params = request()->all();
  27. if($this->userInfo['user_type'] == 2){
  28. $params['business_id'] = $this->userInfo['user_id'];
  29. }
  30. $list = AdvertService::make()->getDataList($params, $pageSize);
  31. $message = array(
  32. "msg" => '操作成功',
  33. "code" => 0,
  34. "data" => isset($list['list'])? $list['list']:[],
  35. "count" => isset($list['total'])? $list['total']:0,
  36. );
  37. return $message;
  38. }
  39. /**
  40. * 获取挂单广告列表
  41. * @return array|mixed
  42. */
  43. public function hall()
  44. {
  45. $pageSize = request()->post('limit', 15);
  46. $params = request()->all();
  47. $list = AdvertService::make()->getDataList($params, $pageSize);
  48. $message = array(
  49. "msg" => '操作成功',
  50. "code" => 0,
  51. "data" => isset($list['list'])? $list['list']:[],
  52. "count" => isset($list['total'])? $list['total']:0,
  53. );
  54. return $message;
  55. }
  56. /**
  57. * 发布广告
  58. * @return array|mixed
  59. */
  60. public function edit()
  61. {
  62. return AdvertService::make()->saveData($this->userInfo['user_id'], request()->all());
  63. }
  64. /**
  65. * 购买广告
  66. * @param AdvertValidator $validate
  67. * @return array
  68. */
  69. public function buy(AdvertValidator $validate)
  70. {
  71. $params = request()->post();
  72. $params = $validate->check($params,'buy');
  73. if(!is_array($params)){
  74. return returnJson($params, false,[]);
  75. }
  76. if(!AdvertOrderService::make()->buy($this->userInfo['user_id'], $params)){
  77. return returnJson(AdvertOrderService::make()->getError(), false);
  78. }else{
  79. return returnJson(AdvertOrderService::make()->getError(), true);
  80. }
  81. }
  82. }