WelcomeController.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 App\Modules\User\Services\UserService;
  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. myLog('test')->info('welcome.send_order_id: ' . $this->send_order_id);
  19. $send_order = SendOrderService::getSendOrderStatic($this->send_order_id);
  20. $quick_send_order = SendOrderService::getQuickAppSendOrderStatic($this->send_order_id);
  21. $this->sendOrderStatistic($send_order);
  22. if ($send_order && $quick_send_order) {
  23. return view('qapp.welcome')->with([
  24. 'gzh_code' => $quick_send_order->child_gzh_name,
  25. 'gzh_name' => $quick_send_order->child_gzh_nickname,
  26. 'hash_bid' => Hashids::encode($send_order->book_id),
  27. 'cid' => $send_order->chapter_id,
  28. 'send_order_id' => $this->send_order_id,
  29. ]);
  30. }
  31. }
  32. }
  33. private function sendOrderStatistic($send_order)
  34. {
  35. $key = date('Y-m-d');
  36. $send_order_flag = Cookie::get('send_order_flag');
  37. $send_orders = explode(',', $send_order_flag);
  38. //uv
  39. if (!Cookie::get('send_order_flag_' . $this->send_order_id) && !in_array($this->send_order_id, $send_orders)) {
  40. Redis::hincrby('send_order_uv_' . $this->send_order_id, $key, 1);
  41. Redis::hincrby('send_order_uv_' . $this->send_order_id, 'total', 1);
  42. array_push($send_orders, $this->send_order_id);
  43. $str = implode(',', $send_orders);
  44. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  45. }
  46. if (Cookie::get('send_order_flag_' . $this->send_order_id)) {
  47. array_push($send_orders, $this->send_order_id);
  48. $str = implode(',', $send_orders);
  49. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  50. Cookie::queue('send_order_flag_' . $this->send_order_id, null, -1);
  51. }
  52. //pv
  53. Redis::hincrby('send_order_pv_' . $this->send_order_id, $key, 1); //每天
  54. Redis::hincrby('send_order_pv_' . $this->send_order_id, 'total', 1); //汇总
  55. Redis::sadd('send_order' . $key, $this->send_order_id);
  56. if (isset($send_order->send_time) && $send_order->send_time) { } 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. }