fetch('', getAdmStoId());
    }
    //订单活动到期,更新活动状态
    public function updateprom_order()
    {
        $time = time();
        M('prom_order')->where(array('store_id' => getAdmStoId(), 'is_end' => 0, 'end_time' => ['<', $time]))->save(array('is_end' => 1));
    }
    //订单活动历史
    public function prom_order_history()
    {
        $parse_type = array('0' => '直接打折', '1' => '减价优惠', '2' => '满额送积分', '3' => '满额送优惠券');
        /*--更新活动状态--*/
        $this->updateprom_order();
        //获取优惠券列表
        $pagenum = 10;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/d');
        }
        $key = urldecode(urldecode(I('actname/s')));
        $condition = 'store_id=' . getAdmStoId() . ' and is_end=1 and is_show=1 ';
        if (!empty($key)) {
            $condition .= 'and name like "%' . $key . '%"';
        }
        $prom_type = I('prom_type');
        if ($prom_type != "") {
            $condition .= ' and type=' . $prom_type;
        }
        $count = M('prom_order')->where($condition)->count();
        $Page = new Page($count, $pagenum);
        $show = $Page->show();
        $list = M('prom_order')->where($condition)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
        $this->assign([
            'key' => $key,
            'pager' => $Page,
            'page' => $show,
            'pagenum' => $pagenum,
            'list' => $list
        ]);
        $this->assign('parse_type', $parse_type);
