Apiylp.php 19.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
<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: JY
 * Date: 2015-09-23
 */

namespace app\home\controller;

use app\home\logic\UsersLogic;
use think\Db;
use think\Exception;
use think\Session;
use think\Controller;
use think\Verify;
use think\Cookie;
use think\Page;
class Apiylp extends Controller
{


    public function _initialize()
    {
        Session::start();
    }
    /*根据ACCDB获取商品列表*/
    public function getgoodslist()
    {
       try {
        $postStr = file_get_contents("php://input");
        if (empty($postStr)) {
            $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        }
      //  $postStr="{\"accdb\":\"ppt\",\"wareno\":\"001\"}";
        if ($postStr) {

            $postjson = json_decode($postStr, true);
            $pagenum = $postjson['pagenum'];
            $pagenum=100;
            if ($postjson['pagenum'])
            {
                $pagenum = $postjson['pagenum'];
            }
            $ACCDB = $postjson['accdb'];

            if ($ACCDB) {
                $where1['ERPId'] = $ACCDB;
                $where1['is_audit']=1;
            }
            $store_res = M('store')->where($where1)->field('store_id')->find();
            if ($store_res)//新版
            {
                $getstoreid=$store_res['store_id'];
                $getpattern=tpCache('distribut.pattern', $getstoreid);//分销模式
                $first_rate=tpCache('distribut.first_rate', $getstoreid);//分销模式
                $second_rate=tpCache('distribut.second_rate', $getstoreid);//分销模式
                $third_rate=tpCache('distribut.third_rate', $getstoreid);//分销模式
                if ($getpattern=="")
                {
                    $getpattern=0;
                }
                if ($first_rate=="")
                {
                    $first_rate=0;
                }
                if ($second_rate=="")
                {
                    $second_rate=0;
                }
                if ($third_rate=="")
                {
                    $third_rate=0;
                }
                $where['store_id'] = $store_res['store_id'];
                if ($postjson['wareno'])
                {
                    $where['a.goods_sn'] =array('like','%'.$postjson['wareno'].'%');
                }
                if ($postjson['sku'])
                {
                    $where['a.sku'] = $postjson['sku'];
                }
                $count = D('goods')->alias("a")
                    ->where($where)->count();

                $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数

                $fiedlist = "a.goods_id,a.erpwareid,a.goods_sn as WareNo,a.goods_name as WareName,a.sku as BarCode,b.name as ClassName,a.cat_id as ClassId,c.name as BrandName,a.brand_id as BrandId,d.name as NationName,a.nation_id as NationId,a.goods_spec as SpecName,a.goods_unitname as UnitName,a.goods_color as ColorName,a.weight as Weight,a.store_count as WebStoQty,a.market_price as PosPrice,a.shop_price as WebPrice,a.goods_content as WebContent";
                if ($getpattern==1)
                {
                    $fiedlist.=",1 as Pattern,a.fir_rate,a.sec_rate,a.thi_rate";
                }
                else{
                    $fiedlist.=",0 as Pattern,$first_rate as fir_rate ,$second_rate as sec_rate, $third_rate as thi_rate";
                }

                $res = M('goods')->alias("a")
                    ->join('(select id,name from wxd_goods_category where store_id='.$getstoreid.') b','a.cat_id=b.id','left')
                    ->join('(select id,name from wxd_brand where store_id='.$getstoreid.') c','a.brand_id=c.id','left')
                    ->join('(select id,name from wxd_nation where store_id='.$getstoreid.') d','a.nation_id=d.id','left')
                    ->where($where)->field($fiedlist)->limit($Page->firstRow . ',' . $Page->listRows)
                    ->order('a.goods_sn asc')->select();

                if ($res) {

                    $jsonres["STATE"] = 1;
                    $jsonres["version"] = 3.0;
                    $jsonres["RECCOUNT"] = $count;
                    $SUMPAGE=$Page->totalPages;

                    $jsonres["SUMPAGE"] = $SUMPAGE;
                    $jsonres["MSG"] = "SUCCESS";

                    foreach ($res as $k => $v) {
                        $imglist = M('goods_images')->where('goods_id', $v['goods_id'])->field('image_url as ImgUrl')->order('ismain desc')->select();
                        if ($imglist) {
                            foreach ($imglist as $k1 => $v1) {
                                $imglist[$k1]["ImgUrl"]= QCLOUD_IMGURL.$v1['ImgUrl'];
                            }
                        }
                       $res[$k]['imglist']=$imglist;

                    }
                    $jsonres["ITEMS"]=$res;

                } else {
                    $jsonres["STATE"] = -1;

                    $jsonres["MSG"] = "没有相关数据";
                }


            }
            else
            {
                //old

                $oldres = httpRequest(IMPORT_URL . "/API/CustInfo.ashx?method=getgoodslist_ylp&pagesize=".$pagenum."&pagenumber=".I('p'),'POST',$postStr,array(),false,30);

                if ($oldres) {



                    $oldres = json_decode($oldres, true);


                    $jsonres["STATE"] = 1;
                    $jsonres["version"] = 2.0;
                    $jsonres["RECCOUNT"] = $oldres['total'];
                    $jsonres["SUMPAGE"] = $oldres['page'];

                    $jsonres["MSG"] = "SUCCESS";
                    $jsonres["ITEMS"] = $oldres['data']["ITEMS"];


                } else {
                    $jsonres["STATE"] = -1;
                    $jsonres["msg"] = "获取失败001";
                }


                //old   end


            }





        }
        else
        {
            $jsonres["STATE"] = -1;
            $jsonres["MSG"] = "传递有误";
        }
        }
        catch (Exception $ex) {
            $jsonres["STATE"] = -1;
            $jsonres["MSG"] = "异常出错";
        }
        return json_encode($jsonres);

    }




