<?php
/**
 * 测试
 * Created by PhpStorm.
 * User=> 小威
 * Date=> 2020/05/16
 * Time=> 11=>31
 */

namespace Jindouyun\Controller\Common;

use JinDouYun\Cache\SkuCache;
use JinDouYun\Cache\Stock;
use JinDouYun\Dao\Customer\DCustomer;
use JinDouYun\Dao\Goods\DGoods;
use JinDouYun\Dao\GoodsCategory\DGoodsCategory;
use JinDouYun\Dao\GoodsManage\DGoodsBasic;
use JinDouYun\Dao\GoodsManage\DGoodsBrand;
use JinDouYun\Dao\GoodsManage\DSku;
use JinDouYun\Dao\GoodsManage\DUnits;
use JinDouYun\Dao\Market\DUserCoupon;
use JinDouYun\Model\Customer\MCustomer;
use JinDouYun\Model\Enterprise\MEnterprise;
use JinDouYun\Model\Finance\MReceive;
use Jindouyun\Model\Finance\MPay;
use JinDouYun\Model\Goods\MGoods;
use JinDouYun\Model\Goods\MQuickGoods;
use JinDouYun\Model\MBaseModel;
use JinDouYun\Model\GoodsManage\MGoodsBasic;
use JinDouYun\Model\Order\MOrder;

use JinDouYun\Model\System\MModule;
use Mall\Framework\Core\ErrorCode;
use Mall\Framework\Cache\Redis;
use Mall\Framework\Core\ResultWrapper;
use Mall\Framework\Core\StatusCode;
use Mall\Framework\Factory;

use Util\KuaiDi100\Query;
use Util\WeiXin\Offiaccount;
use Util\WeiXin\Miniprogram;
use Util\WeiXin\Pay;
use Util\KeRuYun\Open;
use Util\DaDa\Merchant;


class Test
{

    public function index()
    {
        $objStock = new Stock(64);
        $a = $objStock->createSerialSn(0, 'Order');
        echo $a;
        die;
    }

    public function getModuleNameByUri()
    {
        $objMModule = new MModule();
        $objMModule->getModuleNameByUri('GoodsManage/GoodsBasic/getGoodsBasicInfoById');
    }

    private $objDGoods;

    /**
     * @var Redis
     */
    private $cache;

    /**
     * @var string
     */
    private $delayQueueCancelOrderKey = 'delay_queue_cancel_order';

    public function test()
    {
        exit(json_encode([
            'state' => true,
            'data' => '0.30kg',
            'errorMsg' => '',
        ]));
    }

    /**
     * Doc: (des="")
     * User: XMing
     * Date: 2020/9/23
     * Time: 5:04 下午
     * @throws \Exception
     */
    public function pushDelay()
    {
        $this->cache = Factory::cache('default');
        $res = $this->cache->zAdd($this->delayQueueCancelOrderKey . '::1', time(), 100);

        //$orderIds = $this->cache->zrangebyscore($this->delayQueueCancelOrderKey.'::1', 0, time()-60, ['withscores' => TRUE]);
        //print_r($orderIds);die;

        //$res = $this->cache->zrem($this->delayQueueCancelOrderKey.'::1', 100);
        var_dump($res);
    }

    /**
     * Doc: (des="注册补发优惠券")
     * User: XMing
     * Date: 2020/9/22
     * Time: 11:57 上午
     */
    public function couponRegister()
    {
        self::coupon([
            'userCenterId' => '',
            'customerId' => '',
            'enterpriseId' => '',
        ], 'MRegisterCoupon');
    }

    public function codeTest()
    {
        $location = 'eyJwcm92aW5jZU5hbWUiOiLlub/kuJznnIEiLCJjaXR5TmFtZSI6IuS4nOiOnuW4giIsImRpc3RyaWN0TmFtZSI6W10sImFkZHJlc3MiOiLkuK3lm73nn7PljJbkuJzojp7luILpobrovr7liqDmsrnnq5npmYTov5EiLCJsYXRpdHVkZSI6MjMuMDIyMTM1LCJsb25naXR1ZGUiOjExMy43MjI5NzR9';
        $areaArr = json_decode(base64_decode($location), true);
        V($areaArr);

    }

    /**
     * 营销活动(领取优惠券)
     * @param $data
     * @param $className
     */
    protected static function coupon($data, $className)
    {
        $i = 1;
        do {
            $postData = [
                'topicName' => 'MyJob',
                'topicClass' => "Jobs\Model\MTopic\Market\\" . $className,
                'topicMethon' => 'push',
                'topicMethonParams' => [
                    'userCenterId' => $data['userCenterId'],
                    'enterpriseId' => $data['enterpriseId'],
                    'customerId' => $data['customerId'],
                    'payAmount' => isset($data['payAmount']) ? $data['payAmount'] : 0,
                ],
            ];
            $url = QIANNIAO_QUEUE . '/CAddJob/add';
            $result = request($url, $postData);
            print_r($result);
            $i++;
        } while ($result['httpcode'] != 200 && $i <= 3);
    }


    /*******************************
     * @var string
     *
     *
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *      * es-----------------------ip----------------记得换
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     * es-----------------------ip----------------记得换
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     * **/
    private $Authorization;

    private $Token;

    /**
     * 格式化导入数据
     */
    public function formatData()
    {
        //导入数据需要修改以下6处地方  然后把商品信息和商品数组按照key对应
    
        //1.更换请求头token!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        $Authorization = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjI1MTUsImV4cGlyZVRpbWUiOjE2MjU1NjU0MzB9.r1KfvvNgHTTGcFFNNQed22TIB0y0bPLmdwsnh8ksNxg';
        $Token = 'a3af5bf6213ac4bc899c6d0a78d1613e';

        //2.切换config

        //3.切换esip

        //4.修改商品图片(去该企业的图片库复制一个合适的图片)
        $images = ["https://onlineimg.qianniao.vip/162496878735338/a3af5bf6213ac4bc899c6d0a78d1613e/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20210629200937.jpg"];//商品图片

        //5.企业id
        $enterpriseId = 308;

        //6.多单位
        $twoUnit = false;

        //获取数据文件
        $file = file(PROJECT_PATH.'/Public/www/1.txt');

        //引用dao
        $objDGoodsCategory = new DGoodsCategory();
        $objDGoodsCategory->setTable('qianniao_goods_category_' . $enterpriseId);

        $objDGoodsBrand = new DGoodsBrand();
        $objDGoodsBrand->setTable('qianniao_goods_brand_' . $enterpriseId);

        $objDUnits = new DUnits();
        $objDUnits->setTable('qianniao_units_' . $enterpriseId);

        //请求地址
        $apiUrl = 'https://api.qianniao.vip/Goods/QuickGoods/addBasicAndPublishGoods';
        //请求参数
        $curl_option = [
            CURLOPT_HTTPHEADER => [
                'Content-Type:text/plain',
                'Authorization:'.$Authorization,
                'Token:'.$Token,
            ],
        ];

        $i = 0;
        //获取数据
        foreach ($file as $value) {
            
            if(!strpos($value,',')){
                echo '商品数据格式错误';exit;
            }
            $goodsArray = explode(',', $value);
        
            //商品信息
            $categoryName       = isset($goodsArray[0]) ? trim($goodsArray[0]) : '';//分类名称
            $brandName          = isset($goodsArray[3]) ? trim($goodsArray[3]) : '';//品牌名称
            $goodsName          = isset($goodsArray[1]) ? trim($goodsArray[1]) : '';//商品名称

            $describe           = isset($goodsArray[6213]) ? trim($goodsArray[6321]) : '';//商品卖点
            $description        = isset($goodsArray[110]) ? '<p>' . trim($goodsArray[110]) . '</p>' : '';//商品详情

            //主单位信息
            $skuName            = isset($goodsArray[2]) ? trim($goodsArray[2]) : '无';//单位名称
            $barCode            = isset($goodsArray[34]) ? trim($goodsArray[43]) : '';//主单位条码
            $salePrice          = isset($goodsArray[423]) ? trim($goodsArray[432]) : 1;//商品价格
            $salePriceTrue      = isset($goodsArray[52]) ? trim($goodsArray[53]) : bcmul($salePrice, 1.2, 2);//市场价格

            //辅单位信息
            if($twoUnit){
                $skuNameTwo         = isset($goodsArray[56]) ? trim($goodsArray[65]) : '';//辅单位
                $barCodeTwo         = isset($goodsArray[32]) ? trim($goodsArray[32]) : '';//辅单位条码
                $conversion         = isset($goodsArray[56]) ? trim($goodsArray[56]) : 0;//辅单位换算比例
                $salePriceTwo       = isset($goodsArray[65]) ? trim($goodsArray[65]) : 1;//辅单位销售价格
                $salePriceTwoTrue   = isset($goodsArray[34]) ? trim($goodsArray[34]) : bcmul($salePriceTwo, 1.2, 2);//辅单位市场价格
            }

            if (empty($goodsName)) {
                continue;
            }
            /***分类数据***/
            if (!empty($categoryName)) {
                //查询分类是否存在
                $categorySelect = [
                    'title' => $categoryName,
                ];
                $dbResult = $objDGoodsCategory->get($categorySelect);
                if ($dbResult === false) {
                    exit($objDGoodsCategory->error());
                }
                $category = $dbResult;
                unset($dbResult);
                if (empty($category)) {
                    $categoryInsert = [
                        'sort' => 0,
                        'title' => $categoryName,
                        'pid' => 0,
                        'enableStatus' => StatusCode::$standard,
                        'deleteStatus' => StatusCode::$standard,
                        'createTime' => time(),
                        'updateTime' => time(),
                    ];
                    $dbResult = $objDGoodsCategory->insert($categoryInsert);
                    if ($dbResult === false) {
                        exit($objDGoodsCategory->error());
                    }
                    $categoryId = $dbResult;
                    $categoryPath = $dbResult;
                    unset($dbResult);
                } else {
                    $categoryId = $category['id'];
                    if(!empty($category['link'])){
                        $categoryPath = $category['link'] . ',' . $category['id'];
                    }else{
                        $categoryPath = $category['id'];
                    }
                 
                }
            } else {
                $categoryId = 1;
                $categoryPath = '1';
            }
            /***品牌数据***/
            if (!empty($brandName)) {
                //查询品牌是否存在
                $brandSelect = [
                    'title' => $brandName
                ];
                $dbResult = $objDGoodsBrand->get($brandSelect);
                if ($dbResult === false) {
                    exit($objDGoodsBrand->error());
                }
                $brand = $dbResult;
                unset($dbResult);
                if (empty($brand)) {
                    $brandInsert = [
                        'title' => $brandName,
                        'images' => null,
                        'sort' => 0,
                        'enableStatus' => StatusCode::$standard,
                        'createTime' => time(),
                        'updateTime' => time(),
                    ];
                    $dbResult = $objDGoodsBrand->insert($brandInsert);
                    if ($dbResult === false) {
                        exit($objDGoodsBrand->error());
                    }
                    $brandId = $dbResult;
                    unset($dbResult);
                } else {
                    $brandId = $brand['id'];
                }
            } else {
                $brandId = 1;
            }
            /***单位数据***/
            $skuId = NULL;
            if (!empty($skuName)) {
                //查询单位是否存在
                $skuSelect = [
                    'unitName' => $skuName
                ];
                $dbResult = $objDUnits->get($skuSelect);
                if ($dbResult === false) {
                    exit($objDUnits->error());
                }
                $sku = $dbResult;
                unset($dbResult);
                if (empty($sku)) {
                    $skuInsert = [
                        'unitName' => $skuName,
                        'enableStatus' => StatusCode::$standard,
                        'createTime' => time(),
                        'updateTime' => time(),
                    ];
                    $dbResult = $objDUnits->insert($skuInsert);
                    if ($dbResult === false) {
                        exit($objDUnits->error());
                    }
                    $skuId = $dbResult;
                    unset($dbResult);
                } else {
                    $skuId = $sku['id'];
                }
            }
            $skuIdTwo = NULL;
            if (!empty($skuNameTwo)) {
                //查询单位是否存在
                $skuSelect = [
                    'unitName' => $skuNameTwo
                ];
                $dbResult = $objDUnits->get($skuSelect);
                if ($dbResult === false) {
                    exit($objDUnits->error());
                }
                $sku = $dbResult;
                unset($dbResult);
                if (empty($sku)) {
                    $skuInsert = [
                        'unitName' => $skuNameTwo,
                        'enableStatus' => StatusCode::$standard,
                        'createTime' => time(),
                        'updateTime' => time(),
                    ];
                    $dbResult = $objDUnits->insert($skuInsert);
                    if ($dbResult === false) {
                        exit($objDUnits->error());
                    }
                    $skuIdTwo = $dbResult;
                    unset($dbResult);
                } else {
                    $skuIdTwo = $sku['id'];
                }
            }

            if($twoUnit){
                $postData = [
                    "categoryPath" => $categoryPath,
                    "title" => $goodsName,
                    "storage" => "",
                    "delUnitIds" => [],
                    "delSpecSkuIds" => [],
                    "specType" => 1,
                    "specGroup" => [],
                    "specMultiple" => [
                        [
                            "barCode" => $barCode,
                            "weight" => "",
                            "isDefault" => 5,
                            "unitId" => $skuId,
                            "unitName" => $skuName,
                            "isMaster" => 5,
                            "conversion" => 0,
                            "specImage" => "",
                            "specGroup" => [],
                            "salePrice" => [
                                "conversion" => 0,
                                "unitName" => $skuName,
                                "unitId" => $skuId,
                                "isMaster" => 5,
                                "deleteStatus" => 5,
                                "enabledLadder" => 0,
                                "salePriceAreaType" => 1,
                                "salePrice" => $salePrice,
                                "ladderPrice" => [],
                                "marketPrice" => $salePriceTrue,
                                "setNum" => 1
                            ]
                        ],
                        [
                            "barCode" => $barCodeTwo,
                            "isDefault" => 4,
                            "unitId" => $skuIdTwo,
                            "unitName" => $skuNameTwo,
                            "isMaster" => 4,
                            "conversion" => $conversion,
                            "specImage" => "",
                            "specGroup" => [],
                            "salePrice" => [
                                "conversion" => $conversion,
                                "unitName" => $skuNameTwo,
                                "unitId" => $skuIdTwo,
                                "isMaster" => 4,
                                "deleteStatus" => 5,
                                "enabledLadder" => 0,
                                "salePriceAreaType" => 1,
                                "salePrice" => $salePriceTwo,
                                "ladderPrice" => [],
                                "marketPrice" => $salePriceTwoTrue,
                                "setNum" => 1
                            ]
                        ]
                    ],
                    "unitData" => [
                        [
                            "barCode" => "",
                            "weight" => "",
                            "isMaster" => 5,
                            "isDefault" => 5,
                            "unitName" => $skuName,
                            "unitId" => $skuId
                        ],
                        [
                            "unitName" => $skuNameTwo,
                            "isMaster" => 4,
                            "unitId" => $skuIdTwo,
                            "conversion" => $conversion,
                            "isEditSpec" => 5
                        ]
                    ],
                    "describe" => $describe,
                    "code" => "",
                    "barCode" => "",
                    "weight" => "",
                    "categoryId" => $categoryId,
                    "expireTime" => "",
                    "brandId" => $brandId,
                    "tag" => "",
                    "description" => $description,
                    "noSalesShop" => "",
                    "images" => $images,
                    "enableStatus" => 5,
                    "deliverySupIds" => "1,2",
                    "expressType" => 1,
                    "expressFee" => "",
                    "showExpress" => 5,
                    "ruleId" => "",
                    "isStore" => false
                ];
            }else{
                /***插入商品***/
                $specMultiple = [[
                    "barCode" => $barCode,//商品条码
                    "isDefault" => 5,
                    "unitId" => $skuId,
                    "unitName" => $skuName,
                    "isMaster" => 5,
                    "conversion" => 0,
                    "specImage" => "",
                    "specGroup" => [],
                    "salePrice" => [
                        "conversion" => 0,
                        "unitName" => $skuName,
                        "unitId" => $skuId,
                        "isMaster" => 5,
                        "deleteStatus" => 5,
                        "enabledLadder" => 0,
                        "salePriceAreaType" => 1,
                        "salePrice" => $salePrice,//商品价格
                        "ladderPrice" => [],
                        "marketPrice" => $salePriceTrue,
                        "setNum" => 1//限定数量
                    ]
                ]];

                $postData = [
                    'categoryPath' => $categoryPath,
                    'title' => $goodsName,
                    'storage' => '',
                    'delUnitIds' => [],
                    'delSpecSkuIds' => [],
                    'specType' => 1,//1:无规格
                    'specGroup' => [],//无规格为空
                    'specMultiple' => $specMultiple,
                    'unitData' =>
                        [
                            [
                                'barCode' => '',
                                'isMaster' => 5,
                                'isDefault' => 5,
                                'unitName' => $skuName,
                                'unitId' => $skuId,
                            ],
                        ],
                    'describe' => $describe,//商品卖点
                    'code' => '',
                    'barCode' => '',
                    'categoryId' => $categoryId,
                    'expireTime' => '',
                    'brandId' => $brandId,
                    'tag' => '',
                    'description' => $description,//商品详情
                    'noSalesShop' => '',
                    'images' => $images,
                    'enableStatus' => 5,
                ];

            }

            $result = request($apiUrl, json_encode($postData), 10, false, $curl_option);

           
            if ($result['httpcode'] != 200) {
                exit($result['content']);
            }
            $content = json_decode($result['content'], true);
            if ($content['state'] == false) {
                exit($content['data']);
            }
            $i++;
            var_dump('导入成功:'.$goodsName);
//            break;
        }
        exit('执行成功, 共添加' . $i . '条数据');
    }

