WelcomeController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Http\Controllers\QuickApp;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  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. $quick_send_order = SendOrderService::getQuickAppSendOrderStatic($this->send_order_id);
  20. $this->sendOrderStatistic($send_order);
  21. if ($send_order && $quick_send_order) {
  22. return view('qapp.welcome')->with([
  23. 'gzh_code' => $quick_send_order->child_gzh_name,
  24. 'gzh_name' => $quick_send_order->child_gzh_nickname,
  25. 'hash_bid' => Hashids::encode($send_order->book_id),
  26. 'cid' => $send_order->chapter_id,
  27. ]);
  28. }
  29. }
  30. }
  31. private function sendOrderStatistic($send_order)
  32. {
  33. $key = date('Y-m-d');
  34. $send_order_flag = Cookie::get('send_order_flag');
  35. $send_orders = explode(',', $send_order_flag);
  36. //uv
  37. if (!Cookie::get('send_order_flag_' . $this->send_order_id) && !in_array($this->send_order_id, $send_orders)) {
  38. Redis::hincrby('send_order_uv_' . $this->send_order_id, $key, 1);
  39. Redis::hincrby('send_order_uv_' . $this->send_order_id, 'total', 1);
  40. array_push($send_orders, $this->send_order_id);
  41. $str = implode(',', $send_orders);
  42. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  43. }
  44. if (Cookie::get('send_order_flag_' . $this->send_order_id)) {
  45. array_push($send_orders, $this->send_order_id);
  46. $str = implode(',', $send_orders);
  47. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  48. Cookie::queue('send_order_flag_' . $this->send_order_id, null, -1);
  49. }
  50. //pv
  51. Redis::hincrby('send_order_pv_' . $this->send_order_id, $key, 1); //每天
  52. Redis::hincrby('send_order_pv_' . $this->send_order_id, 'total', 1); //汇总
  53. Redis::sadd('send_order' . $key, $this->send_order_id);
  54. if (isset($send_order->send_time) && $send_order->send_time) { } else {
  55. $uv = Redis::hget('send_order_uv_' . $this->send_order_id, $key);
  56. if ($uv && $uv > 20) {
  57. SendOrderService::updateSendOrderTime($this->send_order_id);
  58. }
  59. }
  60. }
  61. /**
  62. * @apiVersion 1.0.0
  63. * @apiDescription 获取客服二维码
  64. * @api {GET} customer_img 获取客服二维码
  65. * @apiHeader {String} [Authorization] token
  66. * @apiGroup User
  67. * @apiName customer_img
  68. * @apiSuccess {String} name 名称.
  69. * @apiSuccess {String} url 图片地址.
  70. * @apiSuccessExample {json} Success-Response:
  71. *
  72. * {
  73. * "code": 0,
  74. * "msg": "",
  75. * "data": {}
  76. */
  77. public function getCustomerServiceImg()
  78. {
  79. $link = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
  80. $name = 'zhenzhenyd';
  81. if ($link && $link->customer_img_url) {
  82. $url = $link->customer_img_url;
  83. } else {
  84. $url = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  85. }
  86. return response()->success(compact('url', 'name'));
  87. }
  88. }