WelcomeController.php 8.2 KB

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