    /**
     * 导入
     * 批量添加客户
     */
    public function autoAddCustomer()
    {
        $apiUrl = 'http://api.qianniao.vip/Customer/Customer/addCustomer';
        $curl_option = [
            CURLOPT_HTTPHEADER => [
                'Content-Type:text/plain',
                'Authorization:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMxMDEsImV4cGlyZVRpbWUiOjE2MDY0NTMxMjB9.gSDdfi4e0Hx_XIE-mGNRB7Ehk0iOclzpsQCv6P3ysXE',
                'Token:95619f5cc272439f87d9b0e6b87be3e4',
            ],
        ];
        $file = file('./1.txt');
        foreach ($file as $key => $value) {
            $array = explode(',', $value);

            $customerName = isset($array[0]) ? trim($array[0]) : '';//客户名称
            $mobile = isset($array[1]) ? trim($array[1]) : '';//手机号
            $remark = isset($array[2]) ? trim($array[2]) : '';//备注
            $shopId = '';//商铺id
            $type = 35;//客户类型id
            if (empty($mobile)) {
                continue;
            }
//            if(empty($mobile) || strlen($mobile) != 11){
//                $len = 4 - strlen($key + 1);
//                $str = '';
//                for($i = 1; $i <= $len; $i++){
//                    $str .= '0';
//                }
//                $mobile = '1111111'.$str.($key + 1);
//            }
            $postData = array(
                'tempSave' => '',
                'latitude' => '',
                'longitude' => '',
                'password' => '',
                'area' => '',
                'mobile' => $mobile,
                'enableStatus' => 5,
                'name' => $customerName,
                'code' => '',
                'type' => $type,
                'provinceCode' => 610000,
                'cityCode' => 610100,
                'districtCode' => 610112,
                'address' => '',
                'managerMobile' => '',
                'shopId' => $shopId,
                'departmentId' => '',
                'salesManId' => '',
                'salesManCode' => '',
                'salesManName' => '',
                'birthday' => 0,
                'remark' => $remark,
                'extend' =>
                    array(
                        'license' => '',
                    ),
                'contact' =>
                    array(
                        'area' => '',
                        'name' => $customerName,
                        'mobile' => $mobile,
                        'provinceCode' => 610000,
                        'cityCode' => 610100,
                        'districtCode' => 610112,
                        'address' => '大明宫万达',
                    ),
            );
            $result = request($apiUrl, json_encode($postData), 10, false, $curl_option);
            if ($result['httpcode'] != 200) {
                exit($result['content']);
            }
            $content = json_decode($result['content'], true);
            if ($content['state'] == false) {
//                exit($content['data']);
            }
        }
    }


    public function enterpriseId97ByTime0907()
    {
        //获取数据
        $file = file('./enterpriseId97ByTime0907.txt');
        //循环数据
        $goodsData = [];
        foreach ($file as $value) {
            //格式化商品数据
            $goodsArray = explode(',', $value);
            $goods['id'] = trim($goodsArray[0]);//商品ID
            $goods['name'] = trim($goodsArray[1]);//商品名称
            $goods['spec'] = [trim($goodsArray[2])];//商品规格
            $goods['category'] = trim($goodsArray[3]);//商品分类
            $goods['price'] = trim($goodsArray[4]);//商品价格
            if (!strripos($goods['category'], " ")) {
                continue;
            }
            if (isset($goodsData[$goods['id']])) {
                $goodsData[$goods['id']]['spec'] = array_merge($goodsData[$goods['id']]['spec'], $goods['spec']);
            } else {
                $goodsData[$goods['id']] = $goods;
            }
        }
        unset($goodsArray);
        unset($goods);
//        V($goodsData);
        //查询所有分类
        $sql = 'select id,link,title from qianniao_goods_category_97';
        $dbResult = $this->objDGoods->query($sql);
        if ($dbResult === false) {
            exit($this->objDGoods->error());
        }
        //格式化分类
        $categoryData = [];
        foreach ($dbResult as $value) {
            $categoryData[$value['title']] = [
                'id' => $value['id'],
                'path' => empty($value['link']) ? $value['id'] : $value['link'] . ',' . $value['id']
            ];
        }

        //请求数据
        $apiUrl = 'http://api.qianniao.vip/Goods/QuickGoods/addBasicAndPublishGoods';
        $curl_option = [
            CURLOPT_HTTPHEADER => [
                'Content-Type:text/plain',
                'Authorization:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjIxMDgsImV4cGlyZVRpbWUiOjE1OTk0Njc5ODN9.gG5Ike-xmmKqe-_CpE5tVbSIESvU7-2AlfTlK-ouLNI',
                'Token:4c8574ddcbf69ea23bcf403c0b0830e9'
            ],
        ];
        $specApiUrl = 'http://api.qianniao.vip/GoodsManage/SpecManage/defineSpec';
        $i = 0;
        foreach ($goodsData as $value) {
            //区分有没有规格
            $specType = 1;//无规格
            $specGroup = [];//无规格
            $specMultipleNo = [];
            $specMultipleNo[] = [
                "barCode" => "",
                "isDefault" => 5,
                "unitId" => 1,
                "unitName" => "件",
                "isMaster" => 5,
                "conversion" => 0,
                "specImage" => "",
                "specGroup" => [],
                "salePrice" => [
                    "conversion" => 0,
                    "unitName" => "件",
                    "unitId" => 1,
                    "isMaster" => 5,
                    "deleteStatus" => 4,
                    "enabledLadder" => 0,
                    "salePriceAreaType" => 1,
                    "salePrice" => $value['price'],
                    "ladderPrice" => [],
                    "marketPrice" => $value['price'] * 1.2,
                    "setNum" => 1
                ]
            ];
            $specMultipleYes = [];
            foreach ($value['spec'] as $specValue) {
                if ($specValue != '999') {
                    $specType = 2;//有规格
                    $specPostData = [
                        'hidden' => 4,
                        'pid' => 4,
                        'specName' => $specValue,
                    ];
                    $result = request($specApiUrl, json_encode($specPostData), 10, false, $curl_option);
                    if ($result['httpcode'] != 200) {
                        exit($result['content']);
                    }
                    $content = json_decode($result['content'], true);
                    $specGroup['groupSpec'] = [
                        'specName' => '默认',
                        'specId' => 4,
                    ];
                    $specGroup['params'][] = [
                        'specValueId' => $content['data']['id'],
                        'specValueName' => $content['data']['specName'],
                    ];
                    $specMultipleYes[] = [
                        'unitId' => 1,
                        'unitName' => '件',
                        'isMaster' => 5,
                        'conversion' => 0,
                        'specImage' => '',
                        'isDefault' => 4,
                        'barCode' => '',
                        'specGroup' => [
                            [
                                'specId' => '4',
                                'specName' => '默认',
                                'specValueName' => $specValue,
                                'specValueId' => '5',
                            ]
                        ],
                        'salePrice' =>
                            [
                                'conversion' => 0,
                                'unitName' => '件_' . $specValue,
                                'unitId' => 1,
                                'isMaster' => 5,
                                'deleteStatus' => 4,
                                'enabledLadder' => 0,
                                'salePriceAreaType' => 1,
                                'salePrice' => $value['price'],
                                'ladderPrice' => [],
                                'marketPrice' => $value['price'] * 1.2,
                                'setNum' => 1,
                            ],
                    ];
                }
            }

            $specMultiple = $specMultipleNo;
            if ($specType == 2) {
                $specMultiple = $specMultipleYes;
            }

            if (!strripos($value['category'], " ")) {
                continue;
            }
            $categoryTitle = substr($value['category'], strripos($value['category'], " ") + 1);
            //分类不存在 跳出本次
            if (!isset($categoryData[$categoryTitle])) {
                continue;
            }
            $postData = array(
                'categoryPath' => $categoryData[$categoryTitle]['path'],
                'title' => $value['name'],
                'storage' => '',
                'delUnitIds' => [],
                'delSpecSkuIds' => [],
                'specType' => $specType,
                'specGroup' => empty($specGroup) ? $specGroup : [$specGroup],
                'specMultiple' => $specMultiple,
                'unitData' =>
                    array(
                        0 =>
                            array(
                                'barCode' => '',
                                'isMaster' => 5,
                                'isDefault' => 5,
                                'unitName' => '件',
                                'unitId' => 1,
                            ),
                    ),
                'describe' => '',
                'code' => '',
                'barCode' => '',
                'categoryId' => $categoryData[$categoryTitle]['id'],
                'expireTime' => '',
                'brandId' => '',
                'tag' => '',
                'description' => '',
                'noSalesShop' => '',
                'images' => ["https://onlineimg.qianniao.vip/159929437078955/4c8574ddcbf69ea23bcf403c0b0830e9/logo.jpg"],
                'enableStatus' => 5,
            );
            $result = request($apiUrl, json_encode($postData), 10, false, $curl_option);
            if ($result['httpcode'] != 200) {
                exit($result['content']);
            }
            $content = json_decode($result['content'], true);
            if ($content['state'] == false) {
                exit($content['data']);
            }
            $i++;
        }

        echo '执行成功, 共添加' . $i . '条商品';
    }

