Weapp.php 68.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: 当燃
 * Date: 2015-09-09
 */

namespace app\manager\controller;

use think\db\Query;
use think\Page;
use think\AjaxPage;
use think\Verify;
use think\Db;
use think\Session;
use think\Cache;

use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;

class Weapp extends Base
{

    public $group;

    /*
    * 初始化操作
    */
    public function __construct()
    {
        parent::__construct();
        $this->group = include APP_PATH . 'admin/conf/menuarr.php';
    }

    /********************************************商家模块**************************************************************/
    /**
     * 获取商家列表
     * @return store_list
     */
    public function index()
    {
        $model = M('weapp');

        $start = urldecode(I('start', date('Y-m-d H:i:s', strtotime('-1 month'))));
        $start_time = strtotime($start);
        $end = urldecode(I('end', date('Y-m-d H:i:s')));
        $end_time = strtotime($end);

        $list = array();
        $pagenum = 20;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/s');
        }

        $keywords = I('keywords/s');
        $is_audit = I('shenghe/s');
        $is_ylpapp = I('is_ylpapp/s');

        $is_version = I('is_version/d', 0);
        $qy = I('qianyi/s');
        $is_usererp = I('is_usererp/s');

        $is_sq = I('is_sq/s');
        $auditnum = I('auditnum/s');

        $searchfield = I('searchfield/s');
        $searchkey = I('searchkey/s');

        if ($is_usererp != "") {
            if ($is_usererp == 1) {
                $where['b.ERPId'] = array('neq', '');
            } else {
                $where['b.ERPId'] = '';
            }
        }

        if ($searchfield != "" && $searchkey) {
            switch ($searchfield) {
                case "1":
                    $where['d.max_release_version'] = array('eq', $searchkey);
                    break;
                case "2":
                    $where['d.max_release_version'] = array('neq', $searchkey);
                    break;
            }
        }

        if ($is_sq != "") {
            switch ($is_sq) {
                case "1":
                    $where['a.sq_func_info'] = array('like', '%,18,%');
                    break;
                case "2":
                    $where['a.sq_func_info'] = array('notlike', '%,18,%');
                    break;
            }
        }
        if ($keywords) {
            $where['a.principal_name|b.ERPId|b.store_name'] = array(['like', '%' . $keywords . '%']);;
        }

        if ($start_time) {
            $where['a.addtime'] = array('egt', $start_time);
        }
        if ($end_time) {
            $where['a.addtime'] = array('elt', $end_time);
        }

        if ($is_version) {
            switch ($is_version) {
                case "1":
                    $where['c.buy_money'] = array('eq', 999);
                    break;
                case "2":
                    $where['c.buy_money'] = array('neq', 999);

                    break;
                default:
                    break;
            }
        }
        if ($auditnum) {
            switch ($auditnum) {
                case "1":
                    $where['ifnull(d.auditnum,0)'] = array('gt', 0);
                    break;
                case "2":
                    $where['ifnull(d.auditnum,0)'] = array('eq', 0);

                    break;
                default:
                    break;
            }
        }


        $count = $model->alias('a')
            ->join('store b', 'a.store_id=b.store_id', 'left')
            ->join("(select ifnull(count(1),0) as auditnum ,store_id,max(release_version) as max_release_version from wxd_weapp_audit where status in(0,2) group by store_id) d", ' a.store_id=d.store_id', 'left')
            ->join('(select buy_money,store_id from (select * from wxd_storage_recharge where type=11  and recharge_state=1 order by id  desc) a group by a.store_id) c', 'a.store_id=c.store_id', 'left')
            ->where($where)->count(1);
        $Page = $pager = new Page($count, $pagenum);
        $list = $model->alias('a')
            ->join('store b', 'a.store_id=b.store_id', 'left')
            ->join("(select ifnull(count(1),0) as auditnum,max(release_version) as max_release_version,store_id from wxd_weapp_audit where status in(0,2) group by store_id) d", ' a.store_id=d.store_id', 'left')
            ->join('(select buy_money,store_id from ( select * from wxd_storage_recharge where type=11  and recharge_state=1 order by id  desc) a group by a.store_id) c', 'a.store_id=c.store_id', 'left')
            ->where($where)
            ->limit($Page->firstRow . ',' . $Page->listRows)->order('id asc')
            ->field('a.*,b.store_name,b.ERPId,c.buy_money,ifnull(d.auditnum,0) as auditnum,d.max_release_version')
            ->order('a.id desc')
            ->select();
        $show = $Page->show();
        $this->assign('keywords', $keywords);
        $this->assign('list', $list);// 赋值数据集
        $this->assign('page', $show);// 赋值分页输出
        $this->assign('pager', $pager);
        $this->assign('pagenum', $pagenum);
        $this->assign('oldurl', urlencode(curPageURL()));
        $this->assign('start', $start);
        $this->assign('end', $end);

