Ad.php 22.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: 当燃      
 * Date: 2015-09-21
 */

namespace app\admin\controller;
use think\Page;
use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;
use think\AjaxPage;
class Ad extends Base{
    public function ad(){
        $oldurl = I('oldurl/s');
        $act = I('get.act','add');
        $ad_id = I('get.ad_id/d');
        $ad_info = array();
        if($ad_id){
            $ad_info = D('ad')->where('ad_id',$ad_id)->find();
            $ad_info['start_time'] = date('Y-m-d H:i:s',$ad_info['start_time']);
            $ad_info['end_time'] = date('Y-m-d H:i:s',$ad_info['end_time']);

        }
        if($act == 'add')
           $ad_info['pid'] = $this->request->param('pid');
        $position = D('ad_position')->where('1=1')->select();
        $this->assign('info',$ad_info);
        $this->assign('act',$act);
        $this->assign('position',$position);
        $this->assign('erpid',getERPId());
        $this->assign('oldurl', $oldurl);

        $qclurl=QCLOUD_IMGURL;
        $this->assign('qclurl',$qclurl);
        return $this->fetch('',getAdmStoId());
    }

    public function adList(){

        delFile(RUNTIME_PATH.'Html'); // 先清除缓存, 否则不好预览
        $Ad =  M('ad');
        $pid = I('pid',0);


        $pagenum=20;//每页显示多少条
        if ((int)I('pagenum/s')>0)
        {
            $pagenum=I('pagenum/s');
        }
        $where['store_id'] = getAdmStoId();
        if($pid){
            $where['pid'] = $pid;
        	$this->assign('pid',I('pid'));
        }
        $keywords = I('keywords/s',false,'trim');
        if($keywords){
            $where['ad_name'] = array('like','%'.$keywords.'%');
        }
        $count = $Ad->where($where)->count();// 查询满足要求的总记录数
        $Page = $pager = new Page($count,$pagenum);// 实例化分页类 传入总记录数和每页显示的记录数
        $res = $Ad->where($where)->order('pid asc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $list = array();
        if($res){
        	$media = array('图片','文字','flash');
        	foreach ($res as $val){
        		$val['media_type'] = $media[$val['media_type']];
        		$list[] = $val;
        	}
        }

        $ad_position_list = M('AdPosition')->getField("position_id,position_name,is_open");
        $this->assign('ad_position_list',$ad_position_list);//广告位
        $show = $Page->show();// 分页显示输出
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->assign('pager',$pager);
        $this->assign('pagenum',$pagenum);
        $this->assign('oldurl',urlencode(curPageURL()));
        return $this->fetch('',getAdmStoId());
    }

    public function position(){
        $act = I('get.act','add');
        $position_id = I('get.position_id/d');
        $info = array();
        if($position_id){
            $info = D('ad_position')->where('position_id',$position_id)->find();
        }
        $this->assign('info',$info);
        $this->assign('act',$act);
        return $this->fetch('',getAdmStoId());
    }

    public function positionList(){
        $Position =  M('ad_position');
        $count = $Position->where('1=1')->count();// 查询满足要求的总记录数
        $Page = $pager = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $list = $Position->order('position_id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign('list',$list);// 赋值数据集
        $show = $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $this->assign('pager',$pager);
        return $this->fetch('',getAdmStoId());
    }

    public function adHandle(){

    	$data = I('post.');
    	$data['start_time'] = strtotime($data['begin']);
    	$data['end_time'] = strtotime($data['end']);
        $oldurl = I('oldurl/s');
        if($oldurl){
            $oldurl = urldecode($oldurl);
            $oldurl = urldecode($oldurl);
        }
        unset($data['oldurl']);
    	if($data['act'] == 'add'){
//            upload_ylp_log('增加广告');
            $data["store_id"]=getAdmStoId();
    		$r = D('ad')->add($data);
    	}

    	if($data['act'] == 'edit'){
//            upload_ylp_log('编辑广告');
            $data["store_id"]=getAdmStoId();
            unset($data['act']);
            unset($data['begin']);
            unset($data['end']);
            $q=D('ad')->where('ad_id', $data['ad_id'])->where($data)->find();
            if($q){
                if($oldurl){
                    $this->success('操作成功',$oldurl);
                }
                else {
                    $this->success("操作成功1", U('Admin/Ad/adList'));
                }
                exit;
            }
    		$r = D('ad')->where('ad_id', $data['ad_id'])->save($data);
    	}

    	if($data['act'] == 'del'){
//            upload_ylp_log('删除广告');
            $d=D('ad')->where('ad_id', $data['del_id'])->find();
            if($d){
                $url=$d['ad_code'];
                if(!empty($url)){
                    mdelFile(ROOT_PATH.$url);
                    vendor('qcloudcos.myqcloudcos');
                    $delres = Myqcloudcos::delFile('wxd', $url);

                }
               $r = D('ad')->where('ad_id', $data['del_id'])->delete();
                if($r) exit(json_encode(1));
            }else{
                $this->error("未找到该广告",$referurl);
                exit;
            }
    	}

    	/*--清除缓存--*/
        ClearALLCache();
        delFile(TEMP_PATH."/".getAdmStoId());


    	$referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : U('Admin/Ad/adList');
        // 不管是添加还是修改广告 都清除一下缓存
        delFile(RUNTIME_PATH.'Html'); // 先清除缓存, 否则不好预览

    	if($r){
    		$this->success("操作成功",U('Admin/Ad/adList'));
    	}else{
    		$this->error("操作失败",$referurl);
    	}
    }

    public function positionHandle(){
        $data = I('post.');
        if($data['act'] == 'add'){
//            upload_ylp_log('增加广告位');
            $r = M('ad_position')->add($data);
        }

        if($data['act'] == 'edit'){
//            upload_ylp_log('编辑广告位');
        	$r = M('ad_position')->where('position_id',$data['position_id'])->save($data);
        }

        if($data['act'] == 'del'){
//            upload_ylp_log('删除广告位');
        	if(M('ad')->where('pid',$data['position_id'])->count()>0){
        		$this->error("此广告位下还有广告,请先清除",U('Admin/Ad/positionList'));
        	}else{
        		$r = M('ad_position')->where('position_id', $data['position_id'])->delete();
        		if($r) exit(json_encode(1));
        	}
        }
        $referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : U('Admin/Ad/positionList');
        if($r){
        	$this->success("操作成功",$referurl);
        }else{
        	$this->error("操作失败",$referurl);
        }
    }

    public function changeAdField(){
//        upload_ylp_log('保存广告');
        $field = $this->request->request('field');
    	$data[$field] = I('get.value');
    	$data['ad_id'] = I('get.ad_id');
    	M('ad')->save($data); // 根据条件保存修改的数据
    }
	//商城首页广告
	public function shop_index(){
		//在页面渲染,无法直接使用,必须赋值给标签才能使用(json)
        $getmintime=date('Y-m-d 00:00:00',time());
        $getmaxtime=date('Y-m-d 23:59:59',time());
        $this->assign('getmaxtime',$getmaxtime);
        $this->assign('getmintime',$getmintime);
		$this->assign('erpid',getERPId());
//		upload_ylp_log('商城首页广告');
		return $this->fetch('',getAdmStoId());

	}
	//商城首页广告
	public function shop_user(){
		//在页面渲染,无法直接使用,必须赋值给标签才能使用(json)
        $getmintime=date('Y-m-d 00:00:00',time());
        $getmaxtime=date('Y-m-d 23:59:59',time());
        $this->assign('getmaxtime',$getmaxtime);
        $this->assign('getmintime',$getmintime);
		$this->assign('erpid',getERPId());
//		upload_ylp_log('个人中心广告');
		return $this->fetch('',getAdmStoId());

	}
    //积分兑换广告
    public function shop_integral(){
        $getmintime=date('Y-m-d 00:00:00',time());
        $getmaxtime=date('Y-m-d 23:59:59',time());
        $this->assign('getmaxtime',$getmaxtime);
        $this->assign('getmintime',$getmintime);
        $this->assign('erpid',getERPId());
        return $this->fetch('',getAdmStoId());

    }
    //客显屏幕广告
    public function erp_kxpm(){
        $getmintime=date('Y-m-d 00:00:00',time());
        $getmaxtime=date('Y-m-d 23:59:59',time());
        $this->assign('getmaxtime',$getmaxtime);
        $this->assign('getmintime',$getmintime);
        $this->assign('erpid',getERPId());
        return $this->fetch('',getAdmStoId());

    }

    public function search_strore()
    {
        $pickup_listid=I('pickup_listid');
        $where='';
        if ($pickup_listid){
            $newstr = substr($pickup_listid,0,strlen($pickup_listid)-1);
            $where="(pickup_id not in($newstr)) and";
        }
        $pagenum = 5;//每页显示多少条
        $getAdmStoId =getAdmStoId();
        $where = "$where store_id=" . $getAdmStoId;
        $kword = urldecode(urldecode(I('keywords/s')));
        //分页
        $intro = I('intro');
        if (!empty($intro)) {
            $where = "$where and " . I('intro') . " = 1";
            $this->assign('intro', $intro);
        }
        //搜索
        if (!empty($kword)) {
            $this->assign('keywords', $kword);
            $where = "$where and (pickup_no like '%" . $kword . "%' or pickup_name like '%" . $kword . "%')";
        }
        $count = M('pick_up')->where($where)->count();

        $Page = new Page($count, $pagenum);
        $stroreList = M('pick_up')->where($where)->order('pickup_id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->select();

        $show = $Page->show();//分页显示输出
        $this->assign('page', $show);//赋值分页输出
        $this->assign('stroreList', $stroreList);
        $this->assign('pickup_listid', $pickup_listid);
        $this->assign('pager', $Page);//赋值分页输出
        $tpl = I('get.tpl', 'search_strore');
        return $this->fetch($tpl, getAdmStoId());
    }


    // 优惠促销增加,编辑
    public function prom_goods_info()
    {
        $prom_id = I('id','0');
        $store_id = getAdmStoId();
        $time = time();
        $info['start_time'] = date('Y-m-d H:i:s');
        $info['end_time'] = date('Y-m-d H:i:s', time() + 3600 * 60 * 24);
        $coupon = M('coupon')->where(['store_id' => $store_id, 'send_end_time' => ['gt', $time], 'type' => 5])->select();
        $gift = M('gift')->where(['store_id' => $store_id, 'is_end' => 0])->select();
        $libao=M('libao_form')->where(['store_id' => $store_id,'isdel'=>0,
            'startime'=>['lt', $time],'endtime' => ['gt', $time]])->select();

        //全场活动的开始时间
        $now = time();
        $wh = " store_id=" . $store_id . " and is_end=0 and prom_type=3 ".
            " and e_time>" . $now . " and good_object=0";
        $wh.=" and act_id<>".$prom_id;

        $fu = M("activitylist")->where($wh)->field('id,goods_listid,s_time,e_time')->find();
        if ($fu) {
            $this->assign('quan_s_time', date('Y-m-d H:i:s', $fu['s_time']));
            $this->assign('quan_e_time', date('Y-m-d H:i:s', $fu['e_time']));
        }

        //其他所有活动的结束时间,开始时间
        $wh1 = " store_id=" . $store_id . " and is_end=0".
            " and end_time>" . $now;
        $wh1.=" and id<>".$prom_id;
        $max=M("prom_goods")->where($wh1)->max('end_time');
        $min=M("prom_goods")->where($wh1)->min('start_time');
        if($max)
            $this->assign('zhiding_e_time', date('Y-m-d H:i:s',$max));
        if($min)
            $this->assign('zhiding_s_time', date('Y-m-d H:i:s',$min));

        //是否有全场的,包括指定商品不参与
        if(empty($prom_id)) {
            if ($fu) {
                if($fu['s_time']<$now) {
                    $this->assign('isfull', 1);
                    if (empty($fu['goods_listid'])) $this->assign('isall', 1);
                }
                else{
                    $this->assign('goods_listid', $fu['goods_listid']);
                }
            }
        }

        if ($prom_id > 0) {
            //是否有全场的,包括指定商品不参与
            if ($fu) {
                if($fu['s_time']<$now) {
                    $this->assign('isfull', 1);
                    if (empty($fu['goods_listid'])) $this->assign('isall', 1);
                }
                else{
                    $this->assign('goods_listid', $fu['goods_listid']);
                }
            }

            $is_full = 'false';
            $info = M('prom_goods')->where(['store_id' => $store_id, 'id' => $prom_id])->find();
            $info['start_time'] = date('Y-m-d H:i:s', $info['start_time']);
            $info['end_time'] = date('Y-m-d H:i:s', $info['end_time']);
            $list = M('prom_goods_list')->where('prom_id', $prom_id)->select();
            foreach ($list as $k => $v) {
                $list[$k]['preferential_type'] = json_decode($v['preferential_type'], true);
            }
            $this->assign('list', $list);
            // $prom_goods = M('goods')->where("prom_id=$prom_id and prom_type=3")->select();
            $activitylist = M('activitylist')->where("act_id=$prom_id and prom_type=3")->field('goods_listid')->find();
            if ($activitylist) {
                $prom_goods = M('goods')->where("goods_id", array('in', '0' . $activitylist['goods_listid'] . '0'))->order('goods_id DESC')->select();
            }
            $this->assign('prom_goods', $prom_goods);

        }
        $tpl = I('tpl', '');
        $this->assign([
            'coupon' => $coupon,
            'info' => $info,
            'gift' => $gift,
            'tpl' => $tpl,
            'libao' => $libao,
        ]);

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

	//商城首页广告数据
    public  function getgg()
    {
        $getstoid=getAdmStoId();
        $gettypid=I('typeid');
        $resgg=M('ad')->where(array('store_id'=>$getstoid,'pid'=>$gettypid))->order('orderby desc')->select();
        if ($resgg)
        {

            foreach ($resgg as $k=>$v){
                $pickup_listid=$resgg[$k]['pickup_listid'];
                if($pickup_listid != null){
                    $newstr = substr($pickup_listid,0,strlen($pickup_listid)-1);
                    $where="(pickup_id IN($newstr))";
                    $pickupList=M('pick_up')->where($where)->select();
                    if($pickupList){
                        $resgg[$k]['pick_list']=$pickupList;
                    }
                }
            }

            return json(['code'=>0,'data'=>json_encode($resgg)]);
        }
        else
        {
            return json(['code'=>1,'msg'=>'没有记录']);
        }
    }
	//商城首页广告添加和修改
	public function addEditAd(){
		$ad_id=I('ad_id');
		$typeid=I('typeid');
		$enable=I('ad_enabled');
		if($enable == null){
			$enable=1;
		}
		$data = I('post.');
		$data['store_id']=getAdmStoId();
    	$data['start_time'] = strtotime($data['start_time']);
    	$data['end_time'] = strtotime($data['end_time']);
		$data['pid'] = $typeid;
		$data['enabled']=$enable;
//		echo "<scrpit>alert('"+$data['pid']+"')</scrpit>";
		if(empty($ad_id)){
			//新增
			$r = D('ad')->add($data);
		}else{
			//修改
            upload_ylp_log('A11商城首页编辑/确认提交');
			$r = D('ad')->where('ad_id', $ad_id)->save($data);
		}
		/*--清除缓存--*/
        ClearALLCache();
        delFile(TEMP_PATH."/".getAdmStoId());
		if($r){
    		$this->success("操作成功",U('Admin/Ad/shop_index'));
    	}else{
    		$this->error("操作失败");
    	}
	}
	//商城个人中心添加和修改广告
	public function addEditAd_user(){
		$ad_id=I('ad_id');
		$typeid=I('typeid');
		$enable=I('ad_enabled');
		$data = I('post.');
		$data['store_id']=getAdmStoId();
    	$data['start_time'] = strtotime($data['start_time']);
    	$data['end_time'] = strtotime($data['end_time']);
		$data['pid'] = $typeid;
		$data['enabled']=$enable;
//		var_dump($data['enabled']);
//		die();
//		echo "<scrpit>alert('"+$data['pid']+"')</scrpit>";
		if(empty($ad_id)){
			//新增
			$r = D('ad')->add($data);
		}else{
			//修改
            upload_ylp_log('A12个人中心页编辑/确认提交');
			$r = D('ad')->where(array('ad_id'=>$ad_id))->save($data);
		}
		/*--清除缓存--*/
        ClearALLCache();
        delFile(TEMP_PATH."/".getAdmStoId());
		if($r){
    		$this->success("操作成功",U('Admin/Ad/shop_user'));
    	}else{
    		$this->error("操作失败");
    	}
	}



	//删除所有广告
	public function delAd(){
//	    upload_ylp_log('删除所有广告');
//		$typeid=$_GET['typeid'];
		$typeid=I('typeid');
		$d=D('ad')->where(array('pid'=>$typeid,'store_id'=>getAdmStoId()))->find();
            if($d){
                $url=$d['ad_code'];
                if(!empty($url)){
                    mdelFile(ROOT_PATH.$url);
                    vendor('qcloudcos.myqcloudcos');
                    $delres = Myqcloudcos::delFile('wxd', $url);
                }

				$r=D('ad')->where(array('pid'=>$typeid,'store_id'=>getAdmStoId()))->delete();
				/*--清除缓存--*/
        		ClearALLCache();
        		delFile(TEMP_PATH."/".getAdmStoId());
                if($r){
                	$this->success("操作成功",U('Admin/Ad/shop_index'));

                }
            }else{
                exit;
            }
	}
//删除轮播
	public function delAdid(){
//	    upload_ylp_log('删除广告轮播');
			$ad_id=$_GET['id'];
			$d=D('ad')->where(array('ad_id'=>$ad_id,'store_id'=>getAdmStoId()))->find();
	            if($d){
	                $url=$d['ad_code'];
	                if(!empty($url)){
	                    vendor('qcloudcos.myqcloudcos');

	                    $urllist=explode(',',$url);
                        $url_len = count($urllist);
                        for ($i = 0; $i < $url_len; $i++) {
                            mdelFile(ROOT_PATH . $urllist[$i]);
                            $delres = Myqcloudcos::delFile('wxd', $urllist[$i]);
                        }

	                }
					$r=D('ad')->where(array('ad_id'=>$ad_id,'store_id'=>getAdmStoId()))->delete();
					/*--清除缓存--*/
	        		ClearALLCache();
	        		delFile(TEMP_PATH."/".getAdmStoId());
	                if($r){
	              		$this->success("操作成功",U('Admin/Ad/shop_index'));
						exit;
	                }
	            }else{
	                exit;
	            }
		}

		//删除单个广告
    public function delId_sigle()
    {
        vendor('qcloudcos.myqcloudcos');
        $ad_id = $_GET['id'];
        $imgurl = $_GET['imgurl'];
        $getadcode = $_GET['ad_code'];
        if ($ad_id) {
            $d = D('ad')->where(array('ad_id' => $ad_id, 'store_id' => getAdmStoId()))->find();
            if ($d) {
                $url = $d['ad_code'];

            }
        } else {
            $url = $getadcode;
        }
        //
        if ($url) {
            $urllist = explode(',', $url);
            $url_len = count($urllist);
            $newurl = "";
            for ($i = 0; $i < $url_len; $i++) {

                if ($urllist[$i] == $imgurl) {
                    if ($imgurl) {
                        mdelFile(ROOT_PATH . $urllist[$i]);
                        $delres = Myqcloudcos::delFile('wxd', $urllist[$i]);
                    }
                } else {
                    if ($urllist[$i]) {
                        if ($newurl) {
                            $newurl .= "," . $urllist[$i];
                        } else {
                            $newurl = $urllist[$i];
                        }
                    }
                }
            }
            if ($ad_id) {
                $r = D('ad')->where(array('ad_id' => $ad_id, 'store_id' => getAdmStoId()))->save(array('ad_code' => $newurl));
                /*--清除缓存--*/
                ClearALLCache();
                delFile(TEMP_PATH . "/" . getAdmStoId());
                if ($r) {
                    return json(array('code' => 1, 'msg' => '删除成功!', 'urllist' => $newurl));
                }
            }
            else
            {
                return json(array('code' => 1, 'msg' => '删除成功!', 'urllist' => $newurl));
            }


        }

        //

    }





    //积分兑换添加和修改广告
    public function addEditAd_integral(){
        $ad_id=I('ad_id');
        $typeid=I('typeid');
        $enable=I('ad_enabled');
        $data = I('post.');
        $data['store_id']=getAdmStoId();
        $data['start_time'] = strtotime($data['start_time']);
        $data['end_time'] = strtotime($data['end_time']);
        $data['pid'] = $typeid;
        $data['enabled']=$enable;
        if(empty($ad_id)){
            //新增
            $r = D('ad')->add($data);
        }else{
            //修改
            upload_ylp_log('A12积分兑换页编辑/确认提交');
            $r = D('ad')->where(array('ad_id'=>$ad_id))->save($data);
        }
        /*--清除缓存--*/
        ClearALLCache();
        delFile(TEMP_PATH."/".getAdmStoId());
        if($r){
            $this->success("操作成功",U('Admin/Ad/shop_integral'));
        }else{
            $this->error("操作失败");
        }
    }


    //客显屏幕广告添加和修改广告
    public function addEditAd_erpkxpm(){
        $ad_id=I('ad_id');
        $typeid=I('typeid');
        $enable=I('ad_enabled');
        $data = I('post.');
        $intype=$data['intype'];
        if($intype==0){
            $data['pickup_listid']='';
        }
        $data['store_id']=getAdmStoId();
        $data['start_time'] = strtotime($data['start_time']);
        $data['end_time'] = strtotime($data['end_time']);
        $data['pid'] = $typeid;
        $data['enabled']=$enable;
        if(empty($ad_id)){
            //新增
            $r = D('ad')->add($data);
        }else{
            //修改
            upload_ylp_log('A12客显屏幕页编辑/确认提交');
            $r = D('ad')->where(array('ad_id'=>$ad_id))->save($data);
        }
        /*--清除缓存--*/
        ClearALLCache();
        delFile(TEMP_PATH."/".getAdmStoId());
        if($r){
            $this->success("操作成功",U('Admin/Ad/erp_kxpm'));
        }else{
            $this->error("操作失败");
        }
    }


}