WelcomeController.php 7.5 KB

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