<?php

namespace App\Http\Controllers\Wechat\OfficialAccount;

use App\Http\Controllers\Channel\BaseController as ChannelBaseController;

// use App\Modules\OfficialAccount\Services\CustomMsgService;
use App\Http\Controllers\Wechat\OfficialAccount\Transformers\WechatTemplatesMsgTransformer;
use App\Http\Controllers\Wechat\OfficialAccount\Transformers\OfficialImgtextUrlsTransformer;
use App\Modules\OfficialAccount\Services\CustomMsgService;
use App\Modules\Promotion\Services\PromotionService;
use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomMsgControllerTransformer;
use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomMsgSwitchTransformer;
use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomSendMsgsTransformers;
use App\Http\Controllers\Channel\Promotion\Transformers\DocumentCoversTransformer;
use App\Http\Controllers\Channel\Promotion\Transformers\HeadlinelTransformer;
use Illuminate\Http\Request;
use GuzzleHttp\Client;
use App\Libs\OSS;
use App\Jobs\SendTemplate;

class WechatCustomerMsgController extends ChannelBaseController
{

    /**
     * @apiDefine OfficialAccount 公众号
     */

    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/wechatTemplateByAppidAndTemplateId 通过Appid和common_template_id获取模板
     * @apiGroup OfficialAccount
     * @apiName wechatTemplateByAppidAndCommonTemplateId
     * @apiParam   {String}  appid 公众号的appid.
     * @apiParam   {String}  common_template_id 公共模版的ID.
     * @apiSuccess {String}  appid 公众号的appid.
     * @apiSuccess {String}  common_template_id 公共模版的ID.
     * @apiSuccess {String}  template_id 公众号对应模版ID.
     * @apiSuccess {String}  name 名称.
     * @apiSuccess {String}  send_time 发送时间.
     * @apiSuccess {String}  template_content 模板内容.
     * @apiSuccess {String}  redirect_url 重定向地址.
     * @apiSuccess {String}  send_appid 公众号appid.
     * @apiParam {String}  status 模板消息状态.
     * @apiParam {String}  remark 备注.
     * @apiParam {Number}  distribution_channel_id 分配的渠道Id.
     * @apiSuccessExample {json} Success-Response:
     *
     *       {
     *           "code": 0,
     *           "msg": "",
     *           "data": {
     *               "appid": "112211",
     *               "common_template_id": "qqqqq",
     *               "template_id": "wqwqwq",
     *           }
     *       }
     */

    function sendNewsTask(Request $request)
    {

        CustomMsgService::sendUnpaid();

        return response()->success();
    }



