瀏覽代碼

Merge branch 'kuaiyingyong' into quickapp_fly

Wang Chen 4 年之前
父節點
當前提交
87d0d8b2f6

+ 10 - 0
app/Cache/AdPosition/AdPositionCache.php

@@ -0,0 +1,10 @@
+<?php
+
+
+namespace App\Cache\AdPosition;
+
+
+class AdPositionCache
+{
+
+}

+ 3 - 0
app/Cache/CacheKeys.php

@@ -25,6 +25,9 @@ class CacheKeys
         'push'     => [
             'user' => 'Push:%s'
         ],
+        'ad'       => [
+            'position' => 'Ad:position'
+        ],
         'activity' => [
             'statsPv' => 'Activity:pv:%s:%s',
             'statsUv' => 'Activity:uv:%s:%s',

+ 43 - 0
app/Console/Commands/Test.php

@@ -0,0 +1,43 @@
+<?php
+
+
+namespace App\Console\Commands;
+
+
+use App\Libs\Utils;
+use Hashids;
+use Illuminate\Console\Command;
+
+class Test extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'test {bid}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '测试';
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $bid   = $this->argument('bid');
+        $enBid = Hashids::encode($bid);
+
+        $enHotBids = array_map(function ($bid) {
+            return Utils::getEncodeId($bid);
+        }, [$bid]);
+
+        dd($bid, $enBid, $enHotBids);
+    }
+}

+ 1 - 0
app/Console/Kernel.php

@@ -37,6 +37,7 @@ class Kernel extends ConsoleKernel
         Commands\updateFromNewYunqi::class,
         Commands\CheckOrderStatus::class,
         Commands\NewVersionPrepare::class,
