<?php

namespace General\Controllers\CompanyAuth;

use App\Consts\SysConsts;
use App\Http\Controllers\Controller;
use General\Controllers\CompanyAuth\Transformers\ActivityTransformer;
use General\Controllers\CompanyAuth\Transformers\ChannelTransformer;
use General\Controllers\CompanyAuth\Transformers\CustomSendMsgsTransformers;
use General\Controllers\CompanyAuth\Transformers\DelaySendMsgsTransformers;
use General\Controllers\CompanyAuth\Transformers\OfficialAccountTransformer;
use General\Controllers\CompanyAuth\Transformers\OrderDayStatsTransformer;
use General\Controllers\CompanyAuth\Transformers\OrderTransformer;
use General\Controllers\CompanyAuth\Transformers\SendOrderTransformer;
use General\Helpers\CommonHelper;
use General\Models\OfficialAccount\OfficialAccount;
use General\Requests\CompanyAuth\BookQueryRequest;
use General\Requests\CompanyAuth\CustomSendMsgRequest;
use General\Requests\CompanyAuth\ChannelQueryRequest;
use General\Requests\CompanyAuth\SingleSendOrderRequest;
use General\Services\Activity\ActivityService;
use General\Services\BaseAuthConfig;
use General\Services\Book\BookConfigService;
use General\Services\Channel\ChannelService;
use General\Services\OfficialAccount\OfficialAccountService;
use General\Services\Order\OrderService;
use General\Services\SendOrder\SendOrderService;
use General\Services\SendOrder\SendOrderStatistic;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class AppController extends Controller
{
    use BaseAuthConfig;
    /**
     * @apiDefine CompanyAuth 第三方授权接口
     */

    /**
     * @api {post} company/auth/channels 授权站点列表
     * @apiVersion 1.0.0
     * @apiName channels
     * @apiGroup CompanyAuth
     * @apiParam {String} is_enabled 状态(0.未启用 1.已启用)
     * @apiParam {String} phone 手机号
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiError {int}         code 状态码
     * @apiError {String}      msg  信息
     * @apiErrorExample {json} Error-Response:
     * HTTP/1.1 200 OK
     * [
     *   {
     *        'code' : 10030,
     *        'msg' : '未授权!'
     *   },
     *   {
     *        'code' : 10031,
     *        'msg' : 'IP未授权!'
     *   },
     *   {
     *        'code' : 10032,
     *        'msg' : '授权时间已过期!'
     *   },
     *   {
     *        'code' : 10033,
     *        'msg' : '授权签名错误!'
     *   },
     *   {
     *        'code' : 10034,
     *        'msg' : '查询数据为空!'
     *   },
     *   {
     *        'code' : 10035,
     *        'msg' : '查询数据时间长度不能超过30天!'
     *   },
     *   {
     *        'code' : 1002,
     *        'msg' : '查询参数错误!'
     *   },
     * ]
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Int}         id 渠道ID
     * @apiSuccess {String}      name 渠道名称
     * @apiSuccess {String}      created_at 创建时间
     * @apiSuccess {String}      site_nick_name 站点昵称
     * @apiSuccess {String}      is_enabled 状态(0.未启用 1.已启用)
     * @apiSuccess {String}      phone 手机号
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     *   {
     *       "code": 0,
     *       "msg": "",
     *       "data": [
     *           {
     *               "id": 130,
     *               "name": "杭州微点",
     *               "created_at": "2018-01-05 09:57:37",
     *               "site_nick_name": "2018-01-05 09:57:37",
     *               "is_enabled": "1",
     *               "phone": "13888888888"
     *           }
     *       ]
     *   }
     */
    public function channels(Request $request)
    {
        $is_enabled = $request->get('is_enabled', '');
        $phone = $request->get('phone', '');
        $service = new ChannelService;
        $channels = $service->getChannelsByChannelUserIds($this->channel_user_ids, $is_enabled, $phone);
        $result = collectionTransform(new ChannelTransformer, $channels);
        return response()->success($result);
    }

    /**
     * @api {post} company/auth/officialAccounts 服务号列表
     * @apiVersion 1.0.0
     * @apiName officials
     * @apiGroup CompanyAuth
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Int}         id 渠道ID
     * @apiSuccess {Int}         channel_id 站点ID
     * @apiSuccess {String}      app_id 服务号APPID
     * @apiSuccess {String}      name 渠道名称
     * @apiSuccess {String}      created_at 创建时间
     * @apiSuccess {String}      sort_no 关注优先级 
     * @apiSuccessExample {json} Success-Response:
     *   {
     *       "code": 0,
     *       "msg": "",
     *       "data": [
     *           {
     *               "app_id": '',
     *               "channel_id": 130,
     *               "name": "半烟溪桥",
     *               "created_at": "2018-01-06 10:38:36"
     *           }
     *       ]
     *   }
     */
    public function officialAccounts(Request $request)
    {
        $phone = $request->get('phone', '');
        $is_enable = $request->get('is_enabled', '');
        if(!empty($phone)) {
            $channel = new ChannelService();
            $distribution_channels = $channel->getChannelsByChannelUserIds([],$is_enable,$phone);
            if($distribution_channels){
                $distribution_channels = $distribution_channels->toArray();
                $this->channel_ids = array_column($distribution_channels,'id');
            }
        }
        $service = new OfficialAccountService;
        $result = collectionTransform(new OfficialAccountTransformer, $service->getOfficialAccountsByChannelIds($this->channel_ids));
        return response()->success($result);
    }

    /**
     * @api {post} company/auth/orders 订单
     * @apiVersion 1.0.0
     * @apiName orders
     * @apiGroup CompanyAuth
     * @apiParam {String} channel_id 站点id
     * @apiParam {String} status 支付状态 PAID:已支付, UNPAID: 未支付
     * @apiParam {String} begin_date 开始时间(时间区间小于60天,格式yyyy-MM-dd HH:mm:ss)
     * @apiParam {String} end_date 截止时间(时间区间小于60天,格式yyyy-MM-dd HH:mm:ss)
     * @apiParam {Int} page 分页页码
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Object}      list 数据结果
     * @apiSuccess {Object}      meta 分页信息
     * @apiSuccess {Int}      total 分页总数
     * @apiSuccess {Int}      uid 用户UID
     * @apiSuccess {Object}      price 充值金额
     * @apiSuccess {String}      trade_no 订单号
     * @apiSuccess {String}      status 支付状态 PAID:已支付, UNPAID: 未支付
     * @apiSuccess {String}      created_at 创建时间
     * @apiSuccess {String}      pay_end_at 支付时间
     * @apiSuccess {Int}         send_order_id 派单ID
     * @apiSuccess {String}      send_order_name 派单名称
     * @apiSuccess {String}      promotion_url 派单链接
     * @apiSuccess {String}      activity_name 活动名称
     * @apiSuccess {String}      keyword 关键词
     * @apiSuccess {Int}         user_charge_times 充值次数
     * @apiSuccess {String}      bid 书号
     * @apiSuccess {String}      book_name 书名
     * @apiSuccess {String}      register_time 用户注册时间
     * @apiSuccess {String}      subscribe_time 关注时间
     * @apiSuccess {String}      app_id 关注app_id
     * @apiSuccess {String}      opend_id 关注公众号的openid,只有强关了才有(公众号号是渠道授权的,用户得点击系统返回的带openid的参数的链接,访问后才算强关,或者从强关二维码进来的也算)
     * @apiSuccess {String}      register_open_id 分销后台订单的openid(是平台系统默认的静默登录的openid)
     * @apiSuccess {String}      wechat_name 关注公众号
     * @apiSuccess {String}      order_type 订单类型[普通充值、包年、包月、包季]
     * @apiSuccess {String}      push_msg_id 推送消息id,标记用[custom_开头是客服消息,template_开头是模板消息,下划线后是id]
     * @apiSuccess {String}      ip 订单创建IP地址
     * @apiSuccess {Int}         activity_id 活动ID
     *     HTTP/1.1 200 OK
     *   {
     *       "code": 0,
     *       "msg": "",
     *       "data": {
     *           "list": [
     *               {
     *                   "uid": 162261533,
     *                   "price": 200.5,
     *                   "trade_no": "343333235sdrf",
     *                   "status": "PAID",
     *                   "created_at": "2019-12-24 11:43:58",
     *                   "pay_end_at": "2019-12-24 11:43:58",
     *                   "send_order_id": 1,
     *                   "send_order_name": "1",
     *                   "activity_name": "",
     *                   "keyword": "",
     *                   "user_charge_times": 1,
     *                   "push_msg_id": "custom_4041988",
     *                   "ip": "36.18.52.247",
     *                   "activity_id": 2522,
     *               }
     *           ],
     *           "meta": {
     *               "total": 1,
     *               "per_page": 100,
     *               "current_page": 1,
     *               "total": 1,
     *               "next_page_url": "",
     *               "prev_page_url": ""
     *           }
     *       }
     *  }
     */
    public function orders(ChannelQueryRequest $request)
    {
        $channel_id = $request->get('channel_id');
        $status = $request->get('status');
        $begin_date = $request->get('begin_date', date('Y-m-d', strtotime('-7 days')));
        $end_date = $request->get('end_date', date('Y-m-d', strtotime('+1 days')));
        if (strtotime($end_date) - strtotime($begin_date) > SysConsts::ONE_DAY_SECONDS * 60) {
            return response()->error('COMPANY_AUTH_OVER_TIME');
        } else {
            $service = new OrderService;
            $result = $service->companyAuthOrders(compact('channel_id', 'status', 'begin_date', 'end_date'));
            $appIds = OfficialAccount::where('distribution_channel_id',$channel_id)->get()->pluck('appid')->toArray();
            foreach($result as $key => $item){
                $result[$key]['app_ids'] = count($appIds) > 0 ? array_filter($appIds) : [];
            }

            return response()->pagination(new OrderTransformer(), $result);
        }
    }

    /**
     * 添加书币
     * @apiVersion 1.0.0
     * @apiName addBookCoin
     * @apiGroup CompanyAuth
     * @apiParam {String} channel_id 站点id
     * @apiParam {String} uid 用户ID
     * @apiParam {String} openid 用户openid
     * @apiParam {String} amount 书币
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     *     HTTP/1.1 200 OK
     *   {
     *       "code": 0,
     *       "msg": "",
     *       "data": {
     *           "success": 1
     *       }
     *  }
     */
    public function addBookCoin(ChannelQueryRequest $request)
    {
        $channel_id = $request->get('channel_id');
        $uid = $request->get('uid');
        $openid = $request->get('openid');
        $amount = (int)$request->get('amount');
        $limit_amount = 2000;

        // 参数判断
        if ((empty($openid) && empty($uid)) || empty($channel_id) || empty($amount) || $amount < 0 || $amount > $limit_amount) {
            return response()->json(['code'=>-1, 'msg'=>'传参有误!']);
        }

        // 获取当前用户信息
        $user_info = '';
        if (!empty($uid)) {
            $user_info = $prev_coin = DB::connection('mysql')->table('users')->where(['id'=>$uid, 'distribution_channel_id'=>$channel_id])
                ->select('id', 'distribution_channel_id', 'balance', 'reward_balance')->first();
        }else if(!empty($openid)) {
            $user_info = $prev_coin = DB::connection('mysql')->table('users')
                ->where(['distribution_channel_id'=>$channel_id, 'openid'=>$openid])
                ->select('id', 'distribution_channel_id', 'balance', 'reward_balance')->first();
        }
        $user_info = (array)$user_info;
        if (!$user_info) return response()->json(['code'=>-1, 'msg'=>'用户不存在!']);

        // 当日该站点该用户获得的总书币
        $sum = DB::connection('mysql')->table('user_coin_logs')->where(['distribution_channel_id'=>$channel_id, 'uid'=>$user_info['id'], 'day'=>date('Y-m-d')])->sum('amount');

        if ($sum + $amount > $limit_amount) {
            return response()->json(['code' => -1, 'msg' => '每个用户每个站点每日加书币的总额不得超过'.$limit_amount.'!']);
        }

        try {
            DB::connection('mysql')->beginTransaction();
            $result = DB::connection('mysql')->table('users')->where(['id'=>$user_info['id']])->update([
                'balance' => $user_info['balance'] + $amount,
                'reward_balance' => $user_info['reward_balance'] + $amount,
            ]);

            if (!$result) {
                DB::connection('mysql')->rollback();
                return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
            }

            $boolen = DB::connection('mysql')->table('user_coin_logs')->insert([
                'distribution_channel_id'   => $user_info['distribution_channel_id'],
                'uid'                       => $user_info['id'],
                'day'                       => date('Y-m-d'),
                'before'                    => $user_info['balance'],
                'amount'                    => $amount,
                'after'                     => $user_info['balance'] + $amount,
                'created_at'                => date('Y-m-d H:i:s'),
                'updated_at'                => date('Y-m-d H:i:s'),
            ]);

            if (!$boolen) {
                DB::connection('mysql')->rollback();
                return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
            }

            DB::connection('mysql')->commit();
        }catch(\Exception $e) {
            DB::connection('mysql')->rollback();
            return response()->json(['code'=>-1, 'msg'=>$e->getMessage()]);
        }
        return response()->json(['code'=>1, 'msg'=>'', 'data'=>['success' => 1]]);
    }

    /**
     * 添加书币或会员有效期
     * @apiVersion 1.0.0
     * @apiName addBookCoinV2
     * @apiGroup CompanyAuth
     * @apiParam {String} channel_id 站点id
     * @apiParam {String} uid 用户ID
     * @apiParam {String} openid 用户openid
     * @apiParam {String} type 类型(coin: 加书币 day: 加会员有效期,单位: 天)
     * @apiParam {String} [amount]  书币(type类型为coin时必填)
     * @apiParam {String} [day]  书币(type类型为day时必填)
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     *     HTTP/1.1 200 OK
     *   {
     *       "code": 0,
     *       "msg": "",
     *       "data": {
     *           "success": 1
     *       }
     *  }
     */
    public function addBookCoinV2(ChannelQueryRequest $request)
    {
        $channel_id = $request->get('channel_id');
        $uid = $request->get('uid');
        $openid = $request->get('openid');
        $app_id = $request->get('app_id');
        $amount = (int)$request->get('amount');
        $type = $request->get('type');
        $day = $request->get('day');
        $limit_amount = 20000;
//        $limit_users = 20;

        // 参数判断
        if ((empty($openid) && empty($uid)) || empty($channel_id)  || empty($type) || !in_array($type, ['coin', 'day'])) {
            return response()->json(['code'=>-1, 'msg'=>'传参有误!']);
        }

        if ($type == 'coin' && (empty($amount) || $amount < 0 || $amount > $limit_amount)) return response()->json(['code'=>-1, 'msg'=>'传参有误!']);
        if ($type == 'day' && (empty($day) || $day < 0 || $day > 366)) return response()->json(['code'=>-1, 'msg'=>'传参有误!']);

        // 获取当前用户信息
        $user_info = '';
        if (!empty($uid)) {
            $user_info = $prev_coin = DB::connection('mysql')->table('users')->where(['id'=>$uid, 'distribution_channel_id'=>$channel_id])
                ->select('id', 'distribution_channel_id', 'balance', 'reward_balance')->first();
        }else if(!empty($openid)) {
            $user_info = $prev_coin = DB::connection('mysql')->table('users')
                ->where(['distribution_channel_id'=>$channel_id, 'openid'=>$openid])
                ->select('id', 'distribution_channel_id', 'balance', 'reward_balance')->first();
        }
        $user_info = (array)$user_info;
        if (!$user_info) return response()->json(['code'=>-1, 'msg'=>'用户不存在!']);

        if ($type == 'day') {   // 加包时日期
            $year_order = DB::connection('mysql')->table('year_orders')->where(['distribution_channel_id'=>$channel_id, 'uid'=>$user_info['id']])->select('id', 'end_time')->first();

            try {
                DB::connection('mysql')->beginTransaction();

                if ($year_order) {
                    $year_order = (array)$year_order;
                    $before_end_time = $year_order['end_time'];
                    $after_end_time = date('Y-m-d H:i:s', (strtotime($before_end_time) + $day * 86400));
                    $result = DB::connection('mysql')->table('year_orders')->where(['id'=>$year_order['id']])->update([
                        'end_time'      => $after_end_time,
                        'updated_at'    => date('Y-m-d H:i:s')
                    ]);
                }else {
                    $before_end_time = date('Y-m-d H:i:s');
                    $after_end_time = date('Y-m-d H:i:s', (time() + $day * 86400));
                    $result = DB::connection('mysql')->table('year_orders')->insert([
                        'uid'                       => $user_info['id'],
                        'begin_time'                => $before_end_time,
                        'end_time'                  => $after_end_time,
                        'distribution_channel_id'   => $channel_id,
                        'send_order_id'             => 0,
                        'created_at'                => date('Y-m-d H:i:s'),
                        'updated_at'                => date('Y-m-d H:i:s'),
                    ]);
                }

                if (!$result) {
                    DB::connection('mysql')->rollback();
                    return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
                }

                $boolen = DB::connection('mysql')->table('user_coin_logs')->insert([
                    'distribution_channel_id'   => $user_info['distribution_channel_id'],
                    'uid'                       => $user_info['id'],
                    'day'                       => date('Y-m-d'),
                    'before_end_time'           => $before_end_time,
                    'day_num'                   => $day,
                    'after_end_time'            => $after_end_time,
                    'type'                      => 2,
                    'created_at'                => date('Y-m-d H:i:s'),
                    'updated_at'                => date('Y-m-d H:i:s'),
                ]);

                if (!$boolen) {
                    DB::connection('mysql')->rollback();
                    return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
                }

                DB::connection('mysql')->commit();
            }catch(\Exception $e) {
                DB::connection('mysql')->rollback();
                return response()->json(['code'=>-1, 'msg'=>$e->getMessage()]);
            }
            return response()->json(['code'=>1, 'msg'=>'', 'data'=>['success' => 1]]);
        }else {     // 加书币
            // 当日该站点该用户获得的总书币
            $sum = DB::connection('mysql')->table('user_coin_logs')->where(['distribution_channel_id'=>$channel_id, 'uid'=>$user_info['id'], 'day'=>date('Y-m-d')])->sum('amount');

            if ($sum + $amount > $limit_amount) {
                return response()->json(['code' => -1, 'msg' => '每个用户每个站点每日加书币的总额不得超过'.$limit_amount.'!']);
            }

            //商户书币限制
            $limit_users = DB::connection('mysql')->table('company_auth_configs')->where('app_id',$app_id)->value('today_user_numbers');
            if(!$limit_users || empty($limit_users)){
                $limit_users = 20;
            }

            // 当日该站点加过书币的总用户数
            $today_users = DB::connection('mysql')->table('user_coin_logs')->where(['distribution_channel_id'=>$channel_id, 'day'=>date('Y-m-d')])->groupBy(['uid'])->get()->pluck('uid')->toArray();
            if (count($today_users) > $limit_users) return response()->json(['code' => -1, 'msg' => '每个站点每日加书币的用户数不得超过'.$limit_users.'!']);
            if (count($today_users) == $limit_users && !in_array($uid, $today_users)) return response()->json(['code' => -1, 'msg' => '每个站点每日加书币的用户数不得超过'.$limit_users.'!']);

            try {
                DB::connection('mysql')->beginTransaction();
                $result = DB::connection('mysql')->table('users')->where(['id'=>$user_info['id']])->update([
                    'balance' => $user_info['balance'] + $amount,
                    'reward_balance' => $user_info['reward_balance'] + $amount,
                ]);

                if (!$result) {
                    DB::connection('mysql')->rollback();
                    return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
                }

                $boolen = DB::connection('mysql')->table('user_coin_logs')->insert([
                    'distribution_channel_id'   => $user_info['distribution_channel_id'],
                    'uid'                       => $user_info['id'],
                    'day'                       => date('Y-m-d'),
                    'before'                    => $user_info['balance'],
                    'amount'                    => $amount,
                    'after'                     => $user_info['balance'] + $amount,
                    'created_at'                => date('Y-m-d H:i:s'),
                    'updated_at'                => date('Y-m-d H:i:s'),
                ]);

                if (!$boolen) {
                    DB::connection('mysql')->rollback();
                    return response()->json(['code'=>-1, 'msg'=>'数据库异常!']);
                }

                DB::connection('mysql')->commit();
            }catch(\Exception $e) {
                DB::connection('mysql')->rollback();
                return response()->json(['code'=>-1, 'msg'=>$e->getMessage()]);
            }
            return response()->json(['code'=>1, 'msg'=>'', 'data'=>['success' => 1]]);
        }
    }

    /**
     * @api {post} company/auth/sendOrders 派单信息列表
     * @apiVersion 1.0.0
     * @apiName sendOrders
     * @apiGroup CompanyAuth
     * @apiParam {String} channel_id 站点id
     * @apiParam {String} begin_date 开始时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
     * @apiParam {String} end_date 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
     * @apiParam {Int} page 分页页码
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Object}      list 数据结果
     * @apiSuccess {Object}      meta 分页信息
     * @apiSuccess {Int}      total 分页总数
     * @apiSuccess {Int}      id 派单ID
     * @apiSuccess {Int}      channel_id 渠道ID
     * @apiSuccess {String}      name 派单名称
     * @apiSuccess {Int}      registerNum 注册用户数
     * @apiSuccess {Int}      chapter_id 推广章节ID
     * @apiSuccess {String}      chapter_name 推广章节
     * @apiSuccess {String}      subscribe_chapter_name 强关章节
     * @apiSuccess {Int}      totalChargeAmount 充值金额
     * @apiSuccess {Int}      fansNum 关注用户数
     * @apiSuccess {Decimal}      cost 成本
     * @apiSuccess {Int}      payUserNum 付费用户数
     * @apiSuccess {Int}      UV UV
     * @apiSuccess {Int}      PV PV
     * @apiSuccess {String}      promotion_url 推广链接
     * @apiSuccess {String}      created_at 创建时间
     * @apiSuccessExample {json} Success-Response:
     *   {
     *       "code": 0,
     *       "msg": "",
     *       "data": {
     *           "list": [
     *               {
     *                   "id": 915338,
     *                   "channel_id": 166,
     *                   "name": "qqq",
     *                   "registerNum": 0,
     *                   "chapter_name": "第二章 断子绝孙",
     *                   "subscribe_chapter_name": "第一章 出嫁",
     *                   "totalChargeAmount": 0,
     *                   "fansNum": 0,
     *                   "cost": "0.00",
     *                   "payUserNum": 0,
     *                   "PV": 0,
     *                   "UV": 0,
     *                   "promotion_url": "https://siteJKa6oWBEzR7Y5Dp8.localhost/yun/915338",
     *                   "created_at":''
     *               }
     *           ],
     *           "meta": {
     *               "total": 1,
     *               "per_page": 100,
     *               "current_page": 1,
     *               "last_page": 1,
     *               "next_page_url": "",
     *               "prev_page_url": ""
     *           }
     *       }
     *   }
     */
    public function sendOrders(ChannelQueryRequest $request)
    {
        $channel_id = $request->get('channel_id', 0);
        $begin_date = $request->get('begin_date', date('Y-m-d', strtotime('-7 days')));
        $end_date = $request->get('end_date', date('Y-m-d', strtotime('+1 days')));
        if (strtotime($end_date) - strtotime($begin_date) > SysConsts::ONE_DAY_SECONDS * 31) {
            return response()->error('COMPANY_AUTH_OVER_TIME');
        } else {
            $service = new SendOrderService;
            $result =  $service->companyAuthSendOrders(compact('channel_id', 'begin_date', 'end_date'));
            $result = (new SendOrderStatistic(collect($result->items())->pluck('id')->all()))->getDataList($result);
            return response()->pagination(new SendOrderTransformer, $result);
        }
    }

    /**
     * @api {post} company/auth/sendOrder 派单明细
     * @apiVersion 1.0.0
     * @apiName sendOrder
     * @apiGroup CompanyAuth
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {Int}    send_order_id 派单ID
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiError {int}         code 状态码
     * @apiError {String}      msg  信息
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {String}      send_order_name 渠道名称
     * @apiSuccess {Int}         distribution_channel_id 渠道ID
     * @apiSuccess {String}      bid 书号
     * @apiSuccess {String}      book_name 书名
     * @apiSuccess {Int}      cid 章节ID
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     *  {
     *      "code": 0,
     *      "msg": "",
     *      "data": {
     *          "send_order_name": "知音书苑-0315-1-张艳",
     *          "distribution_channel_id": 8,
     *          "bid": "5pNo6A7wqQmB1WgQygDjkOM9VZn2vXeY",
     *          "book_name": "一生只求一个你"
     *      }
     *  }
     */
    public function findSendOrder(SingleSendOrderRequest $request)
    {
        $send_order_id = $request->get('send_order_id');
        $service = new SendOrderService;
        $send_order = $service->findSendOrderByChannels($send_order_id, $this->channel_ids);
        if ($send_order) {
            return response()->success([
                'send_order_name' => $send_order->name,
                'distribution_channel_id' => $send_order->distribution_channel_id,
                'bid' => book_hash_encode($send_order->book_id),
                'book_name' => $send_order->book_name,
                'cid' => $send_order->chapter_id,
            ]);
        } else {
            return response()->error('COMPANY_AUTH_EMPTY');
        }
    }

    /**
     * @api {post} company/auth/dayStatistic 订单日统计数据
     * @apiVersion 1.0.0
     * @apiName dayStatistic
     * @apiGroup CompanyAuth
     * @apiParam {String} channel_id 站点id
     * @apiParam {String} begin_date 开始时间(时间区间小于30天,格式yyyy-MM-dd)
     * @apiParam {String} end_date 截止时间(时间区间小于30天,格式yyyy-MM-dd)
     * @apiParam {Int} page 分页页码
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Object}      list 数据结果
     * @apiSuccess {Object}      meta 分页信息
     * @apiSuccess {Int}      total 分页总数
     * @apiSuccess {String}      date 日期
     * @apiSuccess {Int}      channel_id 渠道ID
     * @apiSuccess {Int}      pay_number 总付费用户数
     * @apiSuccess {Int}      charge_amount 总充值金额
     * @apiSuccess {Int}      first_pay_number 首充用户数
     * @apiSuccess {Int}      first_charge_amount 首充充值金额
     * @apiSuccess {Int}      read_uv 阅读人数
     * @apiSuccess {Int}      register_number 注册用户数
     * @apiSuccess {Int}      register_pay_number 当日注册用户首充用户数
     * @apiSuccess {Int}      register_charge_amount 当日注册用户首充金额
     * @apiSuccessExample {json} Success-Response:
     *   {
     *       "code": 0,
     *       "msg": "",
     *       "data": {
     *           "list": [
     *           {
     *               "date": "2020-02-26",
     *               "channel_id": 5,
     *               "pay_number": 283,
     *               "charge_amount": "11123.11",
     *               "first_pay_number": 233,
     *               "first_charge_amount": "8013.20",
     *               "read_uv": 3598,
     *               "register_number": 1669,
     *               "register_pay_number": 201,
     *               "register_charge_amount": "6861.00"
     *            }
     *           ],
     *           "meta": {
     *               "total": 1,
     *               "per_page": 100,
     *               "current_page": 1,
     *               "last_page": 1,
     *               "next_page_url": "",
     *               "prev_page_url": ""
     *           }
     *       }
     *   }
     */
    public function dayStatistic(ChannelQueryRequest $request)
    {
        $channel_id = $request->get('channel_id', 0);
        $begin_date = $request->get('begin_date', date('Y-m-d', strtotime('-7 days')));
        $end_date = $request->get('end_date', date('Y-m-d'));
        $service = new OrderService;
        $result = $service->companyAuthDayStatistic(compact('channel_id', 'begin_date', 'end_date'));
        return response()->pagination(new OrderDayStatsTransformer, $result);
    }

    /**
     * @api {post} company/auth/chapters/free 免费章节列表
     * @apiVersion 1.0.0
     * @apiName freeChapters
     * @apiGroup CompanyAuth
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String}    bid 书号
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Int}         id 章节ID
     * @apiSuccess {Int}         next_cid 下一章章节ID
     * @apiSuccess {String}      content 章节内容
     * @apiSuccess {String}      name 章节名称
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     *  {
     *   "code": 0,
     *   "msg": "",
     *   "data": [
     *       {
     *       "id": 1,
     *       "name": "第1章 初相见",
     *       "next_cid": 1253,
     *       "content": "",
     *       },
     *       {
     *       "id": 1253,
     *       "name": "第2章 姊妹恶",
     *       "next_cid": 1252,
     *       "content": "",
     *       }
     *   ]
     *   }
     */
    public function findBookFreeChapters(BookQueryRequest $request)
    {
        $hash_bid = $request->get('bid', '');
        $bid = CommonHelper::book_hash_decode($hash_bid);
        $service = new BookConfigService;
        $chapters = $service->findBookFreeChapters($bid);
        return response()->success($chapters);
    }

    /**
     * @api {post} company/auth/customMsg 客服消息列表
     * @apiVersion 1.0.0
     * @apiName customMsg
     * @apiGroup CompanyAuth
     * @apiParam {String} start_time 创建时间:开始(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
     * @apiParam {String} end_time 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
     * @apiParam {String} send_start_time 发送时间:开始(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
     * @apiParam {String} send_end_time 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
     * @apiParam {String} book_name 书名 可选
     * @apiParam {String} name 消息名称 可选
     * @apiParam {String} channel_id 站点 
     * @apiParam {Int} page 分页页码 
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Object}      list 数据结果
     * @apiSuccess {Object}      meta 分页信息
     * @apiSuccess {Int}      total 分页总数
     * @apiSuccess {Int}      id 
     * @apiSuccess {String}      appid 微信号APPID
     * @apiSuccess {String}      name 消息名称
     * @apiSuccess {String}      send_time 消息发送时间
     * @apiSuccess {Int}         uv
     * @apiSuccess {Int}         pv
     * @apiSuccess {Int}         user_num 送达人数
     * @apiSuccess {Int}         pay_user_num 充值用户
     * @apiSuccess {Decimal}     charge_amount 充值金额
     * @apiSuccess {String}      book_name 书名
     * @apiSuccess {String}      chapter_name 章节名称
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *   "code": 0,
     *   "msg": "",
     *   "data": {
     *       "list": [
     *       {
     *           "id": 4852,
     *           "appid": null,
     *           "name": "女神小说-0430-客服消息",
     *           "send_time": "2018-04-30 14:00:00",
     *           "uv": 0,
     *           "pv": 0,
     *           "channel_id": 0,
     *           "pay_user_num": 0,
     *           "charge_amount": "",
     *           "book_name": "",
     *           "chapter_name": "",
     *           "create_at": "2018-04-30 12:40:22"
     *       },
     *       {
     *           "id": 4776,
     *           "appid": null,
     *           "name": "女神小说-0429-客服消息",
     *           "send_time": "2018-04-29 14:00:00",
     *           "uv": 0,
     *           "pv": 0,
     *           "channel_id": 0,
     *           "pay_user_num": 0,
     *           "charge_amount": "",
     *           "book_name": "",
     *           "chapter_name": "",
     *           "create_at": "2018-04-29 13:58:01"
     *       },
     *       ],
     *       "meta": {
     *       "total": 2,
     *       "per_page": 15,
     *       "current_page": 1,
     *       "last_page": 1,
     *       "next_page_url": "http://vipchannel.pre.aizhuishu.com/api/company/auth/customMsg?page=2",
     *       "prev_page_url": ""
     *       }
     *   }
     *   }
     */
    public function findCustomSendMsg(CustomSendMsgRequest $request)
    {
        $start_time = $request->get('start_time', date('Y-m-d', strtotime('-7 days')));
        $end_time = $request->get('end_time', date('Y-m-d'));
        $send_start_time = $request->get('send_start_time', '');
        $send_end_time = $request->get('send_end_time', '');
        $book_name = $request->get('book_name', '');
        $name = $request->get('name', '');
        $channel_id = $request->get('channel_id', '');
        $params = [
            'start_time' => $start_time,
            'end_time' => $end_time,
            'book_name' => $book_name,
            'name' => $name,
            'channel_id' => $channel_id,
            'send_start_time' => $send_start_time,
            'send_end_time' => $send_end_time
        ];
        if (strtotime($end_time) - strtotime($start_time) > SysConsts::ONE_DAY_SECONDS * 31) {
            return response()->error('COMPANY_AUTH_OVER_TIME');
        }
        if ($send_start_time && $send_end_time && strtotime($send_start_time) - strtotime($send_end_time) > SysConsts::ONE_DAY_SECONDS * 31) {
            return response()->error('COMPANY_AUTH_OVER_TIME');
        }
        $result = (new OfficialAccountService)->findCustomSendMsgs($params);
        return response()->pagination(new CustomSendMsgsTransformers, $result);
    }

    /**
     * @api {post} company/auth/templateSendMsg 模板消息列表
     * @apiVersion 1.0.0
     * @apiName templateSendMsg
     * @apiGroup CompanyAuth
     * @apiParam {String} start_time 创建时间:开始(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
     * @apiParam {String} end_time 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
     * @apiParam {String} send_start_time 发送时间:开始(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
     * @apiParam {String} send_end_time 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)可选
     * @apiParam {String} book_name 书名 可选
     * @apiParam {String} name 消息名称 可选
     * @apiParam {String} channel_id 站点 
     * @apiParam {Int} page 分页页码 
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Object}      list 数据结果
     * @apiSuccess {Object}      meta 分页信息
     * @apiSuccess {Int}      total 分页总数
     * @apiSuccess {Int}      id 
     * @apiSuccess {String}      appid 微信号APPID
     * @apiSuccess {String}      name 消息名称
     * @apiSuccess {String}      send_time 消息发送时间
     * @apiSuccess {Int}         uv
     * @apiSuccess {Int}         pv
     * @apiSuccess {Int}         user_num 送达人数
     * @apiSuccess {Int}         pay_user_num 充值用户
     * @apiSuccess {Decimal}     charge_amount 充值金额
     * @apiSuccess {String}      book_name 书名
     * @apiSuccess {String}      chapter_name 章节名称
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *   "code": 0,
     *   "msg": "",
     *   "data": {
     *       "list": [
     *       {
     *           "id": 4852,
     *           "appid": null,
     *           "name": "女神小说-0430-客服消息",
     *           "send_time": "2018-04-30 14:00:00",
     *           "uv": 0,
     *           "pv": 0,
     *           "channel_id": 0,
     *           "pay_user_num": 0,
     *           "charge_amount": "",
     *           "book_name": "",
     *           "chapter_name": "",
     *           "create_at": "2018-04-30 12:40:22"
     *       },
     *       {
     *           "id": 4776,
     *           "appid": null,
     *           "name": "女神小说-0429-客服消息",
     *           "send_time": "2018-04-29 14:00:00",
     *           "uv": 0,
     *           "pv": 0,
     *           "channel_id": 0,
     *           "pay_user_num": 0,
     *           "charge_amount": "",
     *           "book_name": "",
     *           "chapter_name": "",
     *           "create_at": "2018-04-29 13:58:01"
     *       },
     *       ],
     *       "meta": {
     *       "total": 2,
     *       "per_page": 15,
     *       "current_page": 1,
     *       "last_page": 1,
     *       "next_page_url": "http://vipchannel.pre.aizhuishu.com/api/company/auth/customMsg?page=2",
     *       "prev_page_url": ""
     *       }
     *   }
     *   }
     */
    public function findTemplateSendMsg(CustomSendMsgRequest $request)
    {
        $start_time = $request->get('start_time', date('Y-m-d', strtotime('-7 days')));
        $end_time = $request->get('end_time', date('Y-m-d'));
        $send_start_time = $request->get('send_start_time', '');
        $send_end_time = $request->get('send_end_time', '');
        $book_name = $request->get('book_name', '');
        $name = $request->get('name', '');
        $channel_id = $request->get('channel_id', '');
        $params = [
            'start_time' => $start_time,
            'end_time' => $end_time,
            'book_name' => $book_name,
            'name' => $name,
            'channel_id' => $channel_id,
            'send_start_time' => $send_start_time,
            'send_end_time' => $send_end_time
        ];
        if (strtotime($end_time) - strtotime($start_time) > SysConsts::ONE_DAY_SECONDS * 31) {
            return response()->error('COMPANY_AUTH_OVER_TIME');
        }
        if ($send_start_time && $send_end_time && strtotime($send_start_time) - strtotime($send_end_time) > SysConsts::ONE_DAY_SECONDS * 31) {
            return response()->error('COMPANY_AUTH_OVER_TIME');
        }
        $result = (new OfficialAccountService)->findWechatTemplateMsgs($params);
        return response()->pagination(new CustomSendMsgsTransformers, $result);
    }

    /**
     * @api {post} company/auth/delayMsg 延时客服消息
     * @apiVersion 1.0.0
     * @apiName delayMsg
     * @apiGroup CompanyAuth
     * @apiParam {String} channel_id 站点 
     * @apiParam {Int} page 分页页码 
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Object}      list 数据结果
     * @apiSuccess {Object}      meta 分页信息
     * @apiSuccess {Int}      total 分页总数
     * @apiSuccess {Int}         id 
     * @apiSuccess {String}      title 标题
     * @apiSuccess {String}         link 链接
     * @apiSuccess {String}         desc 描述
     * @apiSuccess {Int}         time_delay 延时时间
     * @apiSuccess {String}      user_type 用户类型:ALL所有 UNPAID 未付费 PAID 付费用户 
     * @apiSuccess {String}      chapter_info 章节名
     * @apiSuccess {String}      book_info 书名
     * @apiSuccess {String}      type 消息类型 page 页面  book 小说
     * @apiSuccess {Int}      uv 
     * @apiSuccess {Int}  pv 
     * @apiSuccess {Int}      pay_user_num 付费用户数
     * @apiSuccess {Decimal}      charge_amount 充值金额
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *   "code": 0,
     *   "msg": "",
     *   "data": {
     *       "list": [
     *       {
     *           "id":"",
     *           "title":"",
     *           "link":"",
     *           "desc":"",
     *           "time_delay":"",
     *           "user_type":"",
     *           "chapter_name":"",
     *           "book_name":"",
     *           "type":"",
     *           "uv":"",
     *           "pv":"",
     *           "pay_user_num": "",
     *           "charge_amount": "",
     *       }
     *       ],
     *       "meta": {
     *       "total": 1,
     *       "per_page": 15,
     *       "current_page": 1,
     *       "last_page": 1,
     *       "next_page_url": "",
     *       "prev_page_url": ""
     *       }
     *   }
     *   }
     */
    public function delayMsg(CustomSendMsgRequest $request)
    {
        $channel_id = $request->get('channel_id', '');
        $params = [
            'channel_id' => $channel_id,
        ];
        $result = (new OfficialAccountService)->findWechatDelayMsgs($params);
        return response()->pagination(new DelaySendMsgsTransformers, $result);
    }

    /**
     * @api {post} company/auth/activity 促销活动列表
     * @apiVersion 1.0.0
     * @apiName activity
     * @apiGroup CompanyAuth
     * @apiParam {String} channel_id 站点 
     * @apiParam {Int} page 分页页码 
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Object}      list 数据结果
     * @apiSuccess {Object}      meta 分页信息
     * @apiSuccess {Int}      total 分页总数
     * @apiSuccess {Int}         id 
     * @apiSuccess {String}      name 活动名称
     * @apiSuccess {String}      activity_page 活动地址
     * @apiSuccess {String}         created_at 创建时间
     * @apiSuccess {String}         start_time 开始时间
     * @apiSuccess {String}         end_time 结束时间
     * @apiSuccess {Decimal}         price 价格
     * @apiSuccess {Int}     orderCount 订单数量
     * @apiSuccess {Decimal}      totalChargeAmount 充值金额
     * @apiSuccess {Int}      successOrderCount 成功订单数
     * @apiSuccess {Int}      pageUserNum 访问人数
     * @apiSuccess {Int}      is_reader_page_show 是否阅读页展示
     * @apiSuccess {Int}      is_sign_message_show 是否签到页展示
     * @apiSuccess {Decimal}      successrate 订单成功率
     * @apiSuccess {Int}      is_over 是否结束
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *   "code": 0,
     *   "msg": "",
     *   "data": {
     *       "list": [
     *       {
     *           "id":"",
     *           "name":"",
     *           "activity_page":"",
     *           "created_at":"",
     *           "start_time":"",
     *           "end_time":"",
     *           "price":"",
     *           "orderCount":"",
     *           "totalChargeAmount":"",
     *           "successOrderCount":"",
     *           "pageUserNum":"",
     *           "is_reader_page_show": "",
     *           "is_sign_message_show": "",
     *           "successrate": "",
     *           "is_over": ""
     *       }
     *       ],
     *       "meta": {
     *       "total": 1,
     *       "per_page": 15,
     *       "current_page": 1,
     *       "last_page": 1,
     *       "next_page_url": "",
     *       "prev_page_url": ""
     *       }
     *   }
     *   }
     */
    public function activity(ChannelQueryRequest $request)
    {
        $channel_id = $request->get('channel_id', 0);
        $result = (new ActivityService)->getCommonActivitiesWithStats($channel_id);
        return response()->pagination(new ActivityTransformer, $result);
    }

    /**
     * @api {post} company/auth/selfActivity 自定义活动列表
     * @apiVersion 1.0.0
     * @apiName selfActivity
     * @apiGroup CompanyAuth
     * @apiParam {String} channel_id 站点 
     * @apiParam {Int} page 分页页码 
     * @apiParam {String} app_id 分配好的{app_id}
     * @apiParam {String} nonce_str 随机字符串
     * @apiParam {String} timestamp 时间戳
     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
     * @apiSuccess {int}         code 状态码
     * @apiSuccess {String}      msg  信息
     * @apiSuccess {Object}      data 结果集
     * @apiSuccess {Object}      list 数据结果
     * @apiSuccess {Object}      meta 分页信息
     * @apiSuccess {Int}      total 分页总数
     * @apiSuccess {Int}         id 
     * @apiSuccess {String}      name 活动名称
     * @apiSuccess {String}      activity_page 活动地址
     * @apiSuccess {String}         created_at 创建时间
     * @apiSuccess {String}         start_time 开始时间
     * @apiSuccess {String}         end_time 结束时间
     * @apiSuccess {Decimal}         price 价格
     * @apiSuccess {Int}     orderCount 订单数量
     * @apiSuccess {Decimal}      totalChargeAmount 充值金额
     * @apiSuccess {Int}      successOrderCount 成功订单数
     * @apiSuccess {Int}      pageUserNum 访问人数
     * @apiSuccess {Int}      is_reader_page_show 是否阅读页展示
     * @apiSuccess {Int}      is_sign_message_show 是否签到页展示
     * @apiSuccess {Decimal}      successrate 订单成功率
     * @apiSuccess {Int}      is_over 是否结束
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *   {
     *   "code": 0,
     *   "msg": "",
     *   "data": {
     *       "list": [
     *       {
     *           "id":"",
     *           "name":"",
     *           "activity_page":"",
     *           "created_at":"",
     *           "start_time":"",
     *           "end_time":"",
     *           "price":"",
     *           "orderCount":"",
     *           "totalChargeAmount":"",
     *           "successOrderCount":"",
     *           "pageUserNum":"",
     *           "is_reader_page_show": "",
     *           "is_sign_message_show": "",
     *           "successrate": "",
     *           "is_over": ""
     *       }
     *       ],
     *       "meta": {
     *       "total": 1,
     *       "per_page": 15,
     *       "current_page": 1,
     *       "last_page": 1,
     *       "next_page_url": "",
     *       "prev_page_url": ""
     *       }
     *   }
     *   }
     */
    public function selfActivity(ChannelQueryRequest $request)
    {
        $channel_id = $request->get('channel_id', 0);
        $result = (new ActivityService)->getChannelActivitiesWithStats($channel_id);
        return response()->pagination(new ActivityTransformer, $result);
    }
}