ChannelHomeController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace App\Http\Controllers\Channel;
  3. use App\Exceptions\ApiException;
  4. use App\Libs\ApiResponse;
  5. use App\Http\Controllers\Controller;
  6. use App\Libs\Utils;
  7. use App\Services\Channel\ChannelHomeService;
  8. use App\Transformer\Channel\ChannelTransformer;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\Validator;
  11. class ChannelHomeController extends Controller
  12. {
  13. use ApiResponse;
  14. private $channelHomeService;
  15. public function __construct(
  16. ChannelHomeService $channelHomeService
  17. ) {
  18. $this->channelHomeService = $channelHomeService;
  19. }
  20. public function index(Request $request)
  21. {
  22. return view('index');
  23. }
  24. /**
  25. * 获取当前站点信息
  26. * @return mixed
  27. */
  28. public function channelInfo() {
  29. $result = $this->channelHomeService->getChannelInfo();
  30. return $this->success($result);
  31. }
  32. /**
  33. * 设置全站点按本或按章及价格
  34. * @param Request $request
  35. * @return mixed
  36. */
  37. public function setChannelBookChargeType(Request $request) {
  38. $data = $request->all();
  39. $validator = Validator::make($data, [
  40. 'book_charge_type' => 'required|in:MERGE,HYBRID',
  41. 'book_calculate_price_type' => 'required_if:book_charge_type,MERGE,HYBRID|in:bywords,const,all',
  42. 'book_coin' => 'required_if:book_charge_type,MERGE,HYBRID|numeric',
  43. 'chapter_calculate_price_type' => 'required_if:book_charge_type,HYBRID|in:bywords,const,all',
  44. 'chapter_coin' => 'required_if:book_charge_type,HYBRID|numeric',
  45. ], [
  46. 'book_charge_type.required' => '请选择站点类型',
  47. 'book_charge_type.in' => '站点类型选择范围不正确',
  48. 'book_calculate_price_type.required_if' => '请选择短篇书籍收费方式',
  49. 'book_calculate_price_type.in' => '短篇书籍收费方式选择范围不正确',
  50. 'book_coin.required_if' => '请填写短篇书籍价格',
  51. 'book_coin.numeric' => '短篇书籍价格格式不正确',
  52. 'chapter_calculate_price_type.required_if' => '请选择长篇书籍收费方式',
  53. 'chapter_calculate_price_type.in' => '长篇书籍收费方式选择范围不正确',
  54. 'chapter_coin.required_if' => '请填写长篇书籍价格',
  55. 'chapter_coin.numeric' => '长篇书籍价格格式不正确',
  56. ]);
  57. if ($validator->fails()) {
  58. $errors = $validator->errors();
  59. Utils::throwError('1003:'.$errors->all()[0]);
  60. }
  61. $result = $this->channelHomeService->setChannelBookChargeType($data);
  62. return $this->success(['success'=>$result ? 1 : 0]);
  63. }
  64. /**
  65. * 获取子账号信息
  66. * @return mixed
  67. */
  68. public function getSubUser() {
  69. $result = $this->channelHomeService->getSubUser();
  70. return $this->success($result);
  71. }
  72. /**
  73. * 站点总数据
  74. * @param Request $request
  75. * @return mixed
  76. */
  77. public function statisticsByTotal(Request $request) {
  78. $data = $request->all();
  79. $result = $this->channelHomeService->statisticsByTotal($data);
  80. return $this->success($result);
  81. }
  82. /**
  83. * 站点数据按日明细
  84. * @param Request $request
  85. * @return mixed
  86. */
  87. public function statisticsByDay(Request $request) {
  88. $data = $request->all();
  89. $result = $this->channelHomeService->statisticsByDay($data);
  90. return $this->success($result, [new ChannelTransformer(), 'newBuildStatisticsByDay']);
  91. }
  92. /**
  93. * 导出站点统计日明细
  94. *
  95. * @param Request $request
  96. * @return mixed
  97. */
  98. public function exportStatisticsByDay(Request $request)
  99. {
  100. $data = $request->all();
  101. $result = $this->channelHomeService->exportStatisticsByDay($data);
  102. return $this->success(['success' => $result ? 1 : 0]);
  103. }
  104. /**
  105. * 站点数据按日明细
  106. * @param Request $request
  107. * @return mixed
  108. */
  109. public function statisticsByDayForMaster(Request $request) {
  110. $data = $request->all();
  111. $result = $this->channelHomeService->statisticsByDayForMaster($data);
  112. return $this->success($result, [new ChannelTransformer(), 'newBuildStatisticsByDayForMaster']);
  113. }
  114. /**
  115. * 导出站点统计日明细
  116. *
  117. * @param Request $request
  118. * @return mixed
  119. */
  120. public function exportStatisticsByDayForMaster(Request $request)
  121. {
  122. $data = $request->all();
  123. $result = $this->channelHomeService->exportStatisticsByDayForMaster($data);
  124. return $this->success(['success' => $result ? 1 : 0]);
  125. }
  126. /**
  127. * 站点数据按月明细
  128. * @param Request $request
  129. * @return mixed
  130. */
  131. public function statisticsByMonth(Request $request) {
  132. $data = $request->all();
  133. $result = $this->channelHomeService->statisticsByMonth($data);
  134. return $this->success($result, [new ChannelTransformer(), 'newBuildStatisticsByMonth']);
  135. }
  136. /**
  137. * 导出站点统计月明细
  138. *
  139. * @param Request $request
  140. * @return mixed
  141. */
  142. public function exportStatisticsByMonth(Request $request)
  143. {
  144. $data = $request->all();
  145. $result = $this->channelHomeService->exportStatisticsByMonth($data);
  146. return $this->success(['success' => $result ? 1 : 0]);
  147. }
  148. /**
  149. * 站点数据按月明细
  150. * @param Request $request
  151. * @return mixed
  152. */
  153. public function statisticsByMonthForMaster(Request $request) {
  154. $data = $request->all();
  155. $result = $this->channelHomeService->statisticsByMonthForMaster($data);
  156. return $this->success($result, [new ChannelTransformer(), 'newBuildStatisticsByMonthForMaster']);
  157. }
  158. /**
  159. * 导出站点统计月明细
  160. *
  161. * @param Request $request
  162. * @return mixed
  163. */
  164. public function exportStatisticsByMonthForMaster(Request $request)
  165. {
  166. $data = $request->all();
  167. $result = $this->channelHomeService->exportStatisticsByMonthForMaster($data);
  168. return $this->success(['success' => $result ? 1 : 0]);
  169. }
  170. }