    /**
     * 我的锅系统商品添加
     */
    public function addGuoGoods()
    {
        $apiUrl = 'https://store.qianniaovip.com//app/index.php?i=2&c=entry&do=SaveGoods&m=yb_cy';
        $curl_option = [
            CURLOPT_HTTPHEADER => [
                'Content-Type:application/json;charset=UTF-8',
            ],
        ];
        $postData = [
            "id" => "",
            "sort" => "1",
            "categoryIds" => [
                "13"
            ],
            "salesNum" => "",
            "minNum" => 0,
            "maxNum" => 0,
            "icon" => "../addons/yb_cy/template/public/img/set/nopic.jpg",
            "media" => [
                "https => //wodeguo-1303051460.cos.ap-chengdu.myqcloud.com/yb_cy/2020/09/14/0353760156390008.png"
            ],
            "item" => 1,
            "spec" => [
            ],
            "attribute" => [
            ],
            "name" => "千鸟云商测试商品",
            "group" => [
            ],
            "boxMoney" => "",
            "body" => "",
            "outSalesPrice" => 1,
            "outPrice" => 0,
            "outStock" => 1,
            "inSalesPrice" => 1,
            "inPrice" => 0,
            "inStock" => 1,
            "isSpec" => "2",
            "isAttribute" => "2",
            "required" => "2",
            "isMaterial" => "2",
            "MaterialIds" => [
            ],
            "unit" => "13",
            "isMember" => "2",
            "details" => ""
        ];
        $result = request($apiUrl, json_encode($postData), 10, false, $curl_option);
        if ($result['httpcode'] != 200) {
            exit($result['content']);
        }
        $content = json_decode($result['content'], true);
        V($content);
    }

//    public function recived()
//    {
//
//        $i = 1;
//        do {
//            $postData = [
//                'topicName'         => 'MyJob',
//                'topicClass'        => 'Jobs\Model\MTopic\Finance\MReceivable',
//                'topicMethon'       => 'checkExistCreate',
//                'topicMethonParams' => [
//                    'enterpriseId' => 34,
//                ],
//            ];
//
//            $url = 'http://queue.qianniao.vip:8080/CAddJob/add';
//            $result = request($url, $postData);
//            print_r($result);
//            $i++;
//        } while ($result['httpcode'] != 200 && $i <= 3);
//    }

    public function log()
    {
        Logger::logs(E_USER_ERROR, '没有错误信息', __CLASS__, __LINE__, '没有错误信息');
    }

    public function formatUpdateEsData()
    {

        $curl_option = [
            CURLOPT_HTTPHEADER => [
                'Content-Type: application/json'
            ],
        ];
        $postData = [
            'doc' => [
                'status' => 2
            ]
        ];
        for ($i = 1; $i <= 170; $i++) {
            if ($i != 19) {
                $enableApiUrl = 'http://49.235.209.106:9200/online_customer_search/customer/EnterpriseId_13_CustomerId_' . $i . '/_update';
                $result = request($enableApiUrl, json_encode($postData), 1000, false, $curl_option);
                var_dump($result['content']);
                var_dump('<br/>');
            }
        }
    }

    public function autoEnterprise()
    {
        $objMEnterprise = new MEnterprise();
        $return = $objMEnterprise->autoCreateData(1112, 71);
        echo $return->getData();
    }

    public function goodsCateGory()
    {

        $sql = 'select * from qianniao_goods_category_48 where deleteStatus = 5 and pid = 0';
        $category = $this->objDGoods->query($sql);
        if ($category === false) {
            return ResultWrapper::fail($this->objDGoods->error(), ErrorCode::$paramError);
        }

        $map = [];

        foreach ($category as $item) {
            //' and find_in_set('.$condition['categoryId'].',b.categoryPath) ';
            $sql_1 = 'select g.id from qianniao_goods_48 as g left join qianniao_goods_basic_48 as b 
                        on g.basicGoodsId = b.id where find_in_set(' . $item['id'] . ',b.categoryPath) and 
                       g.deleteStatus = 5 And g.enableStatus = 5';
            $sql_2 = 'select g.id from qianniao_goods_48 as g left join qianniao_goods_basic_48 as b 
                        on g.basicGoodsId = b.id where find_in_set(' . $item['id'] . ',b.categoryPath) and 
                       g.deleteStatus = 5 And g.enableStatus = 4';
            $u_count = count($this->objDGoods->query($sql_1));
            $b_count = count($this->objDGoods->query($sql_2));
            $map[] = [
                'id' => $item['id'],
                'categoryName' => $item['title'],
                'u_num' => $u_count,
                'b_num' => $b_count
            ];
        }
        self::export($map);
        die;

    }

    /**
     * 导出方法
     *
     * @param $allOrderData
     */
    private static function export($allOrderData)
    {
        //导出到本地
        header("Content-type:application/vnd.ms-excel");
        header("Content-Disposition:filename=订单记录.csv");
        header('Cache-Control: max-age=0');
        $fp = fopen('php://output', 'a');
        $head = ['ID', '分类名称', '上架数量', '下架数量'];       //定义标题
        foreach ($head as $i => $v) {
            $head[$i] = mb_convert_encoding($v, 'GBK', 'utf-8');     //将中文标题转换编码，否则乱码
        }
        fputcsv($fp, $head);
        $limit = 10000;
        $num = 0;//计数器
        foreach ($allOrderData as $v) {
            //循环数据
            $num++;
            if ($num == $limit) {
                ob_flush();//释放内存
                flush();
            }
            $rows['id'] = $v['id'];
            $rows['categoryName'] = $v['categoryName'];
            $rows['u_num'] = $v['u_num'];
            $rows['b_num'] = $v['b_num'];
            foreach ($rows as $kk => $vv) {
                $rs[$kk] = mb_convert_encoding($vv, 'GBK', 'utf-8');  //转译编码
            }
            fputcsv($fp, $rs);
            $rows = [];
        }
        exit;
    }


    /**
     * 处理文件
     * @throws Exception
     * @throws \Exception
     */
    public function formatFIle()
    {
        $file = file('./1.txt');
        $userCenterId = 969;
        $enterpriseId = 56;
        $objMGoodsBasic = new MGoodsBasic($userCenterId, $enterpriseId);
        $objMQuickGoods = new MQuickGoods($enterpriseId, $userCenterId);
        $objMGoods = new MGoods($enterpriseId, false, $userCenterId);
        $array = [];
        foreach ($file as $key => $value) {
            $goodsArray = explode(',', $value);
            if (empty(trim($goodsArray[0])) || in_array(trim($goodsArray[0]), $array)) continue;

            $title = trim($goodsArray[0]) . trim($goodsArray[3]);//商品名字
            $unitId = trim($goodsArray[1]);
            $unitName = trim($goodsArray[2]);

            $describe = '';//卖点
            $categoryId = 2;
            $categoryPath = '2';
            $shopId = 56;
            $shopName = '品茗苑茶行';
            $brandId = 1;


            $addData = [
                //必填字段
                'title' => $title,//商品名称
                'brandId' => $brandId,//品牌id
                'categoryId' => $categoryId,//分类
                'categoryPath' => $categoryPath,//分类路径
                'unitData' => [['unitName' => $unitName, 'isMaster' => 5, 'conversion' => '0.00', 'unitId' => $unitId, 'barCode' => '']],//单位
                'barCode' => '',//条码
                'describe' => $describe,//卖点
                'specType' => 1,//单规格1 多规格2
                'description' => '',
                'images' => '[]',//商品图册json
                'expireTime' => 0,
                'tag' => '',//关键词
                'link' => '',


//                'specMultiple' => [],
//                'shopId'       => 46,//商铺id
//                'shopName'     => '纺物优选',//商铺名称
//
//                'barCode' => '',
//                'noSalesShop' => '',
//                'specGroup' => [],
//                'extends' => json_encode(['storage'=>'']),
//                'enableStatus' => 4,
//                'createUserName' => '',
//                'sort' => '',
            ];
            //添加商品基础资料
            $modelResult = $objMGoodsBasic->addGoodsBasic($addData);
            if (!$modelResult->isSuccess()) {
                echo $modelResult->getData();
            }
            $basicId = $modelResult->getData();

            $goodsData = [
                'basicGoodsId' => $basicId,//基本资料id
                'goodsName' => $title,//基本资料商品名称
                'shopId' => $shopId,//商铺id
                'shopName' => $shopName,//商铺名称
                'images' => '[]',
                'specType' => 1,//规格类型
                'enableStatus' => StatusCode::$delete,
                'priceData' => '',//接json值
                'createUserName' => '',//添加商品人名称
            ];

            $goodsData['content'] = '';
            $goodsData['isRecommend'] = 4;
            $goodsData['createTime'] = time();
            $goodsData['updateTime'] = time();
            $goodsData['deleteStatus'] = StatusCode::$standard;
            $goodsData['sort'] = 0;
            //添加商品
            $modelResult = $objMGoods->addGoods($goodsData);
            if (!$modelResult->isSuccess()) {
                echo $modelResult->getData();
            }

            $array[] = $title;
            //单店铺添加商品
//            $modelResult = $objMQuickGoods->addBasicAndPublishGoods($addData);
//            if (!$modelResult->isSuccess()) {
//                echo $modelResult->getData();
//            }


//            if($key > 1){
//                break;
//            }
        }
        echo '成功';
    }

    /**
     * 格式化分类
     * @throws Exception
     */
    public function formatFIleCategory()
    {
        $file = file('./2.txt');
        $objDSku = new DSku();
        foreach ($file as $value) {
            $explodeData = explode(':', $value);
            $goodsBasicData = trim($explodeData[0]);
            $goodsCategoryData = trim($explodeData[1]);
            //判断是一级分类还是多级分类
            if (strstr($goodsCategoryData, ',')) {
                //多级分类
                $categoryData = explode(',', $goodsCategoryData);
                $categoryPath = '';
                $categoryId = 0;
                foreach ($categoryData as $key => $v) {
                    $category = trim($v);
                    //查询分类表是否有这个分类的名称
                    $sql = 'select * from qianniao_goods_category_34 where title = ' . trim($category) . ' and pid = ' . $categoryId;
                    $dbResult = $objDSku->query($sql);
                    if ($dbResult === false) {
                        echo $objDSku->error();
                        break;
                    }
                    //如果不存在 插入一条分类
                    if (empty($dbResult)) {
                        $sql = 'insert into qianniao_goods_category_34 (pid, title, createTime, updateTime) values(' . $categoryId . ', "' . trim($category) . '", ' . time() . ', ' . time() . ')';
                        $insertResult = $objDSku->query($sql);
                        if ($insertResult === false) {
                            echo $objDSku->error();
                            break;
                        }
                        $id = $insertResult;
                    } else {
                        $id = $dbResult[0]['id'];
                    }
                    $categoryId = $id;
                    $categoryPath = $categoryId == 0 ? $id : $categoryPath . ',' . $id;
                }
            } else {
                //一级分类
                //查询分类表是否有这个分类的名称
                $sql = 'select * from qianniao_goods_category_34 where title = ' . trim($goodsCategoryData) . ' and pid = 0';
                $dbResult = $objDSku->query($sql);
                if ($dbResult === false) {
                    echo $objDSku->error();
                    break;
                }
                //如果不存在 插入一条分类
                if (empty($dbResult)) {
                    $sql = 'insert into qianniao_goods_category_34 (pid, title, createTime, updateTime) values(0, "' . trim($goodsCategoryData) . '", ' . time() . ', ' . time() . ')';
                    $categoryId = $objDSku->query($sql);
                    if ($categoryId === false) {
                        echo $objDSku->error();
                        break;
                    }
                } else {
                    $categoryId = $dbResult[0]['id'];
                }
                $categoryPath = $categoryId;
            }
            //根据该商品名称修改分类字段
            $sql = 'update qianniao_goods_basic_34 set categoryId = ' . $categoryId . ', categoryPath = ' . $categoryPath . ' where title = "' . $goodsBasicData . '"';
            $dbResult = $objDSku->query($sql);
            if ($dbResult === false) {
                echo $objDSku->error();
                break;
            }
        }
    }

    /**
     * 测试 获取缓存
     * @throws Exception
     */
    public function getCache()
    {
        $objMOrder = new MOrder(1, 1);
        $result = $objMOrder->businessOverview('todayConfirmedOrderNum', '');
        V($result);
    }