    public function add_news_task($wechatCustomer,$users){
        $data = array();
        
        $data['openid'] = 'openid';
        $data['appid'] = 'appid';
        $data['news_content'] = '[[{"title":"标题啊"},{"description":"描述哦"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]';
        $data['type'] = 'last_task';// last_task,one_task
        $data['task_id'] = 3;
        $data['send_time'] = date("Y-m-d H:i:s");
        $send_data=array(
            'send_time'=>date("Y-m-d H:i:s"),
            'data' => $data
        );

        $delay = 0;

//      v('delay:'.$delay);die();
        $job = (new SendTemplate($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_news_list');

    }

    /**
    * 测试
    */

    //-------------------------------------------------客服消息配置开关Start---------------------------CustomMsgSwitchs
    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/customMsgSwitchSetting 客服消息开关设置(测通)
     * @apiGroup OfficialAccount
     * @apiName customMsgSwitchSetting
     * @apiParam {String}  custom_category 客服消息类别.
     * @apiParam {String}  status 客服消息状态 1:开,2:关.
     * @apiSuccessExample {json} Success-Response:
     *
     *       {
     *           "code": 0,
     *           "msg": "",
     *           "data": []
     *       } 
     */
    function  customMsgSwitchSetting(Request $request) {

        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $custom_category = $request->has('custom_category') ? $request->input('custom_category') : '';
        if(empty($custom_category)) {
            return response()->error("PARAM_EMPTY");
        }

        $status = $request->has('status') ? $request->input('status') : '';
        if(empty($status)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomMsgService::customMsgSwitchSetting($distribution_channel_id,$custom_category,$status);

        if($customMsgService == 1) {
            return response()->success();
        }elseif ($customMsgService == 2) {
            return response()->error('CUSTOMS_SETTING_FAILED');
        }elseif ($customMsgService == 0) {
            return response()->error('HAS_NO_CUSTOMS');
        }else{
            return response()->error('CUSTOMS_SETTING_FAILED');
        }

        
    }

    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/customMsgSwitchsByChannelId 客服消息开关列表获取(测通)
     * @apiGroup OfficialAccount
     * @apiName customMsgSwitchsByChannelId
     * @apiSuccessExample {json} Success-Response:
     *
     *      {
     *          "code": 0,
     *          "msg": "",
     *          "data": [
     *              {
     *                  "title": "未支付提醒",
     *                  "custom_category": "not_pay",
     *                  "status": "1",
     *                  "distribution_channel_id": 1,
     *                  "id": 1
     *              },
     *              {
     *                  "title": "定制书籍推送",
     *                  "custom_category": "point_push",
     *                  "status": "0",
     *                  "distribution_channel_id": 1,
     *                  "id": 2
     *              },
     *              {
     *                  "title": "热门书籍推送",
     *                  "custom_category": "hot_push",
     *                  "status": "1",
     *                  "distribution_channel_id": 1,
     *                  "id": 3
     *              }
     *          ]
     *      } 
     */
    function  customMsgSwitchsByChannelId(Request $request) {


        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomMsgService::customMsgSwitchsByChannelId($distribution_channel_id);

        if (!empty($customMsgService)) {
            # code...
            return response()->collection(new CustomMsgSwitchTransformer(), $customMsgService);
        }else{
            return response()->success(['data'=>0]);
        }
        
    }

    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/customMsgSwitchsByChannelCate 获取指定客服消息开关(测通)
     * @apiGroup OfficialAccount
     * @apiParam {String}  custom_category 客服消息类别.
     * @apiName customMsgSwitchsByChannelCate
     * @apiSuccessExample {json} Success-Response:
     *
     *      {
     *          "code": 0,
     *          "msg": "",
     *          "data": {
     *              "title": "热门书籍推送",
     *              "custom_category": "hot_push",
     *              "status": "1",
     *              "distribution_channel_id": 1,
     *              "id": 3
     *          }
     *      } 
     */
    function  customMsgSwitchsByChannelCate(Request $request) {


        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $custom_category = $request->has('custom_category') ? $request->input('custom_category') : '';
        if(empty($custom_category)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomMsgService::customMsgSwitchsByChannelCate($distribution_channel_id,$custom_category);

        if (!empty($customMsgService)) {
            # code...
            return response()->item(new CustomMsgSwitchTransformer(), $customMsgService);
        }else{
            return response()->success(['data'=>0]);
        }
        
    }

//-------------------------------------------------客服消息配置开关End---------------------------CustomMsgSwitchs



//-------------------------------------------------编辑发送客服消息Start---------------------------CustomSendMsg
    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/customSendMsgsByChannelId 发送客服消息列表获取(测通)
     * @apiGroup OfficialAccount
     * @apiName customSendMsgsByChannelId
     * @apiSuccessExample {json} Success-Response:
     *
     *      {
     *          "code": 0,
     *          "msg": "",
     *          "data": [
     *              {
     *                  "id": 2,
     *                  "name": "测试222",
     *                  "send_time": "2017-12-26 11:11:11",
     *                  "content": "横眉冷对千夫指,俯首甘为孺子牛",
     *                  "redirect_url": "http:\/\/www.baidu.com\/what?am=1",
     *                  "status": null,
     *                  "distribution_channel_id": 1,
     *                  "subscribe_time": "z",
     *                  "sex": "z",
     *                  "balance": "z",
     *                  "order_type": "z",
     *                  "category_id": "z"
     *              },
     *              {
     *                  "id": 1,
     *                  "name": "测试111",
     *                  "send_time": "2017-12-26 11:11:11",
     *                  "content": "横眉冷对千夫指,俯首甘为孺子牛",
     *                  "redirect_url": "http:\/\/www.baidu.com\/yes?en",
     *                  "status": null,
     *                  "distribution_channel_id": 1,
     *                  "subscribe_time": "z",
     *                  "sex": "z",
     *                  "balance": "z",
     *                  "order_type": "z",
     *                  "category_id": "z"
     *              }
     *          ]
     *      }
     */
    function  customSendMsgsByChannelId(Request $request) {


        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomMsgService::customSendMsgsByChannelId($distribution_channel_id);

        if (!empty($customMsgService)) {
            # code...
            return response()->collection(new CustomSendMsgsTransformers(), $customMsgService);
        }else{
            return response()->success(['data'=>0]);
        }
        
    }


    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/customSendMsgsById 通过ID获取指定客服消息(测通)
     * @apiGroup OfficialAccount
     * @apiName customSendMsgsById
     * @apiParam {String}  id 客服消息id.
     * @apiSuccessExample {json} Success-Response:
     *
     *      {
     *          "code": 0,
     *          "msg": "",
     *          "data": {
     *              "id": 1,
     *              "name": "测试111",
     *              "send_time": "2017-12-26 11:11:11",
     *              "content": "横眉冷对千夫指,俯首甘为孺子牛",
     *              "redirect_url": "http:\/\/www.baidu.com\/yes?en",
     *              "status": null,
     *              "distribution_channel_id": 1,
     *              "subscribe_time": "z",
     *              "sex": "z",
     *              "balance": "z",
     *              "order_type": "z",
     *              "category_id": "z"
     *          }
     *      }
     */
    function  customSendMsgsById(Request $request) {


        $id = $request->has('id') ? $request->input('id') : '';
        if(empty($id)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomMsgService::customSendMsgsById($id);

        if (!empty($customMsgService)) {
            # code...
            return response()->item(new CustomSendMsgsTransformers(), $customMsgService);
        }else{
            return response()->success(['data'=>0]);
        }
        
    }


    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/stopCustomSendMsgsById 停止发送客服消息
     * @apiGroup OfficialAccount
     * @apiName customSendMsgsById
     * @apiParam {String}  id 客服消息id.
     * @apiSuccessExample {json} Success-Response:
     *
     *      {
     *          "code": 0,
     *          "msg": "",
     *          "data": {
     *          }
     *      }
     */
    function  stopCustomSendMsgsById(Request $request) {


        $id = $request->has('id') ? $request->input('id') : '';
        if(empty($id)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomMsgService::updateCustomSendMsgsStatus($id);
        if ($customMsgService == 1) {
            return response()->success();
        }elseif ($customMsgService == 2) {
            return response()->error('CUSTOMS_SEND_FAILED');
        }elseif ($customMsgService == 0) {
            return response()->error('CUSTOMS_SEND_FAILED');
        }else{
            return response()->error('CUSTOMS_SEND_FAILED');
        }
        
    }



    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/addCustomSendMsgs 发送客服消息(测通)
     * @apiGroup OfficialAccount
     * @apiName addCustomSendMsgs
     * @apiParam {String}  appid 服务号.
     * @apiParam {String}  name 客服消息标题.
     * @apiParam {String}  send_time 客服消息发送时间.
     * @apiParam {String}  content 客服消息内容. 格式:[[{"title":"横眉冷对千夫指,俯首甘为孺子牛"},{"description":"横眉冷对千夫指,俯首甘为孺子牛"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}],[{"title":"来他家做佣人半年,结果天天被男主人这样!"},{"description":"来他家做佣人半年,结果天天被男主人这样!"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]
     * @apiParam {String}  redirect_url 点击消息重定向地址.
     * @apiParam {String}  subscribe_time 用户强关时间段.
     * @apiParam {String}  sex 用户性别.
     * @apiParam {String}  balance 用户账户余额.
     * @apiParam {String}  order_type 用户订单状态.
     * @apiParam {String}  category_id 读书分类.
     * @apiParam {String}  [id] id.
     * @apiSuccessExample {json} Success-Response:
     *
     *       {
     *           "code": 0,
     *           "msg": "",
     *           "data": []
     *       } 
     */
    function  addCustomSendMsgs(Request $request) {

        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $appid = $request->has('appid') ? $request->input('appid') : '';
        if(empty($appid)) {
            return response()->error("PARAM_EMPTY");
        }

        $name = $request->has('name') ? $request->input('name') : '';
        if(empty($name)) {
            return response()->error("PARAM_EMPTY");
        }

        $send_time = $request->has('send_time') ? $request->input('send_time') : '';
        if(empty($send_time)) {
            return response()->error("PARAM_EMPTY");
        }

        $content = $request->has('content') ? $request->input('content') : '';
        if(empty($content)) {
            return response()->error("PARAM_EMPTY");
        }

        $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
        if(empty($redirect_url)) {
            return response()->error("PARAM_EMPTY");
        }

        $subscribe_time = $request->has('subscribe_time') ? $request->input('subscribe_time') : '';
        if(empty($subscribe_time)) {
            return response()->error("PARAM_EMPTY");
        }

        $sex = $request->has('sex') ? $request->input('sex') : '';
        if(empty($sex)) {
            return response()->error("PARAM_EMPTY");
        }

        $balance = $request->has('balance') ? $request->input('balance') : '';
        if(empty($balance)) {
            return response()->error("PARAM_EMPTY");
        }

        $order_type = $request->has('order_type') ? $request->input('order_type') : '';
        if(empty($order_type)) {
            return response()->error("PARAM_EMPTY");
        }

        $category_id = $request->has('category_id') ? $request->input('category_id') : '';
        if(empty($category_id)) {
            return response()->error("PARAM_EMPTY");
        }
        
        $is_full_send = $request->has('is_full_send') ? $request->input('is_full_send') : '0';

        $user_condition = $request->has('user_condition') ? $request->input('user_condition') : '';


        $id = $request->has('id') ? $request->input('id') : '';


        $customMsgPrams['appid'] = $appid;
        $customMsgPrams['name'] = $name;
        $customMsgPrams['send_time'] = $send_time;
        $customMsgPrams['content'] = $content;
        $customMsgPrams['redirect_url'] = $redirect_url;
        $customMsgPrams['subscribe_time'] = $subscribe_time;
        $customMsgPrams['sex'] = $sex;
        $customMsgPrams['balance'] = $balance;
        $customMsgPrams['order_type'] = $order_type;
        $customMsgPrams['category_id'] = $category_id;
        $customMsgPrams['distribution_channel_id'] = $distribution_channel_id;
        $customMsgPrams['id'] = $id;
        $customMsgPrams['status'] = '1';
        $customMsgPrams['is_full_send'] = $is_full_send;
        $customMsgPrams['user_condition'] = $user_condition;

        $customMsgService = CustomMsgService::addCustomSendMsgs($customMsgPrams);

        if ($customMsgService == 1) {
            return response()->success();
        }elseif ($customMsgService == 2) {
            return response()->error('CUSTOMS_SEND_FAILED');
        }elseif ($customMsgService == 0) {
            return response()->error('CUSTOMS_SEND_FAILED');
        }else{
            return response()->error('CUSTOMS_SEND_FAILED');
        }
        
    }


    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/getAllDocumentCovers 获取所有图库素材(测通)
     * @apiGroup OfficialAccount
     * @apiName getAllDocumentCovers
     * @apiSuccessExample {json} Success-Response:
     *
     *       {
     *           "code": 0,
     *           "msg": "",
     *           "data": [
     *                  {
     *                      "id": 1,
     *                      "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/1.jpg"
     *                  },
     *                  {
     *                      "id": 2,
     *                      "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/2.jpg"
     *                  },
     *                  {
     *                      "id": 3,
     *                      "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/3.jpg"
     *                  }   
     *               ]
     *       } 
     */
    function  getAllDocumentCovers(Request $request) {

        $promotionService = PromotionService::getAllMessageDocumentCovers();

        if(!empty($promotionService)) {
            # code...
            return response()->collection(new DocumentCoversTransformer(), $promotionService);
        }else{
            return response()->success(['data'=>0]);
        }
        
    }


    /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/getAllHeadlinesNoType 获取所有标签文案(测通)
     * @apiGroup OfficialAccount
     * @apiName getAllHeadlinesNoType
     * @apiSuccessExample {json} Success-Response:
     *
     *       {
     *           "code": 0,
     *           "msg": "",
     *           "data": [
     *                  {
     *                      "id": 1,
     *                      "title": "三姐妹怀孕,孩子的父亲竟是同一人,婆婆竟然这样说..."
     *                  },
     *                  {
     *                      "id": 2,
     *                      "title": "看哭5000万人,一对32岁夫妻离婚后的聊天记录..."
     *                  } 
     *               ]
     *       } 
     */
    function  getAllHeadlinesNoType(Request $request) {

        $promotionService = PromotionService::getHeadlines();

        if(!empty($promotionService)) {
            # code...
            return response()->collection(new HeadlinelTransformer(), $promotionService);
        }else{
            return response()->success(['data'=>0]);
        }
        
    }

     /**
     * @apiVersion 1.0.0
     * @api {GET} OfficialAccount/testAddCustomSendMsgs 测试向单个用户发送客服消息
     * @apiGroup OfficialAccount
     * @apiName testAddCustomSendMsgs
     * @apiParam {String}  appid 服务号.
     * @apiParam {String}  uid 服务号.
     * @apiParam {String}  name 客服消息标题.
     * @apiParam {String}  content 客服消息内容. 格式:[[{"title":"横眉冷对千夫指,俯首甘为孺子牛"},{"description":"横眉冷对千夫指,俯首甘为孺子牛"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}],[{"title":"来他家做佣人半年,结果天天被男主人这样!"},{"description":"来他家做佣人半年,结果天天被男主人这样!"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]
     * @apiParam {String}  redirect_url 点击消息重定向地址.
     * @apiSuccessExample {json} Success-Response:
     *
     *       {
     *           "code": 0,
     *           "msg": "",
     *           "data": []
     *       } 
     */
    function  testAddCustomSendMsgs(Request $request) {

        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $appid = $request->has('appid') ? $request->input('appid') : '';
        if(empty($appid)) {
            return response()->error("PARAM_EMPTY");
        }

        $name = $request->has('name') ? $request->input('name') : '';
        if(empty($name)) {
            return response()->error("PARAM_EMPTY");
        }

        $content = $request->has('content') ? $request->input('content') : '';
        if(empty($content)) {
            return response()->error("PARAM_EMPTY");
        }

        $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
        if(empty($redirect_url)) {
            return response()->error("PARAM_EMPTY");
        }

        $uid = $request->has('uid') ? $request->input('uid') : '';
        if(empty($uid)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgPrams['appid'] = $appid;
        $customMsgPrams['name'] = $name;
        $customMsgPrams['content'] = $content;
        $customMsgPrams['redirect_url'] = $redirect_url;
        $customMsgPrams['distribution_channel_id'] = $distribution_channel_id;
        $customMsgPrams['uid'] = $uid;

        $customMsgService = CustomMsgService::testAddCustomSendMsgs($customMsgPrams);

        if ($customMsgService == 1) {
            return response()->success();
        }elseif ($customMsgService == 2) {
            return response()->error('CUSTOMS_SEND_FAILED');
        }elseif ($customMsgService == 0) {
            return response()->error('CUSTOMS_SEND_FAILED');
        }else{
            return response()->error('CUSTOMS_SEND_FAILED');
        }
        
    }

//-------------------------------------------------编辑发送客服消息End---------------------------CustomSendMsg

//-------------------------------------------------生成图文链接Start---------------------------

    /**
     * 生成图文链接
     */
    static function createOfficialImgTxtUrl(Request $request)
    {

        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }
     
        //图片链接
        $img_url = $request->has('img_url') ? $request->input('img_url') : '';
        if(empty($img_url)) {
            return response()->error("PARAM_EMPTY");
        }

        //文章内容
        $content = $request->has('content') ? $request->input('content') : '';
        if(empty($content)) {
            return response()->error("PARAM_EMPTY");
        }

        //文章标题
        $title = $request->has('title') ? $request->input('title') : '';
        if(empty($title)) {
            return response()->error("PARAM_EMPTY");
        }

        $book_name = $request->has('book_name') ? $request->input('book_name') : '';
        if(empty($book_name)) {
            return response()->error("PARAM_EMPTY");
        }


        $chapter_sequence = $request->has('chapter_sequence') ? $request->input('chapter_sequence') : '';
        if(empty($chapter_sequence)) {
            return response()->error("PARAM_EMPTY");
        }

        $send_orders_id = $request->has('send_orders_id') ? $request->input('send_orders_id') : '';
        if(empty($send_orders_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $send_orders_name = $request->has('send_orders_name') ? $request->input('send_orders_name') : '';
        if(empty($send_orders_name)) {
            return response()->error("PARAM_EMPTY");
        }

        $send_orders_url = $request->has('send_orders_url') ? $request->input('send_orders_url') : '';
        if(empty($send_orders_url)) {
            return response()->error("PARAM_EMPTY");
        }

        $officialImgTxtUrlPrams['distribution_channel_id'] = $distribution_channel_id;
        $officialImgTxtUrlPrams['img_url'] = $img_url;
        $officialImgTxtUrlPrams['content'] = $content;
        $officialImgTxtUrlPrams['title'] = $title;
        $officialImgTxtUrlPrams['book_name'] = $book_name;
        $officialImgTxtUrlPrams['chapter_sequence'] = $chapter_sequence;
        $officialImgTxtUrlPrams['send_orders_id'] = $send_orders_id;
        $officialImgTxtUrlPrams['send_orders_name'] = $send_orders_name;
        $officialImgTxtUrlPrams['send_orders_url'] = $send_orders_url;

        $customMsgService = CustomMsgService::createOfficialImgTxtUrl($officialImgTxtUrlPrams);

        if (!empty($customMsgService)) {
            # code...
            return response()->success(['img_url'=>$customMsgService]);
        }else{
            return response()->error('OFFICIAL_IMGTXT_FAILED');
        }

    }


    /**
     * 获取图文列表
     */
    static function getOfficialImgTxtUrl(Request $request)
    {
        $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
        if(empty($distribution_channel_id)) {
            return response()->error("PARAM_EMPTY");
        }

        $customMsgService = CustomMsgService::getOfficialImgTxtUrl($distribution_channel_id);
        if (!empty($customMsgService)) {
            # code...
            return response()->collection(new OfficialImgtextUrlsTransformer(), $customMsgService);
        }else{
            return response()->success(['data'=>0]);
        }
    }


    /**
     * 测试 三天回本12小时推送
     */
    static function add_news_recovery_push_hot(Request $request)
    {

        CustomMsgService::add_news_recovery_push_hot();
   
        return response()->success();
        
    }


    /**
     * 测试 三天回本24小时推送
     */
    static function add_news_recovery_push_activity(Request $request)
    {

        CustomMsgService::add_news_recovery_push_activity();
   
        return response()->success();
        
    }


    /**
     * 测试 定制图书推送
     */
    static function add_news_point_book(Request $request)
    {

        CustomMsgService::add_news_point_book();
   
        return response()->success();
        
    }

    /**
     * 测试 热门图书推送
     */
    static function add_news_top_book(Request $request)
    {

        CustomMsgService::add_news_top_book();
   
        return response()->success();
        
    }

    /**
     * 测试 发送未支付消息提醒
     */
    static function sendUnpaid(Request $request)
    {

        CustomMsgService::sendUnpaid();
   
        return response()->success();
        
    }

    /**
     * 付费用户每日提醒
     */
    static function add_template_pay_push_daily(Request $request)
    {
    
    	CustomMsgService::add_template_pay_push_daily();
    	 
    	return response()->success();
    
    }

//-------------------------------------------------生成图文链接End---------------------------

    
}