Jddj.php 69.8 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 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810
<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: 当燃
 * 专题管理
 * Date: 2016-03-09
 */

namespace app\admin\controller;
use app\admin\logic\GiftuserLogic;
use think\AjaxPage;
use think\Page;
use app\admin\logic\GoodsLogic;
use think\db;
use think\Cache;
use think\Cookie;

class Jddj extends Base
{
    function __construct(){
        parent::__construct();
        $nologin = ['not_jd'];
        if (!in_array(ACTION_NAME, $nologin)) {
            $rs=M("store_module_endtime")->where('store_id',getAdmStoId())->where('type',4)->find();
            if($rs){
                if($rs['end_time']<time()) $this->redirect(U('Admin/jddj/not_jd'));
                $this->assign('end_time',$rs['end_time']);
            }else{
                $this->redirect(U('Admin/jddj/not_jd'));
            }
        }
    }

    //基础信息
    public function config()
    {
        $getadmstoid=getAdmStoId();
        $info=M('jd_store')->where(array('store_id'=>$getadmstoid))->find();
        $this->assign("config",$info);
        return $this->fetch('', getAdmStoId());
    }
    //基础信息
    public function handle()
    {
        $param = I('post.');
        $getadmstoid=getAdmStoId();
        $accdb=getERPId();
        $venderid=$param['venderid'];//商家编号
        $infoexit=M('jd_store')->where(array('venderid'=>$venderid,'store_id'=>array('neq',getAdmStoId())))->find();
        if ($infoexit)
        {
            $this->error("该商家编号已被使用,请输入其他商家编号", U('Jddj/config'));
            exit;
        }


        $info=M('jd_store')->where(array('store_id'=>$getadmstoid))->find();
        $param['store_id']=$getadmstoid;
        $param['accdb']=$accdb;
        if ($info)
        {
            M('jd_store')->where(array('store_id'=>$getadmstoid))->save($param);
        }
        else
        {
            M('jd_store')->save($param);
        }
        $this->success("操作成功", U('Jddj/config'));
        exit;
    }
    //-------商品管理------------
    public function goods_up()
    {
        $id = getAdmStoId();
        return $this->fetch('', getAdmStoId());
    }
    public function ajax_goods_up()
    {
        $id = getAdmStoId();
        $p=I("p");
        $pagesize=20;
        $data=["pageSize"=>$pagesize,'pageNo'=>$p,'isFilterDel'=>"0"];
        $gname=I("goods_name");
        $gsn=I("goods_sn");
        $jsku=I("dd_sku");

        if(trim($gname)) $data['skuName']=trim($gname);
        if(trim($gsn)) $data['skuId']=trim($gsn);
        if(trim($jsku)) $data['upcCode']=trim($jsku);

        $oldurl = U('Admin/jddj/goods_up', array(
            "goods_name" => $gname,
            "goods_sn" => $gsn,
            "dd_sku" => $jsku,
            "p" => $p,
        ));
        $this->assign('oldurl', urlencode($oldurl));

        $rs=jd_api('/pms/querySkuInfos',$data,$id);

        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $list=  json_decode($rs['data'],true);
            if($list['result']['count']>0){
                $city=F('jd_city');
                if(empty($city)){
                    $city=$this->get_jd_city();
                    Cache::set("jd_city",$city,3600*4);
                }
                 if($list['result']['result']!=null) {
                     $glist=json_decode($list['result']['result'],true);
                     foreach ($glist as $kl=>$vl){
                         $str="";
                         $cell_city=$vl['sellCities'];
                         foreach($cell_city as $kk=>$vv){
                               if($vv==0) {
                                   $str = "全国";break;
                               }
                               else{
                                   foreach ($city as $kc=>$vc){
                                        if($vc['areaCode']==$vv){ $str.=$vc['areaName']." "; }
                                   }
                               }
                         }
                         $glist[$kl]['scity']=$str;
                     }
                     Cache::set("ajax_cgoodsList_".$id,$glist,3600*4);
                     $this->assign("goodsList",$glist);
                 }
                 $Page  = new AjaxPage($list['result']['count'],$pagesize);

                 $show=$Page->show();
                 $this->assign('page',$show);// 赋值分页输出
                 $this->assign('pager',$Page);

            }
        }

