LinkController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace General\Controllers\LandingPage;
  3. use App\Http\Controllers\Controller;
  4. use App\Jobs\AutoCheckLandingPage;
  5. use App\Libs\AliOSS;
  6. use General\Controllers\BaseControllerConfig;
  7. use General\Controllers\LandingPage\Transformers\BaiDuAdAccountTransformer;
  8. use General\Controllers\LandingPage\Transformers\LinkTransformer;
  9. use General\Controllers\LandingPage\Transformers\ReportOrderTramsformer;
  10. use General\Helpers\ExcelHelper;
  11. use General\Models\LandingPage\LandingPageLink;
  12. use General\Requests\BaiDuAdAccountRequest;
  13. use General\Requests\LandingPageLinkRequest;
  14. use General\Requests\LinkReportTypeRequest;
  15. use General\Requests\QueryReportRequest;
  16. use General\Requests\ReReportRequest;
  17. use General\Services\Config\ConfigService;
  18. use Illuminate\Http\Request;
  19. use General\Services\LandingPage\LandingPageLinkService;
  20. class LinkController extends Controller
  21. {
  22. use BaseControllerConfig;
  23. protected $service;
  24. public function __construct()
  25. {
  26. $this->service = new LandingPageLinkService;
  27. }
  28. public function index(Request $request)
  29. {
  30. $query_params = $request->except('_url');
  31. $query_params['channel_id'] = $this->channel_id;
  32. $result = $this->service->findLinks($query_params, true);
  33. return response()->pagination(new LinkTransformer, $result);
  34. }
  35. public function edit(int $id)
  36. {
  37. $link_model = LandingPageLink::find($id);
  38. if ($link_model) {
  39. if ($this->channel_id != $link_model->channel_id) {
  40. return response()->error('CHANNEL_ERROR');
  41. }
  42. $link_model->content = $link_model->content_path ? AliOSS::getLandingPageString($link_model->content_path) : $link_model->content;
  43. return response()->success($link_model);
  44. }
  45. return response()->error('PARAM_ERROR');
  46. }
  47. protected function getLinkDomain(string $domain)
  48. {
  49. return $domain;
  50. }
  51. public function save(LandingPageLinkRequest $request)
  52. {
  53. $params = $request->except('_url');
  54. if (isset($params['id'])) {
  55. $link_model = LandingPageLink::find($params['id']);
  56. if ($link_model) {
  57. if (in_array($link_model->status, [LandingPageLinkService::APPROVED_STATUS, LandingPageLinkService::WAITTING_APPROVE_STATUS])) {
  58. return response()->error('STATUS_EDIT_ERROR');
  59. }
  60. if ($this->channel_id != $link_model->channel_id) {
  61. return response()->error('CHANNEL_ERROR');
  62. }
  63. }
  64. } else {
  65. if (!isset($params['link_source'])) {
  66. $params['link_source'] = LandingPageLinkService::tiktok;
  67. }
  68. }
  69. $params['channel_id'] = $this->channel_id;
  70. if (isset($params['gzh_biz']) && isset($params['filing'])) {
  71. $params['config'] = json_encode([
  72. 'gzh_biz' => $params['gzh_biz'],
  73. 'filing' => $params['filing'],
  74. ]);
  75. }
  76. $file = $request->file('sub_img');
  77. if ($file) {
  78. $path = 'img/' . time() . '.' . $file->extension();
  79. AliOSS::uploadLandingPageImg($path, $file->path());
  80. $params['sub_img'] = 'https://' . $this->getLinkDomain($params['domain']) . '/' . $path;
  81. }
  82. $gzh_img = $request->file('gzh_img');
  83. if ($gzh_img) {
  84. $path = 'img/' . $params['gzh_code'] . time() . '.' . $gzh_img->extension();
  85. AliOSS::uploadLandingPageImg($path, $gzh_img->path());
  86. $params['gzh_img'] = 'https://' . $this->getLinkDomain($params['domain']) . '/' . $path;
  87. }
  88. if ($params['content']) {
  89. if (isset($link_model) && $link_model->content_path) {
  90. $path = $link_model->content_path;
  91. } else {
  92. $path = 'content/' . time() . '.html';
  93. }
  94. AliOSS::uploadLandingPageString($path, $params['content']);
  95. $params['content_path'] = $path;
  96. }
  97. $params['status'] = LandingPageLinkService::NEW_STATUS;
  98. $this->service->saveLink($params);
  99. return response()->success();
  100. }
  101. public function changeStatus(int $id, Request $request)
  102. {
  103. $status = (int) $request->get('status', 0);
  104. $link_model = LandingPageLink::find($id);
  105. if ($link_model) {
  106. if ($this->channel_id != $link_model->channel_id) {
  107. return response()->error('CHANNEL_ERROR');
  108. }
  109. $remark = $request->get('remark', '');
  110. $this->service->updateLinkStatus($id, $status, $remark);
  111. $service = new ConfigService;
  112. if (($this->is_inner || $service->hasAuth($this->channel_user_id, ConfigService::landing_page_auto_check)) && $status == LandingPageLinkService::WAITTING_APPROVE_STATUS) {
  113. dispatch(new AutoCheckLandingPage($link_model))->onConnection('redis')->onQueue('{auto_check_landing_page_queue}');
  114. }
  115. return response()->success();
  116. } else {
  117. return response()->error('PARAM_ERROR');
  118. }
  119. }
  120. public function delete(int $id)
  121. {
  122. $this->service->deleteLink($id);
  123. return response()->success();
  124. }
  125. public function domain()
  126. {
  127. return response()->success($this->service->findDomains());
  128. }
  129. public function officialAccounts()
  130. {
  131. return response()->success($this->service->findOfficialAccounts($this->channel_id));
  132. }
  133. public function getConfig()
  134. {
  135. $config = $this->service->getChargeFeedBackConfig($this->channel_id, $this->channel_user_id);
  136. return response()->success($config);
  137. }
  138. public function setReportType(LinkReportTypeRequest $request)
  139. {
  140. $type = $request->get('type');
  141. $molecule = (int)$request->get('molecule', 0);
  142. $eligible_count = (int) $request->get('eligible_count', 0);
  143. $this->service->setReportType($this->channel_id, $type, $molecule, $eligible_count);
  144. return response()->success();
  145. }
  146. /**
  147. * 查询上报用户日志
  148. */
  149. public function queryReportLog(QueryReportRequest $request)
  150. {
  151. request()->offsetSet('qapp_account', $this->qapp_account);
  152. $result = $this->service->findUserReportInfos($this->channel_id, $request->all());
  153. return response()->pagination(new ReportOrderTramsformer, $result);
  154. }
  155. public function reportLogExport(QueryReportRequest $request)
  156. {
  157. request()->offsetSet('qapp_account', $this->qapp_account);
  158. $result = $this->service->findUserReportInfos($this->channel_id, $request->all(), false);
  159. $result = collectionTransform(new ReportOrderTramsformer, $result);
  160. $headers = [
  161. '订单号',
  162. '用户ID',
  163. '注册时间',
  164. '注册IP',
  165. '下单金额',
  166. '支付时间',
  167. '下单IP',
  168. '绑定ID',
  169. '广告计划ID',
  170. '推广平台',
  171. '回传状态',
  172. '回传结果类型',
  173. '回传结果',
  174. '回传百分比',
  175. '回传配置百分比'
  176. ];
  177. ExcelHelper::exportWebFileCsv($headers, $result, "回传日志");
  178. }
  179. public function setSwitch(Request $request)
  180. {
  181. $is_orange = $request->get('is_orange', 0);
  182. $status = $request->get('status');
  183. $is_sync = $request->get('is_sync', 0);
  184. if (is_numeric($is_orange) && is_numeric($status) && is_numeric($is_sync)) {
  185. if ($is_sync) {
  186. $this->service->syncSwitchStatus($this->user_channel_ids, $status, $is_orange);
  187. } else {
  188. $this->service->setSwitchStatus($this->channel_id, $status, $is_orange);
  189. }
  190. }
  191. return response()->success();
  192. }
  193. public function addBaiDuAdAccount(BaiDuAdAccountRequest $request)
  194. {
  195. $this->service->addBaiduAdAccount($request->all(), $this->channel_user_id);
  196. return response()->success();
  197. }
  198. public function delBaiDuAdAccount(int $id)
  199. {
  200. $this->service->delBaiduAdAccount($id, $this->channel_user_id);
  201. return response()->success();
  202. }
  203. public function findBaiDuAdAccounts()
  204. {
  205. $result = $this->service->findBaiDuAdAccounts($this->channel_user_id);
  206. return response()->collection(new BaiDuAdAccountTransformer, $result);
  207. }
  208. public function reReport(int $bind_id, ReReportRequest $request)
  209. {
  210. $amount = $request->get('amount');
  211. $order_no = $request->get('order_no');
  212. $this->service->reReport($bind_id, $amount, $order_no);
  213. return response()->success();
  214. }
  215. }