//        upload_ylp_log('历史搭配促销');
        return $this->fetch('', getAdmStoId());
    }
    //抢到记录
    public function flash_sale_orderlist()
    {
        $pagenum = 20;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/s');
        }
        $p = I('p', 1);
        $begin = I('add_time_begin');
        $end = I('add_time_end');
        $this->assign('start_time', $begin);
        $this->assign('end_time', $end);
        $mobile = I('mobile');//手机号码
        $order_sn = I('order_sn');//手机号码
        $flashsaleid = I('flashsaleid');//ID
        $picksle = urldecode(urldecode(trim(I('picksle'))));
        $pstype = I('picksle_type');
        $getisend = I('isend');
        $where = " a.store_id=" . getAdmStoId();
        $where .= " and  a.prom_type=1 and a.prom_id=" . $flashsaleid;
        if (!empty($mobile)) {
            $where .= " and c.mobile='" . $mobile . "' ";
        }
        if (!empty($order_sn)) {
            $where .= " and b.order_sn='" . $order_sn . "' ";
        }
        if ($picksle) {
            if ($pstype)
                $where .= " AND d.pickup_name='" . $picksle . "'";
            else
                $where .= " AND d.pickup_no='" . $picksle . "'";
        }
        if ($begin) {
            $where .= " and b.add_time>=" . strtotime($begin);
        }
        if ($end) {
            $where .= " and b.add_time<=" . strtotime($end);
        }
        $order_status = I('order_status');
        if ($order_status != "") {
            switch ($order_status) {
                case 12:      //待付款
                    $condition['b.order_status'] = 0;
                    $condition['b.pay_status'] = 0;
                    break;
                case 1:      //待发货
                    $condition['b.pay_status'] = 1;
                    $condition['b.order_status'] = ['in', '0,1'];
                    $condition['b.shipping_status'] = 0;
                    break;
                case 11:     //待收货
                    $condition['b.order_status'] = 1;
                    I('shipping_status') != '' ? $condition['b.shipping_status'] = I('shipping_status') : $condition['shipping_status'] = ['in', '1,2']; //是否发货
                    break;
                case 2:     //已收货
                    $condition['b.order_status'] = 2;
                    break;
                case 3:      //已取消
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 4:      //已完成
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 5:      //已作废
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 6:      //已作废
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 13:      //已付款
                    $condition['b.pay_status'] = 1;
                    break;
            }
        }
        $qdrecord = M('order_goods');
        $count = $qdrecord->alias('a')
            ->join('order b', ' a.order_id=b.order_id', 'left')
            ->join('(select nickname,mobile,user_id from wxd_users where store_id=' . getAdmStoId() . ') c', ' b.user_id=c.user_id', 'left')
            ->join('(select pickup_id,pickup_name,pickup_no from  wxd_pick_up where store_id=' . getAdmStoId() . ') d', 'd.pickup_id=b.pickup_id', 'left')
            ->where($where)
            ->where($condition)
            ->count();
        $sumcount = $qdrecord->alias('a')
            ->join('order b', ' a.order_id=b.order_id', 'left')
            ->join('(select nickname,mobile,user_id from wxd_users where store_id=' . getAdmStoId() . ') c', ' b.user_id=c.user_id', 'left')
            ->join('(select pickup_id,pickup_name,pickup_no from  wxd_pick_up where store_id=' . getAdmStoId() . ') d', 'd.pickup_id=b.pickup_id', 'left')
            ->where($where)
            ->where($condition)
            ->sum('a.goods_num');
        $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数
        $redmoneylist = $qdrecord->alias('a')
            ->join('order b', ' a.order_id=b.order_id', 'left')
            ->join('(select nickname,mobile,user_id from wxd_users where store_id=' . getAdmStoId() . ') c', 'b.user_id=c.user_id', 'left')
            ->join('(select pickup_id,pickup_name,pickup_no from  wxd_pick_up where store_id=' . getAdmStoId() . ') d', 'd.pickup_id=b.pickup_id', 'left')
            ->where($where)
            ->where($condition)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->order('b.add_time desc')
            ->field('d.pickup_name,d.pickup_no,b.order_id,c.mobile,c.nickname,b.order_sn,a.goods_num,a.goods_name,b.add_time,b.order_status,b.pay_status,b.shipping_status,b.pay_sn,b.pay_time')
            ->select();// 查询满足要求的总记录数
        foreach ($redmoneylist as $kk => $vv) {
            $order_status_arr = C('ORDER_STATUS_DESC');
            $order_status_code = orderStatusDesc(0, $vv); // 订单状态显示给用户看的
            $redmoneylist[$kk]['order_status_desc'] = $order_status_arr[$order_status_code];
        }
        if ($p == 1 && $getisend == 1) {
            $falshinfo = M('flash_sale')->where(array('store_id' => getAdmStoId(), 'id' => $flashsaleid, 'is_end' => 1))->find();
            if ($falshinfo) {
                if ($falshinfo['buy_num'] != $sumcount) {
                    $updatedata['buy_num'] = $sumcount;
                }
                if ($falshinfo['order_num'] != $count) {
                    $updatedata['order_num'] = $count;
                }
                if ($updatedata) {
                    M('flash_sale')->where(array('store_id' => getAdmStoId(), 'id' => $flashsaleid, 'is_end' => 1))->save($updatedata);
                }
            }
        }
        $show = $Page->show();
        $this->assign('page', $show);
        $this->assign('sumcount', $sumcount);
        $this->assign('total', $count);
        $this->assign('flashsaleid', $flashsaleid);
        $this->assign('order_sn', $order_sn);
        $this->assign('picksle', $picksle);
        $this->assign('pstype', $pstype);
        $this->assign('getorder_status', $order_status);
        $this->assign('mobile', $mobile);
        $this->assign('redmoneylist', $redmoneylist);
        $this->assign('pagenum', $pagenum);
        $this->assign('timegap', date('Y-m-d h:m:s', $this->begin) . ' - ' . date('Y-m-d h:m:s', $this->end));
        return $this->fetch('', getAdmStoId());
    }
    /*秒杀记录导出*/
    public function export_sale_orderlist()
    {
        $begin = I('add_time_begin');
        $end = I('add_time_end');
        $this->assign('start_time', $begin);
        $this->assign('end_time', $end);
        $mobile = I('mobile');//手机号码
        $order_sn = I('order_sn');//手机号码
        $flashsaleid = I('flashsaleid');//ID
        $picksle = trim(I('picksle'));
        $pstype = I('picksle_type');
        $getisend = I('isend');
        $where = " a.store_id=" . getAdmStoId();
        $where .= " and  a.prom_type=1 and a.prom_id=" . $flashsaleid;
        if (!empty($mobile)) {
            $where .= " and c.mobile='" . $mobile . "' ";
        }
        if (!empty($order_sn)) {
            $where .= " and b.order_sn='" . $order_sn . "' ";
        }
        if ($picksle) {
            if ($pstype)
                $where .= " AND d.pickup_name='" . $picksle . "'";
            else
                $where .= " AND d.pickup_no='" . $picksle . "'";
        }
        if ($begin) {
            $where .= " and b.add_time>=" . strtotime($begin);
        }
        if ($end) {
            $where .= " and b.add_time<=" . strtotime($end);
        }
        $order_status = I('order_status');
        if ($order_status != "") {
            switch ($order_status) {
                case 12:      //待付款
                    $condition['b.order_status'] = 0;
                    $condition['b.pay_status'] = 0;
                    break;
                case 1:      //待发货
                    $condition['b.pay_status'] = 1;
                    $condition['b.order_status'] = ['in', '0,1'];
                    $condition['b.shipping_status'] = 0;
                    break;
                case 11:     //待收货
                    $condition['b.order_status'] = 1;
                    I('shipping_status') != '' ? $condition['b.shipping_status'] = I('shipping_status') : $condition['shipping_status'] = ['in', '1,2']; //是否发货
                    break;
                case 2:     //已收货
                    $condition['b.order_status'] = 2;
                    break;
                case 3:      //已取消
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 4:      //已完成
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 5:      //已作废
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 6:      //已作废
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 13:      //已付款
                    $condition['b.pay_status'] = 1;
                    break;
            }
        }
        $qdrecord = M('order_goods');
        $redmoneylist = $qdrecord->alias('a')
            ->join('order b', ' a.order_id=b.order_id', 'left')
            ->join('(select nickname,mobile,user_id from wxd_users where store_id=' . getAdmStoId() . ') c', 'b.user_id=c.user_id', 'left')
            ->join('(select pickup_id,pickup_name,pickup_no from  wxd_pick_up where store_id=' . getAdmStoId() . ') d', 'd.pickup_id=b.pickup_id', 'left')
            ->where($where)
            ->where($condition)
            ->order('b.add_time desc')
            ->field('d.pickup_name,d.pickup_no,b.order_id,c.mobile,c.nickname,b.order_sn,a.goods_num,a.goods_name,b.add_time,b.order_status,b.pay_status,b.shipping_status,b.pay_sn,b.pay_time')
            ->select();// 查询满足要求的总记录数
        foreach ($redmoneylist as $kk => $vv) {
            $order_status_arr = C('ORDER_STATUS_DESC');
            $order_status_code = orderStatusDesc(0, $vv); // 订单状态显示给用户看的
            $redmoneylist[$kk]['order_status_desc'] = $order_status_arr[$order_status_code];
        }
        $strTable = '
';
        $strTable .= '';
        $strTable .= '| 订单号';
        $strTable .= ' | 会员昵称';
        $strTable .= ' | 手机号';
        $strTable .= ' | 门店名称';
        $strTable .= ' | 购买数量';
        $strTable .= ' | 购买时间';
        $strTable .= ' | 状态';
        $strTable .= ' | 
';
        if (is_array($redmoneylist)) {
            foreach ($redmoneylist as $k => $val) {
                $strTable .= '';
                $strTable .= '| ' . $val['order_sn'] . '';
                $strTable .= ' | ' . $val['nickname'] . '';
                $strTable .= ' | ' . $val['mobile'] . '';
                $strTable .= ' | ' . $val['pickup_name'] . '';
                $strTable .= ' | ' . $val['goods_num'] . '';
                $strTable .= ' | ' . date("Y-m-d H:i:s", $val['add_time']) . '';
                $strTable .= ' | ' . $val['order_status_desc'] . '';
                $strTable .= ' | 
';
            }
        }
        $strTable .= '
';
        echo $strTable;
        unset($redmoneylist);
        downloadExcel($strTable, '秒杀订单');
        exit();
    }
    //秒杀记录门店汇总
    public function flash_sale_storecount()
    {
        $pagenum = 20;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/s');
        }
        $p = I('p', 1);
        $begin = I('add_time_begin');
        $end = I('add_time_end');
        $getisend = I('isend');
        $this->assign('start_time', $begin);
        $this->assign('end_time', $end);
        $flashsaleid = I('flashsaleid');//ID
        $picksle = trim(I('picksle'));
        $pstype = I('picksle_type');
        $where = " a.store_id=" . getAdmStoId();
        $where .= " and  a.prom_type=1 and a.prom_id=" . $flashsaleid;
        if ($picksle) {
            if ($pstype)
                $where .= " AND c.pickup_name='" . $picksle . "'";
            else
                $where .= " AND c.pickup_no='" . $picksle . "'";
        }
        if ($begin) {
            $where .= " and b.add_time>=" . strtotime($begin);
        }
        if ($end) {
            $where .= " and b.add_time<=" . strtotime($end);
        }
        $order_status = I('order_status');
        if ($order_status != "") {
            switch ($order_status) {
                case 12:      //待付款
                    $condition['b.order_status'] = 0;
                    $condition['b.pay_status'] = 0;
                    break;
                case 1:      //待发货
                    $condition['b.pay_status'] = 1;
                    $condition['b.order_status'] = ['in', '0,1'];
                    $condition['b.shipping_status'] = 0;
                    break;
                case 11:     //待收货
                    $condition['b.order_status'] = 1;
                    I('shipping_status') != '' ? $condition['b.shipping_status'] = I('shipping_status') : $condition['shipping_status'] = ['in', '1,2']; //是否发货
                    break;
                case 2:     //已收货
                    $condition['b.order_status'] = 2;
                    break;
                case 3:      //已取消
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 4:      //已完成
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 5:      //已作废
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 6:      //已作废
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 13:      //已付款
                    $condition['b.pay_status'] = 1;
                    break;
            }
        }
        $qdrecord = M('order_goods');
        $count = $qdrecord->alias('a')
            ->join('order b', ' a.order_id=b.order_id', 'left')
            ->join('(select pickup_id,pickup_name,pickup_no from  wxd_pick_up where store_id=' . getAdmStoId() . ') c', 'c.pickup_id=b.pickup_id', 'left')
            ->where($where)
            ->where($condition)
            ->count('distinct b.pickup_id');
        $sumcount = $qdrecord->alias('a')
            ->join('order b', ' a.order_id=b.order_id', 'left')
            ->join('(select pickup_id,pickup_name,pickup_no from  wxd_pick_up where store_id=' . getAdmStoId() . ') c', 'c.pickup_id=b.pickup_id', 'left')
            ->where($where)
            ->where($condition)
            ->sum('a.goods_num');
        $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数
        $redmoneylist = $qdrecord->alias('a')
            ->join('order b', ' a.order_id=b.order_id', 'left')
            ->join('(select pickup_id,pickup_name,pickup_no from  wxd_pick_up where store_id=' . getAdmStoId() . ') c', 'c.pickup_id=b.pickup_id', 'left')
            ->where($where)
            ->where($condition)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->order('c.pickup_no asc')
            ->field('count(b.order_id) as ordernum,sum(a.goods_num) as warenum,b.pickup_id,c.pickup_name,c.pickup_no,sum(a.goods_num*a.goods_price) as goods_total_amount,sum(b.total_amount)all_total_amount,sum(order_amount+user_money)all_order_amount')
            ->group('b.pickup_id')
            ->select();// 查询满足要求的总记录数
        if ($p == 1 && $getisend == 1) {
            $falshinfo = M('flash_sale')->where(array('store_id' => getAdmStoId(), 'id' => $flashsaleid, 'is_end' => 1))->find();
            if ($falshinfo) {
                if ($falshinfo['buy_num'] != $sumcount) {
                    $updatedata['buy_num'] = $sumcount;
                }
                if ($falshinfo['order_num'] != $count) {
                    $updatedata['order_num'] = $count;
                }
                if ($updatedata) {
                    M('flash_sale')->where(array('store_id' => getAdmStoId(), 'id' => $flashsaleid, 'is_end' => 1))->save($updatedata);
                }
            }
        }
        $show = $Page->show();
        $this->assign('page', $show);
        $this->assign('sumcount', $sumcount);
        $this->assign('total', $count);
        $this->assign('flashsaleid', $flashsaleid);
        $this->assign('picksle', $picksle);
        $this->assign('pstype', $pstype);
        $this->assign('getorder_status', $order_status);
        $this->assign('redmoneylist', $redmoneylist);
        $this->assign('pagenum', $pagenum);
        $this->assign('timegap', date('Y-m-d h:m:s', $this->begin) . ' - ' . date('Y-m-d h:m:s', $this->end));
        return $this->fetch('', getAdmStoId());
    }
    /*秒杀门店汇总导出*/
    public function export_storecount()
    {
        $begin = I('add_time_begin');
        $end = I('add_time_end');
        $getisend = I('isend');
        $this->assign('start_time', $begin);
        $this->assign('end_time', $end);
        $flashsaleid = I('flashsaleid');//ID
        $picksle = trim(I('picksle'));
        $pstype = I('picksle_type');
        $where = " a.store_id=" . getAdmStoId();
        $where .= " and  a.prom_type=1 and a.prom_id=" . $flashsaleid;
        if ($picksle) {
            if ($pstype)
                $where .= " AND c.pickup_name='" . $picksle . "'";
            else
                $where .= " AND c.pickup_no='" . $picksle . "'";
        }
        if ($begin) {
            $where .= " and b.add_time>=" . strtotime($begin);
        }
        if ($end) {
            $where .= " and b.add_time<=" . strtotime($end);
        }
        $order_status = I('order_status');
        if ($order_status != "") {
            switch ($order_status) {
                case 12:      //待付款
                    $condition['b.order_status'] = 0;
                    $condition['b.pay_status'] = 0;
                    break;
                case 1:      //待发货
                    $condition['b.pay_status'] = 1;
                    $condition['b.order_status'] = ['in', '0,1'];
                    $condition['b.shipping_status'] = 0;
                    break;
                case 11:     //待收货
                    $condition['b.order_status'] = 1;
                    I('shipping_status') != '' ? $condition['b.shipping_status'] = I('shipping_status') : $condition['shipping_status'] = ['in', '1,2']; //是否发货
                    break;
                case 2:     //已收货
                    $condition['b.order_status'] = 2;
                    break;
                case 3:      //已取消
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 4:      //已完成
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 5:      //已作废
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 6:      //已作废
                    $condition['b.order_status'] = I('order_status');
                    break;
                case 13:      //已付款
                    $condition['b.pay_status'] = 1;
                    break;
            }
        }
        $qdrecord = M('order_goods');
        $redmoneylist = $qdrecord->alias('a')
            ->join('order b', ' a.order_id=b.order_id', 'left')
            ->join('(select pickup_id,pickup_name,pickup_no from  wxd_pick_up where store_id=' . getAdmStoId() . ') c', 'c.pickup_id=b.pickup_id', 'left')
            ->where($where)
            ->where($condition)
            ->order('c.pickup_no asc')
            ->field('count(b.order_id) as ordernum,sum(a.goods_num) as warenum,b.pickup_id,c.pickup_name,c.pickup_no,sum(a.goods_num*a.goods_price) as goods_total_amount,sum(b.total_amount)all_total_amount,sum(order_amount+user_money)all_order_amount')
            ->group('b.pickup_id')
            ->select();// 查询满足要求的总记录数
        $strTable = '';
        $strTable .= '';
        $strTable .= '| 门店编号';
        $strTable .= ' | 门店名称';
        $strTable .= ' | 订单数(笔)';
        $strTable .= ' | 购买总数(件)';
        $strTable .= ' | 应收总金额';
        $strTable .= ' | 
';
        if (is_array($redmoneylist)) {
            foreach ($redmoneylist as $k => $val) {
                $strTable .= '';
                $strTable .= '| ' . $val['pickup_no'] . '';
                $strTable .= ' | ' . $val['pickup_name'] . '';
                $strTable .= ' | ' . $val['ordernum'] . '';
                $strTable .= ' | ' . $val['warenum'] . '';
                $strTable .= ' | ' . $val['goods_total_amount'] . '';
                $strTable .= ' | 
';
            }
        }
        $strTable .= '
';
        echo $strTable;
        unset($redmoneylist);
        downloadExcel($strTable, '秒杀门店汇总');
        exit();
    }
    /*--历史订单删除--*/
    public function prom_order_history_del()
    {
        $id = I('del_id');
        if ($id) {
            $data['is_show'] = 0;
            $admid = getAdminId();
            $amdinfo = getAdminInfo($admid);
            $data['edit_man'] = $amdinfo['ERPName'];
            $data['edit_time'] = time();
            $data['edit_ip'] = getIP();
            M('prom_order')->where("id", $id)->where('store_id', getAdmStoId())->save($data);
            ClearALLCache();
            delFile(TEMP_PATH . "/" . getAdmStoId());
//            upload_ylp_log('历史删除');
            exit(json_encode(1));
        } else {
            exit(json_encode(0));
        }
    }
    /**
     * 商品活动列表
     */
    public function prom_goods_list()
    {
        /*--更新活动状态--*/
        $this->updategoodstype(3);
        //获取优惠券列表
        $pagenum = 10;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/d');
        }
        $key = urldecode(urldecode(I('key/s')));
        $type = I('type/d');
        $time = time();
        $condition['store_id'] = getAdmStoId();
        if (!empty($key)) {
            $condition['name'] = array('like', "%$key%");
        }
        if ($type == 1) {
            $condition['start_time'] = ['>', $time];
        }
        if ($type == 2) {
            $condition['start_time'] = ['<', $time];
        }
        $condition['is_end'] = 0;
        $count = M('prom_goods')->where($condition)->count();
        $Page = new Page($count, $pagenum);
        $show = $Page->show();
        $res = M('prom_goods')->where($condition)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
        if (!empty($res)) {
            foreach ($res as $k => $val) {
                if ($val['start_time'] > $time) {
                    $res[$k]['is_end'] = 1;
                }
            }
        }
        $this->assign('key', $key);
        $this->assign('type', $type);
        $this->assign('pager', $Page);
        $this->assign('page', $show);// 赋值分页输出
        $this->assign('pagenum', $pagenum);
        $this->assign('prom_list', $res);
