WelcomeController.php 8.5 KB

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