    public function test_request()
    {
        $apiUrl = 'http://api.qianniao.vip/Goods/Goods/addGoods';

        $enableApiUrl = 'http://api.qianniao.vip/Goods/Goods/updateEnableStatus';
        $curl_option = [
            CURLOPT_HTTPHEADER => [
                'Content-Type:text/plain',
                'Authorization:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjU2OSwiZXhwaXJlVGltZSI6MTU5MTUwMDQ1M30.y5HnUgq7dZ4lgk4bCK_l7FJr_UpelHYtvgLX4Hpa5fs',
                'Token:8fa553d53f44e33123e4d0d51a0de634'
            ],
        ];

        $objDGoodsBasic = new DGoodsBasic();
        $objSku = new DSku();
        $sql = 'select b.* from qianniao_goods_basic_34 as b left join qianniao_goods_34 as g on b.id = g.basicGoodsId WHERE g.basicGoodsId IS NULL';
        $dbResult = $objDGoodsBasic->query($sql);


        foreach ($dbResult as $row) {
            $skuData = $objSku->query('select * from qianniao_sku_34 where goodsId = ' . $row['id'] . ' and deleteStatus = 5');
            $postData = [
                "createUserName" => "陈民",
                "goodsName" => $row['title'],
                "specType" => $row['specType'],
                "goodsBasicId" => $row['id'],
                "shopId" => 38,
                "shopName" => "万货网",
                "images" => json_decode($row['images'], true),
                "salesArea" => [],
                "serviceInfo" => 1,
                "price" => [
                    [
                        "id" => $skuData[0]['id'],
                        "unitId" => $skuData[0]['unitId'],
                        "unitName" => $skuData[0]['unitName'],
                        "conversion" => "0.00",
                        "isMaster" => 5,
                        "enabledLadder" => 0,
                        "marketPrice" => 1000,
                        "salePrice" => 999,
                        "setNum" => 1,
                        "salePriceAreaType" => 1,
                        "ladderPrice" => []
                    ]
                ],
                "specification" => [
                    null
                ],
                "content" => "",
                "isRecommend" => 5,
                "sort" => "1"
            ];

            $result = request($apiUrl, json_encode($postData), 10, false, $curl_option);

            if ($result['httpcode'] != 200) {
                return ResultWrapper::fail($result['content'], ErrorCode::$apiNotResult);
            }

            $reponse = json_decode($result['content'], true);
            if (isset($reponse) && $reponse['errorcode'] == 0) {
                $enableData = [
                    'enableStatus' => StatusCode::$standard,
                    'id' => (int)$reponse['data']
                ];
                $enableResponse = request($enableApiUrl, json_encode($enableData), 10, false, $curl_option);
            }

            //V(123);
        }

        return ResultWrapper::success($reponse['data']);
    }

    /**
     * @throws Exception
     */
    public function syncGoodsAndGoodsBasic()
    {
        $objDGoodsBasic = new DGoodsBasic();
        $objDGoods = new DGoods();
        $objDGoods->setTable('qianniao_goods_34');
        $objDGoodsBasic->setTable('qianniao_goods_basic_34');
        $goodsBasicData = $objDGoodsBasic->select([], 'id,images');
        if ($goodsBasicData === false) {
            exit("sql:" . $objDGoodsBasic->error());
        }

        foreach ($goodsBasicData as $row) {
            $update = $objDGoods->update(['images' => $row['images']], ['basicGoodsId' => $row['id']]);
            if ($update === false) {
                exit("sql:" . $objDGoods->error());
            }
        }

        V("操作成功");
    }

    /**
     * Test constructor.
     */
    public function __construct()
    {
        $this->objDGoods = new DGoods();
//        $this->Authorization = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjgyNywiZXhwaXJlVGltZSI6MTU5NTgzMDUzN30.Rua2aBXgwh_hIAkp6M1KHYYtCzcsTgEdLqvD-c8-pmw';
//        $this->Token = 'a946c2ed5c589bfe0f66e48facb32649';
    }

    /**public function addOrder()
     * {
     * echo "start".PHP_EOL;
     * $apiUrl = 'http://api.qianniao.vip/Order/Order/addOrder/613';
     * $curl_option = [
     * CURLOPT_HTTPHEADER => [
     * 'Content-Type:text/plain',
     * 'Authorization:'.$this->Authorization,
     * 'Token:'.$this->Token
     * ],
     * ];
     * //$postData = '{"deliveryType":1,"customerName":"清扬超市","receiveAddressId":141,"source":"3","orderRemark":"新日期","goodsData":{"totalMoney":"406.05","payMoney":"406.05","preferential":"0.00","vipDiscount":0,"vipDoubleDiscount":0,"activityMoney":"0.00","checkNum":5,"cartNum":5,"goodsNum":29,"goodsData":[{"shopId":38,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","totalMoney":"406.05","preferential":"0.00","payMoney":"406.05","shopGoodsData":[{"id":2536,"goodsId":483,"goodsCode":"MATERIEL000483","buyNum":5,"shopId":38,"goodsBasicId":483,"selection":5,"skuId":483,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2536,"brandName":"","categoryName":"膨化食品","barCode":"6924743919242","storageCode":"H1-2-1-3","goodsName":"乐事墨西哥鸡汁番茄味薯片70g","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591509958101乐事墨西哥鸡汁番茄味薯片70g.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":99,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"4.65","price":"4.65","preferential":0,"totalMoney":"23.25","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"4.3200","inventoryNum":"17.00000000","conversion":0},{"id":2535,"goodsId":517,"goodsCode":"MATERIEL000517","buyNum":4,"shopId":38,"goodsBasicId":517,"selection":5,"skuId":517,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2535,"brandName":"健力宝","categoryName":"膨化食品","barCode":"6920912341852","storageCode":"A2-1-4-1","goodsName":"盼盼家庭号经济包薯片原味108g","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591509094748盼盼家庭号经济包薯片原味108g.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":1,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.45","price":"2.45","preferential":0,"totalMoney":"9.80","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"2.1000","inventoryNum":"54.00000000","conversion":0},{"id":2534,"goodsId":495,"goodsCode":"MATERIEL000495","buyNum":10,"shopId":38,"goodsBasicId":495,"selection":5,"skuId":495,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2534,"brandName":"","categoryName":"膨化食品","barCode":"6909409012802","storageCode":"A1-1-3-4","goodsName":"上好佳草莓味栗米条40g","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591509681566上好佳草莓味栗米条40g.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":102,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.70","price":"2.70","preferential":0,"totalMoney":"27.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"2.6000","inventoryNum":"30.00000000","conversion":0},{"id":2533,"goodsId":64,"goodsCode":"MATERIEL000064","buyNum":8,"shopId":38,"goodsBasicId":64,"selection":5,"skuId":64,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2533,"brandName":"","categoryName":"果汁饮料","barCode":"","storageCode":"","goodsName":"康师傅冰红茶1L*12瓶","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591581053066康师傅茉莉蜜茶1l.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":18,"brandId":109,"categoryPath":"18","isActivity":4,"specType":1,"unitName":"件","specGroup":[],"originPrice":"34.50","price":"34.50","preferential":0,"totalMoney":"276.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"34.6660","inventoryNum":"10.00000000","conversion":0},{"id":2532,"goodsId":63,"goodsCode":"MATERIEL000063","buyNum":2,"shopId":38,"goodsBasicId":63,"selection":5,"skuId":63,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2532,"brandName":"","categoryName":"果汁饮料","barCode":"6921317989847","storageCode":"C1-1-15","goodsName":"康师傅蜂蜜绿茶1L*12瓶","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591581068709康师傅绿茶1l.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":18,"brandId":109,"categoryPath":"18","isActivity":4,"specType":1,"unitName":"件","specGroup":[],"originPrice":"35.00","price":"35.00","preferential":0,"totalMoney":"70.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"34.6500","inventoryNum":"5.00000000","conversion":0}]}],"invalidData":[]}}';
     * $postData = '{"deliveryType":1,"customerName":"诚信百货超市","receiveAddressId":7,"source":"3","orderRemark":"","goodsData":{"totalMoney":"420.75","payMoney":"420.75","preferential":"0.00","vipDiscount":0,"vipDoubleDiscount":0,"activityMoney":"0.00","checkNum":15,"cartNum":15,"goodsNum":60,"goodsData":[{"shopId":38,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","totalMoney":"420.75","preferential":"0.00","payMoney":"420.75","shopGoodsData":[{"id":2552,"goodsId":575,"goodsCode":"MATERIEL000575","buyNum":10,"shopId":38,"goodsBasicId":575,"selection":5,"skuId":575,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2552,"brandName":"","categoryName":"坚果炒货","barCode":"6922742001180","storageCode":"A2-3-3-3","goodsName":"沙土原香瓜子200g","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591504718336沙土原香瓜子200g.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":118,"brandId":104,"categoryPath":"118","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"3.70","price":"3.70","preferential":0,"totalMoney":"37.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"4.2538","inventoryNum":"61.00000000","conversion":0},{"id":2550,"goodsId":574,"goodsCode":"MATERIEL000574","buyNum":20,"shopId":38,"goodsBasicId":574,"selection":5,"skuId":574,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2550,"brandName":"","categoryName":"坚果炒货","barCode":"6922742000848","storageCode":"A2-3-3-2","goodsName":"沙土香瓜子300g","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591504774300沙土香瓜子300g.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":118,"brandId":104,"categoryPath":"118","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"5.95","price":"5.95","preferential":0,"totalMoney":"119.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"5.6200","inventoryNum":"140.00000000","conversion":0},{"id":2549,"goodsId":345,"goodsCode":"MATERIEL000345","buyNum":2,"shopId":38,"goodsBasicId":345,"selection":5,"skuId":345,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2549,"brandName":"","categoryName":"熟食卤味","barCode":"6935284413991","storageCode":"F1-4-3-5","goodsName":"卫龙亲嘴烧选B麦辣鸡汁味28g*20包","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591513223408卫龙亲嘴烧选B麦辣鸡汁味28g.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":13,"brandId":89,"categoryPath":"13","isActivity":4,"specType":1,"unitName":"盒","specGroup":[],"originPrice":"14.50","price":"14.50","preferential":0,"totalMoney":"29.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"13.0000","inventoryNum":"2.00000000","conversion":0},{"id":2548,"goodsId":72,"goodsCode":"MATERIEL000072","buyNum":1,"shopId":38,"goodsBasicId":72,"selection":5,"skuId":72,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2548,"brandName":"","categoryName":"茶饮料","barCode":"4891599366839","storageCode":"C1-1-8","goodsName":"加多宝凉茶植物饮料550ML*15瓶","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591580637360主图-1 (1).jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":15,"brandId":72,"categoryPath":"15","isActivity":4,"specType":1,"unitName":"件","specGroup":[],"originPrice":"43.80","price":"43.80","preferential":0,"totalMoney":"43.80","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"42.0000","inventoryNum":"5.00000000","conversion":0},{"id":2547,"goodsId":440,"goodsCode":"MATERIEL000440","buyNum":3,"shopId":38,"goodsBasicId":440,"selection":5,"skuId":440,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2547,"brandName":"","categoryName":"膨化食品","barCode":"6922330265543","storageCode":"F1-9-1-1","goodsName":"运康牛肉口味锅巴102g袋装","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591510887159运康牛肉口味锅巴102g袋装.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":97,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.30","price":"2.30","preferential":0,"totalMoney":"6.90","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"1.9367","inventoryNum":"51.00000000","conversion":0},{"id":2546,"goodsId":441,"goodsCode":"MATERIEL000441","buyNum":3,"shopId":38,"goodsBasicId":441,"selection":5,"skuId":441,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2546,"brandName":"","categoryName":"膨化食品","barCode":"6922330265529","storageCode":"F1-9-2-1","goodsName":"运康香辣口味锅巴102g袋装","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591510878227运康香辣口味锅巴102g袋装.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":97,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.30","price":"2.30","preferential":0,"totalMoney":"6.90","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"2.0000","inventoryNum":"44.00000000","conversion":0},{"id":2545,"goodsId":442,"goodsCode":"MATERIEL000442","buyNum":3,"shopId":38,"goodsBasicId":442,"selection":5,"skuId":442,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2545,"brandName":"","categoryName":"膨化食品","barCode":"6922330255001","storageCode":"F1-9-1-2","goodsName":"运康五香口味锅巴102g袋装","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591510880914运康五香口味锅巴102g袋装.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":97,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.30","price":"2.30","preferential":0,"totalMoney":"6.90","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"2.0000","inventoryNum":"5.00000000","conversion":0},{"id":2544,"goodsId":443,"goodsCode":"MATERIEL000443","buyNum":3,"shopId":38,"goodsBasicId":443,"selection":5,"skuId":443,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2544,"brandName":"","categoryName":"膨化食品","barCode":"6922330265703","storageCode":"F1-9-2-3","goodsName":"运康鸡肉口味锅巴102g袋装","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591510893356运康鸡肉口味锅巴102g袋装.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":97,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.30","price":"2.30","preferential":0,"totalMoney":"6.90","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"1.9000","inventoryNum":"50.00000000","conversion":0},{"id":2543,"goodsId":444,"goodsCode":"MATERIEL000444","buyNum":3,"shopId":38,"goodsBasicId":444,"selection":5,"skuId":444,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2543,"brandName":"","categoryName":"膨化食品","barCode":"6922330265512","storageCode":"F1-9-2-2","goodsName":"运康烧烤口味锅巴102g袋装","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591510884090运康烧烤口味锅巴102g袋装.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":97,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.30","price":"2.30","preferential":0,"totalMoney":"6.90","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"1.9166","inventoryNum":"60.00000000","conversion":0},{"id":2542,"goodsId":445,"goodsCode":"MATERIEL000445","buyNum":3,"shopId":38,"goodsBasicId":445,"selection":5,"skuId":445,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2542,"brandName":"","categoryName":"膨化食品","barCode":"6922330265581","storageCode":"F1-9-2-4","goodsName":"运康麻辣口味锅巴102g袋装","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591510890646运康麻辣口味锅巴102g袋装.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":97,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.45","price":"2.45","preferential":0,"totalMoney":"7.35","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"1.9397","inventoryNum":"53.00000000","conversion":0},{"id":2541,"goodsId":446,"goodsCode":"MATERIEL000446","buyNum":3,"shopId":38,"goodsBasicId":446,"selection":5,"skuId":446,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2541,"brandName":"","categoryName":"膨化食品","barCode":"","storageCode":"","goodsName":"运康羊肉串口味锅巴102g袋装","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591510875264运康羊肉串口味锅巴102g袋装.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":2,"brandId":97,"categoryPath":"2","isActivity":4,"specType":1,"unitName":"包","specGroup":[],"originPrice":"2.30","price":"2.30","preferential":0,"totalMoney":"6.90","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"1.9000","inventoryNum":"50.00000000","conversion":0},{"id":2540,"goodsId":349,"goodsCode":"MATERIEL000349","buyNum":2,"shopId":38,"goodsBasicId":349,"selection":5,"skuId":349,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2540,"brandName":"","categoryName":"熟食卤味","barCode":"6935284415162","storageCode":"F1-4-2-1","goodsName":"卫龙魔芋爽酸辣素毛肚18g*20包","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591513176969卫龙魔芋爽酸辣素毛肚18g_20.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":13,"brandId":89,"categoryPath":"13","isActivity":4,"specType":1,"unitName":"盒","specGroup":[],"originPrice":"14.50","price":"14.50","preferential":0,"totalMoney":"29.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"12.7343","inventoryNum":"10.00000000","conversion":0},{"id":2539,"goodsId":347,"goodsCode":"MATERIEL000347","buyNum":2,"shopId":38,"goodsBasicId":347,"selection":5,"skuId":347,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2539,"brandName":"","categoryName":"熟食卤味","barCode":"6935284414011","storageCode":"F1-4-3-4","goodsName":"卫龙亲嘴烧选C川香风味28g*20包","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591513220899卫龙亲嘴烧选C川香风味28g_20.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":13,"brandId":89,"categoryPath":"13","isActivity":4,"specType":1,"unitName":"盒","specGroup":[],"originPrice":"14.50","price":"14.50","preferential":0,"totalMoney":"29.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"13.0000","inventoryNum":"2.00000000","conversion":0},{"id":2538,"goodsId":678,"goodsCode":"MATERIEL000678","buyNum":1,"shopId":38,"goodsBasicId":678,"selection":5,"skuId":678,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2538,"brandName":"","categoryName":"方便面/粉","barCode":"","storageCode":"","goodsName":"康师傅鲜虾鱼板面95g*24袋","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591502015830康师傅鲜虾鱼板面95g.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":22,"brandId":109,"categoryPath":"22","isActivity":4,"specType":1,"unitName":"件","specGroup":[],"originPrice":"47.50","price":"47.50","preferential":0,"totalMoney":"47.50","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"46.0000","inventoryNum":"2.00000000","conversion":0},{"id":2537,"goodsId":663,"goodsCode":"MATERIEL000663","buyNum":1,"shopId":38,"goodsBasicId":663,"selection":5,"skuId":663,"warehouseId":1,"activityId":0,"shopName":"济南万货网自营仓","shopLogo":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591611913629fbcd6ad1f75737ddcbd5a9eaaba9586f.png?imageView2/2/w/750/h/750","cartId":2537,"brandName":"","categoryName":"方便面/粉","barCode":"6903252100785","storageCode":"","goodsName":"康师傅红烧牛肉面109g*12桶","goodsImages":"https://onlineimg.qianniao.vip/8fa553d53f44e33123e4d0d51a0de634/1591502332247康师傅红烧牛肉面108g-12桶.jpg?imageView2/2/w/750/h/750","isInvalid":5,"describe":"","categoryId":22,"brandId":109,"categoryPath":"22","isActivity":4,"specType":1,"unitName":"件","specGroup":[],"originPrice":"38.00","price":"38.00","preferential":0,"totalMoney":"38.00","activityMoney":0,"isMutex":4,"vipDiscount":0,"inventory":0,"costPrice":"37.0000","inventoryNum":"7.00000000","conversion":0}]}],"invalidData":[]}}';
     * $result = request($apiUrl, $postData, 60, false, $curl_option);
     * if ($result['httpcode'] != 200) {
     * return ResultWrapper::fail($result['content'], ErrorCode::$apiNotResult);
     * }
     * $reponse = json_decode($result['content'], true);
     * V($reponse);
     * }**/