    /*根据ACCDB获取商品类品牌*/
    public function getbrandlist()
    {
//        try {
        $postStr = file_get_contents("php://input");
        if (empty($postStr)) {
            $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        }

        // $postStr="{\"accdb\":\"ppt\",\"pagenum\":\"10\"}";


        if ($postStr) {

            $postjson = json_decode($postStr, true);
            $pagenum = $postjson['pagenum'];
            $pagenum = 100;
            if ($postjson['pagenum']) {
                $pagenum = $postjson['pagenum'];
            }
            $ACCDB = $postjson['accdb'];

            if ($ACCDB) {
                $where1['ERPId'] = $ACCDB;
                $where1['is_audit'] = 1;
            }
            $store_res = M('store')->where($where1)->field('store_id')->find();
            if ($store_res)//新版
            {
                $getstoreid=$store_res['store_id'];

                $where['a.store_id'] = $store_res['store_id'];

                $count = D('brand')->alias("a")
                    ->where($where)->count();

                $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数

                $fiedlist = "a.id,a.name,a.logo,a.is_hot as isshow";
                $res = M('brand')->alias("a")->where($where)->field($fiedlist)
                    ->limit($Page->firstRow . ',' . $Page->listRows)
                    ->order('a.sort asc')
                  ->select();

                if ($res) {
                    foreach ($res as $k => $v) {
                        $res[$k]['logo']= QCLOUD_IMGURL.$v['logo'];

                    }
                    $jsonres["STATE"] = 1;
                    $jsonres["RECCOUNT"] = $count;
                    $SUMPAGE=$Page->totalPages;
                    $jsonres["version"] = 3.0;
                    $jsonres["MSG"] = "SUCCESS";

                    $jsonres["ITEMS"]=$res;

                } else {
                    $jsonres["STATE"] = -1;
                    $jsonres["MSG"] = "没有相关数据";
                }

            }
            else{

                //old

                $oldres = httpRequest(IMPORT_URL . "/API/CustInfo.ashx?method=getbrandlist_ylp&type=2&pagesize=".$pagenum."&pagenumber=".I('p'),'POST',$postStr,array(),false,30);

                if ($oldres) {



                    $oldres = json_decode($oldres, true);


                    $jsonres["STATE"] = 1;
                    $jsonres["version"] =2.0;
                    $jsonres["RECCOUNT"] = $oldres['total'];
                    $jsonres["SUMPAGE"] = $oldres['page'];

                    $jsonres["MSG"] = "SUCCESS";
                    $jsonres["ITEMS"] = $oldres['data']["ITEMS"];


                } else {
                    $jsonres["STATE"] = -1;
                    $jsonres["msg"] = "获取失败001";
                }


                //old end


            }

        }
        return json_encode($jsonres);
    }