        return $this->fetch();
    }


    /**
     * 审核列表
     * @return store_list
     */
    public function submit_auditlist()
    {
        $model = M('weapp_audit');
        $list = array();
        $pagenum = 20;//每页显示多少条
        if ((int)I('pagenum/d') > 0) {
            $pagenum = I('pagenum/d');
        }

        $getstatus = I('status/s', '');
        $stoid = I('stoid/d');
        $getkeywords = I('keywords/s', '');
        $sversion = I('sversion/s', '');
        $is_release = I('is_release/s', '');
        if ($getkeywords) {
            $where['b.ERPId|b.store_name'] = array("like", '%' . $getkeywords . '%');
        }
        switch ($is_release) {
            case 1:
                $where['a.is_release'] = 0;
                break;
            case 2:
                $where['a.is_release'] = 1;
                break;
        }
        if ($sversion) {
            $where['a.release_version'] = $sversion;
        }
        if ($stoid) {
            $where['a.store_id'] = $stoid;
        }
        if ($getstatus != null) {
            $where['a.status'] = $getstatus;
        } else {
            $getstatus = "-1";
        }
        $count = $model->alias('a')
            ->join("store b", 'a.store_id=b.store_id', 'left')
            ->where($where)->count(1);
        $Page = $pager = new Page($count, $pagenum);
        $list = $model->alias('a')
            ->join("store b", 'a.store_id=b.store_id', 'left')
            ->where($where)
            ->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')
            ->field('a.*,b.ERPId,b.store_name')
            ->select();
        $show = $Page->show();
        $this->assign('getstatus', $getstatus);//
        $this->assign('list', $list);// 赋值数据集
        $this->assign('stoid', $stoid);//
        $this->assign('page', $show);// 赋值分页输出
        $this->assign('pager', $pager);
        $this->assign('pagenum', $pagenum);
        $this->assign('is_release', $is_release);

        $this->assign('oldurl', urlencode(curPageURL()));
        return $this->fetch();
    }

    //更新TOKEN
    function update_token()
    {
        $getstoreid = I('store_id/d', 1);
        weapp_get_access_token(null, $getstoreid);
        return json(['code' => 0, 'msg' => '更新成功']);
    }

    //提交代码 1
    public function sumbitcode()
    {


        $getstoid = I('stoid/d', 0);
        $gettype = I('type/d', 1);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }

        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        $stoinfo = M('store')->where(array('store_id' => $getstoid))->find();
        if (!$weapp) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $man_res = M('manager_config')->find();

        if (IS_POST) {
            $post_data = input('post.');


//            $res = httpRequest("https://api.weixin.qq.com/wxa/gettemplatedraftlist?access_token=".getcomponent_access_token());
//            var_dump($res);die;

            $getweptoken = weapp_get_access_token($weapp, $getstoid);

            $getweptoken = json_decode($getweptoken, true);

            if ($getweptoken['errcode'] != 0) {
                return json(array('errcode' => -1, 'errmsg' => '请重新授权'));
            }
            $getweapp_ext_json = "";
            switch ($gettype) {
                case 1:
                    $getweapp_ext_json = $man_res["weapp_ext_json"];
                    break;
                case 2:
                    $getweapp_ext_json = $man_res["weapp_ext_json1"];
                    break;
                default:
                    break;
            }
            $getauthorizer_access_token = $getweptoken["authorizer_access_token"];

            $PostData_str = '{"template_id":' . $post_data["template_id"] . ',"user_version":"' . $post_data["user_version"] . '","user_desc":"' . $post_data['user_desc'] . '","ext_json":"{\"extAppid\":\"' . $weapp['appid'] . '\",';
            $PostData_str .= '\"ext\":{\"extAppid\":\"' . $weapp['appid'] . '\",\"appCode\":\"UNION_PAY\",\"appName\":\"' . $stoinfo['store_name'] . '\",\"stoid\":\"' . $weapp['store_id'] . '\",\"preDomain\":\"https://test-weshop.yolipai.net/\"},';
            $PostData_str .= '\"extPages\":{},\"pages\":' . $getweapp_ext_json . ',';
            $PostData_str .= ' \"window\":{},\"networkTimeout\":{},\"tabBar\":{\"color\":\"#7f8389\",\"selectedColor\":\"#ff9a0f\",\"borderStyle\":\"white\",';
            $PostData_str .= '\"list\":[{\"pagePath\":\"pages/index/index/index\",\"text\":\"首页\",\"iconPath\":\"images/bar/index.png\",\"selectedIconPath\":\"images/bar/index_on.png\"},{\"pagePath\":\"pages/goods/categoryList/categoryList\",\"text\":\"分类\",\"iconPath\":\"images/bar/fl.png\",\"selectedIconPath\":\"images/bar/fl_on.png\"},{\"pagePath\":\"pages/cart/cart/cart\",\"text\":\"购物车\",\"iconPath\":\"images/bar/car.png\",\"selectedIconPath\":\"images/bar/car_on.png\"},{\"pagePath\":\"pages/user/index/index\",\"text\":\"我的\",\"iconPath\":\"images/bar/user.png\",\"selectedIconPath\":\"images/bar/user_on.png\"}]}}"}';


            //如下是正确格式
            //  $PostData_str='{\"extAppid\":\"wx2ea7cdd3ef52cdff\",\"ext\":{\"extAppid\":\"wx2ea7cdd3ef52cdff\",\"appCode\":\"UNION_PAY\",\"appNickName\":\"万信达商城\",\"shopId\":\"1\",\"preDomain\":\"https://test.yolipai.net/\"},\"extPages\":{},\"pages\":[\"pages/index/index/index\",\"pages/goods/categoryList/categoryList\",\"pages/activity/group_list/group_list\",\"pages/activity/coupon_list/coupon_list\",\"pages/cart/cart/cart\",\"pages/cart/cart2/cart2\",\"pages/cart/cart4/cart4\",\"pages/goods/integralMall/integralMall\",\"pages/goods/brandstreet/brandstreet\",\"pages/goods/goodsInfo/goodsInfo\",\"pages/goods/goodsList/goodsList\",\"pages/goods/search/search\",\"pages/order/refund_order/refund_order\",\"pages/payment/payment/payment\",\"pages/user/index/index\",\"pages/user/order_list/order_list\",\"pages/user/order_detail/order_detail\",\"pages/user/visit_log/visit_log\",\"pages/user/address_list/address_list\",\"pages/user/userinfo/userinfo\",\"pages/user/account/account\",\"pages/user/comment/comment\",\"pages/user/return_goods_list/return_goods_list\",\"pages/user/userinfo_edit/userinfo_edit\",\"pages/user/collect_list/collect_list\",\"pages/user/coupon/coupon\",\"pages/user/checkcoupon/checkcoupon\",\"pages/user/add_address/add_address\",\"pages/user/account_list/account_list\",\"pages/user/points_list/points_list\",\"pages/user/recharge_list/recharge_list\",\"pages/user/withdrawals_list/withdrawals_list\",\"pages/user/add_comment/add_comment\",\"pages/user/return_goods_info/return_goods_info\",\"pages/user/return_goods/return_goods\",\"pages/user/withdrawals/withdrawals\",\"pages/user/recharge/recharge\",\"pages/user/message_notice/message_notice\",\"pages/user/express/express\",\"pages/user/binding_info/binding_info\",\"pages/user/get_user_info/get_user_info\",\"pages/virtual/buy_step/buy_step\",\"pages/virtual/virtual_list/virtual_list\",\"pages/distribut/index/index\",\"pages/distribut/distribut_list/distribut_list\",\"pages/distribut/good_list/good_list\",\"pages/distribut/order_list/order_list\",\"pages/distribut/my_store/my_store\",\"pages/distribut/set_store/set_store\",\"pages/distribut/team/team\",\"pages/index/webview/webview\",\"pages/cart/integral/integral\",\"pages/team/index/index\",\"pages/team/team_info/team_info\",\"pages/team/team_detail/team_detail\",\"pages/team/team_confirm/team_confirm\",\"pages/team/team_coupon/team_coupon\",\"pages/team/team_order/team_order\",\"pages/activity/seckill_list/seckill_list\"],\"window\":{\"backgroundTextStyle\":\"light\",\"navigationBarTextStyle\":\"black\",\"navigationBarTitleText\":\"加载中...\",\"navigationBarBackgroundColor\":\"#ffffff\",\"backgroundColor\":\"#eeeeee\",\"enablePullDownRefresh\":true},\"networkTimeout\":{},\"tabBar\":{\"color\":\"#7f8389\",\"selectedColor\":\"#ff9a0f\",\"borderStyle\":\"white\",\"list\":[{\"pagePath\":\"pages/index/index/index\",\"text\":\"首页\",\"iconPath\":\"images/bar/index.png\",\"selectedIconPath\":\"images/bar/index_on.png\"},{\"pagePath\":\"pages/goods/categoryList/categoryList\",\"text\":\"分类\",\"iconPath\":\"images/bar/fl.png\",\"selectedIconPath\":\"images/bar/fl_on.png\"},{\"pagePath\":\"pages/cart/cart/cart\",\"text\":\"购物车\",\"iconPath\":\"images/bar/car.png\",\"selectedIconPath\":\"images/bar/car_on.png\"},{\"pagePath\":\"pages/user/index/index\",\"text\":\"我的\",\"iconPath\":\"images/bar/user.png\",\"selectedIconPath\":\"images/bar/user_on.png\"}]}}';

            $res = httpRequest("https://api.weixin.qq.com/wxa/commit?access_token=" . $getauthorizer_access_token, "POST", $PostData_str);

            //更新版本
            $updatedata['commit_version'] = $post_data["user_version"];
            $updatedata['commit_remark'] = $post_data["user_desc"];
            M('weapp')->where(array('store_id' => $getstoid))->save($updatedata);
            return json(json_decode($res, true));

        }
        $this->assign('weapp', $weapp);
        return $this->fetch('', getAdmStoId());
    }

    //获取体验小程序的体验二维码 2
    public function get_qrcode()
    {
        $getstoid = I('stoid/d', 0);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }


        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => '该商家取消授权,请重新授权'));
        }

        if ($weapp['qrcode_urlimg']) {
            return json(array('errcode' => 0, 'qrcode_urlimg' => QCLOUD_IMGURL . $weapp['qrcode_urlimg'], 'errmsg' => 'ok'));
        }

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/get_qrcode?access_token=" . $getauthorizer_access_token, 'get');
        $localpath = "/public/upload/weappqrcode/" . $getstoid . "/";
        $picname = time() . ".jpg";
        if (!file_exists(ROOT_PATH . $localpath)) {
            mkdir(ROOT_PATH . $localpath, 0777, true);
        }
        $ret = file_put_contents(ROOT_PATH . $localpath . $picname, $res, true);

        vendor('qcloudcos.myqcloudcos');
        $resfolder = Myqcloudcos::statFolder('wxd', $localpath);

        if ($resfolder && $resfolder['code'] != 0)//不存在创建
        {
            Myqcloudcos::createFolder('wxd', $localpath);

        }
        //上传到腾讯云
        $res = Myqcloudcos::upload('wxd', ROOT_PATH . $localpath . $picname, $localpath . $picname);
        if ($res && $res['code'] == 0)//
        {            //
            $savedata['qrcode_urlimg'] = $localpath . $picname;
            M('weapp')->where(array('store_id' => $getstoid))->save($savedata);
            mdelFile($localpath);
            return json(array('errcode' => 0, 'qrcode_urlimg' => QCLOUD_IMGURL . $localpath . $picname, 'errmsg' => 'ok'));
        } else {
            return json(array('errcode' => -1, 'errmsg' => '生成失败'));
        }
    }

    //获取小程序的第三方提交代码的页面配置(仅供第三方开发者代小程序调用)3
    public function get_page()
    {
        $getstoid = I('stoid/d', 0);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => '该商家取消授权,请重新授权'));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/get_page?access_token=" . $getauthorizer_access_token, 'get');
        return $res;
    }

    //获取草稿箱内的所有临时代码草稿 4
    public function gettemplatedraftlist()
    {
        $res = httpRequest("https://api.weixin.qq.com/wxa/gettemplatedraftlist?access_token=" . getcomponent_access_token(), 'get');
        return $res;
    }

    //获取代码模版库中的所有小程序代码模版 5
    public function gettemplatelist()
    {

        $getstoid = I('stoid/d', 0);
        $batchtype = I('batchtype/d', 0);
        $res = httpRequest("https://api.weixin.qq.com/wxa/gettemplatelist?access_token=" . getcomponent_access_token(), 'get');
        $res = json_decode($res, true);
        if ($res['errcode'] == 0) {
            $template_list = $res['template_list'];
            array_multisort(array_column($template_list, 'template_id'), SORT_DESC, $template_list);
            $this->assign('list', $template_list);// 赋值数据集
        }
        $this->assign('stoid', $getstoid);
        $this->assign('batchtype', $batchtype);
        return $this->fetch();
    }

    //将草稿箱的草稿选为小程序代码模版 6
    public function addtotemplate()
    {
        $draft_id = I('draft_id');
        if ($draft_id == "") {
            return json(array('errcode' => -1, 'errmsg' => '请选择草稿模板'));
        }
        $postdata['draft_id'] = $draft_id;
        $res = httpRequest("https://api.weixin.qq.com/wxa/addtotemplate?access_token=" . getcomponent_access_token(), 'POST', json_encode($postdata));
        return $res;
    }

    //删除指定小程序代码模版 7
    public function deletetemplate()
    {
        $template_id = I('template_id');
        if ($template_id == "") {
            return json(array('code' => -1, 'msg' => '请选择要删除的模版ID'));
        }
        $postdata['template_id'] = $template_id;
        $res = httpRequest("https://api.weixin.qq.com/wxa/deletetemplate?access_token=" . getcomponent_access_token(), 'POST', json_encode($postdata));
        return json(json_decode($res, true));
    }

    //设置小程序业务域名(仅供第三方代小程序调用) 8

    public function setwebviewdomain_index()
    {
        $getstoid = I('stoid/d', 0);


        $this->assign('stoid', $getstoid);
        return $this->fetch();
    }

    public function setwebviewdomain()
    {
        $getstoid = I('stoid/d', 0);
        $getaction = I('action', 'get');
        $webviewdomain = I('webviewdomain');

        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];

        $getpostr = "POST";
        //add添加, delete删除, set覆盖, get获取
        $postdata['action'] = $getaction;
        switch ($getaction) {
            case "get":
                $postdatastr = '{"action":"' . $getaction . '"}';
                break;
            default:
                $postdatastr = '{"action":"' . $getaction . '","webviewdomain":[' . $this->getexp_str($webviewdomain) . ']}';
                break;
        }

        $res = httpRequest("https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=" . $getauthorizer_access_token, $getpostr, $postdatastr);
        return json(json_decode($res, true));
    }

    public function modify_domain_index()
    {
        $getstoid = I('stoid/d', 0);
        $this->assign('stoid', $getstoid);
        return $this->fetch();
    }

    //分割
    public function getexp_str($requestdomain)
    {
        $requestdomain1 = explode(",", $requestdomain);
        $new_requestdomain = "";
        if ($requestdomain1) {
            foreach ($requestdomain1 as $k => $v) {
                if ($new_requestdomain) {
                    $new_requestdomain .= ',"' . $v . '"';
                } else {
                    $new_requestdomain = '"' . $v . '"';
                }
            }
        }
        return $new_requestdomain;
    }

    //设置小程序服务器域名 9
    public function modify_domain()
    {
        $getstoid = I('stoid/d', 0);
        $getaction = I('action', 'get');
        $requestdomain = I('requestdomain');
        $wsrequestdomain = I('wsrequestdomain');
        $uploaddomain = I('uploaddomain');
        $downloaddomain = I('downloaddomain');

        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];

        $getpostr = "POST";
        //add添加, delete删除, set覆盖, get获取
        $postdata['action'] = $getaction;
        switch ($getaction) {
            case "get":
                $postdatastr = '{"action":"' . $getaction . '"}';
                break;
            default:
                $postdatastr = '{"action":"' . $getaction . '","requestdomain":[' . $this->getexp_str($requestdomain) . '],"wsrequestdomain":[' . $this->getexp_str($wsrequestdomain) . '],"uploaddomain":[' . $this->getexp_str($uploaddomain) . '],"downloaddomain":[' . $this->getexp_str($downloaddomain) . ']}';
                break;
        }

        $res = httpRequest("https://api.weixin.qq.com/wxa/modify_domain?access_token=" . $getauthorizer_access_token, $getpostr, $postdatastr,array(),true,0,"ppt");


        return json(json_decode($res, true));
    }

    //

    //获取授权小程序帐号的可选类目10
    public function get_category()
    {
        $getstoid = I('stoid/d', 0);
        $getaction = I('action', 'get');
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/get_category?access_token=" . $getauthorizer_access_token, "GET");
        return $res;
    }


    public function submit_auditindex()
    {
        $getstoid = I('stoid/d', 0);
        $getstoname = "";
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getstoname = $weapp['nick_name'];
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/get_category?access_token=" . $getauthorizer_access_token, "GET");
        if ($res) {
            $res = json_decode($res, true);
            $category_list = $res['category_list'];
            $firstlist = array();
            $secondlist = array();
            foreach ($category_list as $k => $val) {
                $firstlist[0]["first_id"] = $val['first_id'];
                $firstlist[0]['first_class'] = $val['first_class'];

                $secondlist[0]["second_id"] = $val['second_id'];
                $secondlist[0]['second_class'] = $val['second_class'];
            }
            $this->assign('firstlist', $firstlist);
            $this->assign('secondlist', $secondlist);
            $this->assign('category_list', $category_list);
        }
        $this->assign('storename', $getstoname);
        $this->assign('stoid', $getstoid);
        return $this->fetch();
    }

    //将第三方提交的代码包提交审核11
    public function submit_audit()
    {

        $getstoid = I('stoid/d', 0);
        $getaction = I('action', 'get');
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];

        $tag = I('tag');
        $address = I('address');
        $first_class = I('first_class');
        $second_class = I('second_class');
        $third_class = I('third_class');
        $first_id = I('first_id/d');
        $second_id = I('second_id/d');
        $third_id = I('third_id/d');

        $title = I('title');
        if ($tag && $first_class && $second_class && $title) {

            $postdata['item_list'][0]['address'] = $address;
            $postdata['item_list'][0]['tag'] = $tag;
            $postdata['item_list'][0]['first_class'] = $first_class;
            $postdata['item_list'][0]['second_class'] = $second_class;
            $postdata['item_list'][0]['third_class'] = $third_class;
            $postdata['item_list'][0]['first_id'] = $first_id;
            $postdata['item_list'][0]['second_id'] = $second_id;
            $postdata['item_list'][0]['third_id'] = $third_id;
            $postdata['item_list'][0]['title'] = $title;

            $postdatastr = $this->encode_json($postdata);
            //$postdatastr="{\"item_list\":[{\"address\":\"".$address."\",\"tag\":\"".$tag."\",\"first_class\":\"".$first_class."\",\"second_class\":\"".$second_class."\",\"third_class\":\"".$third_class."\",\"first_id\":".$first_id.",\"second_id\":".$second_id.",\"third_id\":".$third_id.",\"title\":\"".$title."\"}]}";
            $res = httpRequest("https://api.weixin.qq.com/wxa/submit_audit?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
            //"{\"errcode\":0,\"errmsg\":\"ok\",\"auditid\":427110678}"
            if (empty($res)) {
                return json(array('errcode' => -1, 'errmsg' => '微信接口返回空值'));
            }

            $res = json_decode($res, true);
            if ($res['errcode'] != 0) {
                return json(array('errcode' => $res['errcode'], 'errmsg' => $this->submit_audit_msg($res['errcode'])));
            }
            //
            if ($res['auditid']) {
                $weapp_audit = M('weapp_audit')->where(array('store_id' => $getstoid, 'auditid' => $res['auditid']))->find();
                if (empty($weapp_audit)) {
                    $add_audit['store_id'] = $getstoid;
                    $add_audit['username'] = $weapp['user_name'];
                    $add_audit['auditid'] = $res['auditid'];
                    $add_audit['weapp_id'] = $weapp['id'];
                    $add_audit['addtime'] = time();
                    $add_audit['release_version'] = $weapp['commit_version'];
                    $add_audit['release_remark'] = $weapp['commit_remark'];
                    $add_audit_res = M('weapp_audit')->save($add_audit);

                }
            }

            return json(array('errcode' => 0, 'errmsg' => '发布成功,待审核'));
        } else {
            return json(array('errcode' => -1, 'errmsg' => '参数有误'));
        }
    }


    //批量提交体验并审核
    function batchsubmit_audit()
    {
        if (IS_POST) {
            $gettype = I('type/d', 1);
            $post_data = input('post.');
            if (empty($post_data)) {
                return json(array('errcode' => -1, 'errmsg' => '提交失败,参数有误!'));
            }


            $user_version = $post_data["user_version"];

            $wepappsql = "select * from wxd_weapp where appid<>'' and store_id not in (select store_id from wxd_weapp_audit where release_version='" . $user_version . "')";

            $weapplist = Db::query($wepappsql);

            if (empty($weapplist)) {
                return json(array('errcode' => -1, 'errmsg' => '未找到授权小程序'));
            }
            $man_res = M('manager_config')->find();
            foreach ($weapplist as $k => $v) {
                $getstoid = $v['store_id'];

                $stoinfo = M('store')->where(array('store_id' => $getstoid))->find();
                $weapp = $v;

                $getweptoken = weapp_get_access_token($weapp, $getstoid);

                $getweptoken = json_decode($getweptoken, true);

                if ($getweptoken['errcode'] == 0) {


                    $getweapp_ext_json = $man_res["weapp_ext_json1"];
                    $getauthorizer_access_token = $getweptoken["authorizer_access_token"];

                    $PostData_str = '{"template_id":' . $post_data["template_id"] . ',"user_version":"' . $post_data["user_version"] . '","user_desc":"' . $post_data['user_desc'] . '","ext_json":"{\"extAppid\":\"' . $weapp['appid'] . '\",';
                    $PostData_str .= '\"ext\":{\"extAppid\":\"' . $weapp['appid'] . '\",\"appCode\":\"UNION_PAY\",\"appName\":\"' . $stoinfo['store_name'] . '\",\"stoid\":\"' . $weapp['store_id'] . '\",\"preDomain\":\"https://test-weshop.yolipai.net/\"},';
                    $PostData_str .= '\"extPages\":{},\"pages\":' . $getweapp_ext_json . ',';
                    $PostData_str .= ' \"window\":{},\"networkTimeout\":{},\"tabBar\":{\"color\":\"#7f8389\",\"selectedColor\":\"#ff9a0f\",\"borderStyle\":\"white\",';
                    $PostData_str .= '\"list\":[{\"pagePath\":\"pages/index/index/index\",\"text\":\"首页\",\"iconPath\":\"images/bar/index.png\",\"selectedIconPath\":\"images/bar/index_on.png\"},{\"pagePath\":\"pages/goods/categoryList/categoryList\",\"text\":\"分类\",\"iconPath\":\"images/bar/fl.png\",\"selectedIconPath\":\"images/bar/fl_on.png\"},{\"pagePath\":\"pages/cart/cart/cart\",\"text\":\"购物车\",\"iconPath\":\"images/bar/car.png\",\"selectedIconPath\":\"images/bar/car_on.png\"},{\"pagePath\":\"pages/user/index/index\",\"text\":\"我的\",\"iconPath\":\"images/bar/user.png\",\"selectedIconPath\":\"images/bar/user_on.png\"}]}}"}';


                    $res = httpRequest("https://api.weixin.qq.com/wxa/commit?access_token=" . $getauthorizer_access_token, "POST", $PostData_str);

                    //更新版本
                    $updatedata['commit_version'] = $post_data["user_version"];
                    $updatedata['commit_remark'] = $post_data["user_desc"];
                    $updatedata['edittime'] = time();

                    $updateweappinfo = M('weapp')->where(array('store_id' => $getstoid))->save($updatedata);

                    if ($updateweappinfo) {

                        $weapp_audit_info = M('weapp_audit')->where(array('store_id' => $getstoid, 'release_version' => $post_data["user_version"], 'status' => array('in', '0,2')))->find();

                        if (empty($weapp_audit_info)) {
                            //获取单个小程序标题及类目
                            $res = httpRequest("https://api.weixin.qq.com/wxa/get_category?access_token=" . $getauthorizer_access_token, "GET");

                            if ($res) {
                                $res = json_decode($res, true);
                                $category_list = $res['category_list'];
                                $firstlist = array();
                                $secondlist = array();
                                foreach ($category_list as $k => $val) {
                                    $firstlist[0]["first_id"] = $val['first_id'];
                                    $firstlist[0]['first_class'] = $val['first_class'];

                                    $secondlist[0]["second_id"] = $val['second_id'];
                                    $secondlist[0]['second_class'] = $val['second_class'];
                                }


                                $tag = "化妆品";
                                $address = "pages/index/index/index";
                                $first_class = $firstlist[0]["first_class"];
                                $second_class = $secondlist[0]["second_class"];
                                $third_class = $category_list[0]['third_class'];
                                $first_id = $firstlist[0]["first_id"];;
                                $second_id = $secondlist[0]["second_id"];
                                $third_id = "";
                                $title = $weapp['nick_name'];


                                if ($tag && $first_class && $second_class && $title) {

                                    $postdata['item_list'][0]['address'] = $address;
                                    $postdata['item_list'][0]['tag'] = $tag;
                                    $postdata['item_list'][0]['first_class'] = $first_class;
                                    $postdata['item_list'][0]['second_class'] = $second_class;
                                    $postdata['item_list'][0]['third_class'] = $third_class;
                                    $postdata['item_list'][0]['first_id'] = $first_id;
                                    $postdata['item_list'][0]['second_id'] = $second_id;
                                    $postdata['item_list'][0]['third_id'] = $third_id;
                                    $postdata['item_list'][0]['title'] = $title;

                                    $postdatastr = $this->encode_json($postdata);
                                    $res = httpRequest("https://api.weixin.qq.com/wxa/submit_audit?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
                                    mlog($getstoid . "返回:" . $res, "batchsubmit_audit");
                                    if ($res) {
                                        $res = json_decode($res, true);
                                        if ($res['errcode'] == 0 && $res['auditid']) {
                                            $weapp_audit = M('weapp_audit')->where(array('store_id' => $getstoid, 'auditid' => $res['auditid']))->find();
                                            if (empty($weapp_audit)) {
                                                $add_audit['store_id'] = $getstoid;
                                                $add_audit['username'] = $weapp['user_name'];
                                                $add_audit['auditid'] = $res['auditid'];
                                                $add_audit['weapp_id'] = $weapp['id'];
                                                $add_audit['addtime'] = time();
                                                $add_audit['release_version'] = $post_data["user_version"];
                                                $add_audit['release_remark'] = $post_data["user_desc"];
                                                $add_audit_res = M('weapp_audit')->save($add_audit);


                                            }
                                        }


                                    }

                                }
                            }
                        }
                    }
                }


            }
            return json(array('errcode' => 0, 'errmsg' => '发布成功,待审核'));
        }

    }

    //
    function submit_audit_msg($code)
    {
        switch ($code) {
            case -1:
                return "系统繁忙";
                break;
            case 86000:
                return "不是由第三方代小程序进行调用";
            case 86001:
                return "不存在第三方的已经提交的代码";
            case 85006:
                return "标签格式错误";
            case 85007:
                return "页面路径错误";
            case 85008:
                return "类目填写错误";
            case 85009:
                return "已经有正在审核的版本";
            case 85010:
                return "item_list有项目为空";
            case 85011:
                return "标题填写错误";
            case 85023:
                return "审核列表填写的项目数不在1-5以内";
            case 85077:
                return "小程序类目信息失效(类目中含有官方下架的类目,请重新选择类目)";
            case 86002:
                return "小程序还未设置昵称、头像、简介。请先设置完后再重新提交";
            case 85085:
                return "近7天提交审核的小程序数量过多,请耐心等待审核完毕后再次提交";
            case 85086:
                return "提交代码审核之前需提前上传代码";
            case 85087:
                return "小程序已使用api navigateToMiniProgram,请声明跳转appid列表后再次提交";
                break;
            default:
                return "系统繁忙,请重试";
                break;

        }
    }

    function encode_json($str)
    {
        return urldecode(json_encode($this->url_encode($str)));
    }

    function url_encode($str)
    {
        if (is_array($str)) {
            foreach ($str as $key => $value) {
                $str[urlencode($key)] = $this->url_encode($value);
            }
        } else {
            $str = urlencode($str);
        }

        return $str;
    }

    //设置小程序隐私设置(是否可被搜索)12
    public function changewxasearchstatus()
    {
        $getstoid = I('stoid/d', 0);
        //  "status":0, //1表示不可搜索,0表示可搜索
        $getstatus = I('status/d', 0);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];


        $postdata['status'] = $getstatus;
        $postdatastr = json_encode($postdata);
        $res = httpRequest("https://api.weixin.qq.com/wxa/changewxasearchstatus?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        return $res;

    }

    //查询小程序当前隐私设置(是否可被搜索)13
    public function getwxasearchstatus()
    {
        $getstoid = I('stoid/d', 0);
        //  "status":0, //1表示不可搜索,0表示可搜索
        $getstatus = I('status/d', 0);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/getwxasearchstatus?access_token=" . $getauthorizer_access_token, "get");
        return $res;
    }

    //获取小程序模板库标题列表14
    public function template_library_list()
    {
        $getstoid = I('stoid/d', 0);
        //  "status":0, //1表示不可搜索,0表示可搜索
        $getp = I('p/d', 1);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getcount = 20;
        $getoffset = 0;
        if ($getp > 1) {
            $getoffset = $getp * $getcount;
        }
        $postdata['offset'] = $getoffset;
        $postdata['count'] = $getcount;
        $postdatastr = json_encode($postdata);
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        return $res;
    }

    //获取模板库某个模板标题下关键词库15
    public function template_library_get()
    {
        $getstoid = I('stoid/d', 0);
        $getid = I('id');
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }
        if (empty($getid)) {
            return json(array('errcode' => -1, 'errmsg' => '请输入模板标题'));
        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $postdata['id'] = $getid;
        $postdatastr = json_encode($postdata);
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        return $res;
    }

    //组合模板并添加至帐号下的个人模板库16
    public function template_add()
    {
        $getstoid = I('stoid/d', 0);
        $getid = I('id');
        $keyword_id_list = I('keyword_id_list');

        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }
        if (empty($getid)) {
            return json(array('errcode' => -1, 'errmsg' => '请输入模板标题'));
        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $postdata['id'] = $getid;
        $postdata['keyword_id_list'] = $keyword_id_list;
        $postdatastr = json_encode($postdata);

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        return $res;
    }


    //获取帐号下已存在的模板列表17
    public function template_list()
    {
        $getstoid = I('stoid/d', 0);
        $getp = I('p/d', 1);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));

        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getcount = 20;
        $getoffset = 0;
        if ($getp > 1) {
            $getoffset = $getp * $getcount;
        }
        $postdata['offset'] = $getoffset;
        $postdata['count'] = $getcount;
        $postdatastr = json_encode($postdata);
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        return $res;
    }

    //组合模板并添加至帐号下的个人模板库18
    public function template_del()
    {
        $getstoid = I('stoid/d', 0);
        $template_id = I('template_id');

        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }
        if (empty($template_id)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择删除模板ID'));
        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $postdata['template_id'] = $template_id;
        $postdatastr = json_encode($postdata);

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        return $res;
    }

    //查询某个指定版本的审核状态19
    public function get_auditstatus()
    {
        $getstoid = I('stoid/d', 0);
        $auditid = I('auditid');

        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }
        if (empty($auditid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择提交审核时获得的审核id'));
        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $postdata['auditid'] = $auditid;
        $postdatastr = json_encode($postdata);

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/get_auditstatus?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        if (empty($res)) {
            return json(array('errcode' => -1, 'errmsg' => '微信接口返回为空,请稍后再试'));
        }
        $res = json_decode($res, true);


        if ($res['errcode'] == 0) {
            $updata['status'] = $res['status'];
            if ($res['status'] == 1) {
                $updata['reason'] = $res['reason'];
                M('weapp_audit')->where(array('store_id' => $getstoid, 'auditid' => $auditid))->save($updata);
                return json(array('errcode' => 0, 'errmsg' => $res['reason']));
            } else {
                switch ($res['status']) {
                    case 0:
                        $msg = "审核成功";
                        break;
                    case 2:
                        $msg = "审核中";
                        break;
                    case 3:
                        $msg = "已撤回";
                        break;
                    default:
                        $msg = $res['status'];
                        break;
                }
                M('weapp_audit')->where(array('store_id' => $getstoid, 'auditid' => $auditid))->save($updata);
                return json(array('errcode' => 0, 'errmsg' => $msg));
            }
        } else {
            return json(array('errcode' => -1, 'errmsg' => '查询失败请稍后再试'));
        }

    }

    //查询最新一次提交的审核状态20
    public function get_latest_auditstatus()
    {
        $getstoid = I('stoid/d', 0);

        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=" . $getauthorizer_access_token, "get");
        if (empty($res)) {
            return json(array('errcode' => -1, 'errmsg' => '微信接口返回为空,请稍后再试'));
        }
        $res = json_decode($res, true);
        if ($res['errcode'] == 0) {

            if ($res['auditid']) {
                $weapp_audit = M('weapp_audit')->where(array('store_id' => $getstoid, 'auditid' => $res['auditid']))->find();
                if (empty($weapp_audit)) {
                    $add_audit['store_id'] = $getstoid;
                    $add_audit['weapp_id'] = $weapp['id'];
                    $add_audit['auditid'] = $res['auditid'];
                    $add_audit['addtime'] = time();

                }
            }

            if ($res['status'] == 1) {

                $add_audit['status'] = 1;
                $add_audit['reason'] = $res['reason'];
                $add_audit_res = M('weapp_audit')->save($add_audit);
                return json(array('errcode' => 0, 'errmsg' => $res['reason']));
            }
            $add_audit['status'] = $res['status'];
            $add_audit_res = M('weapp_audit')->save($add_audit);
            switch ($res['status']) {
                case 0:
                    $msg = "审核成功";
                    break;
                case 2:
                    $msg = "审核中";
                    break;
                case 3:
                    $msg = "已撤回";
                    break;
                default:
                    $msg = $res['status'];
                    break;
            }
            return json(array('errcode' => 0, 'errmsg' => $msg));
        }

    }

    //发布已通过审核的小程序21
    public function release()
    {

        $getstoid = I('stoid/d', 0);
        $getauditid = I('auditid');

        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }

        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $postdatastr = "{}";
        $res = httpRequest("https://api.weixin.qq.com/wxa/release?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        if (empty($res)) {
            return json(array('errcode' => -1, 'errmsg' => '系统繁忙'));
        }
        $res = json_decode($res, true);
        switch ($res['errcode']) {
            case 0:
                $weapp = M('weapp_audit')->where(array('store_id' => $getstoid, 'auditid' => $getauditid))->save(array('is_release' => 1, 'release_time' => time()));
                $msg = "发布成功";
                break;
            case -1:
                $msg = "系统繁忙";
                break;
            case 85019:
                $msg = "没有审核版本";
                break;
            case 85020:
                $msg = "审核状态未满足发布";
                break;
            case 85052:
                $weapp = M('weapp_audit')->where(array('store_id' => $getstoid, 'auditid' => $getauditid))->save(array('is_release' => 1, 'release_time' => time()));
                $msg = "应用程序已经发布";
                break;
            default:
                $msg = $res['errcode'] . $res['errmsg'];
                break;
        }
        return json(array('errcode' => $res['errcode'], 'errmsg' => $msg));

    }


    //加急审核申请
    public function speedupaudit()
    {

        $getstoid = I('stoid/d', 0);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }

        $getauditid = I('auditid', 0);
        if (empty($getauditid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择要加急版本'));
        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $postdata['auditid'] = $getauditid;
        $postdatastr = json_encode($postdata);
        $res = httpRequest("https://api.weixin.qq.com/wxa/speedupaudit?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        if (empty($res)) {
            return json(array('errcode' => -1, 'errmsg' => '系统繁忙'));
        }
        $res = json_decode($res, true);
        switch ($res['errcode']) {
            case 0:
                $msg = "加急成功,请耐心等待审核结果";
                break;
            case -1:
                $msg = "系统繁忙";
                break;
            case 89401:
                $msg = "系统不稳定,请稍后再试,如多次失败请通过社区反馈";
                break;
            case 89402:
                $msg = "审核单不在待审核队列,请检查是否已提交审核或已审完";
                break;
            case 89403:
                $msg = "本单属于平台不支持加急种类,请等待正常审核流程";
                break;
            case 89404:
                $msg = "本单已加速成功,请勿重复提交";
                break;
            case 89405:
                $msg = "本月加急额度不足,请提升提审质量以获取更多额度";
                break;
            default:
                $msg = $res['errcode'] . $res['errmsg'];
                break;
        }
        return json(array('errcode' => $res['errcode'], 'errmsg' => $msg));

    }


    //小程序审核撤回
    public function undocodeaudit()
    {

        $getstoid = I('stoid/d', 0);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }

        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }

        $weapp_audit = M('weapp_audit')->where(array('store_id' => $getstoid, 'status' => 2))->order('addtime desc')->find();
        if (empty($weapp_audit)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家没有正在审核记录'));
        }

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $postdatastr = "{}";
        $res = httpRequest("https://api.weixin.qq.com/wxa/undocodeaudit?access_token=" . $getauthorizer_access_token, "GET", $postdatastr);
        if (empty($res)) {
            return json(array('errcode' => -1, 'errmsg' => '系统繁忙'));
        }
        $res = json_decode($res, true);
        switch ($res['errcode']) {
            case 0:
                M('weapp_audit')->where(array('id' => $weapp_audit['id']))->save(array('status' => 3));
                $msg = "操作成功";
                break;
            case -1:
                $msg = "系统繁忙";
                break;
            case 87013:
                $msg = "撤回次数达到上限(每天一次,每个月10次";
                break;
            default:
                $msg = $res['errcode'] . $res['errmsg'];
                break;
        }
        return json(array('errcode' => $res['errcode'], 'errmsg' => $msg));

    }

    //批量小程序审核撤回
    public function batchundocodeaudit()
    {


        $weapp_audit = M('weapp')->where(array('appid' => array('neq', ''), 'store_id' => array('notin', '197,713')))->order('addtime desc')->select();
        if (empty($weapp_audit)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家没有正在审核记录'));
        }

        foreach ($weapp_audit as $k => $v) {
            $getstoid = $v['store_id'];

            $getweptoken = weapp_get_access_token($v, $getstoid);
            $getweptoken = json_decode($getweptoken, true);
            if ($getweptoken['errcode'] == 0) {
                $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
                $postdatastr = "{}";
                $res = httpRequest("https://api.weixin.qq.com/wxa/undocodeaudit?access_token=" . $getauthorizer_access_token, "GET", $postdatastr);
                mlog($v['store_id'] . ",返回:" . $res, "batchundocodeaudit");
                if ($res) {
                    $res = json_decode($res, true);
                    switch ($res['errcode']) {
                        case 0:
                            $msg = "操作成功";
                            break;
                        case -1:
                            $msg = "系统繁忙";
                            break;
                        case 87013:
                            $msg = "撤回次数达到上限(每天一次,每个月10次";
                            break;
                        default:
                            $msg = $res['errcode'] . $res['errmsg'];
                            break;
                    }

                }
            }


        }
        return json(array('errcode' => 0, 'errmsg' => '操作成功'));


    }

    //修改小程序线上代码的可见状态(仅供第三方代小程序调用)22
    public function change_visitstatus()
    {

        $getstoid = I('stoid/d', 0);
        $getaction = I('action');//close为不可见,open为可见

        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }
        if (empty($getaction)) {
            return json(array('errcode' => -1, 'errmsg' => '请输入可访问状态'));
        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $postdata['action'] = $getaction;
        $postdatastr = json_encode($postdata);

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/change_visitstatus?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        return $res;
    }

    public function memberauth()
    {
        $getstoid = I('stoid/d', 0);
        if (empty($getstoid)) {
            return json(array('errcode' => -1, 'errmsg' => '请选择商家'));
        }

        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $postdata['action'] = "get_experiencer";
        $postdatastr = json_encode($postdata);

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/memberauth?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);
        $res = json_decode($res, true);
        if ($res['errcode'] == 0) {
            $this->assign('list', $res['members']);
        }
        $this->assign('stoid', $getstoid);
        return $this->fetch();
    }

    public function bind_tester()
    {
        $getstoid = I('stoid/d', 0);
        $ispost = I('ispost/d', 0);
        if ($ispost) {
            $wechatid = I('wechatid');
            if (empty($wechatid)) {
                return json(array('errcode' => -1, 'errmsg' => '微信号不能为空'));
            }
            $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
            if (empty($weapp)) {
                return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
            }
            $getweptoken = weapp_get_access_token($weapp, $getstoid);
            $getweptoken = json_decode($getweptoken, true);
            if ($getweptoken['errcode'] != 0) {
                return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
            }

            $postdata['wechatid'] = $wechatid;
            $postdatastr = json_encode($postdata);

            $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
            $res = httpRequest("https://api.weixin.qq.com/wxa/bind_tester?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);

            $res = json_decode($res, true);
            if ($res['errcode'] != 0) {
                $getmsg="";
                switch ($res['errcode'] )
                {
                    case -1:
                        $getmsg="系统失败";
                        break;
                    case 85001:
                        $getmsg="微信号不存在或微信号设置为不可搜索";
                        break;
                    case 85002:
                        $getmsg="小程序绑定的体验者数量达到上限";
                        break;
                    case 85003:
                        $getmsg="微信号绑定的小程序体验者达到上限";
                        break;
                    case 85004:
                        $getmsg="微信号已经绑定";
                        break;
                    default:
                        break;
                }
                return json(array('errcode' => -1, 'errmsg' => $getmsg));
            }
            return json(array('errcode' => 0, 'errmsg' => '添加成功'));
        }
        $this->assign('stoid', $getstoid);
        return $this->fetch();
    }

    public function unbind_tester()
    {
        $getstoid = I('stoid/d', 0);
        $wechatid = I('wechatid');
        if (empty($wechatid)) {
            $this->error('微信号不能为空',U('Weapp/memberauth'));exit;
           // return json(array('errcode' => -1, 'errmsg' => '微信号不能为空'));
        }
        $weapp = M('weapp')->where(array('store_id' => $getstoid))->find();
        if (empty($weapp)) {
            $this->error('该商家未授权',U('Weapp/memberauth'));exit;
          //  return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $getstoid);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }

        $postdata['wechatid'] = $wechatid;
        $postdatastr = json_encode($postdata);

        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/unbind_tester?access_token=" . $getauthorizer_access_token, "POST", $postdatastr);

        $res = json_decode($res, true);
        if ($res['errcode'] != 0) {
          //  return json(array('errcode' => -1, 'errmsg' => $res['errmsg']));
            $this->error('解绑失败',U('Weapp/memberauth'));exit;
        }
        $this->success('解绑成功',U('Weapp/memberauth',array('stoid'=>$getstoid)));exit;
      //  return json(array('errcode' => 0, 'errmsg' => '解绑成功'));

    }

    //查询服务商的当月提审限额(quota)和加急次数
    public function queryquota()
    {
        $weapp = M('weapp')->find();
        if (empty($weapp)) {
            return json(array('errcode' => -1, 'errmsg' => '该商家未授权'));
        }
        $getweptoken = weapp_get_access_token($weapp, $weapp['store_id']);
        $getweptoken = json_decode($getweptoken, true);
        if ($getweptoken['errcode'] != 0) {
            return json(array('errcode' => -1, 'errmsg' => $getweptoken['errmsg']));
        }
        $postdatastr = "{}";
        $getauthorizer_access_token = $getweptoken["authorizer_access_token"];
        $res = httpRequest("https://api.weixin.qq.com/wxa/queryquota?access_token=" . $getauthorizer_access_token, "get", $postdatastr);
        return json_decode($res, true);
    }

}