        return $this->fetch('', getAdmStoId());
    }
    //---订单管理---
    public function orderlist()
    {
        $id = getAdmStoId();
        $p=I("p/d",1);
        $pagesize=500;
        $data=["pageSize"=>$pagesize,'pageNo'=>$p];
        $rs=jd_api('/order/es/query',null,$id);
        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $list=  json_decode($rs['data'],true);
            if($list['result']['count']>0){
                if($list['result']['result']!=null) {
                    $glist=json_decode($list['result']['result'],true);
                    $this->assign("goodsList",$glist);
                }
                $Page  = new AjaxPage($list['result']['count'],$pagesize);
                $show=$Page->show();
                $this->assign('page',$show);// 赋值分页输出
                $this->assign('pager',$Page);
            }
        }


    }
    //--------门店管理-------------
    function format_time($i){
        if($i==48) return "23:59";
        $fir = "";$end = "";
        if ($i % 2 > 0) {
            $fir = ($i - 1) / 2;$end = ":30";
        } else {
            $fir = $i / 2;$end = ":00";
        }
        if (strlen($fir) == 1) $fir = "0" . $fir;
        return $fir . $end;
    }
    public function sto_up()
    {
        return $this->fetch('', getAdmStoId());
    }
    public function ajax_sto_up()
    {
        $id = getAdmStoId();
        $p=I("p");

        $oldurl = U('Admin/jddj/sto_up', array( "p" => $p, ));
        $this->assign('oldurl', urlencode($oldurl));

        $data=null;
        $rs=jd_api('/store/getStationsByVenderId ',$data,$id);
        $rs=json_decode($rs,true);

        $glist=null;
        if($rs['code']==0){
            $list=json_decode($rs['data'],true);
            $arr=$list['result'];
            $count=count($arr);
            if($count>0){
                $fir=($p-1)*20;
                $end=$p*20;
                if($fir<$count){
                    if($end>$count) $end=$count;
                    for($i=$fir;$i<$end;$i++){
                         $data1['StoreNo']=$arr[$i];
                         $rss=jd_api('/storeapi/getStoreInfoByStationNo',$data1,$id);
                         $rss=json_decode($rss,true);
                         $md=json_decode($rss['data'],true)['result'];
                         $md['updateTime']=date('Y-m-d H:i:s',$md['updateTime']['time']/1000);
                         $md['createTime']=date('Y-m-d H:i:s',$md['createTime']['time']/1000);
                         $md['serviceTimeStart1']=$this->format_time($md['serviceTimeStart1']);
                         $md['serviceTimeEnd1']=$this->format_time($md['serviceTimeEnd1']);

                          if(empty($md['cityName'])){
                              $rs=M("jd_sto")->where('store_id',$id)
                                  ->where('stationNo', $data1['StoreNo'])->field('cityname,townname')->find();
                              $md['cityName']=$rs['cityname'];
                              $md['countyName']=$rs['townname'];
                          }

                         $glist[]=$md;
                    }

                    $jj=json_encode($glist);
                    $this->assign("goodsList",$glist);
                    $Page  = new AjaxPage(count($list['result']),20);
                    $show=$Page->show();
                    $this->assign('page',$show);// 赋值分页输出
                    $this->assign('pager',$Page);


                }
            }
        }

        return $this->fetch('', getAdmStoId());
    }
    public function search_goods()
    {
        $GoodsLogic = new GoodsLogic;
        $brandList = $GoodsLogic->getSortBrands();
        $this->assign('brandList', $brandList);
        $categoryList = $GoodsLogic->getSortCategory();
        $this->assign('categoryList', $categoryList);
        $type = I('type', '');
        $isall = I('isall/d', 0);//是否显示全部

        $where="";
        $where = "is_jd=0 and weight>0 and is_on_sale = 1 and store_count>0 and store_id=" . getAdmStoId() ;//搜索条件
        $this->assign('type', $type);

        $intro = I('intro');
        if (!empty($intro)) {
            $where = "$where and " . I('intro') . " = 1";
            $this->assign('intro', $intro);
        }

        if (I('cat_id')) {
            $this->assign('cat_id', I('cat_id'));
            $grandson_ids = getCatGrandson(I('cat_id'));
            $where = " $where  and cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件
        }
        if (I('brand_id')) {
            $this->assign('brand_id', I('brand_id'));
            $where = "$where and brand_id = " . I('brand_id');
        }

        $kword = urldecode(urldecode(I('keywords/s')));
        if (!empty($kword)) {
            $this->assign('keywords', $kword);
            $where = "$where and (goods_sn like '%" . $kword . "%' or goods_name like '%" . $kword . "%' or keywords like '%" . $kword . "%' or sku = '" . $kword . "')";
        }

        $t=time();
        $where.=" and on_time<".$t." and (down_time>".$t." or down_time=0 or down_time='' or down_time is null)";
        $count = M('goods')->where($where)->count();
        $Page = new Page($count, 8);
        $goodsList = M('goods')->where($where)->order('goods_id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $show = $Page->show();//分页显示输出
        $this->assign('page', $show);//赋值分页输出
        $this->assign('goodsList', $goodsList);
        $this->assign('pager', $Page);//赋值分页输出

        return $this->fetch("", getAdmStoId());
    }
    //获取京东分类列表
    public function jd_categoty(){
        $stoid = getAdmStoId();
        $p_id=I('pid',0);
        $data['id']=$p_id;
        $data['fields']=["ID","CATEGORY_NAME","CATEGORY_LEVEL","CATEGORY_STATUS"];
        $rs=jd_api('/api/queryChildCategoriesForOP',$data,$stoid);
        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $data=json_decode($rs['data'],true);
            return json(["code"=>0,'data'=>$data['result']]);
        }else{
            return json(['code'=>-1,'msg'=>'获取失败']);
        }
    }
    //---获取商家店内分类列表----
    public function sto_categoty(){
        $stoid = getAdmStoId();
        $data['fields']=["ID","PID","SHOP_CATEGORY_NAME","SORT",];
        $rs=jd_api('/pms/queryCategoriesByOrgCode',$data,$stoid);
        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $data=json_decode($rs['data'],true);
            return json(["code"=>0,'data'=>$data['result']]);
        }else{
            return json(['code'=>-1,'msg'=>'获取失败']);
        }
    }
    //----------选择品牌--------------
    public function search_brand()
    {
        $id = getAdmStoId();
        $p=I("p",1);
        $key=I("keywords");
        $this->assign('keywords', $key);//赋值分页输出

        $pagesize=10;

        $data=["pageSize"=>$pagesize,'pageNo'=>$p,'fields'=>['BRAND_ID','BRAND_NAME','BRAND_STATUS']];
        if($key){
            $data['brandName']=urldecode(urldecode($key));
        }

        $rs=jd_api('/pms/queryPageBrandInfo',$data,$id);

        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $list=  json_decode($rs['data'],true);
            if($list['result']['count']>0){
                if($list['result']['result']!=null) {
                    $glist=$list['result']['result'];
                    $this->assign("goodsList",$glist);
                }

                $Page = new Page($list['result']['count'], $pagesize);
                $this->assign('pager',$Page);
                $show = $Page->show();//分页显示输出
                $this->assign('page', $show);//赋值分页输出
            }
        }

        return $this->fetch('', getAdmStoId());
    }
    //--------插入商品-----------
    public function insert_goods(){
        try {
            $stoid = getAdmStoId();
            $gid = I("gid");
            $cat_id=I("cat_id");
            $fir_id=I("fir_cat_id");
            $sec_id=I("sec_cat_id");

            $sto_cate_id=I("sto_cate_id");
            $sbrand=I("sbrand");

            $upfilepath = ROOT_PATH . "public/upload/jddj/" . $stoid . "/";  //磁盘地址
            if (!is_dir($upfilepath)) mkdir($upfilepath, 0777, true);
            $path = "/public/upload/jddj/" . $stoid . "/";                     //目录
            //$Host = curHostURL();                                          //本机地址
            $Host = "http://mshop-api.yolipai.net/";                         //本机地址

            $glist = M("goods")->where("goods_id in(" . $gid . ")")
                ->where('is_jd',0)
                ->where('store_id', getAdmStoId())->select();
            if ($glist) {
                foreach ($glist as $k => $v) {

                    $fir = "https://mshopimg.yolipai.net";
                    $img = $fir . $v['original_img'];

                    $filename = uniqid() . "0.jpg";
                    $img = file_get_contents($img);
                    file_put_contents($upfilepath . $filename, $img);

                    //强制格式800*800
                    m_format_img($upfilepath . $filename, 800);
                    $fialename_arr[] = $Host . $path . $filename;
                    $file_path[] = $upfilepath . $filename;

                    $imglist = M("goods_images")->where("goods_id", $v['goods_id'])
                        ->where('store_id', $stoid)->where('ismain', 0)
                        ->field('image_url')
                        ->select();

                    if ($imglist) {
                        $int = 1;
                        foreach ($imglist as $kk => $vv) {
                            $img = $fir . $vv['image_url'];
                            $filename = uniqid() . $int . ".jpg";
                            $img = file_get_contents($img);
                            file_put_contents($upfilepath . $filename, $img);
                            //强制格式800*800
                            m_format_img($upfilepath . $filename, 800);
                            $fialename_arr[] = $Host . $path . $filename;
                            $file_path[] = $upfilepath . $filename;
                            $int++;
                        }
                    }

                    $data['images'] = implode(",", $fialename_arr);

                    if($v['weight']<=0){
                        return json(['code'=>-1,"msg"=>$v['goods_name']."重量没有设置!!"]);
                    }
                    $data['outSkuId'] = $v['goods_sn'];         //商品编号
                    $data['upcCode'] = $v['sku'];               //条码
                    $data['skuName'] = $v['goods_name'];        //商品名称
                    $data['skuPrice'] = $v['shop_price']*100;   //商品价格,要乘以100
                    $data['fixedStatus'] = 1;                   //商品上架
                    $data['weight'] = $v['weight']/1000;        //商品重量
                    $data['images'] = $data['images'];                     //商品图片
                    $data['categoryId'] = $cat_id;              //商品归类
                    $data['shopCategories'] = $sto_cate_id;     //商品店内归类
                    $data['brandId'] = $sbrand;                 //商品导入的品牌ID
                    $data['isSale'] = true;                     //商品是否可销售
                    $data['productDesc'] = $v['goods_content']; //商品描述

                    //$jj=json_encode($data);
                    $rs = jd_api('/pms/sku/addSku', $data, $stoid);
                    mlog($rs."--".json_encode($data),"jddj_insert_goods/".$stoid);

                    $rs_a=json_decode($rs,true)['data'];
                    $rs_a=json_decode($rs_a,true);
                    if($rs_a['code']!=0){
                        return json(['code'=>-1,"msg"=>$v['goods_name'].$rs_a['msg']]);
                    }

                    mlog("图片--".$data['images'],"jddj_insert_goods/".$stoid);


                    $da['outsku']= $data['outSkuId'];
                    $da['images']= $data['images'];
                    $da['firid']= $fir_id;
                    $da['secid']= $sec_id;
                    $da['store_id']= $stoid;
                    M("jd_sku")->save($da);
                    M("goods")->where('goods_id',$v['goods_id'])
                             ->where("store_id",$stoid)->save(['is_jd'=>1]);
                }
            }
            return json(['code'=>0,"msg"=>"插入成功"]);
        }
        catch (\Exception $e){
            return json(['code'=>-1,"msg"=>$e->getMessage()]);
        }
    }
    //---搜索分类----
    public function search_cate(){
      $gcate=M("goods_category")->where('level',1)
          ->where('store_id',getAdmStoId())->select();
      $fir_id=I("fir_id");
      $key=I("keywords");

      $list=null;
      $where="1=1";
      if($fir_id){
          $where.=" and parent_id=".$fir_id;
      }
      if($key){$where.=" and name like '%".$key."%'";}

      if($where!="1=1"){
          $gcate2=M("goods_category")->where($where)->where('store_id',getAdmStoId())
                 ->where('is_jd',0)
                 ->select();
          $list=$gcate2;
      }else{
          foreach ($gcate as $k=>$v){
             if($v['is_jd']==0)  $list[]=$v;
          }
      }
      $this->assign("cateList",$gcate);
      $this->assign("clist",$list);

      return $this->fetch('',getAdmStoId());
    }
    //--------插入品类-----------
    public function insert_cate(){
        try {
            $stoid = getAdmStoId();
            $cat_id=I("cid");
            $glist = M("goods_category")->where("id in(" . $cat_id . ")")
                   ->where('is_jd',0)
                   ->where('store_id', getAdmStoId())->select();

            if ($glist) {
                foreach ($glist as $k => $v) {
                    $data=null;
                    if($v['parent_id']) {
                        $fc = M("goods_category")->where("id", $v['parent_id'])
                            ->where('is_jd', 1)
                            ->field('jd_id')->find();
                        if ($fc && $fc['jd_id']) {
                            $data['pid'] = $fc['jd_id'];       //京东的父层id
                        } else {
                            return json(['code' => -1, "msg" => $v['name'] . "的父层分类还没导入"]);
                        }
                    }
                    else {
                        $data['pid'] = 0;
                    }
                    $data['shopCategoryName'] = $v['name'];   //名称
                    //$jj=json_encode($data);
                    $rs = jd_api('/pms/addShopCategory', $data, $stoid);

                    $rs_a=json_decode($rs,true)['data'];
                    $rs_a=json_decode($rs_a,true);
                    if($rs_a['code']!=0){
                        return json(['code'=>-1,"msg"=>$v['goods_name'].$rs_a['msg']]);
                    }

                    $jd_id=$rs_a['result']['id'];
                    M("goods_category")->where('id',$v['id'])
                        ->where("store_id",$stoid)->save(['is_jd'=>1,'jd_id'=>$jd_id]);
                    mlog($rs, "addShopCategory/" . $stoid);
                }
            }
            return json(['code'=>0,"msg"=>"插入成功"]);
        }
        catch (\Exception $e){
            return json(['code'=>-1,"msg"=>$e->getMessage()]);
        }
    }
    //--------搜索门店-------
    public function search_mendian(){

        $type = I('type', '');
        $isall = I('isall/d', 0);//是否显示全部

        $where="";
        $where = "is_jd=0 and store_id=" . getAdmStoId() ;//搜索条件

        $kword = urldecode(urldecode(I('keywords/s')));
        if (!empty($kword)) {
            $this->assign('keywords', $kword);
            $where = "$where and pickup_name like '%" . $kword . "%'";
        }

        $prov_id=I("prov_id");
        if($prov_id)  $where.=" and province_id=".$prov_id;
        $city_id=I("city_id");
        if($city_id)  $where.=" and city_id=".$city_id;
        $dis_id=I("dis_id");
        if($dis_id)  $where.=" and district_id=".$dis_id;
        $category_id=I("category_id");
        if($category_id)  $where.=" and category_id=".$category_id;


        $count = M('pick_up')->where($where)->count();
        $Page = new Page($count, 8);
        $goodsList = M('pick_up')->where($where)->order('pickup_id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $show = $Page->show();//分页显示输出
        $this->assign('page', $show);//赋值分页输出
        $this->assign('goodsList', $goodsList);
        $this->assign('pager', $Page);//赋值分页输出

        $this->assign('prov_id', $prov_id);//省
        $this->assign('city_id', $city_id);//市
        $this->assign('dis_id', $dis_id);  //区
        $this->assign('category_id', $category_id);  //门店分类


        $rg=M("region")->where('parent_id',0)->select();
        $this->assign('rg', $rg);//赋值分页输出

        if($city_id){
            $rg=M("region")->where('parent_id',$prov_id)->select();
            $this->assign('rg1', $rg);//赋值分页输出
        }
        if($dis_id){
            $rg=M("region")->where('parent_id',$city_id)->select();
            $this->assign('rg2', $rg);//赋值分页输出
        }

      $sto_c=M("storage_category")->where('store_id',getAdmStoId())->select();
      $this->assign('sto_c', $sto_c);//赋值分页输出

        return $this->fetch("", getAdmStoId());
    }
    //----------------插入门店------------------
    public function insert_mendian(){
        $stoid=getAdmStoId();
        $mid=I("mid");
        $radius=I("radius");

        $t_s=I('time_start');
        $t_e=I('time_end');

        //先缓存京东的城市,如果京东的城市缓存已经过期
        $city=F('jd_city');
        if(empty($city)){
            $city=$this->get_jd_city();
            Cache::set("jd_city",$city,3600*4);
        }

        $plist = M("pick_up")->where("pickup_id in(" . $mid . ")")
            ->where('is_jd',0)
            ->where('store_id',$stoid)->select();

        if ($plist) {
            foreach ($plist as $k => $v) {
                if(empty($v['pickup_phone'])) {
                    return json(['code' => -1, "msg" => '联系电话不能为空']);
                }
                if(empty($v['pickup_contact'])) {
                    return json(['code' => -1, "msg" => '门店管理员不能为空']);
                }
                if(empty($v['province_id']) || empty($v['city_id'])  || empty($v['district_id']) ) {
                    return json(['code' => -1, "msg" => '门店地区不能为空']);
                }

                $data['stationName'] = $v['pickup_name'];           //门店名称
                $data['outSystemId'] = $v['pickup_no'];             //门店编号
                $data['phone'] = $v['pickup_phone'];                //门店电话
                $data['stationName'] = $v['pickup_name'];           //门店名称
                $data['stationAddress'] = $v['pickup_address'];     //门店地址
                $data['operator'] = $v['pickup_contact'];           //管理员

                //-------计算时间--------
                /*----
                if($t_s=="23:59") $t_s=48;
                else{
                    $arr0=explode(":",$t_s);
                    $num0=$arr0[0]*2+($arr0[0]>30?1:0);
                    $t_s=$num0;
                }
                if($t_e=="23:59") $t_e=48;
                else{
                    $arr=explode(":",$t_e);
                    $num=$arr[0]*2+($arr[0]>30?1:0);
                    $t_e=$num;
                }---*/

                $data['serviceTimeStart1'] = $t_s;  //营业开始时间
                $data['serviceTimeEnd1'] = $t_e;    //营业结束时间
                $data['lat'] = $v['lat'];          //纬度
                $data['lng'] = $v['lon'];          //经度
                $data['deliveryRangeType'] = 3;    //范围类型
                $data['coordinateType'] = 4;       //腾讯地图
                $data['deliveryRangeRadius'] = $radius;    //服务半径
                $data['standByPhone'] = $v['pickup_phone'];//备联电话

                //-----------选找城市------------
                $pn=getregion($v['province_id']);
                $pc=getregion($v['city_id']);
                $city_no=0;
                foreach ($city as $kk=>$vv){
                    if($vv['areaName']==$pn || $vv['areaName']==$pc){
                        $city_no=$vv['areaCode']; break;
                    }
                }
                if($city_no==0) {
                    return json(['code' => -1, "msg" => '未找到京东在' . $pc . '地区的业务城市']);
                }
                //------------寻找地区------------
                $qname=getregion($v['district_id']);
                $qu_no=0;
                $qu_list=$this->get_js_addrnext($city_no);
                if($qu_list){
                    foreach ($qu_list as $kt=>$vt){
                        if($vt['areaName']==$qname){
                            $qu_no=$vt['areaCode']; break;
                        }
                    }
                    if($qu_no==0) {
                        return json(['code' => -1, "msg" => '未找到京东在' . $qname . '地区的业务城市']);
                    }
                }else{
                    return json(['code' => -1, "msg" => '未找到京东在' . $pc . '地区的业务城市']);
                }
                $data['city'] = $city_no;//城市
                $data['county'] =$qu_no; //区
                $jj=json_encode($data);

                $rs = jd_api('/store/createStore', $data, $stoid);
                $rs_a=json_decode($rs,true);
                if($rs_a['code']!=0){
                    mlog($rs_a['msg'], "createStore /" . $stoid);
                    return json(['code'=>-1,"msg"=>"插入失败"]);
                }

                $rs_a=$rs_a['data'];
                $rs_a=json_decode($rs_a,true);
                if($rs_a['code']!=0){
                    return json(['code'=>-1,"msg"=>$v['pickup_name'].$rs_a['msg']]);
                }

                //---保存门店----
                $da['stationNo']=$rs_a['result'];
                $da['radius']=$radius;
                $da['store_id']=$stoid;
                M("jd_sto")->save($da);

                M("pick_up")->where('pickup_id',$v['pickup_id'])
                    ->where("store_id",$stoid)->save(['is_jd'=>1]);
                mlog($rs, "createStore/" . $stoid);
            }

            return json(['code'=>0,"msg"=>"插入成功"]);
        }
    }
    //获取京东的业务城市
    function get_jd_city(){
        $rs = jd_api('/address/allcities', null, getAdmStoId());
        $rs_a=json_decode($rs,true)['data'];
        $rs_a=json_decode($rs_a,true);
        if($rs_a['code']==0){
            return $rs_a['result'];
        }
        return null;
    }
    //获取京东的业务城市
    function get_js_addrnext($code){
        $data['areaCode']=$code;
        $data['pin']='test';
        $rs = jd_api('/address/getNextLevelByType ', $data, getAdmStoId());
        $rs_a=json_decode($rs,true)['data'];
        $rs_a=json_decode($rs_a,true);
        if($rs_a['code']==0){
            return $rs_a['result'];
        }
        return null;
    }
    /*------------批量上架下架------------*/
    function up_down(){
        $osku=I("oskulist");
        $ind=I("ind");
        $arr=explode(",",$osku);
        foreach ($arr as $k=>$v){
            $data["outSkuId"]=$v;
            $data["fixedStatus"]=$ind;
            $rs = jd_api('/pms/sku/updateSku', $data, getAdmStoId());
        }
        return json(["code"=>0,"msg"=>"操作成功"]);
    }
    //----------设置前缀和广告---------
    function gd_set(){
        $type=I("type");
        $this->assign('type', $type);

        $info['start_time'] = date('Y-m-d H:i:s');
        $info['end_time'] = date('Y-m-d 23:59:59', time() + 3600 * 24 * 60);
        $this->assign('info', $info);

        return $this->fetch("",getAdmStoId());
    }
    /*------------批量商品设置------------*/
    function goods_set(){
        $osku=I("oskulist");
        $type=I("type");
        $val=I("val");
        $val2=I("val2");
        $start=I("start_time");
        $end=I("end_time");

        $arr=explode(",",$osku);
        foreach ($arr as $k=>$v){
            $data["outSkuId"]=$v;
            switch ($type){
                case "1"://设置前缀
                    $data["prefixKeyId"]=$val2;
                    $data["prefixKey"]=$val;
                    $data["preKeyStartTime"]=$start;
                    $data["preKeyEndTime"]=$end;
                    break;
                case "2"://设置广告词
                    $data["slogan"]=$val;
                    $data["sloganStartTime"]=$start;
                    $data["sloganEndTime"]=$end;
                    break;
                case "3"://设置店内分类
                    $data["shopCategories"]=$val;
                    break;
                case "4"://批量删除
                    $data["fixedStatus"]=4;
                    break;
            }
            $rs = jd_api('/pms/sku/updateSku', $data, getAdmStoId());
            mlog($rs, "updateSku/".getAdmStoId());
        }
        return json(["code"=>0,"msg"=>"操作成功"]);
    }
    /*------------获取前缀--------------*/
    function qz_set(){
        $p=I('p',1);
        $pz=36;
        $data=['pageNo'=>$p,'pageSize'=>$pz,'fields'=>["ID","KEYVALUE"]];

        $keywords=I("keywords");
        if($keywords) $data['keyValue']=$keywords;


        $rs = jd_api('/pms/queryKeyWordDicInfo', $data, getAdmStoId());
        $rs=json_decode($rs,true);
        $rsa=json_decode($rs['data'],true)['result'];

        $Page = new Page($rsa['count'], $pz);
        $this->assign('pager',$Page);
        $show = $Page->show();//分页显示输出
        $this->assign('page', $show);//赋值分页输出
        $qzList=$rsa['result'];
        $this->assign('qzList',$qzList);

        return $this->fetch("",getAdmStoId());
    }
    /*-----批量门店休息中,营业中-----*/
    public  function close_status(){
        $stoid=getAdmStoId();
        $stolist=I("stolist");
        $status=I("status");  //1营业  2休息
        $arr=explode(",",$stolist);
        foreach ($arr as $k=>$v){
            $data["stationNo"]=$v;
            $data["operator"]= Cookie::get("newshop_admin_erpuser");
            $data["closeStatus"]=$status==1?0:1;
            $rs = jd_api('/store/updateStoreInfo4Open', $data, getAdmStoId());
            mlog($rs, "updateSku/".getAdmStoId());

            $rs=json_decode($rs,true);
            if($rs['code']!=0){
                return json(["code"=>-1,"msg"=>"操作失败:".$rs['msg']]);
            }
            $rs=json_decode($rs['data'],true);
            if($rs['success']==false){
                return json(["code"=>-1,"msg"=>"门店:".$v.":".$rs['msg']]);
            }

        }
        return json(["code"=>0,"msg"=>"操作成功"]);

    }
    //------------编辑商品-------------
    function editgoods(){
        $this->initEditor();
        $stoid=getAdmStoId();

        $erpid=tpCache("shop_info.ERPId",$stoid);
        $this->assign('erpid',$erpid);
        $this->assign('qurl',QCLOUD_IMGURL);

        $oskiid=I('skuId');
        $data['skuId']=$oskiid;
        $rs = jd_api('/pms/querySkuInfos', $data, getAdmStoId());
        $rs=json_decode($rs,true);

        if($rs['code']==0){
            $rs= json_decode($rs['data'],true);
            if($rs['code']==0){
                 $res=json_decode($rs['result']['result'],true)[0];
                 //获取城市
                 $city=F('jd_city');
                 if(empty($city)){
                    $city=$this->get_jd_city();
                    Cache::set("jd_city",$city,3600*4);
                 }
                 $this->assign('city',$city);
				 $cell_city=$res['sellCities'];
				 $str="";
				 $cidlist="";

				 if($res['productDescHtml']) {
                     $html = file_get_contents($res['productDescHtml']);
                     $css_zheng_ze = "/<body>([\s\S]*)<\/body>/Ui";
                     $arr = array();
                     preg_match_all($css_zheng_ze, $html, $arr);

                     $ht = $arr[0][0];
                     $ht = str_replace("<body>", "", $ht);
                     $ht = str_replace("</body>", "", $ht);
                     $res['productDescHtml'] = $ht;
                 }
				 
				 foreach($cell_city as $kk=>$vv){
					   if($vv==0) {
						   $str = "全国"; $cidlist=0;break;
					   }
					   else{
						   $cidlist.=$vv.",";
						   foreach ($city as $kc=>$vc){
								if($vc['areaCode']==$vv){ 
								    $str.=$vc['areaName']." ";
								}
						   }
					   }
				 }

                 $cidlist = substr($cidlist,0,strlen($cidlist)-1);
                 $res['scity']=$str;
                 $res['cidlist']=$cidlist;

                 if($res['shopCategories']){
                     $sto_cat_list="";
                     foreach ($res['shopCategories'] as $kl=>$vl){
                         $sto_cat_list.=$vl.",";
                     }
                     $sto_cat_list = substr($sto_cat_list,0,strlen($sto_cat_list)-1);
                     $res['sto_cat_list']=$sto_cat_list;
                 }

                 $gdetail=M("jd_sku")->where('store_id',$stoid)
                          ->where('outsku',$res['outSkuId'])->find();
                 if($gdetail) {
                     //$res['images'] = explode(',',$gdetail['images']);
                     $res['firid'] = $gdetail['firid'];
                     $res['secid'] = $gdetail['secid'];
                     $res['ifViewDesc'] = $gdetail['ifViewDesc'];
                     $res['productDesc'] = $gdetail['productDesc'];

                     $da['fields']=["ID","CATEGORY_NAME","CATEGORY_LEVEL","CATEGORY_STATUS"];
                     $da['id']=$res['firid'];
                     $rs=jd_api('/api/queryChildCategoriesForOP',$da,$stoid);
                     $rs=json_decode($rs,true);
                     if($rs['code']==0) {
                         $data = json_decode($rs['data'], true);
                         $this->assign('sec_list',$data['result']);
                     }


                     $da['fields']=["ID","CATEGORY_NAME","CATEGORY_LEVEL","CATEGORY_STATUS"];
                     $da['id']=$res['secid'];
                     $rs=jd_api('/api/queryChildCategoriesForOP',$da,$stoid);
                     $rs=json_decode($rs,true);
                     if($rs['code']==0) {
                         $data = json_decode($rs['data'], true);
                         $this->assign('thi_list',$data['result']);
                     }
                 }

                 $gd=M('goods')->where('sku',$res['upcCode'])
                     ->where('store_id',$stoid)->find();

                 $images=M("goods_images")->where('goods_id',$gd['goods_id'])->where('store_id',$stoid)->select();
                 $res['images']=$images;

				 $this->assign('info',$res);		
            }
        }
        return $this->fetch("",getAdmStoId());
    }
    //------------编辑门店-------------
    function editsto(){
        $stoid=getAdmStoId();

        $oskiid=I('StoreNo');
        $data['StoreNo']=$oskiid;
        $rs = jd_api('/storeapi/getStoreInfoByStationNo', $data, getAdmStoId());
        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $rs=json_decode($rs['data'],true);
            $rs=$rs['result'];
            $quyu=$this->get_js_addrnext($rs['city']);
            $this->assign('quyu',$quyu);

            foreach ($quyu as $kl=>$vl){
               if($vl['areaCode']==$rs['county']){
                   $rs['townname']=$vl['areaName']; break;
               }
            }

            if(empty($rs['operator']))
                $rs['operator']=$rs['createPin'];

            $gdetail=M("jd_sto")->where('store_id',$stoid)
                ->where('stationNo',$oskiid)->find();
            if($gdetail) {
                $rs['gonggao'] = $gdetail['gonggao'];
                $rs['radius'] = $gdetail['radius'];
                if(empty($rs['cityName']))
                    $rs['cityName']=$gdetail['cityname'];

            }
            $this->assign('info',$rs);
        }

        return $this->fetch("",getAdmStoId());
		
    }
    //------------商品资料修改保存-------------
    function goods_handle(){
        $stoid=getAdmStoId();

        $fir="http://mshopimg.yolipai.net";
        $Goods = I('post.');

        //商品保存
        $res['firid'] = $Goods['jd_cat_id'];
        $res['secid'] = $Goods['jd_cat_id_2'];
        //$js=json_encode($Goods);
        unset($Goods['jd_cat_id']);
        unset($Goods['jd_cat_id_2']);
        unset($Goods['iseditimg']);
        if($Goods['jd_cat_id_3']) $Goods['categoryId']=(int)$Goods['jd_cat_id_3'];
        unset($Goods['jd_cat_id_3']);

        unset($Goods['images']);
        /*----
        if($Goods['images']==[""]) unset($Goods['images']);
        else{
            $imglist="";
            foreach ($Goods['images'] as $ky=>$vy){
                if(trim($vy)!=""){
                    if(strpos($vy,'http')!==false){
                        $imglist.=$vy.",";
                    }else{
                        $imglist.=$fir.$vy.",";
                    }
                }
            }
            $imglist = substr($imglist,0,strlen($imglist)-1);
            $Goods['images']=$imglist;
            $res['images'] = $imglist;
        }----*/

        if(empty($Goods['slogan'])) {
            unset($Goods['slogan']);
            unset($Goods['sloganEndTime']);
            unset($Goods['sloganStartTime']);
        }

        //------商品描述------
        $Goods['ifViewDesc']=$Goods['ifViewDesc']-1;
        $res['ifViewDesc'] = $Goods['ifViewDesc'];
        $prodesc=trim($Goods['productDesc']);
        if(empty($prodesc)) {
            unset($Goods['productDesc']);
        }else{
            $res['productDesc'] = $Goods['productDesc'];
        }

        if($Goods['upcCode']) {
            $Goods['upc'] = $Goods['upcCode'];
            unset($Goods['upcCode']);
        }


        $Goods['transportAttribute']=($Goods['transportAttribute']-1).'';
        $Goods['liquidStatue']=$Goods['liquidStatue'].'';
        $Goods['prescripition']=$Goods['prescripition'].'';

        $Goods['traceId']=uuid();

        //$rs = jd_api('/pms/sku/updateSku', $Goods, getAdmStoId());
        $rs = jd_api('/pms/updateSku', $Goods, getAdmStoId());
        $rs=json_decode($rs,true);
        if($rs['code']==0){
            //------存入本地-------
            $sku=M("jd_sku")->where('outsku',$Goods['outSkuId'])
                ->where('store_id',$stoid)->find();
            if($sku){
                M("jd_sku")->where('outsku',$Goods['outSkuId'])
                    ->where('store_id',$stoid)->save($res);
            }else{
                $res['store_id'] = $stoid;
                $res['outsku'] = $Goods['outSkuId'];
                M("jd_sku")->save($res);
            }
            return json(['code'=>0,'msg'=>"修改成功"]);
        }else{
            return json(['code'=>-1,'msg'=>$rs['msg']]);
        }
    }
    //----------门店资料修改保存-----------
    function sto_handle(){
        $stoid=getAdmStoId();

        $Goods = I('post.');
        $res=null;

        $res['gonggao']=$Goods['storeNotice'];
        $res['cityname']=trim($Goods['cityName']);
        $res['townname']=trim($Goods['townname']);

        if(empty($Goods['storeNotice'])) {
            unset($Goods['storeNotice']);
        }else{
            $res['gonggao']=$Goods['storeNotice'];
        }
        if(empty($Goods['deliveryRangeRadius'])){
            unset($Goods['deliveryRangeRadius']);
        }else{
            $res['radius']=$Goods['deliveryRangeRadius'];
        }

        if(empty($Goods['mobile'])) unset($Goods['mobile']);
        if(empty($Goods['mobile'])) unset($Goods['mobile']);
        $rs = jd_api('/store/updateStoreInfo4Open', $Goods, getAdmStoId());
        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $rs=json_decode($rs['data'],true);
            if($rs['success']==false){
                return json(['code'=>-1,'msg'=>$rs['msg']]);
            }
            //------存入本地-------
            if($res){
                $sku=M("jd_sto")->where('stationNo',$Goods['stationNo'])
                    ->where('store_id',$stoid)->find();
                if($sku){
                    M("jd_sto")->where('stationNo',$Goods['stationNo'])
                        ->where('store_id',$stoid)->save($res);
                }else{
                    $res['store_id'] = $stoid;
                    $res['stationNo'] = $Goods['stationNo'];
                    M("jd_sto")->save($res);
                }
            }

            return json(['code'=>0,'msg'=>"修改成功"]);
        }else{
            return json(['code'=>-1,'msg'=>$rs['msg']]);
        }
    }
    //------------导出------------
    function good_export(){
        $id = getAdmStoId();
        $p=I("p");
        $pagesize=20;
        $data=["pageSize"=>$pagesize,'pageNo'=>$p,'isFilterDel'=>"0"];
        $gname=I("goods_name");
        $gsn=I("goods_sn");
        $jsku=I("dd_sku");

        if($gname) $data['skuName']=$gname;
        if($gsn) $data['skuId']=$gsn;
        if($jsku) $data['upcCode']=$jsku;

        $oldurl = U('Admin/jddj/goods_up', array(
            "goods_name" => $gname,
            "goods_sn" => $gsn,
            "dd_sku" => $jsku,
            "p" => $p,
        ));
        $this->assign('oldurl', urlencode($oldurl));

        $rs=jd_api('/pms/querySkuInfos',$data,$id);

        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $list=  json_decode($rs['data'],true);
            if($list['result']['count']>0){
                $city=F('jd_city');
                if(empty($city)){
                    $city=$this->get_jd_city();
                    Cache::set("jd_city",$city,3600*4);
                }
                if($list['result']['result']!=null) {
                    $glist=json_decode($list['result']['result'],true);
                    foreach ($glist as $kl=>$vl){
                        $str="";
                        $cell_city=$vl['sellCities'];
                        foreach($cell_city as $kk=>$vv){
                            if($vv==0) {
                                $str = "全国";break;
                            }
                            else{
                                foreach ($city as $kc=>$vc){
                                    if($vc['areaCode']==$vv){ $str.=$vc['areaName']." "; }
                                }
                            }
                        }
                        $glist[$kl]['scity']=$str;
                    }


                    $this->assign("goodsList",$glist);
                }
                $Page  = new AjaxPage($list['result']['count'],$pagesize);
                $show=$Page->show();
                $this->assign('page',$show);// 赋值分页输出
                $this->assign('pager',$Page);
            }
        }
    }
    //---------店内分类列表---------
    public function category_list(){
        $stoid = getAdmStoId();
        $data['fields']=["ID","PID","SHOP_CATEGORY_NAME","SORT",];
        $rs=jd_api('/pms/queryCategoriesByOrgCode',$data,$stoid);
        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $data=json_decode($rs['data'],true);
            $catelist=$data['result'];
            $rslist=[];

            if($catelist) {
                foreach ($catelist as $k => $v) {
                    if ($v['pid'] == 0) {
                        $rslist[] = ["id" => $v['id'], "shopCategoryName" => $v["shopCategoryName"], "ary" => null];
                    } else {
                        foreach ($rslist as $kv => $vv) {
                            if ($vv['id'] == $v['pid']) {
                                $rslist[$kv]['ary'][] = $v;
                            }
                        }
                    }
                }
                $this->assign('s_catelist', $rslist);
            }
        }

        return $this->fetch("",getAdmStoId());
    }
    //----------编辑店内分类-----------
    public function addEditCategory(){
        $stoid = getAdmStoId();
        $data['fields']=["ID","PID","SHOP_CATEGORY_NAME","SORT",];
        $rs=jd_api('/pms/queryCategoriesByOrgCode',$data,$stoid);
        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $data=json_decode($rs['data'],true);
            $catelist=$data['result'];
            $rslist=[];
            if($catelist) {
                foreach ($catelist as $k => $v) {
                    if ($v['pid'] == 0) {
                        $rslist[] = ["id" => $v['id'], "shopCategoryName" => $v["shopCategoryName"]];
                    }
                }
                $this->assign('s_catelist', $rslist);
            }
        }
        return $this->fetch("_category",getAdmStoId());
    }
    //-------分类保存----------
    public function category_handle(){
        $stoid = getAdmStoId();
        $id=I("id");
        $pid=I("pid");
        $shopCategoryName=I("shopCategoryName");
        mlog("1","category_handle/".$stoid);

        if($id) {
            mlog("2","category_handle/".$stoid);
            mlog("2".$id,"category_handle/".$stoid);
            $data['id'] = $id;
            $data['shopCategoryName'] = $shopCategoryName;
            $rs = jd_api('/pms/updateShopCategory', $data, $stoid);
            $rs = json_decode($rs, true);
            if ($rs['code'] == 0) {
                $rs = json_decode($rs['data'], true);
                if($rs['success']){
                    return json(['code' => 0, 'msg' => "保存成功"]);
                }
                return json(['code' => -1, 'msg' => $rs['msg']]);
            }else{
                return json(['code' => -1, 'msg' => $rs['msg']]);
            }
        }else{

            mlog("3","category_handle/".$stoid);
            mlog("3".$pid,"category_handle/".$stoid);

            $data['pid'] = $pid;
            $data['shopCategoryName'] = $shopCategoryName;
            $rs = jd_api('/pms/addShopCategory', $data, $stoid);
            $rs = json_decode($rs, true);
            if ($rs['code'] == 0) {
                $rs = json_decode($rs['data'], true);
                if($rs['success']){
                    return json(['code' => 0, 'msg' => "保存成功"]);
                }
                return json(['code' => -1, 'msg' => $rs['msg']]);
            }else{
                return json(['code' => -1, 'msg' => '操作失败']);
            }
        }
    }
    //----------删除分类----------
    public function category_del(){
        $stoid = getAdmStoId();
        $id=I("id");
        $data['id'] = $id;
        $rs = jd_api('/pms/delShopCategory ', $data, $stoid);
        $rs = json_decode($rs, true);
        if ($rs['code'] == 0) {
            $rs = json_decode($rs['data'], true);
            if($rs['success']){
                return json(['code' => 0, 'msg' => "保存成功"]);
            }
            return json(['code' => -1, 'msg' => $rs['msg']]);
        }else{
            return json(['code' => -1, 'msg' => '操作失败']);
        }
    }
    //---------门店商品管理----------
    function sto_gd_up(){
        $stoid=getAdmStoId();
        $rs=jd_api('/store/getStationsByVenderId ',null,$stoid);
        $rs=json_decode($rs,true);
        $glist=null;
        if($rs['code']==0){
            $list=json_decode($rs['data'],true);
            $arr=$list['result'];
            $count=count($arr);
            for($i=0;$i<1;$i++){
                $data1['StoreNo']=$arr[$i];
                $rss=jd_api('/storeapi/getStoreInfoByStationNo',$data1,$stoid);
                $rss=json_decode($rss,true);
                $md=json_decode($rss['data'],true)['result'];
                $md['updateTime']=date('Y-m-d H:i:s',$md['updateTime']['time']/1000);
                $md['createTime']=date('Y-m-d H:i:s',$md['createTime']['time']/1000);
                $md['serviceTimeStart1']=$this->format_time($md['serviceTimeStart1']);
                $md['serviceTimeEnd1']=$this->format_time($md['serviceTimeEnd1']);
                $glist[]=$md;
            }
            //$jj=json_encode($glist);
            $this->assign("stoList",$glist);
        }
        return $this->fetch("",getAdmStoId());
    }
    public function ajax_sto_gd_up()
    {
        $id = getAdmStoId();
        $stationName=I("stationName");
        $outStationNo=I("outStationNo");
        $stationNo=I("stationNo");

        $p=I("p");
        $pagesize=20;
        $data=["pageSize"=>$pagesize,'pageNo'=>$p,'isFilterDel'=>"0"];
        $gname=I("goods_name");
        $gsn=I("goods_sn");
        $jsku=I("dd_sku");

        if(trim($gname)) $data['skuName']=trim($gname);
        if(trim($gsn)) $data['skuId']=trim($gsn);
        if(trim($jsku)) $data['upcCode']=trim($jsku);

        $oldurl = U('Admin/jddj/goods_up', array(
            "goods_name" => $gname,
            "goods_sn" => $gsn,
            "dd_sku" => $jsku,
            "p" => $p,
        ));
        $this->assign('oldurl', urlencode($oldurl));
        $rs=jd_api('/pms/querySkuInfos',$data,$id);

        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $list=  json_decode($rs['data'],true);
            if($list['result']['count']>0){
                $city=F('jd_city');
                if(empty($city)){
                    $city=$this->get_jd_city();
                    Cache::set("jd_city",$city,3600*4);
                }
                if($list['result']['result']!=null) {
                    $glist=json_decode($list['result']['result'],true);
                    $outskulist=null;

                    foreach ($glist as $kl=>$vl){
                        $str="";
                        $cell_city=$vl['sellCities'];
                        foreach($cell_city as $kk=>$vv){
                            if($vv==0) {
                                $str = "全国";break;
                            }
                            else{
                                foreach ($city as $kc=>$vc){
                                    if($vc['areaCode']==$vv){ $str.=$vc['areaName']." "; }
                                }
                            }
                        }
                        $glist[$kl]['scity']=$str;
                        $glist[$kl]['outStationNo']=$outStationNo;
                        $glist[$kl]['stationNo']=$stationNo;
                        $glist[$kl]['stationName']=$stationName;

                        $outskulist[]=['outSkuId'=>$vl['outSkuId']];
                    }

                    $kdata['outStationNo']=$outStationNo;
                    $kdata['skuIds']=$outskulist;
                    $kdata["userPin"]= Cookie::get("newshop_admin_erpuser");
                    $rss=jd_api('/stock/queryStockCenter',$kdata,$id);
                    $rss=json_decode($rss,true);
                    if($rss['code']==0){
                        $rss=json_decode($rss['data'],true);
                        if($rss['code']==0){
                             foreach ($glist as $ky=>$vy){
                                 if($rss['data']) {
                                     foreach ($rss['data'] as $kt => $vt) {
                                         if ($vy['outSkuId'] == $vt['outSkuId']) {
                                             $glist[$ky]['kcun'] = $vt;
                                         }
                                     }
                                 }
                             }
                        }
                    }
                    $this->assign("goodsList",$glist);
                }
                $Page  = new AjaxPage($list['result']['count'],$pagesize);
                $show=$Page->show();
                $this->assign('page',$show);// 赋值分页输出
                $this->assign('pager',$Page);

            }
        }
        return $this->fetch('', getAdmStoId());
    }
    //-----------修改可售状态------------
    function UpdateVendibility(){
        $id=getAdmStoId();
        $stationNo=I("stationNo");
        $osku=I("oskulist");
        $doSale=I("doSale");//1可售  2不可售

        $kdata["userPin"]= Cookie::get("newshop_admin_erpuser");
        $kdata["outStationNo"]=$stationNo;

        $outSkuId_arr=explode(',',$osku);
        $stockVendibilityList=null;
        foreach ($outSkuId_arr as $k=>$v){
            $stockVendibilityList[]=["outSkuId"=>$v,"doSale"=>$doSale==1];
        }
        $kdata["stockVendibilityList"]=$stockVendibilityList;

        $rs=jd_api('/stock/batchUpdateVendibility ',$kdata,$id);
        $rs=json_decode($rs,true);

        if($rs['code']==0){
            $rs=json_decode($rs['data'],true);
            if($rs['code']==0){
                return json(['code'=>0,'msg'=>'修改成功']);
            }
        }else{
            return json(['code'=>-1,'msg'=>'修改失败']);
        }
    }
    //-----------修改置顶状态------------
    function Update_stick(){
        $up=I("up");  //1置顶   2取消置顶
        $stationNo=I("stationNo");
        $osku=I("oskulist");

        $rs=null;$stoid=getAdmStoId();
        if($up==1){
            $kdata["storeId"]=$stationNo;
            $kdata["skuIds"]=$osku;
            $rs=jd_api('/OrgSortService/addByStoreAndSkus',$kdata,$stoid);
        }else{
            $kdata["storeId"]=$stationNo;
            $kdata["skuIds"]=$osku;
            $rs=jd_api('/OrgSortService/deleteByIdsWithCheck ',$kdata,$stoid);

        }

        $rs=json_decode($rs,true);
        if($rs['code']==0){
            $rs=json_decode($rs['data'],true);
            if($rs['status']==200){
                return json(['code'=>0,'msg'=>'修改成功']);
            }
            return json(['code'=>-1,'msg'=>'修改失败']);
        }else{
            return json(['code'=>-1,'msg'=>'修改失败']);
        }
    }
    //-----------搜索门店------------
    function search_sto(){
        $id = getAdmStoId();
        $p=I("p",1);
        $data=null;
        $rs=jd_api('/store/getStationsByVenderId',$data,$id);
        $rs=json_decode($rs,true);
        $pz=15;
        $glist=null;
        if($rs['code']==0){
            $list=json_decode($rs['data'],true);
            $arr=$list['result'];
            $count=count($arr);
            if($count>0){
                $fir=($p-1)*$pz;
                $end=$p*$pz;
                if($fir<$count){
                    if($end>$count) $end=$count;
                    for($i=$fir;$i<$end;$i++){
                        $data1['StoreNo']=$arr[$i];
                        $rss=jd_api('/storeapi/getStoreInfoByStationNo',$data1,$id);
                        $rss=json_decode($rss,true);
                        $md=json_decode($rss['data'],true)['result'];
                        $md['updateTime']=date('Y-m-d H:i:s',$md['updateTime']['time']/1000);
                        $md['createTime']=date('Y-m-d H:i:s',$md['createTime']['time']/1000);
                        $md['serviceTimeStart1']=$this->format_time($md['serviceTimeStart1']);
                        $md['serviceTimeEnd1']=$this->format_time($md['serviceTimeEnd1']);
                        $glist[]=$md;
                    }
                    $this->assign('glist',$glist);

                    $Page = new Page(count($list['result']), $pz);
                    $this->assign('pager',$Page);
                    $show = $Page->show();//分页显示输出
                    $this->assign('page', $show);//赋值分页输出
                }
            }
        }
        return $this->fetch('', getAdmStoId());
    }
    //---------修改商品的现货库存,锁定库存---------
    function change_kucun(){
         $stoid=getAdmStoId();
         $type=I("type"); //1修改现货  2.修改锁定  3俩个都修改
         $outStationNo=I("outStationNo");
         $stationNo=I("stationNo");

         $outSkuId=I("outSkuId");
         $skuId=I("skuId");

         $outSkuId=explode(',',$outSkuId);
         $skuId=explode(',',$skuId);
         switch ($type){
             case "1":  //现货库存
                 $qty=I("qty");$lt=null;
                 $data["userPin"]= Cookie::get("newshop_admin_erpuser");
                 $data['outStationNo']=$outStationNo;
                 foreach ($outSkuId as $kh=>$vh){
                     $lt[]=['outSkuId'=>$vh,'stockQty'=>(int)$qty];
                 }
                 $data['skuStockList']=$lt;
                 $rs=jd_api('/stock/batchUpdateCurrentQtys',$data,$stoid);
                 $rs=json_decode($rs,true);
                 $rs=json_decode($rs['data'],true);
                 $rs=$rs['data'];
                 if($rs[0]['code']==0){
                     return json(['code'=>0,'msg'=>'修改成功']);
                 }
                 return json(['code'=>-1,'msg'=>'修改失败']);

                 break;
             case "2": //锁定库存
                 $qty=I("qty");$lt=null;
                 foreach ($skuId as $kh=>$vh){
                     $lt[]=['skuId'=>$vh,'stockQty'=>$qty,'stationNo'=>$stationNo];
                 }
                 $data['listBaseStockCenterRequest']=$lt;
                 $rs=jd_api('/stock/updateOpenLockQtys ',$data,$stoid);
                 $rs=json_decode($rs,true);
                 if($rs['code']=="0"){
                     return json(['code'=>0,'msg'=>'修改成功']);
                 }
                 return json(['code'=>-1,'msg'=>'修改失败']);

                 break;
             case "3":

                 $qty1=I("qty1");$lt=null;
                 $data["userPin"]= Cookie::get("newshop_admin_erpuser");
                 $data['stationNo']=$stationNo;
                 foreach ($outSkuId as $kh=>$vh){
                     $lt[]=['outSkuId'=>$vh,'stockQty'=>$qty1];
                 }
                 $data['skuStockList']=$lt;
                 $rs=jd_api('/stock/batchUpdateCurrentQtys',$data,$stoid);
                 $rs=json_decode($rs,true);
                 $rs=json_decode($rs['data'],true);
                 $rs=$rs['data'];
                 if($rs[0]['code']!=0){
                     return json(['code'=>-1,'msg'=>'修改现货库存失败']);
                 }


                 $qty2=I("qty2");$lt=null;
                 foreach ($skuId as $kh=>$vh){
                     $lt[]=['skuId'=>$vh,'stockQty'=>$qty2,'stationNo'=>$stationNo];
                 }
                 $data['listBaseStockCenterRequest']=$lt;
                 $rs=jd_api('/stock/updateOpenLockQtys ',$data,$stoid);
                 $rs=json_decode($rs,true);
                 if($rs['code']!="0"){
                     return json(['code'=>-1,'msg'=>'修改锁定失败']);
                 }

                 return json(['code'=>0,'msg'=>'修改成功']);
                 break;
         }
    }

    //-----导出商品-------
    function export_goods(){
        $glist=F("ajax_cgoodsList_".getAdmStoId());
        $strTable = '<table  border="1"><thead>';
        $strTable .= '<tr style="font-weight: bold;">';
        $strTable .= '<th style="text-align:center;width:150px;" >商品信息</th>';
        $strTable .= '<th style="text-align:center;" width="100" >sku编码</th>';
        $strTable .= '<th style="text-align:center;" width="100" >商品编码</th>';
        $strTable .= '<th style="text-align:center;" width="100" >商家商品编码/条码</th>';
        $strTable .= '<th style="text-align:center;" width="50" >销售城市</th>';
        $strTable .= '<th style="text-align:center;" width="50" >商家价格</th>';
        $strTable .= '<th style="text-align:center;" width="100" >商品状态</th>';
        $strTable .= '</tr></thead><tbody>';

        if ($glist) {
             foreach ($glist as $k=>$val) {
                 $upstr = "";
                 if ($val['fixedStatus'] == 1) $upstr = "上架";
                 if ($val['fixedStatus'] == 2) $upstr = "下架";
                 if ($val['fixedStatus'] == 4) $upstr = "删除";
                 $strTable .= '<tr>';
                 $strTable .= '<td style="text-align:left;" >&nbsp;' . $val['skuName'] . '</td>';
                 $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['skuId'] . ' </td>';
                 $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['skuId'] . '</td>';
                 $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['outSkuId'] . '<br>&nbsp;' . $val['upcCode'] . '</td>';
                 $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['scity'] . '</td>';
                 $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['skuPrice']/100 . '</td>';
                 $strTable .= '<td style="text-align:center;" >&nbsp;' . $upstr . '</td>';
                 $strTable .= "</tr>";
             }
        }

        $strTable .= '</tbody></table>';
        echo $strTable;
        unset($orderList);
        downloadExcel($strTable, 'goods');
        exit();
    }
    //-----导出商品-------
    function export_sto(){
        $id=getAdmStoId();
        $data=null;
        $rs=jd_api('/store/getStationsByVenderId ',$data,$id);
        $rs=json_decode($rs,true);
        $glist=null;

        if($rs['code']==0){
            $list=json_decode($rs['data'],true);
            $arr=$list['result'];
            $count=count($arr);
            if($count>0){
                    for($i=0;$i<$count;$i++){
                        $data1['StoreNo']=$arr[$i];
                        $rss=jd_api('/storeapi/getStoreInfoByStationNo',$data1,$id);
                        $rss=json_decode($rss,true);
                        $md=json_decode($rss['data'],true)['result'];
                        $md['updateTime']=date('Y-m-d H:i:s',$md['updateTime']['time']/1000);
                        $md['createTime']=date('Y-m-d H:i:s',$md['createTime']['time']/1000);
                        $md['serviceTimeStart1']=$this->format_time($md['serviceTimeStart1']);
                        $md['serviceTimeEnd1']=$this->format_time($md['serviceTimeEnd1']);
                        $glist[]=$md;
                    }
            }
        }

        $strTable = '<table  border="1"><thead>';
        $strTable .= '<tr style="font-weight: bold;">';
        $strTable .= '<th style="text-align:center;width:150px;" >门店编号</th>';
        $strTable .= '<th style="text-align:center;" width="100" >门店名称</th>';
        $strTable .= '<th style="text-align:center;" width="100" >商家门店编号</th>';
        $strTable .= '<th style="text-align:center;" width="100" >所在城市</th>';
        $strTable .= '<th style="text-align:center;" width="100" >所在区县</th>';
        $strTable .= '<th style="text-align:center;" width="100" >营业时间</th>';
        $strTable .= '<th style="text-align:center;" width="100" >联系方式</th>';
        $strTable .= '<th style="text-align:center;" width="100" >备联电话</th>';
        $strTable .= '<th style="text-align:center;" width="100" >创建时间</th>';
        $strTable .= '<th style="text-align:center;" width="100" >更新时间</th>';
        $strTable .= '<th style="text-align:center;" width="100" >最后一次操作人</th>';
        $strTable .= '<th style="text-align:center;" width="100" >营业状态</th>';
        $strTable .= '<th style="text-align:center;" width="100" >启用状态</th>';

        $strTable .= '</tr></thead><tbody>';
        if ($glist) {
            foreach ($glist as $k=>$val) {
                $upstr = "";
                if ($val['closeStatus'] == 0) $upstr = "正常营业";
                if ($val['closeStatus'] == 1) $upstr = "休息中";

                $yn="";
                if ($val['yn'] == 0) $yn = "启用";
                if ($val['yn'] == 1) $yn = "禁用";

                $strTable .= '<tr>';
                $strTable .= '<td style="text-align:left;" >&nbsp;' . $val['stationNo'] . '</td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['stationName'] . ' </td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['outSystemId'] . '</td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['cityName'] . '</td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['countyName'] . '</td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['serviceTimeStart1'] . '-'.$val['serviceTimeEnd1'].'</td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['phone'] . '/'.$val['mobile'].'</td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['standByPhone'] . ' </td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['createTime'] . ' </td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['updateTime'] . ' </td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $val['updatePin'] . ' </td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' . $upstr . ' </td>';
                $strTable .= '<td style="text-align:center;" >&nbsp;' .  $yn . ' </td>';
                $strTable .= "</tr>";
            }
        }
        $strTable .= '</tbody></table>';
        echo $strTable;
        unset($orderList);
        downloadExcel($strTable, 'storage');
        exit();
    }
    function getregion(){
       $id=I("id");
       $rg=M("region")->where("parent_id",$id)->select();
       return  json(['code'=>"0",'data'=>$rg]);
    }

    //-----获取到缴费界面-----
    public function  not_jd(){
        //先判断缴费记录是否有该商家的记录
        $rss=M('store_module_endtime')->where('store_id='.getAdmStoId())->where('is_sy',0)
            ->where('type',4)->find();
        if($rss){
            $this->assign('is_jd_open', 1);
            $end_time=strtotime('+1 year',$rss['end_time']);
            $end_time=date("Y-m-d H:i:s",$end_time);
            $this->assign('end_time', $end_time);
        }else{
            $end_time=strtotime('+1 year',time());
            $end_time=date("Y-m-d H:i:s",$end_time);
            $this->assign('end_time', $end_time);
        }
        return $this->fetch('', getAdmStoId());
    }


    /**
     * 初始化编辑器链接
     * 本编辑器参考 地址 http://fex.baidu.com/ueditor/
     */
    private function initEditor()
    {
        $this->assign("URL_upload", U('admin/Ueditor/imageUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片上传目录
        $this->assign("URL_imageUp", U('admin/Ueditor/imageUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); //  不知道啥图片
        $this->assign("URL_fileUp", U('admin/Ueditor/fileUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 文件上传s
        $this->assign("URL_scrawlUp", U('admin/Ueditor/scrawlUp', array('savepath' => 'goods', 'savepath1' => getERPId())));  //  图片流
        $this->assign("URL_getRemoteImage", U('admin/Ueditor/getRemoteImage', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 远程图片管理
        $this->assign("URL_imageManager", U('admin/Ueditor/imageManager', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片管理
        $this->assign("URL_getMovie", U('admin/Ueditor/getMovie', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 视频上传
        $this->assign("URL_Home", "");
    }


    /***
     * 商品图片同步处理
     */
    public function goods_handle_images(){
        $gd_sn=I("goods_sn");
        $stoid=getAdmStoId();

        $gd = M("goods")->where("goods_sn",$gd_sn)
            ->where('store_id',$stoid)
            ->field("original_img,goods_id")
            ->find();
        $imglist= M("goods_images")->where("goods_id",$gd['goods_id'])
            ->where('store_id',$stoid)->where('ismain',0)
            ->field('image_url')
            ->select();

        $imghost="https://mshopimg.yolipai.net";                     //腾讯云图片地址
        $upfilepath = ROOT_PATH . "public/upload/jddj/".$stoid."/";  //磁盘地址
        if (!is_dir($upfilepath))
            mkdir($upfilepath,0777,true);


        $path="/public/upload/jddj/".$stoid."/";                     //目录
        //$Host=curHostURL();                                          //本机地址
        $Host = "http://mshop-api.yolipai.net/";                         //本机地址

        $filename=uniqid()."0.jpg";
        $img = file_get_contents($imghost.$gd['original_img']);
        file_put_contents($upfilepath.$filename,$img);

        //强制格式800*800
        m_format_img($upfilepath.$filename,800);
        $fialename_arr[]=$Host.$path.$filename;
        $file_path[]=$upfilepath.$filename;

        $int=1;
        foreach ($imglist as $ky=>$vy){
            $img = file_get_contents($imghost.$vy['image_url']);
            $filename=uniqid().$int.".jpg";
            file_put_contents($upfilepath.$filename,$img);
            //强制格式800*800
            m_format_img($upfilepath.$filename,800);
            $fialename_arr[]=$Host.$path.$filename;
            $file_path[]=$upfilepath.$filename;
            $int++;
        }
        $Goods['outSkuId']=$gd_sn;
        $Goods['images']=implode(",",$fialename_arr);


        mlog("tu:".json_encode($fialename_arr),"goods_handle_images/".$stoid);
        $rs = jd_api('/pms/sku/updateSku', $Goods, getAdmStoId());
        mlog("jieguo:".$rs,"goods_handle_images/".$stoid);


        $rs=json_decode($rs,true);
        if($rs['code']==0){
            return json(['code'=>0,'msg'=>'同步成功,请等5分钟查看图片']);
        }else{
            return json(['code'=>-1,'msg'=>'保存失败']);
        }

    }

}