    /*根据ACCDB获取商品国家*/
    public function getnationlist()
    {
//        try {
        $postStr = file_get_contents("php://input");
        if (empty($postStr)) {
            $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        }

       // $postStr="{\"accdb\":\"mkm\",\"pagenum\":\"10\"}";


        if ($postStr) {

            $postjson = json_decode($postStr, true);
            $pagenum = $postjson['pagenum'];
            $pagenum = 100;
            if ($postjson['pagenum']) {
                $pagenum = $postjson['pagenum'];
            }
            $ACCDB = $postjson['accdb'];

            if ($ACCDB) {
                $where1['ERPId'] = $ACCDB;
                $where1['is_audit'] = 1;
            }
            $store_res = M('store')->where($where1)->field('store_id')->find();
            if ($store_res)//新版
            {
                $getstoreid=$store_res['store_id'];

                $where['a.store_id'] = $store_res['store_id'];

                $count = D('nation')->alias("a")
                    ->where($where)->count();

                $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数

                $fiedlist = "a.id,a.name,a.logo,a.is_hot as isshow";
                $res = M('nation')->alias("a")->where($where)->field($fiedlist)
                    ->limit($Page->firstRow . ',' . $Page->listRows)
                    ->order('a.sort asc')
                    ->select();

                if ($res) {
                    foreach ($res as $k => $v) {
                        $res[$k]['logo']= QCLOUD_IMGURL.$v['logo'];

                    }
                    $jsonres["STATE"] = 1;
                    $jsonres["RECCOUNT"] = $count;
                    $SUMPAGE=$Page->totalPages;
                    $jsonres["version"] = 3.0;
                    $jsonres["MSG"] = "SUCCESS";

                    $jsonres["ITEMS"]=$res;

                } else {
                    $jsonres["STATE"] = -1;
                    $jsonres["MSG"] = "没有相关数据";
                }

            }
            else{

                $oldres = httpRequest(IMPORT_URL . "/API/CustInfo.ashx?method=getbrandlist_ylp&type=3&pagesize=".$pagenum."&pagenumber=".I('p'),'POST',$postStr,array(),false,30);

                if ($oldres) {



                    $oldres = json_decode($oldres, true);
                    if ($oldres['code']==0) {
                        $jsonres["STATE"] = 1;
                        $jsonres["version"] = 2.0;
                        $jsonres["RECCOUNT"] = $oldres['total'];
                        $jsonres["SUMPAGE"] = $oldres['page'];

                        $jsonres["MSG"] = "SUCCESS";
                        $jsonres["ITEMS"] = $oldres['data']["ITEMS"];
                    }else{
                        $jsonres["STATE"] = -1;
                        $jsonres["msg"] =  $oldres['msg'];
                    }


                } else {
                    $jsonres["STATE"] = -1;
                    $jsonres["msg"] = "获取失败001";
                }




            }

        }
        else
        {
            $jsonres["STATE"] = -1;
            $jsonres["msg"] = "POST为空";
        }
        return json_encode($jsonres);
    }


    /*根据ACCDB获取商品类别*/
    public function getcatlist()
    {
//        try {
        $postStr = file_get_contents("php://input");
        if (empty($postStr)) {
            $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        }

        // $postStr="{\"accdb\":\"xym\",\"pagenum\":\"10\"}";


        if ($postStr) {

            $postjson = json_decode($postStr, true);
            $pagenum = $postjson['pagenum'];
            $pagenum = 100;
            if ($postjson['pagenum']) {
                $pagenum = $postjson['pagenum'];
            }
            $ACCDB = $postjson['accdb'];

            if ($ACCDB) {
                $where1['ERPId'] = $ACCDB;
                $where1['is_audit'] = 1;
            }
            $store_res = M('store')->where($where1)->field('store_id')->find();
            if ($store_res)//新版
            {
                $getstoreid=$store_res['store_id'];

                $where['a.store_id'] = $store_res['store_id'];

                $count = D('goods_category')->alias("a")
                    ->where($where)->count();

                $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数

                $fiedlist = "a.id,a.name,a.parent_id,a.image as logo,a.is_show as isshow";
                $res = M('goods_category')->alias("a")->where($where)->field($fiedlist)
                    ->limit($Page->firstRow . ',' . $Page->listRows)
                    ->order('parent_id asc,level asc,sort_order asc')
                    ->select();

                if ($res) {
                    foreach ($res as $k => $v) {
                        $res[$k]['logo']= QCLOUD_IMGURL.$v['logo'];

                    }
                    $jsonres["STATE"] = 1;
                    $jsonres["RECCOUNT"] = $count;
                    $SUMPAGE=$Page->totalPages;
                    $jsonres["version"] = 3.0;
                    $jsonres["MSG"] = "SUCCESS";

                    $jsonres["ITEMS"]=$res;

                } else {
                    $jsonres["STATE"] = -1;
                    $jsonres["MSG"] = "没有相关数据";
                }

            }
            else{


                $oldres = httpRequest(IMPORT_URL . "/API/CustInfo.ashx?method=getbrandlist_ylp&type=1&pagesize=".$pagenum."&pagenumber=".I('p'),'POST',$postStr,array(),false,30);


                if ($oldres) {


                    $oldres = json_decode($oldres, true);
                    if ($oldres['data']) {

                        $jsonres["STATE"] = 1;
                        $jsonres["version"] = 2.0;
                        $jsonres["RECCOUNT"] = $oldres['total'];
                        $jsonres["SUMPAGE"] = $oldres['page'];

                        $jsonres["MSG"] = "SUCCESS";
                        $jsonres["ITEMS"] = $oldres['data']["ITEMS"];


                    } else {
                        $jsonres["STATE"] = -1;
                        $jsonres["msg"] = "获取失败001";
                    }


                }
                else{
                    $jsonres["STATE"] = -1;
                    $jsonres["msg"] = "获取失败002";
                }


            }

        }
        else
        {
            $jsonres["STATE"] = -1;
            $jsonres["msg"] = "未获取参数";
        }
        return json_encode($jsonres);
    }