    public function bugCategoryPath()
    {
        $fields = 'b.id,b.title,b.categoryPath,b.categoryId';
        $sql = 'SELECT ' . $fields . ' FROM qianniao_goods_basic_48 as b  
                LEFT JOIN qianniao_goods_category_48 as c ON 
                c.id = b.categoryId WHERE c.pid != 0';
        $result = $this->objDGoods->query($sql);
        if ($result === false) {
            echo 'sql' . $this->objDGoods->error();
            die;
        }

        $allCategoryIds = [];
        foreach ($result as $item) {
            $allCategoryIds[] = $item['categoryId'];
        }

        //获取这些分类的全路径
        $c_sql = 'SELECT id,pid,title FROM qianniao_goods_category_48 WHERE deleteStatus=5';
        $category = $this->objDGoods->query($c_sql);
        $allCategory = [];
        foreach ($category as $item) {
            $allCategory[$item['id']] = $item;
        }

        foreach ($allCategory as &$item) {
            if ($item['pid'] == 0) {
                $item['categoryPath'] = $item['id'];
            } else {
                $item['categoryPath'] = $item['pid'] . ',' . $item['id'];
            }
        }
        unset($item);


        foreach ($result as $key => $item) {
            $result[$key]['categoryPath'] = $allCategory[$item['categoryId']]['categoryPath'];
        }

        $objDGoodsBasic = new DGoodsBasic();
        $objDGoodsBasic->setTable('qianniao_goods_basic_48');

        foreach ($result as $value) {
            $update = $objDGoodsBasic->update([
                'categoryPath' => $value['categoryPath']
            ], ['id' => $value['id']]);
            if ($update === true) {
                echo 'sql' . $objDGoodsBasic->error();
            }
        }

        echo 'success';
    }

    /**
     * 基础商品
     * @return ResultWrapper
     */
    public function goodsBasic()
    {
        echo "start" . PHP_EOL;
        $apiUrl = 'http://api.qianniao.vip/GoodsManage/GoodsBasic/fixEsData';
        $curl_option = [
            CURLOPT_HTTPHEADER => [
                'Content-Type:text/plain',
                'Authorization:' . $this->Authorization,
                'Token:' . $this->Token
            ],
        ];

        $postData = [
            "page" => 0,
            "pageSize" => 2000,
        ];
        $result = request($apiUrl, json_encode($postData), 60, false, $curl_option);

        if ($result['httpcode'] != 200) {
            return ResultWrapper::fail($result['content'], ErrorCode::$apiNotResult);
        }
        $reponse = json_decode($result['content'], true);
        V($reponse);
    }

    /**
     * 修补商品es数据
     */
    public function goods_fixEsData()
    {
        echo 'start' . PHP_EOL;
        $apiUrl = 'http://api.qianniao.vip/Goods/Goods/fixEsData';
        $curl_option = [
            CURLOPT_HTTPHEADER => [
                'Content-Type:text/plain',
                'Authorization:' . $this->Authorization,
                'Token:' . $this->Token
            ],
        ];
        $postData = [
            "page" => 0,
            "pageSize" => 2000
        ];
        $result = request($apiUrl, json_encode($postData), 60, false, $curl_option);

        if ($result['httpcode'] != 200) {
            return ResultWrapper::fail($result['content'], ErrorCode::$apiNotResult);
        }
        $reponse = json_decode($result['content'], true);
        V($reponse);
    }

    /**
     * 基础资料
     * @throws Exception
     */
    public function test_replace()
    {
        $objDGoodsBasic = new DGoodsBasic();
        $objDGoodsBasic->setTable('qianniao_goods_basic_1');
        $sql = 'select id,images,description from qianniao_goods_basic_1';
        $dbResult = $objDGoodsBasic->query($sql);
        if ($dbResult === false) {
            exit("获取数据失败" . $objDGoodsBasic->error());
        }

        foreach ($dbResult as $row) {
            if (empty($row['images'])) {
                continue;
            }
            $images = json_decode($row['images'], true);
            foreach ($images as &$item) {
                $item = str_replace('https://image.saiyin168.cn', 'https://image.qpl123.com', $item);
            }
            $images = json_encode($images);

            $description = str_replace('https://image.saiyin168.cn', 'https://image.qpl123.com', $row['description']);

            $updateResult = $objDGoodsBasic->update(['images' => $images, 'description' => $description], ['id' => $row['id']]);
            if ($updateResult === false) {
                exit('更新失败' . $objDGoodsBasic->error());
            }
        }

        exit('操作成功');
    }

    /**
     *
     * @throws Exception
     */
    public function test_replace_goods()
    {
        $objDGoods = new DGoods();
        $objDGoods->setTable('qianniao_goods_1');
        $sql = 'select id,images,content from qianniao_goods_1';
        $dbResult = $objDGoods->query($sql);
        if ($dbResult === false) {
            exit("获取数据失败" . $objDGoods->error());
        }

        foreach ($dbResult as $row) {
            if (empty($row['images'])) {
                continue;
            }
            $images = json_decode($row['images'], true);
            foreach ($images as &$item) {
                $item = str_replace('https://image.saiyin168.cn', 'https://image.qpl123.com', $item);
            }
            $images = json_encode($images);
            $content = str_replace('https://image.saiyin168.cn', 'https://image.qpl123.com', $row['content']);
            $updateResult = $objDGoods->update(['images' => $images, 'content' => $content], ['id' => $row['id']]);
            if ($updateResult === false) {
                exit('更新失败' . $objDGoods->error());
            }
        }

        exit('操作成功');
    }

    /**
     *
     * @throws Exception
     */
    public function test_replace_category()
    {
        $objDGoodsCategory = new DGoodsCategory();
        $objDGoodsCategory->setTable('qianniao_goods_category_1');
        $sql = 'select id,images,adImage from qianniao_goods_category_1';
        $dbResult = $objDGoodsCategory->query($sql);
        if ($dbResult === false) {
            exit("获取数据失败" . $objDGoodsCategory->error());
        }

        foreach ($dbResult as $row) {
            if (empty($row['images'])) {
                continue;
            }
            $images = str_replace('https://image.saiyin168.cn', 'https://image.qpl123.com', $row['images']);
            $adImage = str_replace('https://image.saiyin168.cn', 'https://image.qpl123.com', $row['adImage']);
            $updateResult = $objDGoodsCategory->update(['images' => $images, 'adImage' => $adImage], ['id' => $row['id']]);
            if ($updateResult === false) {
                exit('更新失败' . $objDGoodsCategory->error());
            }
        }

        exit('操作成功');
    }

    public function forApi()
    {
        $objMCustomer = new MCustomer(4, 29);


        $obj = new DCustomer();
        $sql = 'select * from qianniao_customer_4 where deleteStatus = 5';
        $result = $obj->query($sql);

        foreach ($result as $key => $value) {
            $a = $objMCustomer->updateEsData($value['id']);
        }
    }

    /**
     * @throws Exception
     */
    public function syncSku()
    {
        $objSkuCache = new SkuCache(1);
        $objDSku = new DSku();
        $objDSku->setTable('qianniao_sku_1');

        $skuResult = $objDSku->select([]);
        if ($skuResult === false) {
            exit($objDSku->error());
        }

        foreach ($skuResult as $item) {
            $map = self::cacheMappersSku($item);
            $objSkuCache->delSku($item['id']);
            $cacheRes = $objSkuCache->cacheSku($item['id'], $map);
            if (!$cacheRes->isSuccess()) {
                exit("缓存失败");
            }
        }

        exit("缓存成功");
    }

    /**
     * @param array $data
     * @return array
     */
    public static function cacheMappersSku(array $data)
    {
        $map = [];
        if (empty($data)) {
            return $map;
        }

        $map = [
            'id' => $data['id'],
            'unitId' => $data['unitId'],
            'unitName' => $data['unitName'],
            'isMaster' => $data['isMaster'],
            'conversion' => $data['conversion'],
            'specType' => $data['specType'],
            'specImage' => $data['specImage'],
            'specData' => $data['specData'],
            'specGroupHash' => $data['specGroupHash'],
            'barCode' => $data['barCode'],
            'goodsId' => $data['goodsId']
        ];
        return $map;
    }

    /**
     * 测试打印
     */
    public function sendMsg()
    {
        $CloudPrint = new CloudPrint();
        $BaseModel = new MBaseModel();
        $data = [
            'shopName' => '千鸟云商',
            'title' => '销售单',
            'code' => '0000000009',
            'codeName' => '订单编号',
            'userName' => '海燕',
            'mobile' => 13626403927,
            'address' => '西安大明宫万达',
            'createTime' => time(),
            'details' => [
                [
                    'title' => '紫苏焖鹅+梅菜肉饼+椒盐虾+北京烤鸭',
                    'skuData' => [
                        [
                            'skuName' => '白色;XL',
                            'unitName' => '件',
                            'num' => 11,
                            'unitPrice' => 10.00,
                            'amountPrice' => 110.00
                        ],
                        [
                            'skuName' => '白色;XL',
                            'unitName' => '件',
                            'num' => 11,
                            'unitPrice' => 10.00,
                            'amountPrice' => 110.00
                        ],
                        [
                            'skuName' => '白色;XL',
                            'unitName' => '件',
                            'num' => 11,
                            'unitPrice' => 10,
                            'amountPrice' => 110
                        ],
                        [
                            'skuName' => '白色;XL',
                            'unitName' => '件',
                            'num' => 11,
                            'unitPrice' => 10,
                            'amountPrice' => 110
                        ],
                    ]
                ],
                [
                    'title' => '紫苏焖鹅+梅菜肉饼+椒盐虾+北京烤鸭',
                    'skuData' => [
                        [
                            'skuName' => '橘子味',
                            'unitName' => '瓶',
                            'num' => 1,
                            'unitPrice' => 5,
                            'amountPrice' => 5,
                        ]
                    ],
                ]
            ],
            'totalMoney' => 12.00,
            'preferential' => 0,
            'payAmount' => 12.00
        ];
//        $data = $BaseModel->formatMsg($data);
//        $result = $CloudPrint->sendMsg($data);
//        $result = $CloudPrint->getStatus();
//        $result = $CloudPrint->setVolume(0);

        //测试飞鹅打印机
        $data = $BaseModel->formatMsg($data, 2);
        $result = $CloudPrint->feieSendMsg($data);
        V($result);

    }