+        Commands\Test::class,
     ];
 
     /**

+ 2 - 1
app/Http/Controllers/QuickApp/Activity/ActivityController.php

@@ -10,6 +10,7 @@ use App\Libs\Utils;
 use App\Modules\Activity\Services\ActivityService;
 use App\Modules\Channel\Services\ChannelService;
 use App\Modules\Product\Services\ProductService;
+use App\Modules\SendOrder\Models\QappSendOrder;
 use App\Modules\SendOrder\Models\QuickAppSendOrder;
 use App\Modules\Subscribe\Services\OrderService;
 use App\Modules\User\Models\QappChannelAccount;
@@ -207,7 +208,7 @@ class ActivityController extends BaseController
         $sendOrderId   = $this->send_order_id;
         $qappAccountId = (int)getProp($activity, 'qapp_account_id');
         if ($qappAccountId && $sendOrderId) {
-            $sendOrder   = QuickAppSendOrder::getSendOrderById($sendOrderId);
+            $sendOrder   = QappSendOrder::getSendOrderById($sendOrderId);
             $qappAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
             if ($qappAccountId !== (int)getProp($qappAccount, 'id')) {
                 Utils::throwError(ErrorConst::ACTIVITY_INVALID);

+ 4 - 4
app/Http/Controllers/QuickApp/Activity/Transformers/ReBuildData.php

@@ -21,10 +21,10 @@ class ReBuildData
             'endTime'     => getProp($activity, 'end_time'),
             'from'        => $param['from'],
             'activityId'  => getProp($activity, 'id'),
-            'isForever'   => getProp($activity, 'end_time') === '9999-12-30 23:59:59' ? '1' : '0',
+            'isForever'   => getProp($activity, 'end_time') === '9999-12-30 23:59:59' ? 1 : 0,
             'payChannels' => [
-                'ali'    => '1',
-                'wechat' => '1',
+                'ali'    => 1,
+                'wechat' => 1,
             ],
             'products'    => $this->buildProducts($param['products'], $param['settingProducts'])
         ];
@@ -51,7 +51,7 @@ class ReBuildData
 
             // 支付产品信息
             $product = collect($products)->firstWhere('id', $productId);
-            $price   = (int)getProp($product, 'price');
+            $price   = getProp($product, 'price');
             $total   = $price * 100 + (int)getProp($product, 'given');
 
             $result[] = [

+ 56 - 43
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -2,6 +2,8 @@
 
 namespace App\Http\Controllers\QuickApp\Book;
 
+use App\Libs\Utils;
+use App\Modules\Book\Services\BookAuditService;
 use App\Modules\RecommendBook\Services\RecommendService;
 use App\Modules\Book\Services\RecoBannerService;
 use Illuminate\Http\Request;
@@ -23,7 +25,7 @@ class BookController extends BaseController
 {
     public function index(Request $request, $bid)
     {
-        $bid = BookService::decodeBidStatic($bid);
+        $bid       = BookService::decodeBidStatic($bid);
         $book_info = BookConfigService::getBookById($bid);
         if (!$book_info) {
             return response()->error('QAPP_SYS_ERROR');
@@ -31,18 +33,18 @@ class BookController extends BaseController
         if (!in_array($book_info->is_on_shelf, [2])) {
             return response()->error('QAPP_OFF_SHELF');
         }
-        $is_on_shelf = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid, $bid);
+        $is_on_shelf                   = UserShelfBooksService::getUserShelfBooksListByUidAndBid($this->uid, $bid);
         $book_info['is_on_user_shelf'] = 0;
 
         if ($is_on_shelf) {
             $book_info['is_on_user_shelf'] = 1;
         }
-        $last_chapter = ChapterService::getChapterNameById($book_info['last_cid'], $bid);
+        $last_chapter                     = ChapterService::getChapterNameById($book_info['last_cid'], $bid);
         $book_info['last_chapter_is_vip'] = $last_chapter['is_vip'];
-        $book_info['is_need_charge'] = $this->isNeedCharge($bid, $last_chapter, $book_info);
-        $record = ReadRecordService::getBookReadRecordStatic($this->uid, $bid);
+        $book_info['is_need_charge']      = $this->isNeedCharge($bid, $last_chapter, $book_info);
+        $record                           = ReadRecordService::getBookReadRecordStatic($this->uid, $bid);
         if ($record) {
-            $book_info['record_chapter_id'] = $record['record_chapter_id'];
+            $book_info['record_chapter_id']   = $record['record_chapter_id'];
             $book_info['record_chapter_name'] = $record['record_chapter_name'];
         }
         return response()->item(new BookTransformer(), $book_info);
@@ -70,7 +72,7 @@ class BookController extends BaseController
         //章节订购记录
         $chapterOrder = new ChapterOrderService();
 
-        if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id))  return true;
+        if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
 
         return false;
     }
@@ -115,7 +117,7 @@ class BookController extends BaseController
                 return $this->isBookNeedCharge($bid, $price);
             default:
                 $price = $last_chapter->is_vip ? $this->getPrice($book_info, $last_chapter->size) : 0;
-                return  $last_chapter->is_vip ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
+                return $last_chapter->is_vip ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
         }
     }
 
@@ -129,7 +131,7 @@ class BookController extends BaseController
     {
         if ($book_info->charge_type == 'BOOK')
             return $book_info->price * 100;
-        return   ceil($chapter_size / 100);
+        return ceil($chapter_size / 100);
     }
 
     /**
@@ -137,17 +139,27 @@ class BookController extends BaseController
      */
     public function getBookLists(Request $request, $sex)
     {
+        // 获取基本数据
+        $package     = $request->header('x-package', '');
+        $brand       = $request->header('x-nbrand', '');
+        $codeVersion = $request->header('x-codeversion', '');
+
+        // 根据包名、平台、版本号判断是否审核
+        if (Utils::checkIsAudit($package, $brand, $codeVersion)) {
+            $result = BookAuditService::getHomeBooksData($sex);
+            return response()->success($result);
+        }
 
         if ($sex == 'male') {
-            $channel = 1;
+            $channel          = 1;
             $reco_banner_type = ['MALE', 'PUBLIC'];
         } else {
             $reco_banner_type = ['FEMALE', 'PUBLIC'];
-            $channel = 2;
+            $channel          = 2;
         }
         $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
         $books->transform(function ($item) {
-            $result = $this->getBidCidFromUrl($item->redirect_url);
+            $result    = $this->getBidCidFromUrl($item->redirect_url);
             $item->bid = $result['bid'];
             $item->cid = $result['cid'];
             if ($result['cid']) {
@@ -157,19 +169,11 @@ class BookController extends BaseController
             }
             return $item;
         });
-        $package   = $request->header('x-package', '');
-        $checkOpen = env('CHECK_OPEN', false);
-        if ($checkOpen && $package === 'com.juyu.kuaiying.rmyq') {
-            $hotBids   = config('home.hot.' . $sex);
-            $liveBids  = config('home.live.' . $sex);
-            $recomBids = config('home.recom.' . $sex);
-            $newBids   = config('home.new_recom.' . $sex);
-        } else {
-            $hotBids   = RecommendService::getRecommendIdsStatic($channel, 'hot');
-            $liveBids  = RecommendService::getRecommendIdsStatic($channel, 'live');
-            $recomBids = RecommendService::getRecommendIdsStatic($channel, 'recom');
-            $newBids   = RecommendService::getRecommendIdsStatic($channel, 'new_recom');
-        }
+
+        $hotBids   = RecommendService::getRecommendIdsStatic($channel, 'hot');
+        $liveBids  = RecommendService::getRecommendIdsStatic($channel, 'live');
+        $recomBids = RecommendService::getRecommendIdsStatic($channel, 'recom');
+        $newBids   = RecommendService::getRecommendIdsStatic($channel, 'new_recom');
 
         $result = [
             ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
@@ -199,10 +203,10 @@ class BookController extends BaseController
 
     public function library(Request $request)
     {
-        $where = [];
-        $order = [];
+        $where                = [];
+        $order                = [];
         $where['is_on_shelf'] = [2];
-        $category_id = $request->input('category_id');
+        $category_id          = $request->input('category_id');
         if ($category_id) {
             if ($category_id == 1) {
                 $where['channel_name'] = '男频';
@@ -218,8 +222,8 @@ class BookController extends BaseController
             BookConfigService::saveUserSearchLog($key, $uid);
         }
         $where['key'] = $key;
-        $order_field = $request->input('order_field');
-        $order_seq = $request->input('order_seq');
+        $order_field  = $request->input('order_field');
+        $order_seq    = $request->input('order_seq');
         if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
             if ($order_field == 'update') {
                 $order = ['book_configs.updated_at', 'desc'];
@@ -236,12 +240,21 @@ class BookController extends BaseController
                 $order = [$order_field, 'desc'];
             }
         }
+
+        // 审核状态默认值
+        $package     = $request->header('x-package', '');
+        $brand       = $request->header('x-nbrand', '');
+        $codeVersion = $request->header('x-codeversion', '');
+        if ($order_field === 'recommend_index' && Utils::checkIsAudit($package, $brand, $codeVersion)) {
+            $order = ['book_configs.bid', 'desc'];
+        }
+
         $status = $request->input('status');
         if ($status != '') {
             $where['status'] = $status;
         }
         $page_size = $request->input('page_size', 15);
-        $books = BookConfigService::getBooks($where, $order, $page_size);
+        $books     = BookConfigService::getBooks($where, $order, $page_size);
         return response()->pagination(new BookTransformer, $books);
     }
 
@@ -254,14 +267,14 @@ class BookController extends BaseController
     public function similarRecom(Request $request)
     {
         $category_id = $request->input('category_id');
-        $bid = $request->input('bid');
+        $bid         = $request->input('bid');
         if (empty($bid) || empty($category_id)) {
             return response()->error('PARAM_ERROR');
         }
-        $bid = BookService::decodeBidStatic($bid);
+        $bid   = BookService::decodeBidStatic($bid);
         $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
         $books = BookConfigService::getBooks($where, [], 4);
-        $data = [];
+        $data  = [];
         foreach ($books as $v) {
             if ($v->bid != $bid && count($data) < 3) {
                 $data[] = $v;
@@ -276,21 +289,21 @@ class BookController extends BaseController
         if (empty($bid)) {
             return response()->error('PARAM_ERROR');
         }
-        $bid = BookService::decodeBidStatic($bid);
-        $book_info = BookConfigService::getBookById($bid);
-        $res = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
+        $bid         = BookService::decodeBidStatic($bid);
+        $book_info   = BookConfigService::getBookById($bid);
+        $res         = BookConfigService::getRecommendBooks($bid, $book_info->channel_name);
         $urge_status = 0;
         if ($book_info->status == 0 && !BookUrgeUpdateService::isHadUrged($this->uid, $bid)) {
             $urge_status = 1;
         }
         $recommend_result = collectionTransform(new BookTransformer(), $res);
-        $book_status = [
-            'status' => $book_info->status,
+        $book_status      = [
+            'status'      => $book_info->status,
             'urge_status' => $urge_status
         ];
-        $data = [
+        $data             = [
             'recommend_result' => $recommend_result,
-            'book_status' => $book_status
+            'book_status'      => $book_status
         ];
         return response()->success($data);
     }
@@ -314,9 +327,9 @@ class BookController extends BaseController
     public function recommen()
     {
         $reco_banner_type = ['FEMALE', 'PUBLIC'];
-        $books = (new RecoBannerService)->getByType($reco_banner_type, 2);
+        $books            = (new RecoBannerService)->getByType($reco_banner_type, 2);
         $books->transform(function ($item) {
-            $result = $this->getBidCidFromUrl($item->redirect_url);
+            $result    = $this->getBidCidFromUrl($item->redirect_url);
             $item->bid = $result['bid'];
             $item->cid = $result['cid'];
             if ($result['cid']) {

+ 29 - 29
app/Http/Controllers/QuickApp/Book/Transformers/BookTransformer.php

@@ -15,37 +15,37 @@ class BookTransformer
     public function transform($book)
     {
         return [
-            'book_id' => Hashids::encode($book->bid),
-            'book_name' => $book->book_name,
-            'book_summary' => $book->intro,
-            'book_author' => $book->author,
-            'cover_url' => $book->cover,
-            'book_word_count' => $book->size,
-            'book_chapter_total' => $book->chapter_count,
-            'book_category_id' => $book->category_id,
-            'book_category' => $book->category_name,
-            'book_end_status' => $book->status,
-            'book_published_time' =>  $book->updated_at ?? '',
-            'copyright' =>  $book->copyright ?? '',
-            'charge_type' =>  $book->charge_type ?? '',
+            'book_id'                    => Hashids::encode($book->bid),
+            'book_name'                  => $book->book_name,
+            'book_summary'               => $book->intro,
+            'book_author'                => $book->author,
+            'cover_url'                  => $book->cover,
+            'book_word_count'            => $book->size,
+            'book_chapter_total'         => $book->chapter_count,
+            'book_category_id'           => $book->category_id,
+            'book_category'              => $book->category_name,
+            'book_end_status'            => $book->status,
+            'book_published_time'        => $book->updated_at ?? '',
+            'copyright'                  => $book->copyright ?? '',
+            'charge_type'                => $book->charge_type ?? '',
             'force_subscribe_chapter_id' => $book->force_subscribe_chapter_seq,
-            'update_time' => $book->updated_at ?? '',
+            'update_time'                => $book->updated_at ?? '',
             // 'is_on_shelf' => $book->is_on_shelf ?? 0,
-            'book_price' => $book->price ?? 0,
-            'keyword' => $book->keyword,
-            'recommend_index' => $book->recommend_index,
-            'is_show_index_content' => $book->is_show_index_content,
-            'click_count' => $book->click_count,
-            'product_id' => $book->product_id,
-            'sex_preference' => $book->channel_name,
-            'last_cid' => $book->last_cid,
-            'last_chapter' => $book->last_chapter,
-            'first_cid' => $book->first_cid,
-            'is_on_user_shelf' => $book->is_on_user_shelf,
-            'last_chapter_is_vip' => $book->last_chapter_is_vip ?? 0,
-            'is_need_charge' => $book->is_need_charge ? 1 : 0,
-            'record_chapter_id' => $book->record_chapter_id ?? 0,
-            'record_chapter_name' => $book->record_chapter_name ?? '',
+            'book_price'                 => $book->price ?? 0,
+            'keyword'                    => $book->keyword,
+            'recommend_index'            => $book->recommend_index,
+            'is_show_index_content'      => $book->is_show_index_content,
+            'click_count'                => $book->click_count,
+            'product_id'                 => $book->product_id,
+            'sex_preference'             => $book->channel_name,
+            'last_cid'                   => $book->last_cid,
+            'last_chapter'               => $book->last_chapter,
+            'first_cid'                  => $book->first_cid,
+            'is_on_user_shelf'           => $book->is_on_user_shelf,
+            'last_chapter_is_vip'        => $book->last_chapter_is_vip ?? 0,
+            'is_need_charge'             => $book->is_need_charge ? 1 : 0,
+            'record_chapter_id'          => $book->record_chapter_id ?? 0,
+            'record_chapter_name'        => $book->record_chapter_name ?? '',
         ];
     }
 }

+ 26 - 4
app/Http/Controllers/QuickApp/WelcomeController.php

@@ -2,6 +2,9 @@
 
 namespace App\Http\Controllers\QuickApp;
 
+use App\Modules\AdPosition\Services\AdPositionService;
+use App\Modules\SendOrder\Models\QappSendOrder;
+use App\Modules\User\Models\QappChannelAccount;
 use App\Modules\User\Services\QappPackageService;
 use Illuminate\Http\Request;
 use App\Modules\OfficialAccount\Services\CustomMsgService;
@@ -84,7 +87,7 @@ class WelcomeController extends BaseController
      *         "msg": "",
      *         "data": {}
      */
-    public function getCustomerServiceImg()
+    public function getCustomerServiceImg(Request $request)
     {
         $link = CustomMsgService::customerImgUrlByChannelId($this->distribution_channel_id);
         $name = 'zhenzhenyd';
@@ -93,6 +96,16 @@ class WelcomeController extends BaseController
         } else {
             $url = env('KE_FU_QRCODE', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
         }
+
+        // 获取客服信息
+        $package  = $request->header('x-package', '');
+        $supports = config('option.supports');
+        $support  = getProp($supports, $package, []);
+        if ($support) {
+            $url  = getProp($support, 'customerImage', 'https://cdn-novel.iycdm.com/static/img/kefu20190319.jpg');
+            $name = getProp($support, 'customerAccount', 'zhenzhenyd');
+        }
+
         return response()->success(compact('url', 'name'));
     }
 
@@ -103,12 +116,21 @@ class WelcomeController extends BaseController
     public function getOptions(Request $request)
     {
         // 获取包名
-        $package = $request->header('x-package', '');
+        $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,
@@ -117,8 +139,8 @@ class WelcomeController extends BaseController
                 'pay_back_alert_show' => 1,
             ],
             'position'    => [
-                'home_alert'    => [],
-                'reader_banner' => []
+                'home_alert'    => getProp($adPositions, 'home_alert', []),
+                'reader_banner' => getProp($adPositions, 'reader_banner', [])
             ]
         ];
 

+ 45 - 0
app/Libs/Singleton.php

@@ -0,0 +1,45 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: wangchen
+ * Date: 2019-04-23
+ * Time: 11:42
+ */
+
+namespace App\Libs;
+
+trait Singleton
+{
+    /**
+     * 该属性用来保存实例
+     * @var
+     */
+    private static $instance;
+
+    /**
+     * 创建一个用来实例化对象的方法
+     */
+    public static function getInstance(...$args)
+    {
+        return new static($args);
+//        if (!(self::$instance instanceof self)) {
+//            self::$instance = new static($args); // 后期静态绑定
+//        }
+//        return self::$instance;
+    }
+
+    /**
+     * 构造函数为private,防止创建对象
+     */
+    public function __construct()
+    {
+    }
+
+    /**
+     * 防止对象被复制
+     */
+    private function __clone()
+    {
+        trigger_error('Clone is not allowed!');
+    }
+}

+ 29 - 0
app/Libs/Utils.php

@@ -60,6 +60,35 @@ class Utils
     }
 
     /**
+     * 加密批量bid
+     * @param $bids
+     * @return array
+     */
+    public static function getEncodeIds($bids)
+    {
+        return array_map(function ($bid) {
+            return Hashids::encode($bid);
+        }, $bids);
+    }
+
+    /**
+     * 审核状态判断,true为审核状态,false默认
+     * @param $package
+     * @param $brand
+     * @param $codeVersion
+     * @return bool
+     */
+    public static function checkIsAudit($package, $brand, $codeVersion): bool
+    {
+        $audit = getProp(config('audit'), $package, []);
+        if ($audit && $codeVersion === getProp($audit, 'codeVersion') && strtolower($brand) === getProp($audit, 'brand')) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
      * 获取redis的key
      * @param       $keyStr // 例如:wap.rank_page
      * @param array $args // 例如:[10, 2000]

+ 14 - 0
app/Modules/Ad/Models/QappAdPosition.php

@@ -0,0 +1,14 @@
+<?php
+
+
+namespace App\Modules\Ad\Models;
+
+
+use Illuminate\Database\Eloquent\Model;
+
+class QappAdPosition extends Model
+{
+    protected $table = 'qapp_ad_position';
+    protected $fillable = ['name', 'ident', 'max_num', 'content_type', 'property', 'show_type', 'status'];
+    
+}

+ 15 - 0
app/Modules/Ad/Models/QappAdPositionDispatch.php

@@ -0,0 +1,15 @@
+<?php
+
+
+namespace App\Modules\Ad\Models;
+
+
+use Illuminate\Database\Eloquent\Model;
+
+class QappAdPositionDispatch extends Model
+{
+    protected $table = 'qapp_ad_position_dispatch';
+    protected $fillable = ['title', 'ad_position_id', 'link_url', 'link_type', 'image_url', 'desc', 'type', 'content_type',
+        'priority', 'status', 'filter_condition', 'channel_id', 'qapp_account_id', 'start_time', 'end_time'];
+
+}

+ 23 - 0
app/Modules/AdPosition/Models/AdPosition.php

@@ -0,0 +1,23 @@
+<?php
+
+
+namespace App\Modules\AdPosition\Models;
+
+
+use Illuminate\Database\Eloquent\Model;
+
+class AdPosition extends Model
+{
+    protected $table = 'qapp_ad_position';
+    protected $fillable = ['name', 'ident', 'max_num', 'content_type', 'property', 'show_type', 'status', 'default_img'];
+
+    /**
+     * 获取所有有效的广告位
+     * @return array
+     */
+    public static function getAllValidAdPositions(): array
+    {
+        $result = self::where('status', 1)->get();
+        return $result ? $result->toArray() : [];
+    }
+}

+ 38 - 0
app/Modules/AdPosition/Models/AdPositionDispatch.php

@@ -0,0 +1,38 @@
+<?php
+
+
+namespace App\Modules\AdPosition\Models;
+
+
+use Illuminate\Database\Eloquent\Model;
+
+class AdPositionDispatch extends Model
+{
+    protected $table = 'qapp_ad_position_dispatch';
+    protected $fillable = ['title', 'ad_position_id', 'link_url', 'link_type', 'image_url', 'desc', 'type', 'content_type',
+        'priority', 'status', 'filter_condition', 'channel_id', 'qapp_account_id', 'start_time', 'end_time'];
+
+    /**
+     * 获取有效的广告位分配
+     * @param $adPositionIds
+     * @param $qappAccountId
+     * @return array
+     */
+    public static function getValidPositionDispatches($adPositionIds, $qappAccountId): array
+    {
+        if (empty($adPositionIds) || empty($qappAccountId)) {
+            return [];
+        }
+
+        $result = self::whereIn('ad_position_id', $adPositionIds)
+            ->where('qapp_account_id', $qappAccountId)
+            ->where('status', 1)
+            ->where('start_time', '<=', date('Y-m-d H:i:s'))
+            ->where('end_time', '>=', date('Y-m-d H:i:s'))
+            ->orderBy('priority', 'DESC')
+            ->orderBy('end_time', 'ASC')
+            ->get();
+
+        return $result ? $result->toArray() : [];
+    }
+}

+ 166 - 0
app/Modules/AdPosition/Services/AdPositionService.php

@@ -0,0 +1,166 @@
+<?php
+
+
+namespace App\Modules\AdPosition\Services;
+
+
+use App\Libs\Singleton;
+use App\Modules\AdPosition\Models\AdPosition;
+use App\Modules\AdPosition\Models\AdPositionDispatch;
+use App\Modules\Trade\Services\OrderService;
+use App\Modules\User\Models\QappUser;
+
+class AdPositionService
+{
+    use Singleton;
+
+    /**
+     * @param $uid
+     * @param $accountId
+     * @return array
+     */
+    public function getAdPositions($uid, $accountId): array
+    {
+        // 参数判断
+        if (empty($uid) || empty($accountId)) {
+            return [];
+        }
+
+        // 获取广告位
+        $positions = AdPosition::getAllValidAdPositions();
+        if (empty($positions)) {
+            return [];
+        }
+
+        // 获取广告位分配信息
+        $positionIds = array_column($positions, 'id');
+        $dispatches  = AdPositionDispatch::getValidPositionDispatches($positionIds, $accountId);
+        if (empty($dispatches)) {
+            return [];
+        }
+
+        // 针对分配数据筛选出优先级最高的分配任务
+        $result     = [];
+        $dispatches = collect($dispatches)->groupBy('ad_position_id')->all();
+        foreach ($positions as $position) {
+            // 相关变量获取
+            $positionId        = getProp($position, 'id');
+            $ident             = getProp($position, 'ident');
+            $filterContentJson = getProp($position, 'filter_condition');
+
+            // 获取优先级最高的任务
+            $validDispatches = getProp($dispatches, $positionId, []);
+            $validDispatch   = $validDispatches ? $validDispatches[0] : [];
+            if (empty($validDispatch)) {
+                continue;
+            }
+
+            // 过滤条件判断
+            $matchFilter = $this->filterDispatch($uid, $filterContentJson);
+            if (!$matchFilter) {
+                continue;
+            }
+
+            // 添加到数据中
+            $result[$ident][] = $this->buildPositionData($validDispatch, $position);
+        }
+
+        return $result;
+    }
+
+    /**
+     * 过滤条件筛选
+     * @param $uid
+     * @param $filterContentJson
+     * @return bool
+     */
+    private function filterDispatch($uid, $filterContentJson): bool
+    {
+        // 过滤条件
+        $filterContent = json_decode($filterContentJson, true);
+        if (empty($uid) || empty($filterContentJson) || empty($filterContent)) {
+            return true;
+        }
+
+        // 判断注册时间
+        $registerFilter = true;
+        $registerAtArr  = getProp($filterContent, 'registerAt');
+        if ($registerAtArr) {
+            // 默认值
+            $registerFilter = false;
+
+            // 获取用户信息
+            $user         = QappUser::getUserByUid($uid);
+            $registerAt   = getProp($user, 'created_at');
+            $registerUnix = strtotime($registerAt);
+
+            // 循环条件,满足一条即可
+            foreach ($registerAtArr as $register) {
+                $unit  = getProp($register, 'unit');
+                $range = getProp($register, 'range');
+                sort($range);
+                [$min, $max] = $range;
+                $startUnix = strtotime('-' . $max . ' ' . $unit);
+                $endUnix   = strtotime('-' . $min . ' ' . $unit);
+                if ($registerUnix >= $startUnix && $registerUnix <= $endUnix) {
+                    $registerFilter = true;
+                    break;
+                }
+            }
+        }
+
+        // 判断付费情况
+        $paidFilter = true;
+        if (isset($filterContent['isPaid'])) {
+            // 默认值
+            $paidFilter = false;
+
+            // 获取用户付费情况
+            $order = OrderService::getUserLastestOrder($uid);
+
+            // 有付费
+            if ($order && $filterContent['isPaid']) {
+                $paidFilter = true;
+            }
+
+            // 未付费
+            if (!$order && !$filterContent['isPaid']) {
+                $paidFilter = true;
+            }
+        }
+
+        // 两者全部满足条件才可展示
+        return $registerFilter && $paidFilter;
+    }
+
+    /**
+     * 返回可显示数据
+     * @param $validDispatch
+     * @param $position
+     * @return array
+     */
+    private function buildPositionData($validDispatch, $position): array
+    {
+        if (empty($validDispatch)) {
+            return [];
+        }
+
+        // 链接做特殊处理
+        $url    = getProp($validDispatch, 'link_url');
+        $urlArr = parse_url($url);
+        parse_str(getProp($urlArr, 'query'), $queryArr);
+
+        // 广告位图片
+        $image = getProp($validDispatch, 'image_url');
+        if (empty($image)) {
+            $image = getProp($position, 'default_img');
+        }
+
+        return [
+            'img'    => $image,
+            'url'    => getProp($urlArr, 'path'),
+            'title'  => getProp($validDispatch, 'title'),
+            'params' => $queryArr ?: (object)[]
+        ];
+    }
+}

+ 61 - 0
app/Modules/Book/Services/BookAuditService.php

@@ -0,0 +1,61 @@
+<?php
+
+
+namespace App\Modules\Book\Services;
+
+
+use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
+
+class BookAuditService
+{
+    /**
+     * 审核数据
+     * @param $sex
+     * @return array
+     */
+    public static function getHomeBooksData($sex): array
+    {
+        // 基本配置数据
+        $home = config('home');
+
+        // banner
+        $banner      = $home['reco_banner'];
+        $bannerBooks = $banner[$sex];
+
+        // 模块
+        [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
+        [$hotBids, $liveBids, $recomBids, $newBids] = [$hot[$sex], $live[$sex], $recom[$sex], $new[$sex]];
+
+        // 一次性获取书籍列表
+        $bids  = array_merge($hotBids, $liveBids, $recomBids, $newBids);
+        $books = BookConfigService::getBooksByIds($bids);
+
+        return [
+            [
+                'type'  => 'reco_banner',
+                'lable' => $banner['label'],
+                'books' => $bannerBooks
+            ],
+            [
+                'type'  => 'hot',
+                'lable' => $hot['label'],
+                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
+            ],
+            [
+                'type'  => 'zhibo',
+                'lable' => $live['label'],
+                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
+            ],
+            [
+                'type'  => 'recom',
+                'lable' => $recom['label'],
+                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
+            ],
+            [
+                'type'  => 'new_recom',
+                'lable' => $new['label'],
+                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
+            ],
+        ];
+    }
+}

+ 30 - 0
app/Modules/SendOrder/Models/QappSendOrder.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Modules\SendOrder\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class QappSendOrder extends Model
+{
+    protected $table = 'qapp_send_orders';
+    protected $fillable = [
+        'send_order_id',
+        'account',
+        'channel_user_id',
+        'distribution_channel_id',
+    ];
+
+    /**
+     * @param $sendOrderId
+     * @return array
+     */
+    public static function getSendOrderById($sendOrderId)
+    {
+        if (empty($sendOrderId)) {
+            return [];
+        }
+
+        $result = self::where('send_order_id', $sendOrderId)->first();
+        return $result ? $result->toArray() : [];
+    }
+}

+ 0 - 13
app/Modules/SendOrder/Models/QuickAppSendOrder.php

@@ -14,17 +14,4 @@ class QuickAppSendOrder extends Model
         'child_gzh_name',
     ];
 
-    /**
-     * @param $sendOrderId
-     * @return array
-     */
-    public static function getSendOrderById($sendOrderId)
-    {
-        if (empty($sendOrderId)) {
-            return [];
-        }
-        
-        $result = self::where('id', $sendOrderId)->first();
-        return $result ? $result->toArray() : [];
-    }
 }

+ 9 - 0
app/Modules/Trade/Models/Order.php

@@ -460,4 +460,13 @@ class Order extends Model
 
         return $result ? $result->toArray() : [];
     }
+
+    public static function getUserLastestOrder($uid)
+    {
+        if (empty($uid)) {
+            return [];
+        }
+
+        return self::where('uid', $uid)->where('status', 'PIAD')->orderBy('id')->limit(1)->get();
+    }
 }

+ 5 - 0
app/Modules/Trade/Services/OrderService.php

@@ -210,4 +210,9 @@ class OrderService
     {
         return Order::getOrdersByActivityId($channelId, $createdAt, $activityId);
     }
+
+    public static function getUserLastestOrder($uid)
+    {
+        return Order::getUserLastestOrder($uid);
+    }
 }

+ 13 - 0
app/Modules/User/Models/QappUser.php

@@ -18,4 +18,17 @@ class QappUser extends Model
         'phone',
         'channel_id',
     ];
+
+    /**
+     * @param $uid
+     * @return array
+     */
+    public static function getUserByUid($uid)
+    {
+        if (empty($uid)) {
+            return [];
+        }
+
+        return self::where('uid', $uid)->first();
+    }
 }

+ 7 - 0
config/audit.php

@@ -0,0 +1,7 @@
+<?php
+return [
+    'com.app.kyy.xjxs' => [
+        'brand'       => 'huawei',
+        'codeVersion' => '0.0.2'
+    ],
+];

+ 45 - 4
config/home.php

@@ -1,18 +1,59 @@
 <?php
 return [
-    'hot'       => [
+    'reco_banner' => [
+        'label'  => '首页banner',
+        'male'   => [
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145102SYGL.jpg',
+                'bid'          => 'vEY8QJe51DA9WKoekOg7Bj6bmGM2qPXr', // 11529 神医归来
+                'cid'          => 0
+            ],
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145004ZQSS.jpg',
+                'bid'          => 'pNo6A7wqQmB1WgQ5NrgDjkOM9VZn2vXe', // 11601 最强杀手
+                'cid'          => 0
+            ],
+        ],
+        'female' => [
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145001JSWL.jpg',
+                'bid'          => '2JWv0Xk1B3yqYRPkqYg6Gejno54PZrO9', // 10479 江山万里不如你
+                'cid'          => 0
+            ],
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145101JJDZXQ.jpg',
+                'bid'          => '0DNW9mYOqL7XGg3NpxlPk16eQx45dB8w', // 10467 将军的掌心妻
+                'cid'          => 0
+            ],
+            [
+                'redirect_url' => 'views/Detail',
+                'banner_url'   => 'https://cdn-novel.iycdm.com/h5/reco_banner/20200820145103SSYF.jpg',
+                'bid'          => '0DNW9mYOqL7XGg3N3YlPk16eQx45dB8w', // 10823 圣手医妃
+                'cid'          => 0
+            ]
+        ],
+    ],
+    'hot'         => [
+        'label'  => '今日主推',
         'male'   => [11601, 11529, 3365, 11833, 11543, 10377],
         'female' => [1479, 7836, 7891, 8129, 8167, 8337],
     ],
