WelcomeController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Http\Controllers\QuickApp;
  3. use App\Modules\AdPosition\Services\AdPositionService;
  4. use App\Modules\SendOrder\Models\QappSendOrder;
  5. use App\Modules\User\Models\QappChannelAccount;
  6. use App\Modules\User\Services\QappPackageService;
  7. use Illuminate\Http\Request;
  8. use App\Modules\OfficialAccount\Services\CustomMsgService;
  9. use App\Modules\SendOrder\Services\SendOrderService;
  10. use Hashids;
  11. use Cookie;
  12. use Redis;
  13. class WelcomeController extends BaseController
  14. {
  15. private $send_order_id;
  16. public function index(Request $request, string $send_order_id_encode)
  17. {
  18. $decode_id = Hashids::decode($send_order_id_encode);
  19. if ($decode_id) {
  20. $this->send_order_id = $decode_id[0];
  21. $send_order = SendOrderService::getSendOrderStatic($this->send_order_id);
  22. $distribution_channel_id = $send_order->distribution_channel_id;
  23. $qappPackage = QappPackageService::getPackage($distribution_channel_id);
  24. if ($send_order && $qappPackage) {
  25. $this->sendOrderStatistic($send_order);//统计
  26. return view('qapp.welcome')->with([
  27. 'package' => $qappPackage->package,
  28. 'hash_bid' => Hashids::encode($send_order->book_id),
  29. 'cid' => $send_order->chapter_id,
  30. 'send_order_id' => $this->send_order_id
  31. ]);
  32. }
  33. }
  34. }
  35. private function sendOrderStatistic($send_order)
  36. {
  37. $key = date('Y-m-d');
  38. $send_order_flag = Cookie::get('send_order_flag');
  39. $send_orders = explode(',', $send_order_flag);
  40. //uv
  41. if (!Cookie::get('send_order_flag_' . $this->send_order_id) && !in_array($this->send_order_id, $send_orders)) {
  42. Redis::hincrby('send_order_uv_' . $this->send_order_id, $key, 1);
  43. Redis::hincrby('send_order_uv_' . $this->send_order_id, 'total', 1);
  44. array_push($send_orders, $this->send_order_id);
  45. $str = implode(',', $send_orders);
  46. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  47. }
  48. if (Cookie::get('send_order_flag_' . $this->send_order_id)) {
  49. array_push($send_orders, $this->send_order_id);
  50. $str = implode(',', $send_orders);
  51. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  52. Cookie::queue('send_order_flag_' . $this->send_order_id, null, -1);
  53. }
  54. //pv
  55. Redis::hincrby('send_order_pv_' . $this->send_order_id, $key, 1); //每天
  56. Redis::hincrby('send_order_pv_' . $this->send_order_id, 'total', 1); //汇总
  57. Redis::sadd('send_order' . $key, $this->send_order_id);
  58. if (isset($send_order->send_time) && $send_order->send_time) {
  59. } else {
  60. $uv = Redis::hget('send_order_uv_' . $this->send_order_id, $key);
  61. if ($uv && $uv > 20) {
  62. SendOrderService::updateSendOrderTime($this->send_order_id);
  63. }
  64. }
  65. }
  66. /**
  67. * @apiVersion 1.0.0
  68. * @apiDescription 获取客服二维码
  69. * @api {GET} customer_img 获取客服二维码
  70. * @apiHeader {String} [Authorization] token
  71. * @apiGroup User
  72. * @apiName customer_img
  73. * @apiSuccess {String} data.name 名称.
  74. * @apiSuccess {String} data.url 图片地址.
  75. * @apiSuccessExample {json} Success-Response:
  76. *
  77. * {
  78. * "code": 0,
  79. * "msg": "",
  80. * "data": {}
  81. */
  82. public function getCustomerServiceImg()
  83. {
  84. $link = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
  85. $name = 'zhenzhenyd';
  86. if ($link && $link->customer_img_url) {
  87. $url = $link->customer_img_url;
  88. } else {
  89. $url = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  90. }
  91. return response()->success(compact('url', 'name'));
  92. }
  93. /**
  94. * 系统设置
  95. * @return mixed
  96. */
  97. public function getOptions(Request $request)
  98. {
  99. // 获取包名
  100. $package = $request->header('x-package', '');
  101. $sendOrderId = $request->header('send-order-id', '');
  102. // 获取客服信息
  103. $supports = config('option.supports');
  104. $support = getProp($supports, $package, (object)[]);
  105. // 获取派单信息
  106. $adPositions = [];
  107. if ($sendOrderId) {
  108. $sendOrder = QappSendOrder::getSendOrderById($sendOrderId);
  109. $channelAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
  110. $adPositions = AdPositionService::getInstance()->getAdPositions($this->uid, getProp($channelAccount, 'id'));
  111. }
  112. // 配置
  113. $data = [
  114. 'support' => $support,
  115. 'task_center' => [
  116. 'home_show' => 1,
  117. 'pay_back_alert_show' => 1,
  118. ],
  119. 'position' => [
  120. 'home_alert' => getProp($adPositions, 'home_alert', []),
  121. 'reader_banner' => getProp($adPositions, 'reader_banner', [])
  122. ]
  123. ];
  124. return response()->success($data);
  125. }
  126. }