WelcomeController.php 4.5 KB

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