<?php


namespace App\Http\Controllers\QuickApp\SendOrder;


use App\Exceptions\ApiException;
use App\Http\Controllers\QuickApp\BaseController;
use App\Modules\SendOrder\Models\QappSendOrder;
use Hashids\Hashids;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;

class TxAdqNewNoAdvBookController extends  BaseController
{
    use ValidatesRequests;
    /**
     * 腾讯广告新版,非点击广告访问链接的用户将看到配置的非广告书籍
     * - 如果是通过腾讯adq广告投放的hap链接中，会有腾讯广告那边添加的参数，形如：hap://app/com.beidao.kuaiying.zsy/views/Reader?send_order_id=3402324&bid=5pNo6A7wqQmB1WgQygDjkOM9VZn2vXeY&chapter_id=1252&platform=tx_adq_new&back_name=%E5%BE%AE%E8%A7%86&back_pkg=com.tencent.weishi&back_url=weishi%3A%2F%2F
     * - 否则，形如：hap://app/com.beidao.kuaiying.zsy/views/Reader?send_order_id=3521701&bid=PGZq37EQ1brwdgpeyaR8Voa42OXNk6Ap&chapter_id=23655059&platform=huawei_fyp
     * @param $sendOrderId
     * @return mixed
     * @throws ApiException
     */
    public function getNoAdvBookInfo(Request $request) {
        $this->validate($request,[
            'send_order_id' => 'required'
        ],[
            'required' => ':attribute 必传'
        ], [
            'send_order_id' => '派单id'
        ]);
        $extraConfig = QappSendOrder::where('send_order_id', $request->input('send_order_id'))
            ->where('platform', 'tx_adq_new')
            ->value('extra_config');
        if($extraConfig) {
            $extraConfigDecode = \json_decode($extraConfig, true);
            $bid = $extraConfigDecode['txAdqNoAdvBid'] ?? '';
            $cid = $extraConfigDecode['txAdqNoAdvCid'] ?? 0;
            if($bid) {
                return response()->success([
                    'bid' => $bid,
                    'cid' => $cid,
                ]);
            }
        }
        return response()->error('QAPP_SEND_ORDER_BOOK_NOT_FIND');
    }
}