    public function bugCoupon()
    {
        $objDUserCoupon = new DUserCoupon();
        $objDUserCoupon->setTable('qianniao_user_coupon_13');
        $userCenterIds = [];
        $couponIds = [];
        $couponIdsStr = implode(',', $couponIds);
        $sql = 'select * from qianniao_coupon_13 where id in (' . $couponIdsStr . ')';
        $coupon = $this->objDGoods->query($sql);
        if ($coupon === false) {
            echo 'sql' . $this->objDGoods->error();
        }

        $couponMap = [];
        foreach ($coupon as $key => $value) {
            if ($value['receiveNum'] >= $value['totalNum']) {
                unset($coupon[$key]);
                continue;
            }
            $couponMap[$value['id']] = $value;
        }

        $insert = [];
        foreach ($userCenterIds as $item) {
            foreach ($couponMap as $key => $value) {
                $count = $objDUserCoupon->count(['couponId' => $value['id'], 'userId' => $item['uid']]);
                if ($count >= $value['allowNum']) {
                    continue;
                }

                //剩余数量不足每人领取数量
                if ($value['receiveNum'] + $value['allowNum'] > $value['totalNum']) {
                    $rec = $value['totalNum'] - $value['receiveNum'];
                    for ($i = 0; $i < $rec; $i++) {
                        $insert[] = [
                            'couponId' => $value['id'],
                            'name' => $value['name'],
                            'remark' => $value['remark'],
                            'couponType' => $value['couponType'],
                            'reducePrice' => $value['reducePrice'],
                            'minPrice' => $value['minPrice'],
                            'startTime' => $value['startTime'],
                            'endTime' => $value['endTime'],
                            'applyRange' => $value['applyRange'],
                            'categoryCollect' => $value['categoryCollect'],
                            'brandCollect' => $value['brandCollect'],
                            'isExpire' => StatusCode::$delete,
                            'isUse' => StatusCode::$standard,
                            'userId' => $item['uid'],
                            'useShop' => $value['useShop'],
                            'customerId' => $item['cId'],
                            'source' => $value['grantType'],
                            'createTime' => time(),
                            'updateTime' => time(),
                            'customerIds' => $value['customerIds'],
                            'isMutex' => isset($value['isMutex']) ? $value['isMutex'] : StatusCode::$standard,
                        ];
                    }

                    continue;
                }

                for ($i = 0; $i < $value['allowNum']; $i++) {
                    $insert[] = [
                        'couponId' => $value['id'],
                        'name' => $value['name'],
                        'remark' => $value['remark'],
                        'couponType' => $value['couponType'],
                        'reducePrice' => $value['reducePrice'],
                        'minPrice' => $value['minPrice'],
                        'startTime' => $value['startTime'],
                        'endTime' => $value['endTime'],
                        'applyRange' => $value['applyRange'],
                        'categoryCollect' => $value['categoryCollect'],
                        'brandCollect' => $value['brandCollect'],
                        'isExpire' => StatusCode::$delete,
                        'isUse' => StatusCode::$standard,
                        'userId' => $item['uid'],
                        'useShop' => $value['useShop'],
                        'customerId' => $item['cId'],
                        'source' => $value['grantType'],
                        'createTime' => time(),
                        'updateTime' => time(),
                        'customerIds' => $value['customerIds'],
                        'isMutex' => isset($value['isMutex']) ? $value['isMutex'] : StatusCode::$standard,
                    ];
                }
            }
        }

        print_r($insert);
        die;

    }

    public function testKuaiDi100()
    {
        $kuaidi100Config = Factory::config()->get('kuaidi100');
        if (empty($kuaidi100Config) || !isset($kuaidi100Config['customer']) || !isset($kuaidi100Config['key'])) {
            $this->sendOutput('快递100配置错误', ErrorCode::$configEroor);
        }
        $objQuery = new Query($kuaidi100Config['customer'], $kuaidi100Config['key']);

        $kuaidiData = [
            'com' => 'zhongtong',
            'num' => '73140775283454',
            'phone' => 17600105150,
        ];
        $result = $objQuery->pollQuery($kuaidiData);
        if (!$result->isSuccess()) {
            echo $result->getData() . $result->getErrorCode();
        }
        V($result->getData());
    }

    // 快递100查询返回数据内容
    public function msg()
    {
        $str = '{"message":"ok","nu":"3103922659603","ischeck":"1","condition":"D01","com":"yunda","status":"200","state":"3","data":[{"time":"2020-09-01 22:02:08","ftime":"2020-09-01 22:02:08","context":"[陕西西安北郊一公司未央二区寄存点分部]【代收点】您的快件已签收，签收人在【君泰烟酒店(凤城一路锦园君逸西区东门斜对面君泰烟酒店（免费代收）)】领取。"},{"time":"2020-09-01 20:36:29","ftime":"2020-09-01 20:36:29","context":"[陕西西安北郊一公司未央二区寄存点分部]【代收点】您的快件已送达 君泰烟酒店 保管，地址：凤城一路锦园君逸西区东门斜对面君泰烟酒店（免费代收），请及时领取，如有疑问请电联快递员：韩生斌【13519168931】。"},{"time":"2020-09-01 18:51:13","ftime":"2020-09-01 18:51:13","context":"[陕西西安北郊一公司未央二区寄存点分部]【西安市】陕西西安北郊一公司未央二区寄存点分部 快递员 韩生斌13519168931 正在为您派件【95114/95121/9501395546为韵达快递员外呼专属号码，请放心接听】"},{"time":"2020-09-01 17:50:26","ftime":"2020-09-01 17:50:26","context":"[陕西西安北郊一公司]【西安市】已离开 陕西西安北郊一公司；发往 陕西西安北郊一公司未央二区寄存点分部"},{"time":"2020-09-01 12:52:14","ftime":"2020-09-01 12:52:14","context":"[陕西西安分拨中心]【西安市】已离开 陕西西安分拨中心；发往 陕西西安北郊一公司"},{"time":"2020-09-01 12:45:28","ftime":"2020-09-01 12:45:28","context":"[陕西西安分拨中心]【西安市】已到达 陕西西安分拨中心"},{"time":"2020-08-31 19:51:10","ftime":"2020-08-31 19:51:10","context":"[山东济南分拨中心]【济南市】已离开 山东济南分拨中心；发往 陕西西安地区包"},{"time":"2020-08-31 19:42:34","ftime":"2020-08-31 19:42:34","context":"[山东济南分拨中心]【济南市】已到达 山东济南分拨中心"},{"time":"2020-08-30 10:37:09","ftime":"2020-08-30 10:37:09","context":"[山东市场部鹏程KH分部]【济南市】山东市场部鹏程KH分部 已揽收"}]}';

        V(json_decode($str, true));
    }

//    public function testKDNiao()
//    {
//        $kdniaoConfig = Factory::config()->get('kdniao');
//        if (empty($kdniaoConfig) || !isset($kdniaoConfig['EBusinessID']) || !isset($kdniaoConfig['key'])) {
//            $this->sendOutput('快递100配置错误', ErrorCode::$configEroor);
//        }
//        $objQuery = new KDNiaoQuery($kdniaoConfig['EBusinessID'], $kdniaoConfig['key']);
//
//        $kuaidiData = [
//            'com' => 'HTKY',
//            'num' => '557021498255630',
//        ];
//        $result = $objQuery->EbusinessOrderHandle($kuaidiData);
//        if (!$result->isSuccess()) {
//            parent::sendOutput($result->getData(), $result->getErrorCode());
//        }
//        parent::sendOutput($result->getData());
//    }

    // 快递鸟查询返回数据内容
    public function msg1()
    {
        $str = '{
  "LogisticCode" : "557021498255630",
  "ShipperCode" : "HTKY",
  "Traces" : [ {
    "AcceptStation" : "【太仓】，【扫描壹/13913775727】已揽收",
    "AcceptTime" : "2020-08-30 17:56:19"
  }, {
    "AcceptStation" : "到【上海转运中心】",
    "AcceptTime" : "2020-08-30 21:44:19"
  }, {
    "AcceptStation" : "【上海转运中心】，正发往【西安转运中心】",
    "AcceptTime" : "2020-08-30 21:46:44"
  }, {
    "AcceptStation" : "到【西安转运中心】",
    "AcceptTime" : "2020-09-01 01:32:36"
  }, {
    "AcceptStation" : "【西安转运中心】，正发往【西安北郊一站】",
    "AcceptTime" : "2020-09-01 02:16:14"
  }, {
    "AcceptStation" : "【陈仕友/15229250633】正在派件，【西安北郊一站/网点电话18821713238 029-68569101】",
    "AcceptTime" : "2020-09-01 08:42:50"
  }, {
    "AcceptStation" : "派件送达【兔喜快递超市】君泰烟酒店，请前往凤城一路锦园君逸西区东门斜对面君泰烟酒店（免费代收）领取您的包裹，联系电话：15309281529",
    "AcceptTime" : "2020-09-01 10:23:10"
  }, {
    "AcceptStation" : "客户已取件，提货点：【兔喜快递超市】 君泰烟酒店（15309281529 凤城一路锦园君逸西区东门斜对面君泰烟酒店（免费代收））",
    "AcceptTime" : "2020-09-01 22:01:48"
  } ],
  "State" : "3",
  "EBusinessID" : "1670600",
  "Success" : true
}';

