| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 | <?phpnamespace App\Http\Controllers\QuickApp;use App\Modules\AdPosition\Services\AdPositionService;use App\Modules\SendOrder\Models\QappSendOrder;use App\Modules\SendOrder\Models\QuickAppSendOrder;use App\Modules\User\Models\QappChannelAccount;use App\Modules\User\Services\QappPackageService;use Illuminate\Http\Request;use App\Modules\OfficialAccount\Services\CustomMsgService;use App\Modules\SendOrder\Services\SendOrderService;use Hashids;use Cookie;use Redis;class WelcomeController extends BaseController{    private $send_order_id;    public function index(Request $request, string $send_order_id_encode)    {        $decode_id = Hashids::decode($send_order_id_encode);        if ($decode_id) {            $this->send_order_id     = $decode_id[0];            $send_order              = SendOrderService::getSendOrderStatic($this->send_order_id);            $distribution_channel_id = $send_order->distribution_channel_id;            $qappPackage             = QappPackageService::getPackage($distribution_channel_id);            if ($send_order && $qappPackage) {                $this->sendOrderStatistic($send_order);//统计                return view('qapp.welcome')->with([                    'package'       => $qappPackage->package,                    'hash_bid'      => Hashids::encode($send_order->book_id),                    'cid'           => $send_order->chapter_id,                    'send_order_id' => $this->send_order_id                ]);            }        }    }    private function sendOrderStatistic($send_order)    {        $key             = date('Y-m-d');        $send_order_flag = Cookie::get('send_order_flag');        $send_orders     = explode(',', $send_order_flag);        //uv        if (!Cookie::get('send_order_flag_' . $this->send_order_id) && !in_array($this->send_order_id, $send_orders)) {            Redis::hincrby('send_order_uv_' . $this->send_order_id, $key, 1);            Redis::hincrby('send_order_uv_' . $this->send_order_id, 'total', 1);            array_push($send_orders, $this->send_order_id);            $str = implode(',', $send_orders);            Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);        }        if (Cookie::get('send_order_flag_' . $this->send_order_id)) {            array_push($send_orders, $this->send_order_id);            $str = implode(',', $send_orders);            Cookie::queue('send_order_flag', $str, env('U_COOKIE_EXPIRE'), null, null, false, false);            Cookie::queue('send_order_flag_' . $this->send_order_id, null, -1);        }        //pv        Redis::hincrby('send_order_pv_' . $this->send_order_id, $key, 1); //每天        Redis::hincrby('send_order_pv_' . $this->send_order_id, 'total', 1); //汇总        Redis::sadd('send_order' . $key, $this->send_order_id);        if (isset($send_order->send_time) && $send_order->send_time) {        } else {            $uv = Redis::hget('send_order_uv_' . $this->send_order_id, $key);            if ($uv && $uv > 20) {                SendOrderService::updateSendOrderTime($this->send_order_id);            }        }    }    /**     * @apiVersion 1.0.0     * @apiDescription 获取客服二维码     * @api {GET} customer_img 获取客服二维码     * @apiHeader {String} [Authorization]  token     * @apiGroup User     * @apiName customer_img     * @apiSuccess {String}  data.name 名称.     * @apiSuccess {String}  data.url 图片地址.     * @apiSuccessExample {json} Success-Response:     *     *     {     *         "code": 0,     *         "msg": "",     *         "data": {}     */    public function getCustomerServiceImg()    {        $link = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);        $name = 'zhenzhenyd';        if ($link && $link->customer_img_url) {            $url = $link->customer_img_url;        } else {            $url = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');        }        return response()->success(compact('url', 'name'));    }    /**     * 系统设置     * @return mixed     */    public function getOptions(Request $request)    {        // 获取包名        $package     = $request->header('x-package', '');        $sendOrderId = $request->header('send-order-id', '');        // 获取客服信息        $supports = config('option.supports');        $support  = getProp($supports, $package, (object)[]);        // 获取派单信息        $adPositions = [];        if ($sendOrderId) {            $sendOrder      = QappSendOrder::getSendOrderById($sendOrderId);            $channelAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));            $adPositions    = AdPositionService::getInstance()->getAdPositions($this->uid, getProp($channelAccount, 'id'));        }        // 配置        $data = [            'support'     => $support,            'task_center' => [                'home_show'           => 1,                'pay_back_alert_show' => 1,            ],            'position'    => [                'home_alert'    => getProp($adPositions, 'home_alert', []),                'reader_banner' => getProp($adPositions, 'reader_banner', [])            ]        ];        return response()->success($data);    }}
 |