assign('start_time',$begin); $this->assign('end_time',$end); if($timegap) { $this->begin = strtotime($begin); $this->end = strtotime($end); $this->assign('timegap',date('Y-m-d h:m:s',$this->begin).' - '.date('Y-m-d h:m:s',$this->end)); } $this->assign('ishis',$ishis); } public function index() { return $this->fetch('', getAdmStoId()); } /*--渲染商品--*/ function getGoods() { return $this->fetch('search', getAdmStoId()); } /*--访问接口选择商品--*/ public function SelectGood() { $p = I('p/d', 1); $key = trim(urldecode(I('key/s'))); if ($key) { $where['WareName|WareNo|BarCode'] = array('like', '%' . $key . '%'); } $getapi_token = tpCache('shop_info.api_token', getAdmStoId()); $erp_id=getERPId(); if (empty($erp_id)) //非ERP { $where['store_id'] = getAdmStoId(); $rs = M('goods')->where($where)->order('goods_id desc')->page("$p,20")->select(); if ($rs) { $data['code']=1; $data['msg']= "获取商品列表成功"; $data['count']=count($rs); foreach ($rs as $k => $v) { $data['data'][$k]['Id']= $v['goods_id']; $data['data'][$k]['WaresType']=$v['is_virtual']==1?2:0; $data['data'][$k]['WareNo']= $v['goods_sn']; $data['data'][$k]['WareName']= $v['goods_name']; $data['data'][$k]['BarCode']= $v['sku']; $data['data'][$k]['PosPrice'] = number_format(empty($v['market_price']) ? 0 : $v['market_price'], 2, ".", ""); $data['data'][$k]['VipPrice'] = number_format(empty($v['shop_price']) ? 0 : $v['shop_price'], 2, ".", ""); } return json($data); } else { return json(["code" => -1, "msg" => "无商品信息"]); } } else { $rs = getApiData('wxd.base.wares.list.get', $getapi_token, null, $where, $p, 10, null); mlog($rs, "good/" . getAdmStoId()); if ($rs) { $data = json_decode($rs, true); if ($data['data']) { foreach ($data['data'] as $k => $v) { $data['data'][$k]['PurPrice'] = number_format(empty($v['PurPrice']) ? 0 : $v['PurPrice'], 2, ".", ""); $data['data'][$k]['PosPrice'] = number_format(empty($v['PosPrice']) ? 0 : $v['PosPrice'], 2, ".", ""); $data['data'][$k]['VipPrice'] = number_format(empty($v['VipPrice']) ? 0 : $v['VipPrice'], 2, ".", ""); $data['data'][$k]['TradePrice'] = number_format(empty($v['TradePrice']) ? 0 : $v['TradePrice'], 2, ".", ""); } return json($data); } else { return json(["code" => -1, "msg" => "未找到您要搜索的商品"]); } } else { return json(["code" => -1, "msg" => "获取接口数据错误"]); } } } /*--渲染优惠券--*/ function getCp() { return $this->fetch('searchcp', getAdmStoId()); } /*--访问接口选择优惠券--*/ public function SelectCp() { $p = I('p/d', 1); $key = trim(urldecode(I('key/s'))); if($key) { $where['name|money|condition'] = array('like', '%' . $key . '%'); } $where['store_id'] = array('=', getAdmStoId()); $cptype = I('coupontype'); $w=" and ((endtype=0 and (use_end_time>".time()." or use_end_time=0)) or endtype=1)"; $w.= " and send_end_time>".time(); if($cptype){ $where['type'] = array('=',$cptype); } $count = M('coupon')->where($where)->where('type<>9 and type<>8 and type<>7 and type<>2 and type<>3'.$w)->count(); $Page = new Page($count,10); $show = $Page->show(); $data = M('coupon')->where($where)->where('type<>9 and type<>8 and type<>7 and type<>2 and type<>3'.$w) ->order('add_time desc')->limit($Page->firstRow.','.$Page->listRows)->select(); mlog(json_encode($data,true).' 记录数:'.$count.'页面:'.$Page->firstRow.','.$Page->listRows.' 条件:'.json_encode($where), "lbcp/" . getAdmStoId()); // upload_ylp_log('商品选择'); if ($data) { foreach ($data as $k => $v) { $data[$k]['use_end_time']=date('Y-m-d H:i:s', $v['use_end_time']); $data[$k]['use_start_time']=date('Y-m-d H:i:s', $v['use_start_time']); switch ($v['type']) { case 1: $data[$k]['type']='免费发放'; break; case 2: $data[$k]['type']='注册发放'; break; case 3: $data[$k]['type']='邀请发放'; break; case 5: $data[$k]['type']='优惠活动'; break; case 6: $data[$k]['type']='包邮券'; $data[$k]['money']='无'; break; default:break; } } return json(['code'=>1,"data"=>$data,'msg'=>'数据获取成功','count'=>$count]); } else { return json(["code" => -1, "msg" => "未找到您要搜索的优惠券"]); } } /** * 礼包列表 */ public function lblist() { //更新成为历史 $res=M('libao_form')->where(array('store_id' => getAdmStoId(), 'isdel' => 0, 'endtime' => ['<', time()]))->save(array('isdel' => 1)); $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $lbtype=I('lbtype') ? trim(I('lbtype')) : ''; // 礼包类型 $ishis=I('ishis'); $getp = I('p'); $pagenum = 10;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $oldurl = U('Admin/Libao/lblist', array( "key_word" => $key_word, "pagenum" => $pagenum, "p" => $getp, 'ishis'=>$ishis )); $this->assign('oldurl', urlencode($oldurl)); $this->assign('key_word', $key_word); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $getp); // $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 addlb() { $oldurl = I('oldurl/s'); if ($oldurl) { $oldurl = urldecode(urldecode($oldurl)); } $this->assign('oldurl', $oldurl); $type = I('id') > 0 ? 2 : 1; // 标识自动验证时的 场景 1 表示插入 2 表示更新 $islook=I('islook'); $this->assign('islook',$islook); if ($type == 2) { $getid = I('id'); $getpostdata["resourceId"] = $getid; $data = M('libao_form')->where(array('store_id'=>getAdmStoId(),'id'=>$getid))->select(); if ($data) { $data=$data[0]; $data['endtime'] = date('Y-m-d H:i:s', $data['endtime']); $data['startime'] = date('Y-m-d H:i:s', $data['startime']); $data['lburls']=QCLOUD_IMGURL.$data['lburl']; if($data['lbtype']==1) { $data1=M('libao_list')->where('lbid='.$getid)->select(); } else{//优惠券· $data1 = db::name('libao_list') ->alias('a') ->join('coupon b ', 'a.cpid=b.id', 'left') ->where('a.lbid='.$getid) ->field('a.goods_num,b.*') ->order('a.id desc') ->select(); foreach ($data1 as $k => $v) { $data1[$k]['use_end_time']=date('Y-m-d H:i:s', $v['use_end_time']); $data1[$k]['use_start_time']=date('Y-m-d H:i:s', $v['use_start_time']); switch ($v['type']) { case 1: $data1[$k]['type']='免费发放'; break; case 2: $data1[$k]['type']='注册发放'; break; case 3: $data1[$k]['type']='邀请发放'; break; case 5: $data1[$k]['type']='优惠活动'; break; case 6: $data1[$k]['type']='包邮券'; $data1[$k]['money']='无'; break; default:break; } } } $this->assign('goods',$data1); $this->assign('deatillp', $data); } } else{ $m = db::query("select max(sort_order)odr from __PREFIX__libao_form where store_id=". getAdmStoId()); $md = (int)$m[0]["odr"]; $md++; $data['startime'] = date('Y-m-d H:i:s'); $data['endtime'] = date('Y-m-d 23:59:59', time() + 3600 * 24 * 60); $data['sort_order']=$md; $this->assign('deatillp', $data); } //ajax提交验证 if (IS_POST) { $data = input('post.'); $lbid = $data['lbid']; // $resource['store_id'] = getAdmStoId(); $resource["lbtitle"] = $data['lbtitle']; $resource["startime"] = strtotime($data['startime']); $resource["endtime"] = strtotime($data['endtime']); $resource['lbtype']= $data['lbtype']; $resource["lburl"] = $data['lburl']; $resource['isgift']=$data['isgift']; $resource["lbprice"] = $data['lbprice']; $resource["oldprice"] = $data['oldprice']; $resource["lbintegral"] = $data['lbintegral']; $resource["num"] = $data['num']; $resource["limitnum"] = $data['limitnum']; $resource["usertype"] = $data['usertype']; $resource['codetype']=0; $resource["lbintro"] = $data['lbintro']; $resource["expday"] = $data['expday']; $resource["sort_order"] = $data['sort_order']; $resource["billdate"] = time(); //启动事务 db::startTrans(); try { if (empty($lbid)) { //插入 $result=M('libao_form')->add($resource); $lbid=$result; } else { M('libao_list')->where('lbid='.$lbid)->delete(); $result=M('libao_form')->where('id='.$lbid)->save($resource); } if ($result > 0) { // $return_arr = array( // 'status' => 1, // 'msg'=>'操作成功', // 'data' => array('url' => U('admin/Marketing/lblist')), // ); for($i=0;$iwhere('id='.$lbid)->save(array('codetype'=>1)); $lblist['state']=2; //有虚拟商品(服务按次) } else{ $lblist['state']=1; //实物 } $lblist['goods_sn']=$data['goods_sn'][$i]; $lblist['goods_name']=$data['goods_name'][$i]; $lblist['goods_code']=$data['goods_code'][$i]; $lblist['pos_price']=$data['pos_price'][$i]; } else { $lblist['state']=3; //优惠券 $lblist['cpid']=$data['cpid'][$i]; } $lblist['goods_num']=$data['goods_num'][$i]; $lblist['lbid']=$lbid; $lblist['store_id']=getAdmStoId(); $lblist['billdate']=time(); M('libao_list')->add($lblist); } $results=1; } Db::commit(); }catch (\Exception $e) { // 回滚事务 db::rollback(); // M('libao_form')->where('id='.$result)->delete(); } if($results){ $this->success('操作成功', U('admin/Libao/lblist')); exit; } else{ $this->error('操作失败'); exit; } upload_ylp_log('添加修改礼包'); // $this->ajaxReturn($return_arr); } return $this->fetch('_libin', getAdmStoId()); } /** * 礼包列表 */ public function ajaxlbList() { $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $lbtype=I('lbtype') ? trim(I('lbtype')) : ''; // 礼包类型 $begin = $this->begin; $end =$this->end; $ishis=I('ishis'); $cur_page = 1;//当前页数 if ((int)I('p/s') > 0) { $cur_page = I('p/s'); } $pagenum = 10;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $where['store_id'] = array('=',getAdmStoId()); if ($key_word !== "") { $where['lbtitle']=array('like','%'.$key_word.'%'); } if($lbtype!=="") { $where['lbtype']=array('=',$lbtype); } if ($begin) { $where['startime'] = array('egt', $begin); } if ($end) { $where['endtime'] = array('elt', $end); } if($ishis)//有值时为历史 { $where['isdel']=1; } else{ $where['isdel']=0; } $data1=M('libao_form')->where($where)->select(); $count = count($data1); $Page = new AjaxPage($count, $pagenum); $show = $Page->show(); $data=M('libao_form')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order(array('sort_order','billdate'=>'desc'))->select(); $oldurl = U('Admin/Libao/lbList', array( "key_word" => $key_word, "pagenum" => $pagenum, "p" => $cur_page )); $this->assign('oldurl', urlencode($oldurl)); $this->assign('key_word', $key_word); $this->assign('page', $show); $this->assign('pager', $Page); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $cur_page); //$this->assign('store_warning_storage',tpCache('basic.warning_storage', getAdmStoId())); // var_dump($data);die; $this->assign('goodsList', $data); return $this->fetch('', getAdmStoId()); } //删除礼包活动 public function dellb() { $id = $this->request->param('id'); //启动事务 db::startTrans(); try { M('libao_form')->where(array('store_id'=>getAdmStoId(),'id'=>$id))->save(array('isdel'=>1)); // M('libao_list')->where(array('store_id'=>getAdmStoId(),'lbid'=>$id))->delete(); Db::commit(); $return_arr = array( 'status' => 1, 'msg' => '操作成功', 'data' => array('url' => U('admin/Libao/lbList')), // 'data' => array('url' => $oldurl), ); }catch (\Exception $e) { // 回滚事务 db::rollback(); $return_arr = array( 'status' => 0, 'msg' => '删除失败', 'data' => array('url' => U('admin/Libao/lbList')), // 'data' => array('url' => $oldurl), ); } $this->ajaxReturn($return_arr); } //购买礼包记录 public function salelist() { $pagenum = 20;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $p = I('p', 1); $start_time=I('add_time_begin'); $end_time=I('add_time_end'); $begin = $this->begin; $end = $this->end; if(empty($start_time)) { $lastweek = date('Y-m-d',strtotime("-1 month"));//30天前 $start_time = $lastweek.' 00:00:00'; } if(empty($end_time)) { $end_time = I('end',date('Y-m-d')).' 23:59:59'; } $this->assign('start_time', $start_time); $this->assign('end_time', $end_time); $mobile = I('mobile');//手机号码 $order_sn = I('order_sn');//手机号码 $lbid = I('lbid');//礼包ID $this->assign('lbid',$lbid); $keyword=I('keyword');//关键字 if(empty($keyword)) $keyword=$mobile; // $picksle=trim(I('picksle')); // $pstype=I('picksle_type'); // $getisend=I('isend'); $where = " a.store_id=" . getAdmStoId(); // if (!empty($mobile)) { // $where .= " and c.mobile='" . $mobile . "' "; // } if($keyword) { $where.=" and (c.mobile='" . $keyword . "' or c.vipname like '%".$keyword."%') "; } if($lbid) { $where.=" and a.lbid=".$lbid; } // if($picksle){ // if($pstype) // $where .= " AND d.pickup_name='".$picksle."'"; // else // $where .= " AND d.pickup_no='".$picksle."'"; // } if ($start_time) { $start_time=urldecode($start_time); $where.=" and a.add_time>=".strtotime($start_time); } if ($end_time) { $end_time=urldecode($end_time); $where.=" and a.add_time<=".strtotime($end_time); } $lbtype=I('lbtype'); if($lbtype!="") { //$condition['b.lbtype'] = $lbtype; $where.=" and b.lbtype=".$lbtype; } $paytype=I('paytype'); switch($paytype) { case 3: //未付款 //$condition['fbillstate']=0; $where.=" and fbillstate=0 "; break; case 1: //积分兑换 $where.=" and a.fbillstate=1 and a.paytype=1 "; break; case 2: //微支付 $where.=" and a.fbillstate=1 and a.paytype=2 "; break; } //SELECT a.*,b.vipname,b.mobile,c.lbtype,c.lbtitle from wxd_libao_formvip a left join wxd_users b on a.user_id=b.user_id LEFT JOIN wxd_libao_form c on a.lbid=c.id //where a.store_id=1 ORDER BY a.id DESC $qdrecord = M('libao_formvip'); $count = $qdrecord->alias('a') ->join('libao_form b',' a.lbid=b.id','left') ->join('(select vipname,mobile,user_id from wxd_users where store_id='.getAdmStoId().') c',' a.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(); $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数 $redmoneylist = $qdrecord->alias('a') ->join('libao_form b',' a.lbid=b.id','left') ->join('(select vipname,mobile,user_id from wxd_users where store_id='.getAdmStoId().') c',' a.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('a.add_time desc') ->field('a.*,c.vipname,c.mobile,b.lbtype,b.lbtitle') ->select();// 查询满足要求的总记录数 $lblist=M('libao_form')->where('store_id='.getAdmStoId())->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('lblist',$lblist); $this->assign('p',$p-1); $this->assign('order_sn', $order_sn); // $this->assign('picksle', $picksle); // $this->assign('pstype', $pstype); $this->assign('lbtype', $lbtype); $this->assign('paytype',$paytype); $this->assign('keyword', $keyword); $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_salelist() { $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');//手机号码 $lbid = I('lbid');//礼包ID $this->assign('lbid',$lbid); $keyword=I('keyword');//关键字 // $picksle=trim(I('picksle')); // $pstype=I('picksle_type'); // $getisend=I('isend'); $where = " a.store_id=" . getAdmStoId(); // if (!empty($mobile)) { // $where .= " and c.mobile='" . $mobile . "' "; // } if($keyword) { $where.=" and (c.mobile='" . $keyword . "' or c.vipname like '%".$keyword."%') "; } if($lbid) { $where.=" and a.lbid=".$lbid; } // if($picksle){ // if($pstype) // $where .= " AND d.pickup_name='".$picksle."'"; // else // $where .= " AND d.pickup_no='".$picksle."'"; // } if ($begin) { $where.=" and a.add_time>=".strtotime($begin); } if ($end) { $where.=" and a.add_time<=".strtotime($end); } $lbtype=I('lbtype'); if($lbtype!="") { $condition['b.lbtype'] = $lbtype; } $paytype=I('paytype'); switch($paytype) { case 3: //未付款 $condition['fbillstate']=0; break; case 1: //积分兑换 $where.=" and a.fbillstate=1 and a.paytype=1 "; break; case 2: //微支付 $where.=" and a.fbillstate=1 and a.paytype=2 "; break; } $qdrecord = M('libao_formvip'); $redmoneylist = $qdrecord->alias('a') ->join('libao_form b',' a.lbid=b.id','left') ->join('(select vipname,mobile,user_id from wxd_users where store_id='.getAdmStoId().') c',' a.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('a.add_time desc') ->field('a.*,c.vipname,c.mobile,b.lbtype,b.lbtitle') ->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 .= ''; // $strTable .= ''; $strTable .= ''; if(is_array($redmoneylist)){ foreach($redmoneylist as $k=>$val){ $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; // $strTable .= ''; // $strTable .= ''; $strTable .= ''; // $strTable .= ''; $strTable .= ''; } } $strTable .='
序号礼包名称礼包类型会员昵称手机号门店名称购买数量购买时间状态
 '.($k+1).''.$val['lbtitle'].' '.($val['lbtype']==1?'礼品礼包':'礼券礼包').''.$val['vipname'].' '.$val['mobile'].''.$val['pickup_name'].' '.$val['goods_num'].' '.date("Y-m-d H:i:s",$val['add_time']).''.$val['order_status_desc'].'
'; echo $strTable; unset($redmoneylist); downloadExcel($strTable,'购买礼包记录'); exit(); } public function details() { $lbvipid=I('id'); $libao=M('libao_formvip') ->alias('a') ->join('libao_form b','a.lbid=b.id','left') ->where('a.id='.$lbvipid) ->field('a.*,b.lbtype') ->find(); if($libao['lbtype']==1) //礼品 { $list=M('libao_listvip')->where('lbvipid',$lbvipid)->select(); } else if($libao['lbtype']==2) //礼券 { $list=M('libao_listvip') ->alias('a') ->join('coupon b','a.goods_name=b.id','left') ->where('a.lbvipid='.$lbvipid) ->field('a.*,b.name,b.type') ->select(); } $this->assign('lbtype',$libao['lbtype']); $this->assign('isget',$libao['isget']); $this->assign('list',$list); return $this->fetch('', getAdmStoId()); } //核销码核销 public function getcodepro() { //测试 // $storageid=I('STORAGEID');//线下门店ID // $dbaccid=I('ACCID'); // $code=I('CODE'); // $storagename=''; // $operator=''; $code=I('code');//核销码 $wh['store_id']=getAdmStoId(); $wh['code']=$code; $rs=M('code_record')->where($wh)->field('id')->find(); if($rs){ $jsonres["state"] = 0; $jsonres["msg"] = "该核销码已核销"; return json($jsonres); } $admin=M("admin")->where('admin_id',getAdminId())->field('ERPName')->find(); $operator=$storagename=$admin['ERPName'];//线下门店 $store_id=getAdmStoId(); $tempcode=mb_substr($code, 0, 4); $sql=''; Db::startTrans(); try { if($tempcode==9007)//礼包核销 { $tempcode_next=mb_substr($code, 4, 1); if($tempcode_next==1 || $tempcode_next==2) { $list=M('libao_listvip')->where("store_id=".$store_id." and freebh='".$code."' and goods_num>usenum")->field('id,lbvipid,goods_name,goods_sn,goods_num,usenum,user_id,lb_state')->select(); if($list[0]) { $libaoindex=M('libao_formvip')->where('id',$list[0]['lbvipid'])->find(); if($libaoindex['expdate']>time()) { $libaoindex=M('libao_form')->where('id='.$libaoindex['lbid'].' and store_id='.$store_id)->find();//对应礼包活动 $user_id=$list[0]['user_id']; $res1=M('users')->where(array('store_id'=>$store_id,'user_id'=>$user_id))->find(); $jsonres['vipid']=$res1['erpvipid']; if($tempcode_next==1)//(礼包单个) { $libaoindex['lbprice']=0; // unset($list); $list1=M('libao_listvip')->where(array('freebh'=>$code))->field('goods_sn,1 as goods_num')->select(); Db::execute("update wxd_libao_listvip set usenum=usenum+1,admdate=".time()." where freebh='".$code."'"); $data1['code']=$code; $data1['user_id']=$user_id; $data1['store_id']=$store_id; $data1['billdate']=time(); $data1['proid']=$list[0]['id']; $data1['prodetails']=json_encode($list); $data1['storagename']=$storagename; $data1['operator']=$operator; M('code_record')->add($data1); } else if($tempcode_next==2)//(礼包全部) { // unset($list); $list1=M('libao_listvip')->where(array('freebh'=>$code))->field('goods_sn,goods_num')->select(); Db::execute("update wxd_libao_listvip set usenum=goods_num,admdate=".time()." where freebh='".$code."'"); Db::execute('update wxd_libao_formvip set isget=1 where id='.$list[0]['lbvipid']); $data1['code']=$code; $data1['user_id']=$user_id; $data1['store_id']=$store_id; $data1['billdate']=time(); $data1['proid']=$list[0]['id']; $data1['prodetails']=json_encode($list); $data1['storagename']=$storagename; $data1['operator']=$operator; M('code_record')->add($data1); } $jsonres["state"] = 1; $jsonres["msg"] = "获取成功!"; $jsonres["data"]=$list1; $jsonres['sum']=$libaoindex['lbprice']; $jsonres['actnumber']=$libaoindex['id']; $jsonres['actname']=$libaoindex['lbtitle']; } else{ $jsonres["state"] = -1; $jsonres["msg"] = "兑换时间已过期"; } } else{ unset($list); $list=M('code_record')->where(array('code'=>$code))->find(); if($list) { if($tempcode_next==1)//单个商品 { $libaoindex=M('libao_listvip')->where('id='.$list['proid'])->find(); $libaoindex=M('libao_formvip')->where('id='.$libaoindex['lbvipid'])->find(); $libaoindex=M('libao_form')->where('id='.$libaoindex['lbid'])->find(); $libaoindex['lbprice']=0; } else if($tempcode_next==2)//整个礼包 { $libaoindex=M('libao_formvip')->where('id='.$list['proid'])->find(); $libaoindex=M('libao_form')->where('id='.$libaoindex['lbid'])->find(); } $user_id=$list['user_id']; $res1=M('users')->where(array('store_id'=>$store_id,'user_id'=>$user_id))->find(); $jsonres['vipid']=$res1['erpvipid']; $list1=json_decode($list['prodetails'],true); foreach ($list1 as $k=>$vo) { $list2[$k]['goods_sn']=$vo['goods_sn']; if($tempcode_next==1) { $list2[$k]['goods_num']=1; } else { $list2[$k]['goods_num']=$vo['goods_num']; } } $jsonres["state"] = 0; $jsonres["msg"] = "该核销码已核销"; $jsonres['data']=$list2; $jsonres['sum']=$libaoindex['lbprice']; $jsonres['actnumber']=$libaoindex['id']; $jsonres['actname']=$libaoindex['lbtitle']; } else{ $jsonres["state"] = -1; $jsonres["msg"] = "找不到该核销码"; } } } else{ $jsonres["state"] = -1; $jsonres["msg"] = "请输入正确核销码"; } } else{ $jsonres["state"] = -1; $jsonres["msg"] = "请输入正确核销码"; } Db::commit(); }catch (\Exception $e) { // 回滚事务 Db::rollback(); mlog($e.message,'getcodepro'); $jsonres["state"] = -1; $jsonres["msg"] = "获取失败!"; } $jsonres['acttag']=$tempcode; mlog('返回值:'.json_encode($jsonres),'getcodepro'); return json($jsonres); } //礼包核销页面 public function lb_write_off(){ return $this->fetch('', getAdmStoId()); } public function lb_record_list(){ return $this->fetch('', getAdmStoId()); } public function ajax_lb_record_list(){ $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $key_word2 = I('libaoming') ? trim(I('libaoming')) : ''; // 礼包名称 $begin = $this->begin; $end =$this->end; $cur_page = 1;//当前页数 if ((int)I('p/s') > 0) { $cur_page = I('p/s'); } $pagenum = 10;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $where['a.store_id'] = array('=',getAdmStoId()); if ($key_word !== "") { $where['a.code']=array('like','%'.$key_word.'%'); } if ($key_word2 !== "") { $where['d.lbtitle']=array('like','%'.$key_word2.'%'); } if ($begin) { $where['a.billdate'] = array('egt', $begin); } if ($end) { $where['a.billdate'] = array('elt', $end); } $count = M('code_record') ->alias('a')->join('libao_listvip b','a.proid=b.id') ->join('libao_formvip c','c.id=b.lbvipid') ->join('libao_form d','c.lbid=d.id') ->where($where)->count(); $Page = new AjaxPage($count, $pagenum); $show = $Page->show(); $data=M('code_record') ->alias('a')->join('libao_listvip b','a.proid=b.id') ->join('libao_formvip c','c.id=b.lbvipid and a.store_id=c.store_id') ->join('libao_form d','c.lbid=d.id and a.store_id=c.store_id') ->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('billdate desc') ->field('a.*,d.lbtitle') ->select(); $oldurl = U('Admin/Libao/lbList', array( "key_word" => $key_word, "pagenum" => $pagenum, "p" => $cur_page )); $this->assign('oldurl', urlencode($oldurl)); $this->assign('key_word', $key_word); $this->assign('page', $show); $this->assign('pager', $Page); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $cur_page); $this->assign('goodsList', $data); return $this->fetch('', getAdmStoId()); } public function lb_wf_ajax(){ $code=I('code');//核销码 $wh['store_id']=getAdmStoId(); $wh['code']=$code; $rs=M('code_record')->where($wh)->field('id')->find(); if($rs){ return -1; } $tempcode=mb_substr($code, 0, 4); $store_id=getAdmStoId(); if($tempcode==9007)//礼包核销 { $tempcode_next = mb_substr($code, 4, 1); if ($tempcode_next == 1 || $tempcode_next == 2) { $list = M('libao_listvip')->where("store_id=" . $store_id . " and freebh='" . $code . "' and goods_num>usenum")->field('goods_name,goods_sn,goods_num,usenum,lb_state')->select(); if ($list) { $this->assign("libao_list", $list); return $this->fetch('', getAdmStoId()); } } } return "-1"; } public function show_gd(){ $id=I('id'); $cd=M('code_record')->where('id',$id)->field('prodetails')->find(); if($cd){ $data=json_decode($cd['prodetails'],true); $this->assign('goodlist',$data); } return $this->fetch('', getAdmStoId()); } }