WelcomeController.php 3.7 KB

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