WelcomeController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace App\Http\Controllers\QuickApp;
  3. use App\Consts\PushConst;
  4. use App\Libs\Push\OPPOPush\OPPOPushCommon;
  5. use App\Modules\AdPosition\Services\AdPositionService;
  6. use App\Modules\SendOrder\Models\QappSendOrder;
  7. use App\Modules\User\Models\QappCallbackParams;
  8. use App\Modules\User\Models\QappChannelAccount;
  9. use App\Modules\User\Models\User;
  10. use App\Modules\User\Services\QappPackageService;
  11. use Illuminate\Http\Request;
  12. use App\Modules\OfficialAccount\Services\CustomMsgService;
  13. use App\Modules\SendOrder\Services\SendOrderService;
  14. use Hashids;
  15. use Cookie;
  16. use Redis;
  17. class WelcomeController extends BaseController
  18. {
  19. private $send_order_id;
  20. public function index(Request $request, string $send_order_id_encode)
  21. {
  22. $decode_id = Hashids::decode($send_order_id_encode);
  23. if ($decode_id) {
  24. $this->send_order_id = $decode_id[0];
  25. $send_order = SendOrderService::getSendOrderStatic($this->send_order_id);
  26. $distribution_channel_id = $send_order->distribution_channel_id;
  27. $qappPackage = QappPackageService::getPackage($distribution_channel_id);
  28. $this->getCallbackParams($request);
  29. $showGzh = 0;
  30. $sendOrderId = $this->send_order_id;
  31. if ($sendOrderId && in_array($sendOrderId, explode(',', env('SHOW_GZH_SEND_ORDER_IDS')))) {
  32. $showGzh = 1;
  33. }
  34. if ($send_order && $qappPackage) {
  35. $this->sendOrderStatistic($send_order);//统计
  36. return view('qapp.start')->with([
  37. 'package' => $qappPackage->package,
  38. 'hash_bid' => Hashids::encode($send_order->book_id),
  39. 'cid' => $send_order->chapter_id,
  40. 'send_order_id' => $this->send_order_id,
  41. 'show_gzh' => $showGzh
  42. ]);
  43. }
  44. }
  45. }
  46. /**
  47. * 平台附加在推广链接后的参数存储
  48. * @param $request
  49. */
  50. private function getCallbackParams($request)
  51. {
  52. $tid = $request->get('tid','');
  53. $pageId = $request->get('pageId','');
  54. if(!empty($tid) && !empty($pageId)){
  55. $qapp_send_order = QappSendOrder::getSendOrderById($this->send_order_id);
  56. \Log::info('$qapp_send_order:'.json_encode($qapp_send_order).'$this->send_order_id:'.$this->send_order_id);
  57. if($qapp_send_order && !empty($qapp_send_order)){
  58. if(isset($qapp_send_order['platform']) && $qapp_send_order['platform'] == PushConst::PROVIDER_OPPO){
  59. //用户ip
  60. $ip = _getIp();
  61. $provider = $qapp_send_order['platform'];
  62. $send_order_id = $this->send_order_id;
  63. $params = json_encode(compact('tid','pageId'));
  64. QappCallbackParams::firstOrcreate(compact('ip','send_order_id','provider','params'));
  65. }
  66. }
  67. }
  68. }
  69. private function sendOrderStatistic($send_order)
  70. {
  71. $key = date('Y-m-d');
  72. $send_order_flag = Cookie::get('send_order_flag');
  73. $send_orders = explode(',', $send_order_flag);
  74. //uv
  75. if (!Cookie::get('send_order_flag_' . $this->send_order_id) && !in_array($this->send_order_id, $send_orders)) {
  76. Redis::hincrby('send_order_uv_' . $this->send_order_id, $key, 1);
  77. Redis::hincrby('send_order_uv_' . $this->send_order_id, 'total', 1);
  78. array_push($send_orders, $this->send_order_id);
  79. $str = implode(',', $send_orders);
  80. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  81. }
  82. if (Cookie::get('send_order_flag_' . $this->send_order_id)) {
  83. array_push($send_orders, $this->send_order_id);
  84. $str = implode(',', $send_orders);
  85. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  86. Cookie::queue('send_order_flag_' . $this->send_order_id, null, -1);
  87. }
  88. //pv
  89. Redis::hincrby('send_order_pv_' . $this->send_order_id, $key, 1); //每天
  90. Redis::hincrby('send_order_pv_' . $this->send_order_id, 'total', 1); //汇总
  91. Redis::sadd('send_order' . $key, $this->send_order_id);
  92. if (isset($send_order->send_time) && $send_order->send_time) {
  93. } else {
  94. $uv = Redis::hget('send_order_uv_' . $this->send_order_id, $key);
  95. if ($uv && $uv > 20) {
  96. SendOrderService::updateSendOrderTime($this->send_order_id);
  97. }
  98. }
  99. }
  100. /**
  101. * @apiVersion 1.0.0
  102. * @apiDescription 获取客服二维码
  103. * @api {GET} customer_img 获取客服二维码
  104. * @apiHeader {String} [Authorization] token
  105. * @apiGroup User
  106. * @apiName customer_img
  107. * @apiSuccess {String} data.name 名称.
  108. * @apiSuccess {String} data.url 图片地址.
  109. * @apiSuccessExample {json} Success-Response:
  110. *
  111. * {
  112. * "code": 0,
  113. * "msg": "",
  114. * "data": {}
  115. */
  116. public function getCustomerServiceImg(Request $request)
  117. {
  118. $link = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
  119. $name = 'zhenzhenyd';
  120. if ($link && $link->customer_img_url) {
  121. $url = $link->customer_img_url;
  122. } else {
  123. $url = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  124. }
  125. // 获取客服信息
  126. $package = $request->header('x-package', '');
  127. $supports = config('option.supports');
  128. $support = getProp($supports, $package, []);
  129. if ($support) {
  130. $url = getProp($support, 'customerImage', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  131. $name = getProp($support, 'customerAccount', 'zhenzhenyd');
  132. }
  133. return response()->success(compact('url', 'name'));
  134. }
  135. /**
  136. * 系统设置
  137. * @return mixed
  138. */
  139. public function getOptions(Request $request)
  140. {
  141. // 获取包名
  142. $package = $request->header('x-package', '');
  143. // 获取客服信息
  144. $supports = config('option.supports');
  145. $support = getProp($supports, $package, (object)[]);
  146. // 获取用户信息
  147. $user = User::getUser($this->uid);
  148. $sendOrderId = getProp($user, 'send_order_id');
  149. // 获取派单信息
  150. $adPositions = [];
  151. if ($sendOrderId) {
  152. $sendOrder = QappSendOrder::getSendOrderById($sendOrderId);
  153. $channelAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
  154. $adPositions = AdPositionService::getInstance()->getAdPositions($this->uid, getProp($channelAccount, 'id'));
  155. }
  156. // 配置
  157. $data = [
  158. 'support' => $support,
  159. 'task_center' => [
  160. 'home_show' => 1,
  161. 'pay_back_alert_show' => 1,
  162. ],
  163. 'add_desk_alert' => [
  164. 'sign_out_app_show' => $sendOrderId ? 1 : 0,
  165. 'sign_out_reader_show' => $sendOrderId ? 1 : 0,
  166. ],
  167. 'position' => [
  168. 'home_alert' => getProp($adPositions, 'home_alert', []),
  169. 'reader_banner' => getProp($adPositions, 'reader_banner', []),
  170. 'open_alert' => getProp($adPositions, 'open_alert', []),
  171. ]
  172. ];
  173. return response()->success($data);
  174. }
  175. }