OrderService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Ad;
  4. use App\Model\AdPlace;
  5. use App\Model\Order;
  6. use App\Model\OrderAd;
  7. use App\Tools\Result;
  8. use Hyperf\RpcServer\Annotation\RpcService;
  9. #[RpcService(name: "OrderService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  10. class OrderService implements OrderServiceInterface
  11. {
  12. /**
  13.  * 查询没有广告的广告位
  14.  * @param
  15.  * @return void
  16. */
  17. public function getAD(array $data): array
  18. {
  19. $where = [
  20. 'width' => $data['width'],
  21. 'height' => $data['height']
  22. ];
  23. $start = $data['starttime'];
  24. $end = $data['endtime'];
  25. $rep=Ad::where($where)
  26. ->where('fromtime','<',$start)
  27. ->where('totime','>',$end)
  28. ->orderBy('id')
  29. ->limit($data['pageSize'])
  30. ->offset(($data['page']-1)*$data['pageSize'])->get();
  31. $count = Ad::where($where)->count();
  32. $data = [
  33. 'rows'=>$rep->toArray(),
  34. 'count'=>$count
  35. ];
  36. $ads = Ad::whereIn($data['id'])
  37. ->leftJoin('ad_place','ad.pid','ad_place.id')
  38. ->leftJoin("article_data","article.id","article_data.article_id")
  39. ->select("ad_place.*","ad.*")
  40. ->orderBy("ad.id","desc")
  41. ->limit($data['pageSize'])
  42. ->offset(($data['page']-1)*$data['pageSize'])->get();
  43. $count = Ad::whereIn($data['id'])->count();
  44. $data = [
  45. 'rows'=>$ads->toArray(),
  46. 'count'=>$count
  47. ];
  48. if(empty($rep)){
  49. return Result::error("没有信息数据");
  50. }
  51. return Result::success($data);
  52. }
  53. /**
  54. * 添加订单
  55. * @param
  56. * @return void
  57. */
  58. public function addOrder(array $data): array
  59. {
  60. $ads = Ad::whereIn($data['id'])
  61. ->leftJoin('ad_place','ad.pid','ad_place.id')
  62. ->leftJoin("article_data","article.id","article_data.article_id")
  63. ->select("ad_place.*","ad.*")
  64. ->orderBy("ad.id","desc")
  65. ->limit($data['pageSize'])
  66. ->offset(($data['page']-1)*$data['pageSize'])->get();
  67. $count = Ad::whereIn($data['id'])->count();
  68. $data = [
  69. 'rows'=>$ads->toArray(),
  70. 'count'=>$count
  71. ];
  72. if(empty($rep)){
  73. return Result::error("没有信息数据");
  74. }
  75. return Result::success($data);
  76. }
  77. }