//        upload_ylp_log('优惠促销');
        return $this->fetch('', 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 prom_goods_info2()
    {
        $level = M('user_level')->where("  store_id=" . getAdmStoId() . " ")->select();
        $this->assign('level', $level);
        $prom_id = I('id');
        $info['start_time'] = date('Y-m-d H:i:s');
        $info['end_time'] = date('Y-m-d H:i:s', time() + 3600 * 60 * 24);
        if ($prom_id > 0) {
            $info = M('prom_goods')->where("  store_id=" . getAdmStoId() . " and 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']);
            $gsid = M('activitylist')->where('prom_type=3 and act_id=' . $prom_id)->field('goods_listid')->find();
            $gsidarr = explode(',', $gsid['goods_listid']);
            $prom_goods = M('goods')->where('goods_id', 'in', $gsidarr)->select();
            $this->assign('prom_goods', $prom_goods);
        }
        $sql = "select * from __PREFIX__coupon where type=0 and store_id=" . getAdmStoId();
        $rdata = Db::query($sql);
        $this->assign('sql', $rdata);
        $this->assign('info', $info);
        $this->assign('isout', 1);
        $this->assign('min_date', date('Y-m-d'));
        $this->initEditor();
//        upload_ylp_log('查看');
        return $this->fetch('', getAdmStoId());
    }
    public function prom_goods_save()
    {
        ClearALLCache();
        delFile(TEMP_PATH . "/" . getAdmStoId());
        $prom_id = I('id');
        $data = I('post.');
        $data_list = $data['data'];
        unset($data['data']);
        $type = $data['prom_type'];
        unset($data['prom_type']);
        $data['start_time'] = strtotime($data['start_time']);
        $data['end_time'] = strtotime($data['end_time']);
        $data['store_id'] = getAdmStoId();
        $admid = getAdminId();
        $amdinfo = getAdminInfo($admid);
        $data['edit_man'] = $amdinfo['ERPName'];
        $good_list = '';
        if ($data['goods_id']) $good_list = implode(',', $data['goods_id']);
        if ($prom_id > 0) {
            M("goods")->where("prom_id=$prom_id and prom_type=3")->save(array('prom_id' => 0, 'prom_type' => 0));
        }
//        if ($data['end_time'] <= $data['start_time']) {
//            $this->error('结束时间必须大于结束时间');
//        }
//        if ($data['expression'] <= 0) {
//            $this->error('优惠必须大于0');
//        }
        /*---操作活动总表---*/
        $adata['edit_man'] = $amdinfo['ERPName'];
        $adata['prom_type'] = 3;
        if ($good_list)
            $adata['goods_listid'] = ',' . $good_list . ',';
        else
            $adata['goods_listid'] = '';
        $adata['is_show'] = 1;
        $adata['is_end'] = 0;
        $adata['warm_uptime'] = 0;
        $adata['s_time'] = $data['start_time'];
        $adata['e_time'] = $data['end_time'];
        $adata['prom_integral'] = 0;
        $adata['store_id'] = getAdmStoId();
        $adata['good_object'] = $data['good_object'];
        if ($prom_id > 0) {
            $data['edit_time'] = time();
            $data['edit_ip'] = getIP();
            M('prom_goods')->where("  store_id=" . getAdmStoId() . " and id=$prom_id")->save($data);
//            upload_ylp_log('修改了商品促销');
            adminLog("管理员修改了商品促销 " . I('name'));
            $adata['edit_time'] = $data['edit_time'];
            $adata['edit_man'] = $data['edit_man'];
            $adata['edit_ip'] = $data['edit_ip'];
            M('activitylist')->where('act_id', $prom_id)->where('prom_type', 3)->save($adata);
            foreach ($data_list as $v) {
                $id = $v['id'];
                unset($v['id']);
                $condition = $v['condition'];
                unset($v['condition']);
                if ($v['coupon'] == 0 || $v['is_coupon'] == 0) {
                    $v['coupon'] = $v['is_coupon'] = 0;
                }
                if ($v['money'] == 0 || $v['is_money'] == 0) {
                    $v['money'] = $v['is_money'] = 0;
                }
                if ($v['sale'] == 0 || $v['is_sale'] == 0) {
                    $v['sale'] = $v['is_sale'] = 0;
                }
                if ($v['int'] == 0 || $v['is_int'] == 0) {
                    $v['int'] = $v['is_int'] = 0;
                }
                if ($v['gift'] == 0 || $v['is_gift'] == 0) {
                    $v['gift'] = $v['is_gift'] = 0;
                }
                $json = json_encode($v);
                if ($id > 0) {
                    M('prom_goods_list')->where(['id' => $id, 'prom_id' => $prom_id])->save(['prom_type' => $type, 'condition' => $condition, 'preferential_type' => $json, 'edit_man' => $amdinfo['ERPName'], 'edit_ip' => getIP(), 'edit_time' => time()]);
                } else {
                    M('prom_goods_list')->save(['prom_id' => $prom_id, 'prom_type' => $type, 'add_time' => time(), 'edit_man' => $amdinfo['ERPName'], 'preferential_type' => $json, 'condition' => $condition]);
                }
            }
            upload_ylp_log('B22优惠促销编辑/确认提交');
        } else {
            unset($data['id']);
            $data['add_time'] = time();
            $data['add_ip'] = getIP();
            $prom_id = M('prom_goods')->add($data);
//            upload_ylp_log('添加了商品促销');
            adminLog("管理员添加了商品促销 " . I('name'));
            $adata['add_time'] = time();
            $adata['add_ip'] = getIP();
            $adata['act_id'] = $prom_id;
            M('activitylist')->save($adata);
            foreach ($data_list as $v) {
                unset($v['id']);
                $condition = $v['condition'];
                unset($v['condition']);
                if ($v['coupon'] == 0 || $v['is_coupon'] == 0) {
                    $v['coupon'] = $v['is_coupon'] = 0;
                }
                if ($v['money'] == 0 || $v['is_money'] == 0) {
                    $v['money'] = $v['is_money'] = 0;
                }
                if ($v['sale'] == 0 || $v['is_sale'] == 0) {
                    $v['sale'] = $v['is_sale'] = 0;
                }
                if ($v['int'] == 0 || $v['is_int'] == 0) {
                    $v['int'] = $v['is_int'] = 0;
                }
                if ($v['gift'] == 0 || $v['is_gift'] == 0) {
                    $v['gift'] = $v['is_gift'] = 0;
                }
                $json = json_encode($v);
                /*--优惠促销从表--*/
                $bdata[] = ['prom_id' => $prom_id, 'prom_type' => $type, 'add_time' => time(), 'edit_man' => $amdinfo['ERPName'], 'preferential_type' => $json, 'condition' => $condition];
            }
            M('prom_goods_list')->insertAll($bdata);
        }
        if (!empty($good_list)) {
            if ($data['good_object'] == 1) {
                M("goods")->where("goods_id in($good_list)")->save(array('prom_id' => $prom_id, 'prom_type' => 3));
            }
        }
        $this->success('编辑促销活动成功', U('Promotion/prom_goods_list'));
    }
    public function prom_goods_del()
    {
        $prom_id = I('id/d');
        Db::startTrans();
        try {
            $admid = getAdminId();
            $amdinfo = getAdminInfo($admid);
            $data['edit_man'] = $amdinfo['ERPName'];
            $data['edit_time'] = time();
            $data['edit_ip'] = getIP();
            $data['is_end'] = 1;
            $adata['edit_time'] = $data['edit_time'];
            $adata['edit_man'] = $data['edit_man'];
            $adata['edit_ip'] = $data['edit_ip'];
            $adata['is_end'] = 1;
            M('activitylist')->where(['act_id' => $prom_id, 'prom_type' => 3])->save($adata);
            /*---
            $order_goods = M('order_goods')->where("  store_id=".getAdmStoId()." and  prom_type = 3 and prom_id = $prom_id")->find();
                if (!empty($order_goods)) {
                    $this->error("该活动有订单参与不能删除!");
                }
            ----*/
            M("goods")->where("store_id=" . getAdmStoId() . " and  prom_id=$prom_id and prom_type=3")->save(array('prom_id' => 0, 'prom_type' => 0));
//      upload_ylp_log('删除商品促销活动');
            M('prom_goods')->where("store_id=" . getAdmStoId() . " and id=$prom_id")->save($data);
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            exit(json_encode(0));
        }
        ClearALLCache();
        delFile(TEMP_PATH . "/" . getAdmStoId());
        $this->success('删除活动成功', U('Promotion/prom_goods_list'));
    }
    /**
     * 活动列表
     */
    public function prom_order_list()
    {
        $this->updateprom_order();
        //获取优惠券列表
        $pagenum = 10;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/s');
        }
        $actname = I('actname');
        $prom_type = I('prom_type');
        $parse_type = array('0' => '直接打折', '1' => '减价优惠', '2' => '满额送积分', '3' => '满额送优惠券');
        $level = M('user_level')->where("  store_id=" . getAdmStoId() . " ")->select();
        if ($level) {
            foreach ($level as $v) {
                $lv[$v['level_id']] = $v['level_name'];
            }
        }
        $condition['store_id'] = getAdmStoId();
        $condition['is_end'] = 0;
        if (!empty($actname)) {
            $condition['name'] = array('like', "%$actname%");
        }
        if ($prom_type != "") {
            $condition['type'] = array('like', "%$prom_type%");
        }
        $count = M('prom_order')->where($condition)->count();
        $Page = new Page($count, $pagenum);
        $show = $Page->show();
        $res = M('prom_order')->where($condition)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        if ($res) {
            foreach ($res as $val) {
                if (!empty($val['group']) && !empty($lv)) {
                    $val['group'] = explode(',', $val['group']);
                    foreach ($val['group'] as $v) {
                        $val['group_name'] .= $lv[$v] . ',';
                    }
                }
                $prom_list[] = $val;
            }
        }
        $this->assign('pager', $Page);// 赋值分页输出
        $this->assign('page', $show);// 赋值分页输出
        $this->assign("parse_type", $parse_type);
        $this->assign('prom_list', $prom_list);
        $this->assign('pagenum', $pagenum);
        $this->assign('prom_type', $prom_type);
//        upload_ylp_log('订单促销');
        return $this->fetch('', getAdmStoId());
    }
    public function prom_order_info()
    {
        $this->assign('min_date', date('Y-m-d H:i:s'));
        $level = M('user_level')->where("  store_id=" . getAdmStoId() . " ")->select();
        $this->assign('level', $level);
        $prom_id = I('id');
        $info['start_time'] = date('Y-m-d H:i:s');
        $info['end_time'] = date('Y-m-d H:i:s', time() + 3600 * 24 * 60);
        if ($prom_id > 0) {
            $info = M('prom_order')->where("  store_id=" . getAdmStoId() . " and 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']);
        }
        $this->assign('info', $info);
        $this->assign('min_date', date('Y-m-d'));
        $this->initEditor();
        return $this->fetch('', getAdmStoId());
    }
    public function prom_order_save()
    {
        $prom_id = I('id');
        $data = I('post.');
        ClearALLCache();
        delFile(TEMP_PATH . "/" . getAdmStoId());
        $data['start_time'] = strtotime($data['start_time']);
        $data['end_time'] = strtotime($data['end_time']);
        if (!empty($data['group'])) {
            $data['group'] = implode(',', $data['group']);
        } else {
            $data['group'] = "";
        }
        $data['store_id'] = getAdmStoId();
        if ($data['end_time'] <= $data['start_time']) {
            $this->error('结束时间必须大于结束时间');
        }
        if ($data['expression'] <= 0) {
            $this->error('优惠必须大于0');
        }
        if (empty($prom_id)) {
            $rs = M('prom_order')
                ->where("is_end=0 and store_id=" . getAdmStoId() . " and end_time>=" . $data['end_time'] . " and start_time<=" . $data['end_time'])
                ->whereOr("is_end=0 and store_id=" . getAdmStoId() . " and end_time<=" . $data['end_time'] . " and end_time>=" . $data['start_time'])
                ->select();
            if ($rs) {
                $this->error('该时间段已经有订单活动,先修改时间');
            }
        } else {
            $rs = M('prom_order')
                ->where("is_end=0 and id<> " . $prom_id . " and store_id=" . getAdmStoId() . " and end_time>=" . $data['end_time'] . " and start_time<=" . $data['end_time'])
                ->whereOr("is_end=0 and id<> " . $prom_id . " and store_id=" . getAdmStoId() . " and end_time<=" . $data['end_time'] . " and end_time>=" . $data['start_time'])
                ->select();
            if ($rs) {
                $this->error('该时间段已经有订单活动,先修改时间');
            }
        }
        if ($prom_id) {
//          upload_ylp_log('修改了订单促销');
            upload_ylp_log('B23订单促销编辑/确认提交');
            $admid = getAdminId();
            $amdinfo = getAdminInfo($admid);
            $data['edit_man'] = $amdinfo['ERPName'];
            $data['edit_time'] = time();
            $data['edit_ip'] = getIP();
            M('prom_order')->where(" store_id=" . getAdmStoId() . " and id=$prom_id")->save($data);
            adminLog("管理员修改了商品促销 " . I('name'));
        } else {
            $data['add_time'] = time();
//            upload_ylp_log('添加了订单促销');
            M('prom_order')->add($data);
            adminLog("管理员添加了商品促销 " . I('name'));
        }
        $this->success('编辑促销活动成功', U('Promotion/prom_order_list'));
    }
    public function prom_order_del()
    {
        $prom_id = I('id');
        /*---
        $order = M('order')->where("  store_id=" . getAdmStoId() . " and order_prom_id = $prom_id")->find();
        if (!empty($order)) {
            $this->error("该活动有订单参与不能删除!");
        }--*/
        Db::startTrans();
        try {
            $admid = getAdminId();
            $amdinfo = getAdminInfo($admid);
            $data['edit_man'] = $amdinfo['ERPName'];
            $data['edit_time'] = time();
            $data['edit_ip'] = getIP();
            $data['is_end'] = 1;
            M('prom_order')->where(" store_id=" . getAdmStoId() . " and id=$prom_id")->save($data);
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            exit(json_encode(0));
        }
        ClearALLCache();
        delFile(TEMP_PATH . "/" . getAdmStoId());
        $this->success('删除活动成功', U('Promotion/prom_order_list'));
    }
    public function group_buy_list()
    {
        $this->updategoodstype(2);
        $pagenum = 10;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/s');
        }
        $actname = I('actname');
        $begin = strtotime(I('add_time_begin'));
        $end = strtotime(I('add_time_end'));
        if ($begin) {
            $condition['a.start_time'] = array('egt', $begin);
        }
        if ($end) {
            $condition['a.end_time'] = array('elt', $end);
        }
        $condition['a.store_id'] = getAdmStoId();
        if (!empty($actname)) {
            $condition['a.title|c.goods_sn|c.sku'] = array('like', "%$actname%");
        }
        $condition['is_end'] = 0;
        $count = M('group_buy')->alias('a')
            ->join('(select goods_id,goods_sn,sku from wxd_goods where store_id='.getAdmStoId().') c',' c.goods_id=a.goods_id','left')
            ->where($condition)->count();
        $Page = new Page($count, $pagenum);
        $show = $Page->show();
        $res = M('group_buy')->alias('a')
            ->join('(select goods_id,goods_sn,sku from wxd_goods where store_id='.getAdmStoId().') c',' c.goods_id=a.goods_id','left')
            ->where($condition)->limit($Page->firstRow . ',' . $Page->listRows)
            ->field('a.*,c.goods_sn,c.sku')
            ->order('a.ordid asc,a.id desc')->select();
        if ($res) {
            foreach ($res as $val) {
                $val['start_time'] = date('Y-m-d H:i:s', $val['start_time']);
                $val['end_time'] = date('Y-m-d H:i:s', $val['end_time']);
                $list[] = $val;
            }
        }
        $this->assign('list', $list);
        $show = $Page->show();
        $this->assign('page', $show);
        $this->assign('pager', $Page);
        $this->assign('pagenum', $pagenum);
//        upload_ylp_log('团购管理');
        return $this->fetch('', getAdmStoId());
    }
    public function group_buy()
    {
        $this->updategoodstype(2);
        $act = I('GET.act', 'add');
        $groupbuy_id = I('get.id');
        $group_info = array();
        $group_info['start_time'] = date('Y-m-d H:i:s');
        $group_info['end_time'] = date('Y-m-d H:i:s', time() + 3600 * 365);
        $group_info['store_id'] = getAdmStoId();
        if ($groupbuy_id) {
            $group_info = D('group_buy')->where(" store_id=" . getAdmStoId() . " and id=" . $groupbuy_id)->find();
            //是否开始
            $is_start=0;
            if( $group_info['start_time']