        V(json_decode($str, true));
    }


    /**
     * sql执行
     * 该方法只执行需要拼接企业id的表  不要拼接企业id的表请自行手动执行
     */
    public function batchSql()
    {
        $sqlParent = "

ALTER TABLE `www.qianniao.vip`.`qianniao_staff_1` MODIFY COLUMN `userCenterId` int(11) NULL DEFAULT NULL COMMENT '用户中心id' AFTER `id`, MODIFY COLUMN `departmentId` int(11) NULL DEFAULT NULL COMMENT '部门id' AFTER `userCenterId`, MODIFY COLUMN `balance` decimal(10, 2) NULL COMMENT '余额' AFTER `rule`;

";
        //执行语句
        $sql = substr($sqlParent, stripos($sqlParent, "` ") + 2);
        $sqlIndex = $sql;

        //执行语句表所属数据库
        $dbName = substr($sqlParent, stripos($sqlParent, ' `') + 2, stripos($sqlParent, '`.') - stripos($sqlParent, ' `') - 2);

        //企业表所属数据库
        $dbIndexName = 'www.qianniao.vip';

        //库存数据库名
        $stockDbName = 'stock.qianniao.vip';

        //表名
        $sqlTable = substr($sqlParent, stripos($sqlParent, '.`') + 2, stripos($sqlParent, '` ') - stripos($sqlParent, '.`') - 2);
        $tableNameIndex = substr($sqlTable, 0, strripos($sqlTable, '_') + 1);

        //是否执行企业1表
        $oneEnterpriseTable = true;

        //从某个企业执行
        $startEnterpriseId = 0;

        //按照用户人数分表 例:tableName_1_1
        $userByTables = [
            'qianniao_order_',
            'qianniao_order_coupon_',
            'qianniao_order_goods_',
            'qianniao_order_receive_',
            'qianniao_goods_collect_',
        ];

        //按照仓库id分表
        $warehouseTable = [
            'qianniao_inventory_batch_'
        ];

        //按照季度分表 例:tableName_1_2020_3
        $dateByTable = [
            'qianniao_commission_order_',
            'qianniao_customerPriceAdjustmentSheet_'
        ];

        //按照季度分表2 例:tableName_1_201
        $dateByTableTwo = [
            'qianniao_inventory_locking_',
        ];

        //按照仓库id和季度分表  例:tableName_1_1_194
        $warehouseAndDateByTable = [
            'qianniao_inventory_details_'
        ];

        $runTrue = 0;
        $runFalse = 0;
        $runTrueTableName = [];
        $runFalseTableName = [];
        $tableNum = 0;
        $existNum = 0;
        $existTable = [];

        if (empty($sqlIndex)) {
            exit('请输入sql语句');
        }
        if (empty($dbIndexName)) {
            exit('请输入数据库名');
        }
        if (empty($tableNameIndex)) {
            exit('请输入表名');
        }

        //查询所有企业
        $whereSql = '';
        if ($startEnterpriseId) {
            $whereSql = ' where id >= ' . $startEnterpriseId;
        }
        $sql = 'select id from `' . $dbIndexName . '`.`qianniao_enterprise_1`' . $whereSql;
        $dbResult = $this->objDGoods->query($sql);
        if ($dbResult === false) {
            exit($this->objDGoods->error());
        }
        $enterpriseResult = $dbResult;
        unset($dbResult);
        unset($sql);
        if (empty($enterpriseResult)) {
            self::prompt('企业数据为空', 0, $enterpriseResult, 0, $existNum, $runTrue, $runFalse, $runTrueTableName, $runFalseTableName);
        }

        //按人数分表  因为用户数据量小 所以统一后缀加_1
        $tableSuffix = [];
        foreach ($userByTables as $value) {
            if ($tableNameIndex == $value) {
                $tableSuffix[] = '_1';
                break;
            }
        }

        $start = 2020;
        $end = (int)date('Y', time());

        //按日期季度分表
        foreach ($dateByTable as $value) {
            if ($tableNameIndex == $value) {
                for ($ii = $start; $ii <= $end; $ii++) {
                    for ($i = 1; $i <= 4; $i++) {
                        $tableSuffix[] = '_' . $ii . '_' . $i;
                    }
                }
                break;
            }
        }

        //按照季度分表2
        foreach ($dateByTableTwo as $value) {
            if ($tableNameIndex == $value) {
                for ($ii = $start; $ii <= $end; $ii++) {
                    for ($i = 1; $i <= 4; $i++) {
                        $tableSuffix[] = '_' . substr($ii, -2) . $i;
                    }
                }
                break;
            }
        }

        //按日期季度分表 拼接仓库id
        $isWarehouseId = false;
        foreach ($warehouseAndDateByTable as $value) {
            if ($tableNameIndex == $value) {
                $isWarehouseId = true;
                for ($ii = $start; $ii <= $end; $ii++) {
                    for ($i = 1; $i <= 4; $i++) {
                        $tableSuffix[] = '_' . substr($ii, -2) . $i;
                    }
                }
                break;
            }
        }

        //按照仓库id分表
        foreach ($warehouseTable as $value) {
            if ($tableNameIndex == $value) {
                $isWarehouseId = true;
                break;
            }
        }
        if ($isWarehouseId && empty($stockDbName)) {
            exit($tableNameIndex . '按照仓库分表, 请输入仓库表对应数据库名称');
        }
        $enterpriseFormat = array_column($enterpriseResult, null, 'id');
        if (!isset($enterpriseFormat[1])) {
            $enterprise1 = [
                'id' => 1,
            ];
            array_unshift($enterpriseResult, $enterprise1);
        }
        $enterpriseData = [];
        $emptyTable = [];
        foreach ($enterpriseResult as $value) {
            $tableList = [];
            //拿出企业id
            $enterpriseId = $value['id'];
            //判断是否执行1企业
            if ($enterpriseId == 1) {
                if ($oneEnterpriseTable == false) {
                    continue;
                } else {
                    if (!empty($tableSuffix)) {
                        $tableList[] = $tableNameIndex . $enterpriseId;
                    }
                }
            }
            if ($isWarehouseId) {
                //查询仓库的商铺
                $sql = 'select id from `' . $stockDbName . '`.`qianniao_warehouse_' . $enterpriseId . '`';
                $dbResult = $this->objDGoods->query($sql);
                if ($dbResult === false) {
                    self::prompt($this->objDGoods->error(), $enterpriseId, $enterpriseResult, $tableNum, $existNum, $runTrue, $runFalse, $runTrueTableName, $runFalseTableName);
                }
                $warehouseResult = $dbResult;
                unset($dbResult);
                //循环仓库数据
                foreach ($warehouseResult as $warehouse) {
                    $warehouseId = $warehouse['id'];
                    //判断是否有日期后缀
                    if (!empty($tableSuffix)) {
                        foreach ($tableSuffix as $suffix) {
                            //拼接表名
                            $tableList[] = $tableNameIndex . $enterpriseId . '_' . $warehouseId . $suffix;
                        }
                    } else {
                        $tableList[] = $tableNameIndex . $enterpriseId . '_' . $warehouseId;
                    }
                }
            } else {
                //判断是否有日期后缀
                if (!empty($tableSuffix)) {
                    foreach ($tableSuffix as $suffix) {
                        //拼接表名
                        $tableList[] = $tableNameIndex . $enterpriseId . $suffix;
                    }
                } else {
                    $tableList[] = $tableNameIndex . $enterpriseId;
                }
            }

            foreach ($tableList as $tableName) {
                $tableNum++;
                //查询表是否存在
                $sql = 'select count(TABLE_NAME) as isTable from information_schema.TABLES where TABLE_SCHEMA = "' . $dbName . '" and TABLE_NAME = "' . $tableName . '"';
                $dbResult = $this->objDGoods->query($sql);
                if ($dbResult === false) {
                    self::prompt($this->objDGoods->error(), $enterpriseId, $enterpriseResult, $tableNum, $existNum, $runTrue, $runFalse, $runTrueTableName, $runFalseTableName);
                }
                $isTable = 0;
                if (!empty($dbResult)) {
                    if (isset($dbResult[0]['isTable']) && $dbResult[0]['isTable'] == 1) {
                        $isTable = 1;
                    }
                }

                unset($dbResult);
                //判断表是否存在
                if ($isTable) {
                    $existNum++;
                    $existTable[] = $tableName;
                    $enterpriseData[$enterpriseId][] = ['enterpriseId' => $enterpriseId, 'tableName' => $tableName];
                } else {
                    $emptyTable[] = $tableName;
                }
            }
        }
//        V($existTable);
//        self::prompt('', 0, $enterpriseResult, $tableNum, $existNum, $runTrue, $runFalse, $runTrueTableName, $runFalseTableName);
        //执行语句
        foreach ($enterpriseData as $enterpriseId => $value) {
            foreach ($value as $enterprise) {
                $enterpriseId = $enterprise['enterpriseId'];
                $tableName = $enterprise['tableName'];
                //拼接修改sql语句
                $sql = "ALTER TABLE `" . $dbName . "`.`" . $tableName . "` " . $sqlIndex;
                $dbResult = $this->objDGoods->query($sql);
                if ($dbResult === false) {
                    $runFalse++;
                    $runFalseTableName[] = $tableName;
                    self::prompt($this->objDGoods->error(), $enterpriseId, $enterpriseResult, $tableNum, $existNum, $runTrue, $runFalse, $runTrueTableName, $runFalseTableName);
                }
                $runTrue++;
                $runTrueTableName[] = $tableName;
                unset($dbResult);
            }
        }
        self::prompt('', 0, $enterpriseResult, $tableNum, $existNum, $runTrue, $runFalse, $runTrueTableName, $runFalseTableName);
    }

    public function prompt($info = '', $enterpriseId = 0, $enterpriseResult, $tableNum, $existNum, $runTrue, $runFalse, $runTrueTableName, $runFalseTableName)
    {
        $title = '';
        if (!empty($info)) {
            $title = '执行到企业' . $enterpriseId . '时有报错:
                ' . $info . '
            ';
        }
        $title .= '一共' . count($enterpriseResult) . '个企业, 需要修改' . $tableNum . '个表, 存在的表有' . $existNum . '个, 修改成功的表' . $runTrue . '个, 修改失败的表' . $runFalse . '个, 成功的有:' . implode(',', $runTrueTableName) . '; 失败的有:' . implode(',', $runFalseTableName);
        exit($title);
    }


    /**
     * 批量删除某个企业的表
     */
    public function dropEnterpriseTable()
    {
        $date = [];
        for ($i = 2; $i <= 100; $i++) {
            $date[] = $i;
        }
        $sql = 'select id from `www.qianniao.vip`.`qianniao_enterprise_1`';
        $dbResult = $this->objDGoods->query($sql);
        $aa = [];
        foreach ($dbResult as $value) {
            $aa[] = $value['id'];
        }
        $dbResult = array_diff($date, $aa);
//        V($dbResult);
//        $sql = 'select id from `www.qianniao.vip`.`qianniao_enterprise_1` where expireTime <= '.time();
//        $dbResult = $this->objDGoods->query($sql);

        if (empty($dbResult)) {
            exit('没有过期企业');
        }
        $i = 0;
        foreach ($dbResult as $value) {
            $enterpriseId = $value;
//            $enterpriseId = $value['id'];
            $sql = 'DROP TABLE `www.qianniao.vip`.`qianniao_activity_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_activity_goods_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_cart_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_commission_businessman_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_coupon_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_customer_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_customer_contact_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_customer_shipping_address_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_department_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_department_role_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_goods_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_goods_basic_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_goods_brand_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_goods_category_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_goods_collect_' . $enterpriseId . '_1`, `www.qianniao.vip`.`qianniao_material_content_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_message_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_order_' . $enterpriseId . '_1`, `www.qianniao.vip`.`qianniao_order_coupon_' . $enterpriseId . '_1`, `www.qianniao.vip`.`qianniao_order_goods_' . $enterpriseId . '_1`, `www.qianniao.vip`.`qianniao_order_index_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_order_receive_' . $enterpriseId . '_1`, `www.qianniao.vip`.`qianniao_order_return_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_order_return_details_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_order_statistics_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_page_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_role_acl_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_sku_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_spec_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_staff_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_units_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_user_coupon_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_vip_card_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_vip_card_order_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_allocate_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_allocate_details_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_inventory_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_inventory_batch_' . $enterpriseId . '_1`, `stock.qianniao.vip`.`qianniao_inventory_details_' . $enterpriseId . '_1_203`, `stock.qianniao.vip`.`qianniao_inventory_in_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_inventory_in_details_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_inventory_locking_' . $enterpriseId . '_203`, `stock.qianniao.vip`.`qianniao_inventory_out_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_inventory_out_details_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_purchase_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_purchase_goods_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_purchase_out_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_purchase_out_goods_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_stocktaking_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_stocktaking_details_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_supplier_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_warehouse_' . $enterpriseId . '`, `stock.qianniao.vip`.`qianniao_warehouse_beginning_' . $enterpriseId . '`, `price.qianniao.vip`.`qianniao_customerPriceAdjustmentSheet_' . $enterpriseId . '_2020_3`, `price.qianniao.vip`.`qianniao_customerPriceEffective_' . $enterpriseId . '`, `price.qianniao.vip`.`qianniao_customerTypePriceAdjustmentSheet_' . $enterpriseId . '_2020_3`, `price.qianniao.vip`.`qianniao_customerTypePriceEffective_' . $enterpriseId . '`, `price.qianniao.vip`.`qianniao_lastEffectiveSalePriceAreaType_' . $enterpriseId . '`, `price.qianniao.vip`.`qianniao_nationalUnifiedPrice_' . $enterpriseId . '`, `price.qianniao.vip`.`qianniao_priceAdjustmentSheet_' . $enterpriseId . '_2020_3`, `price.qianniao.vip`.`qianniao_priceRangeSheet_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_account_transfer_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_customer_balance_' . $enterpriseId . '_1`, `finance.qianniao.vip`.`qianniao_customer_balance_detail_' . $enterpriseId . '_2020_3`, `finance.qianniao.vip`.`qianniao_customer_balance_detail_index_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_customer_balance_index_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_paid_' . $enterpriseId . '_2020_3`, `finance.qianniao.vip`.`qianniao_paid_account_' . $enterpriseId . '_2020_3`, `finance.qianniao.vip`.`qianniao_paid_index_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_pay_receipt_' . $enterpriseId . '_2020_3`, `finance.qianniao.vip`.`qianniao_pay_receipt_index_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_receive_receipt_' . $enterpriseId . '_2020_3`, `finance.qianniao.vip`.`qianniao_receive_receipt_index_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_received_' . $enterpriseId . '_2020_3`, `finance.qianniao.vip`.`qianniao_received_account_' . $enterpriseId . '_2020_3`, `finance.qianniao.vip`.`qianniao_received_index_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_supplier_balance_' . $enterpriseId . '_1`, `finance.qianniao.vip`.`qianniao_supplier_balance_detail_' . $enterpriseId . '_2020_3`, `finance.qianniao.vip`.`qianniao_supplier_balance_detail_index_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_supplier_balance_index_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_commission_flow_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_commission_goods_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_commission_goods_statistics_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_commission_order_' . $enterpriseId . '_2020_3`, `www.qianniao.vip`.`qianniao_commission_order_index_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_commission_withdrawals_' . $enterpriseId . '`, `price.qianniao.vip`.`qianniao_priceAdjustmentSheet_' . $enterpriseId . '_2020_2`, `finance.qianniao.vip`.`qianniao_customer_balance_detail_' . $enterpriseId . '_2020_2`, `finance.qianniao.vip`.`qianniao_pay_receipt_' . $enterpriseId . '_2020_2`, `finance.qianniao.vip`.`qianniao_receive_receipt_' . $enterpriseId . '_2020_2`, `finance.qianniao.vip`.`qianniao_received_' . $enterpriseId . '_2020_2`, `finance.qianniao.vip`.`qianniao_received_account_' . $enterpriseId . '_2020_2`, `finance.qianniao.vip`.`qianniao_supplier_balance_detail_' . $enterpriseId . '_2020_2`, `www.qianniao.vip`.`qianniao_common_app_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_delivery_rule_' . $enterpriseId . '`, `www.qianniao.vip`.`qianniao_delivery_self_rule_' . $enterpriseId . '`, `finance.qianniao.vip`.`qianniao_customer_balance_detail_' . $enterpriseId . '_2020_1`, `finance.qianniao.vip`.`qianniao_account_detail_' . $enterpriseId . '_1`, `finance.qianniao.vip`.`qianniao_paid_' . $enterpriseId . '_2020_1`, `finance.qianniao.vip`.`qianniao_paid_account_' . $enterpriseId . '_2020_1`, `finance.qianniao.vip`.`qianniao_pay_receipt_' . $enterpriseId . '_2020_1`, `finance.qianniao.vip`.`qianniao_receive_receipt_' . $enterpriseId . '_2020_1`, `finance.qianniao.vip`.`qianniao_received_' . $enterpriseId . '_2020_1`, `finance.qianniao.vip`.`qianniao_received_account_' . $enterpriseId . '_2020_1`, `www.qianniao.vip`.`qianniao_enterprise_template_module_' . $enterpriseId . '`';

//            $enterpriseSql = 'DELETE FROM `www.qianniao.vip`.`qianniao_enterprise_1` WHERE `id` = '.$enterpriseId;
//            $this->objDGoods->query($enterpriseSql);
            $enterpriseBandUserCenterSql = 'DELETE FROM `www.qianniao.vip`.`qianniao_user_bind_enterprise` WHERE `enterpriseId` = ' . $enterpriseId;
            $this->objDGoods->query($enterpriseBandUserCenterSql);
            $this->objDGoods->query($sql);
            $i++;
        }

        exit('执行成功, 共删除' . $i . '个企业');
    }


    // 客如云
    public function keruyun()
    {
        $keruyunConfig = Factory::config()->get('keruyun');
        if (empty($keruyunConfig)) {
            $this->sendOutput('客如云配置错误', ErrorCode::$configEroor);
        }

        $objOpen = new Open($keruyunConfig['shopIdenty'], $keruyunConfig['appKey'], $keruyunConfig['secretKey']);
        $result = $objOpen->getToken();
        if (!$result->isSuccess()) {
            echo($result->getData() . $result->getErrorCode());
        }
        $token = $result->getData();

        /*
        unset($result);
        $result = $objOpen->dishMenu($token['token'],1,1);
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $goodsData = $result->getData();*/


        /*
        unset($result);
        $result = $objOpen->dishMenuByIds($token['token'], ['245842575890634752']);
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $goodsData = $result->getData();V($goodsData);*/


        /*
        $customerData = [
            'birthday'   => time(), // 生日时间戳
            'loginId'    => '17600105150', // 手机号或者微信id
            'loginType'  => 0,
            'name'       => '刘鑫',
            'sex'        => -1,
        ];

        unset($result);
        $result = $objOpen->createCustomer($token['token'], $customerData);
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $customerInfo = $result->getData(); V($customerInfo);*/

        /*
        $customerData = [
            'birthday'   => time(), // 生日时间戳
            'loginId'    => '17600105150', // 手机号或者微信id
            'loginType'  => 0,
            'name'       => '刘鑫',
            'sex'        => -1,
        ];

        unset($result);
        $result = $objOpen->createOrUpgradeMember($token['token'], $customerData);
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $customerInfo = $result->getData(); V($customerInfo); */


        unset($result);
        $result = $objOpen->login($token['token'], '18992853313');
        if (!$result->isSuccess()) {
            echo($result->getData() . $result->getErrorCode());
        }
        $customerInfo = $result->getData();
        V($customerInfo);


        /*
        unset($result);
        $result = $objOpen->getCustomerDetailById($token['token'], 402153925286827008);
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $customerInfo = $result->getData(); V($customerInfo);*/


        /*
        unset($result);
        $result = $objOpen->recharge($token['token'], ['customerId'=>'402153925286827008','amount'=>10000,'tpOrderId'=>'3120200910727']);
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $customerInfo = $result->getData(); V($customerInfo);*/

        /*
        unset($result);
        $result = $objOpen->orderExportDetail($token['token'], ['401332262188390400']);
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $customerInfo = $result->getData(); V($customerInfo);*/

        /*
        unset($result);
        $result = $objOpen->dinnerOrderDetail($token['token'], 'b28e5f7529ac4c64b04a39104429ef26');
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $customerInfo = $result->getData(); V($customerInfo);*/

        /*
        unset($result);
        $result = $objOpen->cancel($token['token'], 'f52b36b49c304823b6fcb3b8f3a934df');
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $customerInfo = $result->getData(); V($customerInfo);*/

        /*
        $orderData = [
            'tpOrderId'   => '31202009107241774406',
            'createTime'  => time(),
            'updateTime'  => time(),
            'payment' => [
                'memberId' => 402153925286827008,
                'memberPassword' => md5('105150'),
                'payType' => 1, //支付方式 1:会员卡余额 2:优惠券 3:订单来源支付
                'platformDiscountFee' => 0,
                'serviceFee' => 0,
                'shopDiscountFee' => 0,
                'shopFee' => 1,
                'totalDiscountFee' => 0,
                'totalFee' => 1,
                'userFee'  => 1
            ],
            'peopleCount' => 1, // 就餐人数
            'print'       => 1, // 打印
            'remark'      => '小程序订单', // 备注
            'status'      => 2, // 已经确认
            'shopIdenty' => $keruyunConfig['shopIdenty'],
            'shopName'   => '千鸟云商',
            'products' => [[
                'tpId' => 40740829341443072,
                'name' => '水煮牛肉',
                'price' => 1,
                'type'  => 0,
                'unit'  => '件',
                'quantity' => 1,
                'totalFee' => 1
            ]],
            'customers'   => [
                'phoneNumber' => '17600105150',
                'name' => '刘鑫',
                'gender' => 1,
            ],
            'totalPrice' => 1,
        ];

        unset($result);
        $result = $objOpen->createSnackOrder($token['token'], $orderData);
        if(!$result->isSuccess()){
            echo($result->getData().$result->getErrorCode());
        }
        $customerInfo = $result->getData(); V($customerInfo); */


        $orderData = [
            'tpOrderId' => '31202009107241774406',
            'tpShopId' => 100,
            'createTime' => time(),
            'shopName' => '千鸟云商',
            'products' => [[
                'name' => '水煮牛肉',
                'type' => 0,
                'tpId' => 40740829341443072,
                'quantity' => 1,          // 商品数量
                'price' => 1,             // 商品单价
                'unit' => '件',
                'packagePrice' => 0,      // 餐盒单价
                'packageQuantity' => 0,   // 餐盒数量
                'totalFee' => 1           // 商品总金额
            ]],
            'delivery' => [
                'expectTime' => 0, // 期望送达时间
                'deliveryParty' => 1, // 配送方式
                'receiverName' => '刘鑫', // 收货人姓名
                'receiverPhone' => 17600105150, // 收货人电话
            ],
            'payment' => [
                'totalFee' => 1,      // 订单总价=商品总金额+餐盒费+配送费
                'deliveryFee' => 0,   // 配送费
                'packageFee' => 0,   // 餐盒费=餐盒数量 * 餐盒单价
                'discountFee' => 0,   // 优惠总金额=平台优惠总金额+商户优惠总金额
                'platformDiscountFee' => 0, // 平台优惠总金额
                'shopDiscountFee' => 0,  // 商家优惠
                'shopFee' => 1, // 商户实收总价
                'userFee' => 1, // 用户实付=订单总价-优惠总金额
                'serviceFee' => 0, // 服务费(商户向平台支付的佣金等)
                'subsidies' => 0, // 平台补贴
                'payType' => 3,  // 支付方式 1:线下支付/货到付款 2:在线支付 4:优惠券 3:会员卡余额
                'memberId' => 402153925286827008,
                'memberPassword' => md5('105150'),
            ],
            'customers' => [
                'phoneNumber' => '17600105150', // 会员电话
                'name' => '刘鑫',  // 会员名字
                'gender' => 1,    // 会员性别
            ]
        ];

        unset($result);
        $result = $objOpen->createTakeoutOrder($token['token'], $orderData);
        if (!$result->isSuccess()) {
            echo($result->getData() . $result->getErrorCode());
        }
        $customerInfo = $result->getData();
        V($customerInfo);
    }

    /**
     * 客如云菜品变更通知
     */
    public function dishChaangeNotify()
    {
        $postStr = file_get_contents('php://input');
        file_put_contents('/www/wwwroot/logs/api.junhailan.com/keruyun.log', date('Y-m-d H:i:s') . '回调数据' . var_export($postStr, true) . PHP_EOL, FILE_APPEND);
    }

    /**
     * 测试发布订阅消息
     */
    public function subscribeMessageSend()
    {
        $miniprogramConfigData = Factory::config()->getAppoint('weixin', 'miniprogram');
        if (empty($miniprogramConfigData)) {
            echo('小程序配置项错误');
            exit();
        }
        // 获取access_token
        $objOffiaccount = new Offiaccount($miniprogramConfigData['appid'], $miniprogramConfigData['appSecret']);
        $result = $objOffiaccount->token();
        if (!$result->isSuccess()) {
            echo $result->getData(), $result->getErrorCode();
        }
        $access_token = $result->getData();
        unset($result);

        // 发送订阅消息
        $data = [
            'name1' => [
                'value' => '千鸟云商店铺',
            ],
            'date2' => [
                'value' => '2020年10月27日',
            ],
            'amount3' => [
                'value' => '￥100元',
            ],
            'character_string4' => [
                'value' => '31202010273559779663',
            ],
        ];

        $objMiniprogram = new Miniprogram($miniprogramConfigData['appid'], $miniprogramConfigData['appSecret']);
        $result = $objMiniprogram->subscribeMessageSend($access_token, '7h2cBfuDxPPxovL3xGj9SLojcrVJGNHEzd8OcCUukq4', 'oISU64zx81Uq4oc_kzz1wg4PSNs8', '/pages/index/index', $data);
        V($result);
    }

    /**
     * 添加模板
     */
    public function addtemplate()
    {
        $miniprogramConfigData = Factory::config()->getAppoint('weixin', 'miniprogram');
        if (empty($miniprogramConfigData)) {
            echo('小程序配置项错误');
            exit();
        }
        // 获取access_token
        $objOffiaccount = new Offiaccount($miniprogramConfigData['appid'], $miniprogramConfigData['appSecret']);
        $result = $objOffiaccount->token();
        if (!$result->isSuccess()) {
            echo $result->getData(), $result->getErrorCode();
        }
        $access_token = $result->getData();
        unset($result);

        $objMiniprogram = new Miniprogram($miniprogramConfigData['appid'], $miniprogramConfigData['appSecret']);
        $result = $objMiniprogram->addtemplate($access_token, '3637', [2, 3, 8, 10], '发货通知');
        V($result);
    }

    public function webstockConnect()
    {
        $swooleServerConfigData = Factory::config()->getAppoint('swooleServer', 'order');
        if (empty($swooleServerConfigData)) {
            echo('swoole服务端链接信息配置项错误');
            exit();
        }
        $swooleClient = Factory::swoole($swooleServerConfigData, 'WebsocketClient');

        // 触发商家新订单通知
        $data = [
            'controller' => 'NewOrder',
            'action' => 'createConnect',
            'params' => [
                'platfrom' => 'qianniaoSAAS',
                'shop_id' => 1,
                'userId' => 200,
            ]
        ];
        $swooleClient->sendJson($data);
        V($swooleClient->recv());
    }

    public function test1()
    {
        $obj = new MBaseModel(1, 1);
        V($obj->sendMessage(1, 'NewOrder', 'order'));
    }

    /**
     * 测试下webstock
     * @throws \Exception
     */
    public function webstock()
    {
        $swooleServerConfigData = Factory::config()->getAppoint('swooleServer', 'order');

        
        
        if (empty($swooleServerConfigData)) {
            echo('swoole服务端链接信息配置项错误');
            exit();
        }
        $swooleClient = Factory::swoole($swooleServerConfigData, 'WebsocketClient');

        // 触发商家新订单通知
        $data = [
            'controller' => 'NewOrder',
            'action' => 'autoSend',
            'params' => [
                'platfrom' => 'qianniaoSAAS',
                'shop_id' => 9,
            ]
        ];
        $swooleClient->sendJson($data);
        V($swooleClient->recv());
    }

    /**
     * 达达配送接口
     */
    public function dada()
    {
        $dataConfigData = Factory::config()->get('dada');
        if (empty($dataConfigData)) {
            echo('达达配送配置项错误');
            exit();
        }

        $objMerchant = new Merchant($dataConfigData['app_key'], $dataConfigData['app_secret'], 73753);
        $reuslt = $objMerchant->cityCodeList();
        V($reuslt->getData());
    }

    /**
     * 测试退款
     */
    public function refund()
    {
        $miniprogramConfigData = Factory::config()->get('weixin');
        if (empty($miniprogramConfigData)) {
            echo('小程序配置项错误');
            exit();
        }
        $objPay  =new Pay($miniprogramConfigData['miniprogram']['appid'], $miniprogramConfigData['pay']['mch_id'],$miniprogramConfigData['pay']['apiPartnerKey'] );
        V($objPay->transfers('4200000989202104119581846831', '20210411-0009','0.01','0.01'));
    }


    /**
     * 临时财务脚本解决应收单索引表id重复问题
     */
    public function tmp()
    {
        $objMReceive = new MReceive(64, 1);
        $result = $objMReceive->tmp();
        if ($result->isSuccess()) {
            V($result->getData());
        } else {
            V($result->getData(), $result->getErrorCode());
        }
    }

    /**
     * 临时财务脚本解决应付表索引表id重复问题
     */
    public function tmp1()
    {
        $objMPay = new MPay(64, 1);
        $result = $objMPay->tmp1();
        if ($result->isSuccess()) {
            V($result->getData());
        } else {
            V($result->getData(), $result->getErrorCode());
        }
    }
}