WelcomeController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. try {
  55. if(!empty($tid) && !empty($pageId)){
  56. $qapp_send_order = QappSendOrder::getSendOrderById($this->send_order_id);
  57. \Log::info('$qapp_send_order:'.json_encode($qapp_send_order).'$this->send_order_id:'.$this->send_order_id);
  58. if($qapp_send_order && !empty($qapp_send_order)){
  59. if(isset($qapp_send_order['platform']) && $qapp_send_order['platform'] == PushConst::PROVIDER_OPPO){
  60. //用户ip
  61. $ip = _getIp();
  62. $provider = $qapp_send_order['platform'];
  63. $send_order_id = $this->send_order_id;
  64. $lbid = $request->get('lbid','');
  65. $params = json_encode(compact('tid','pageId','lbid'));
  66. QappCallbackParams::firstOrCreate(compact('ip','send_order_id','provider'),compact('params'));
  67. }
  68. }
  69. }
  70. } catch (\Exception $e) {
  71. \Log::info('oppo_request_error:'.$e->getMessage());
  72. }
  73. }
  74. private function sendOrderStatistic($send_order)
  75. {
  76. $key = date('Y-m-d');
  77. $send_order_flag = Cookie::get('send_order_flag');
  78. $send_orders = explode(',', $send_order_flag);
  79. //uv
  80. if (!Cookie::get('send_order_flag_' . $this->send_order_id) && !in_array($this->send_order_id, $send_orders)) {
  81. Redis::hincrby('send_order_uv_' . $this->send_order_id, $key, 1);
  82. Redis::hincrby('send_order_uv_' . $this->send_order_id, 'total', 1);
  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. }
  87. if (Cookie::get('send_order_flag_' . $this->send_order_id)) {
  88. array_push($send_orders, $this->send_order_id);
  89. $str = implode(',', $send_orders);
  90. Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);
  91. Cookie::queue('send_order_flag_' . $this->send_order_id, null, -1);
  92. }
  93. //pv
  94. Redis::hincrby('send_order_pv_' . $this->send_order_id, $key, 1); //每天
  95. Redis::hincrby('send_order_pv_' . $this->send_order_id, 'total', 1); //汇总
  96. Redis::sadd('send_order' . $key, $this->send_order_id);
  97. if (isset($send_order->send_time) && $send_order->send_time) {
  98. } else {
  99. $uv = Redis::hget('send_order_uv_' . $this->send_order_id, $key);
  100. if ($uv && $uv > 20) {
  101. SendOrderService::updateSendOrderTime($this->send_order_id);
  102. }
  103. }
  104. }
  105. /**
  106. * @apiVersion 1.0.0
  107. * @apiDescription 获取客服二维码
  108. * @api {GET} customer_img 获取客服二维码
  109. * @apiHeader {String} [Authorization] token
  110. * @apiGroup User
  111. * @apiName customer_img
  112. * @apiSuccess {String} data.name 名称.
  113. * @apiSuccess {String} data.url 图片地址.
  114. * @apiSuccessExample {json} Success-Response:
  115. *
  116. * {
  117. * "code": 0,
  118. * "msg": "",
  119. * "data": {}
  120. */
  121. public function getCustomerServiceImg(Request $request)
  122. {
  123. $link = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
  124. $name = 'zhenzhenyd';
  125. if ($link && $link->customer_img_url) {
  126. $url = $link->customer_img_url;
  127. } else {
  128. $url = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  129. }
  130. // 获取客服信息
  131. $package = $request->header('x-package', '');
  132. $supports = config('option.supports');
  133. $support = getProp($supports, $package, []);
  134. if ($support) {
  135. $url = getProp($support, 'customerImage', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
  136. $name = getProp($support, 'customerAccount', 'zhenzhenyd');
  137. }
  138. return response()->success(compact('url', 'name'));
  139. }
  140. /**
  141. * 系统设置
  142. * @return mixed
  143. */
  144. public function getOptions(Request $request)
  145. {
  146. // 获取包名
  147. $package = $request->header('x-package', '');
  148. // 获取客服信息
  149. $supports = config('option.supports');
  150. $support = getProp($supports, $package, (object)[]);
  151. // 获取用户信息
  152. $user = User::getUser($this->uid);
  153. $sendOrderId = getProp($user, 'send_order_id');
  154. // 获取派单信息
  155. $adPositions = [];
  156. if ($sendOrderId) {
  157. $sendOrder = QappSendOrder::getSendOrderById($sendOrderId);
  158. $channelAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
  159. $adPositions = AdPositionService::getInstance()->getAdPositions($this->uid, getProp($channelAccount, 'id'));
  160. }
  161. // 配置
  162. $data = [
  163. 'support' => $support,
  164. 'task_center' => [
  165. 'home_show' => 1,
  166. 'pay_back_alert_show' => 1,
  167. ],
  168. 'add_desk_alert' => [
  169. 'sign_out_app_show' => $sendOrderId ? 1 : 0,
  170. 'sign_out_reader_show' => $sendOrderId ? 1 : 0,
  171. ],
  172. 'position' => [
  173. 'home_alert' => getProp($adPositions, 'home_alert', []),
  174. 'reader_banner' => getProp($adPositions, 'reader_banner', []),
  175. 'open_alert' => getProp($adPositions, 'open_alert', []),
  176. ]
  177. ];
  178. return response()->success($data);
  179. }
  180. }