-    'live'      => [
+    'zhibo'       => [
+        'label'  => '大家都在看',
         'male'   => [11696, 2533, 6458, 9024, 11457, 11498],
         'female' => [8469, 8557, 9117, 9997, 8148, 8476],
     ],
-    'recom'     => [
+    'recom'       => [
+        'label'  => '主编精选',
         'male'   => [11506, 11674, 11826, 2563, 11499, 9509],
         'female' => [9423, 9248, 9973, 9990, 11766, 7629],
     ],
-    'new_recom' => [
+    'new_recom'   => [
+        'label'  => '畅销精品',
         'male'   => [10986, 11674, 10375, 10378, 11496, 11501],
         'female' => [10139, 9248, 7854, 1576, 1952, 2434],
     ],

+ 5 - 1
config/option.php

@@ -5,6 +5,10 @@ return [
         'com.beidao.kuaiying.zsy' => [
             'customerAccount' => 'zhenzhenyd',
             'customerImage'   => 'https://cdn-novel.iycdm.com/static/img/kefu20190331.png'
-        ]
+        ],
+        'com.app.kyy.xjxs'        => [
+            'customerAccount' => 'youyou1552',
+            'customerImage'   => 'http://zhuishuyun.oss-cn-hangzhou.aliyuncs.com/service/customimage_868_1552544217.%E5%AE%A2%E6%9C%8D.jpg'
+        ],
     ]
 ];