WelcomeController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. $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. '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) { } else {
  56. $uv = Redis::hget('send_order_uv_' . $this->send_order_id, $key);
  57. if ($uv && $uv > 20) {
  58. SendOrderService::updateSendOrderTime($this->send_order_id);
  59. }
  60. }
  61. }
  62. /**
  63. * @apiVersion 1.0.0
  64. * @apiDescription 获取客服二维码
  65. * @api {GET} customer_img 获取客服二维码
  66. * @apiHeader {String} [Authorization] token
  67. * @apiGroup User
  68. * @apiName customer_img
  69. * @apiSuccess {String} data.name 名称.
  70. * @apiSuccess {String} data.url 图片地址.
  71. * @apiSuccessExample {json} Success-Response:
  72. *
  73. * {
  74. * "code": 0,
  75. * "msg": "",
  76. * "data": {}
  77. */
  78. public function getCustomerServiceImg()
  79. {
  80. $link = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
  81. $name = 'zhenzhenyd';
  82. if ($link && $link->customer_img_url) {
  83. $url = $link->customer_img_url;
  84. } else {
  85. $url = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  86. }
  87. return response()->success(compact('url', 'name'));
  88. }
  89. /**
  90. * @apiVersion 1.0.0
  91. * @apiDescription 更新派单ID
  92. * @api {GET} user/setSendOrder 更新派单ID
  93. * @apiHeader {String} [Authorization] token
  94. * @apiGroup User
  95. * @apiName setSendOrder
  96. * @apiSuccessExample {json} Success-Response:
  97. *
  98. * {
  99. * "code": 0,
  100. * "msg": "",
  101. * "data": {}
  102. */
  103. public function setSendOrder(Request $request)
  104. {
  105. $send_order_id = $request->get('send_order_id', 0);
  106. if ($send_order_id) {
  107. UserService::setUserSendOrder($this->uid, $send_order_id);
  108. }
  109. return response()->success();
  110. }
  111. }