    //美妆图库
    public function getskuinfo()
    {
        $postStr = file_get_contents("php://input");
        if (empty($postStr)) {
            $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        }
      // $postStr="{\"sku\":\"6954776300762\"}";

        if (empty($postStr)) {
            $jsonres["STATE"] = -1;
            $jsonres["msg"] = "未获取参数";
            return json_encode($jsonres);
        }
        $postjson = json_decode($postStr, true);
        $sku=$postjson['sku'];
        if (empty($sku))
        {
            $jsonres["STATE"] = -1;
            $jsonres["msg"] = "SKU不能为空";
            return json_encode($jsonres);
        }
        //过滤掉ppt、tpty、cdzy
        $res = M('barcodegoods')->where("sku='" . $sku ."' and store_id not in(1,23,39) and goods_content is not null")->find();
        if (empty($res)) {
            return json(['STATE' => -1, 'msg' => '美妆图库还没有记录']);
        }
        $img = M('barcodegoods_images')->where(['goods_id' => $res['goods_id'], 'ismain' => 0])->select();
        return json(['STATE' => 1, 'msg' => '获取成功', 'des' => $res, 'img' => $img]);
    }

    //会员统计

    public function getviplist()
    {
        //  try {
        $postStr = file_get_contents("php://input");
        if (empty($postStr)) {
            $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : "";
        }

        //  $postStr="{\"accdb\":\"ppt\",\"pagenum\":\"10\"}";
        if (empty($postStr)) {
            $jsonres["STATE"] = -1;
            $jsonres["msg"] = "未获取参数";
            return json_encode($jsonres);
        }


        $postjson = json_decode($postStr, true);
        $pagenum = $postjson['pagenum'];
        $pagenum = 100;
        if ($postjson['pagenum']) {
            $pagenum = $postjson['pagenum'];
        }
        $ACCDB = $postjson['accdb'];

        if ($ACCDB) {
            $where1['ERPId'] = $ACCDB;
            $where1['is_audit'] = 1;
        }
        $store_res = M('store')->where($where1)->field('store_id')->find();
        if ($store_res)//新版
        {
            $getstoreid = $store_res['store_id'];

            $where['a.store_id'] = $store_res['store_id'];
            $where['a.mobile'] = array('neq', '');
            $count = D('users')->alias("a")
                ->where($where)->count();

            $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数

            $fiedlist = "a.vipname,a.mobile,ifnull(b.pickup_no,'') pickup_no,a.is_distribut,ifnull(c.mobile,'') as fromuser_mobile";
            $res = M('users')->alias("a")->where($where)->field($fiedlist)
                ->join('pick_up b', 'a.pickup_id=b.pickup_id', 'left')
                ->join('(select mobile,user_id from  wxd_users where store_id=' . $store_res['store_id'] . ' and mobile<>"" ) c', 'a.fromuser_id=c.user_id', 'left')
                ->limit($Page->firstRow . ',' . $Page->listRows)
                ->order('a.user_id asc')
                ->select();

            if ($res) {
                $jsonres["STATE"] = 1;
                $jsonres["RECCOUNT"] = $count;
                $SUMPAGE = $Page->totalPages;
                $jsonres["version"] = 3.0;
                $jsonres["MSG"] = "SUCCESS";

                $jsonres["ITEMS"] = $res;

            } else {
                $jsonres["STATE"] = -1;
                $jsonres["MSG"] = "没有相关数据";
            }

        } else {
            $jsonres["STATE"] = -1;
            $jsonres["MSG"] = "找不到相关账套信息";

        }


        return json_encode($jsonres);

    }

}