0) { $pagenum=I('pagenum/s'); } $couponname = I('couponname'); $coupontype = I('coupontype'); $condition['store_id']=getAdmStoId(); if(!empty($couponname)){ $condition['name'] = array('like',"%$couponname%"); } if(!empty($coupontype)){ $condition['type'] = array('like',"%$coupontype%"); } $count = M('coupon')->where($condition)->count(); $Page = new Page($count,$pagenum); $show = $Page->show(); $lists = M('coupon')->where($condition)->order('add_time desc')->limit($Page->firstRow.','.$Page->listRows)->select(); $this->assign('lists',$lists); $this->assign('store_id',getAdmStoId()); $this->assign('pager',$Page);// 赋值分页输出 $this->assign('page',$show);// 赋值分页输出 $this->assign('coupons',C('COUPON_TYPE')); $this->assign('pagenum',$pagenum); // upload_ylp_log('优惠券'); return $this->fetch('',getAdmStoId()); } /* * 添加编辑一个优惠券类型 */ public function coupon_info(){ if(IS_POST){ ClearALLCache(); delFile(TEMP_PATH."/".getAdmStoId()); $data = I('post.'); $data['send_start_time'] = strtotime($data['send_start_time']); $data['send_end_time'] = strtotime($data['send_end_time']); $data['use_start_time'] = strtotime($data['use_start_time']); if($data['send_start_time'] > $data['send_end_time']){ $this->error('发放日期结束时间必须大于开始时间'); } //当有效时间为0,表示无限制 if($data['endtype']==1){ if(empty($data['days'])){ $data['use_end_time']=""; } } if ($data['use_end_time']!="") { $data['use_end_time'] = strtotime($data['use_end_time']); if($data['send_start_time'] > $data['use_end_time'] && $data['endtype']==0){ $this->error('使用日期结束时间必须大于开始时间'); } } if($data['money'] <= 0){ $this->error('优惠券面额必须大于0'); } if($data['money'] >= $data['condition']){ $this->error('优惠券面额不能大于等于消费金额'); } if (empty($data['useobjecttype'])) { $data['useobjectname']=""; $data['useobjectno']=""; $data['useobjectid']=""; } if(empty($data['id'])){ $data['store_id']=getAdmStoId(); $data['add_time'] = time(); // $finddata = M('coupon')->where(array('store_id'=>getAdmStoId(),'type'=>$data['type']))->find(); // if ($finddata) // { // $this->error('当前类型已添加,请返回列表进行编辑!'); // } // else { // $row = M('coupon')->add($data); // } // upload_ylp_log('添加优惠券'); $row = M('coupon')->add($data); }else{ // upload_ylp_log('修改优惠券'); $row = M('coupon')->where(array('store_id'=>getAdmStoId(),'id'=>$data['id']))->save($data); } if(!$row) $this->error('编辑失败或者没有做修改'); $this->success('编辑代金券成功',U('Admin/Coupon/index')); exit; } $cid = I('get.id/d'); $type = I('type/d',0); if($cid){ $coupon = M('coupon')->where(array('store_id'=>getAdmStoId(),'id'=>$cid))->find(); $this->assign('coupon',$coupon); }else{ if (empty($type)){ $def['type']=1;//默认优惠券类型 }else{ $def['type']=5; } $def['send_start_time'] = strtotime("+0 day"); $def['send_end_time'] = strtotime("+1 month"); $def['use_start_time'] = strtotime("+0 day"); $def['use_end_time'] = strtotime("+1 year"); $this->assign('coupon',$def); } $feemail=M('area_feemail')->where('store_id='.getAdmStoId())->order('id desc')->select(); $this->assign('feemail',$feemail); return $this->fetch('',getAdmStoId()); } /* * 优惠券发放 */ public function make_coupon(){ //获取优惠券ID $cid = I('get.id/d'); $type = I('get.type'); //查询是否存在优惠券 $data = M('coupon')->where(array('store_id'=>getAdmStoId(),'id'=>$cid))->find(); $remain = $data['createnum'] - $data['send_num'];//剩余派发量 if($remain<=0) $this->error($data['name'].'已经发放完了'); if(!$data) $this->error("优惠券类型不存在"); if($type != 4) $this->error("该优惠券类型不支持发放"); if(IS_POST){ ClearALLCache(); delFile(TEMP_PATH."/".getAdmStoId()); $num = I('post.num/d'); if($num>$remain) $this->error($data['name'].'发放量不够了'); if(!$num > 0) $this->error("发放数量不能小于0"); $add['cid'] = $cid; $add['type'] = $type; $add['send_time'] = time(); $add['store_id']=getAdmStoId(); for($i=0;$i<$num; $i++){ do{ $code = get_rand_str(8,0,1);//获取随机8位字符串 $check_exist = M('coupon_list')->where(array('store_id'=>getAdmStoId(),'code'=>$code))->find(); }while($check_exist); $add['code'] = $code; M('coupon_list')->add($add); } M('coupon')->where("id",$cid)->setInc('send_num',$num); // upload_ylp_log('发放优惠券'); adminLog("发放".$num.'张'.$data['name']); $this->success("发放成功",U('Admin/Coupon/index')); exit; } $this->assign('coupon',$data); return $this->fetch('',getAdmStoId()); } public function ajax_get_user(){ //搜索条件 $condition = array(); I('mobile') ? $condition['mobile'] = I('mobile') : false; I('email') ? $condition['email'] = I('email') : false; $nickname = I('nickname'); if(!empty($nickname)){ $condition['nickname'] = array('like',"%$nickname%"); } $condition['store_id']=getAdmStoId(); $model = M('users'); $count = $model->where($condition)->count(); $Page = new AjaxPage($count,10); foreach($condition as $key=>$val) { $Page->parameter[$key] = urlencode($val); } $show = $Page->show(); $userList = $model->where($condition)->order("user_id desc")->limit($Page->firstRow.','.$Page->listRows)->select(); $user_level = M('user_level')->where(" store_id=".getAdmStoId()."")->getField('level_id,level_name',true); $this->assign('user_level',$user_level); $this->assign('userList',$userList); $this->assign('page',$show); $this->assign('pager',$Page); return $this->fetch('',getAdmStoId()); } public function send_coupon(){ $cid = I('cid/d'); if(IS_POST){ ClearALLCache(); delFile(TEMP_PATH."/".getAdmStoId()); $level_id = I('level_id'); $user_id = I('user_id/a'); $insert = ''; $coupon = M('coupon')->where("id",$cid)->find(); if($coupon['createnum']>0){ $remain = $coupon['createnum'] - $coupon['send_num'];//剩余派发量 if($remain<=0) $this->error($coupon['name'].'已经发放完了'); } if(empty($user_id) && $level_id>=0){ if($level_id==0){ $user = M('users')->where(" store_id=".getAdmStoId()." and is_lock=0")->select(); }else{ $user = M('users')->where(" and store_id=".getAdmStoId()." and is_lock=0 and level_id=".$level_id."")->select(); } if($user){ $able = count($user);//本次发送量 if($coupon['createnum']>0 && $remain<$able){ $this->error($coupon['name'].'派发量只剩'.$remain.'张'); } foreach ($user as $k=>$val){ $time = time(); $insert[] = ['cid' => $cid, 'type' => 1, 'uid' => $val['user_id'], 'send_time' => $time,'store_id'=>getAdmStoId()]; } }else{ $this->error("未找到该等级的用户"); exit; } }else{ $able = count($user_id);//本次发送量 if($coupon['createnum']>0 && $remain<$able){ $this->error($coupon['name'].'派发量只剩'.$remain.'张'); } foreach ($user_id as $k=>$v){ $time = time(); $insert[] = ['cid' => $cid, 'type' => 1, 'uid' => $v, 'send_time' => $time,'store_id'=>getAdmStoId()]; } if(empty($insert)){ $this->error("未找到用户"); exit; } } DB::name('coupon_list')->insertAll($insert); M('coupon')->where("id",$cid)->setInc('send_num',$able); adminLog("发放".$able.'张'.$coupon['name']); // upload_ylp_log('发放优惠券'); $this->success("发放成功"); exit; } $level = M('user_level')->where(" store_id=".getAdmStoId()."")->select(); $this->assign('level',$level); $this->assign('cid',$cid); return $this->fetch('',getAdmStoId()); } public function send_cancel(){ } /* * 删除优惠券类型 */ public function del_coupon(){ ClearALLCache(); delFile(TEMP_PATH."/".getAdmStoId()); //获取优惠券ID $cid = I('get.id/d'); //查询是否存在优惠券 $row = M('coupon')->where(array('store_id'=>getAdmStoId(),'id'=>$cid))->delete(); if($row){ // upload_ylp_log('删除优惠券类型'); //删除此类型下的优惠券 M('coupon_list')->where(array('cid'=>$cid))->delete(); $this->success("删除成功"); }else{ $this->error("删除失败"); } } /* * 优惠券详细查看 */ public function coupon_list(){ //获取优惠券ID $cid = I('get.id/d'); //查询是否存在优惠券 $check_coupon = M('coupon')->field('id,type')->where(array('store_id'=>getAdmStoId(),'id'=>$cid))->find(); if(!$check_coupon['id'] > 0) $this->error('不存在该类型优惠券'); //查询该优惠券的列表的数量 $sql = "SELECT count(1) as c FROM __PREFIX__coupon_list l ". "LEFT JOIN __PREFIX__coupon c ON c.id = l.cid ". //联合优惠券表查询名称 "LEFT JOIN __PREFIX__order o ON o.order_id = l.order_id ". //联合订单表查询订单编号 "LEFT JOIN __PREFIX__users u ON u.user_id = l.uid WHERE l.cid = :cid and l.store_id=:store_id"; //联合用户表去查询用户名 $count = DB::query($sql,['cid' => $cid,'store_id'=>getAdmStoId()]); $count = $count[0]['c']; $Page = new Page($count,10); $show = $Page->show(); //查询该优惠券的列表 $sql = "SELECT l.*,c.name,o.order_sn,u.nickname FROM __PREFIX__coupon_list l ". "LEFT JOIN __PREFIX__coupon c ON c.id = l.cid ". //联合优惠券表查询名称 "LEFT JOIN __PREFIX__order o ON o.order_id = l.order_id ". //联合订单表查询订单编号 "LEFT JOIN __PREFIX__users u ON u.user_id = l.uid WHERE l.cid = :cid and l.store_id=:store_id". //联合用户表去查询用户名 " limit {$Page->firstRow} , {$Page->listRows}"; $coupon_list = DB::query($sql,['cid' => $cid,'store_id'=>getAdmStoId()]); $this->assign('coupon_type',C('COUPON_TYPE')); $this->assign('type',$check_coupon['type']); $this->assign('lists',$coupon_list); $this->assign('page',$show); $this->assign('pager',$Page); return $this->fetch('',getAdmStoId()); } /* * 删除一张优惠券 */ public function coupon_list_del(){ //获取优惠券ID $cid = I('get.id'); if(!$cid) $this->error("缺少参数值"); //查询是否存在优惠券 $row = M('coupon_list')->where(array('id'=>$cid,'store_id'=>getAdmStoId()))->delete(); if(!$row) $this->error('删除失败'); // upload_ylp_log('删除一张优惠券'); $this->success('删除成功'); } //统计 public function statistics() { $pagenum = 10;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $p = I('p/d', 1); $start = urldecode(I('start', date('Y-m-d H:i:s', strtotime('-1 month')))); $end = urldecode(I('end', date('Y-m-d H:i:s'))); $key = trim(urldecode(urldecode(I('key/s')))); $no = I('no/s'); $is = I('is/d'); $sum = I('sum/d'); $type = trim(urldecode(urldecode(I('type/s')))); //有账套 if (getERPId()) { $where['SendMan'] = ['in', '免费发放,注册发放,邀请发放,优惠活动']; if ($key) { $where['VIPName|MobileTel'] = ['like', '%' . $key . '%']; } if ($no) { $where['CashRepNo'] = ['like', '%' . $no . '%']; } if ($is) { $where['IsUse'] = $is - 1; } if ($type) { $where['SendMan'] = $type; } if ($sum) { $where['Sum'] = $sum; } $where['Billdate'] = ['between', [$start, $end]]; $tk['api_token']=tpCache("shop_info.api_token",getAdmStoId()); $res = getApiData("wxd.vip.cash.list.get", $tk['api_token'], null, $where, $p, $pagenum); $data = json_decode($res, true); $count = (int)$data['count']; $list = $data['data']; $Page = new Page($count, $pagenum); $show = $Page->show(); if (!empty($list)) { foreach ($list as $k => $v) { if ($v['BeginDate']) $list[$k]['BeginDate'] = substr($v['BeginDate'], 0, -4); if ($v['ValidDate']) $list[$k]['ValidDate'] = date('Y-m-d 23:59:59',strtotime($v['ValidDate'])); } session('excelstatistics_'.getAdmStoId(),$list); } }else { if ($key) { $where['b.nickname|b.vipname|b.mobile'] = ['like', '%' . $key . '%']; } if ($no) { $where['a.code'] = ['like', '%' . $no . '%']; } if ($is) { $where['a.is_user'] = $is - 1; } if ($type) { $where['a.remark'] = $type; } if ($sum) { $where['a.sum'] = $sum; } $where['a.send_time'] = ['between', [strtotime($start), strtotime($end)]]; $filed="a.code as CashRepNo,a.sum as Sum,a.buysum as BuySum,a.send_time as BillDate,a.remark as SendMan,a.is_user as IsUse,b.mobile as MobileTel,b.nickname,b.vipname as VIPName,a.begintime,a.validtime"; $model=M('coupon_list'); $count = $model->alias('a') ->join('users b','a.uid=b.user_id','left') ->where($where)->count(); $Page = $pager = new AjaxPage($count,$pagenum); $show = $Page->show(); $list = $model->alias('a') ->join('users b','a.uid=b.user_id','left') ->where($where)->order('send_time DESC') ->field($filed) ->limit($Page->firstRow.','.$Page->listRows) ->select(); if($list) { foreach ($list as $k => $v) { if ($v['begintime']) $list[$k]['BeginDate'] =date('Y-m-d',$v['begintime']); if ($v['validtime']) $list[$k]['ValidDate'] =date('Y-m-d 23:59:59',$v['validtime']); if ($v['BillDate']) $list[$k]['BillDate'] =date('Y-m-d h:i:s',$v['BillDate']); } session('excelstatistics_'.getAdmStoId(),$list); } } $this->assign([ 'start_time' => $start, 'pagenum' => $pagenum, 'end_time' => $end, 'key' => $key, 'no' => $no, 'is' => $is, 'sum' => $sum, 'type' => $type, 'pager' => $Page, 'page' => $show, 'list' => $list ]); return $this->fetch('', getAdmStoId()); } //会员管理导出 public function exportreport_statistics() { $res = session('excelstatistics_' . getAdmStoId()); $page=I('page/d',1); if (empty($res)) { return json(array('code' => -1, 'msg' => '无数据')); } $strTable = ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; if (is_array($res)) { foreach ($res as $k => $val) { $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; } } $strTable .= '
会员姓名手机券号券面值(元)需购买额(元)开始时间结束时间领取时间发放类型状态
 ' . $val['VIPName'] . ' ' . $val['MobileTel'] . '  ' . $val['CashRepNo'] . ' ' . $val['Sum'] . '' . $val['BuySum'] . '' . ($val['BeginDate']==""?'无限制':$val['BeginDate']) . '' . ($val['ValidDate']==""?'无限制':$val['ValidDate']) . '' . $val['BillDate'] . '' . $val['SendMan'] . '' . ($val['IsUse']==0?'未使用':'已使用') . '
'; echo $strTable; unset($res); downloadExcel($strTable, '优惠券领取记录'); exit(); } //season 20181026 选择性导入 public function useobjecttype() { $pagenum = 10; $type = I('type/d', 1); $parentclassno = I('parentclassno'); $this->assign('type', $type); $this->assign('pagenum', $pagenum); $this->assign('parentclassno', $parentclassno); return $this->fetch('', getAdmStoId()); } public function ajax_useobjecttype() { $pagenum = I('pagenum/d', 10); $type = I('type/d', 1); $page = I('p/d', 1); $parentclassno = I('parentclassno'); if (empty($parentclassno)) { $parentclassno="-1"; } $stoid = getAdmStoId(); $erpid = getERPId(); // $tk = tpCache('shop_info.api_token', $stoid); $keywords = I('keywords'); // $where=" ParentClassNo='".$parentclassno."'"; // // if ($keywords) { // $where.=" and cname like '%$keywords%'"; // } switch ($type) { case 1: $api_name='/api/erp/msg/brand/page'; break; case 2: $api_name='/api/erp/msg/class/page'; break; case 11: $api_name='/api/erp/msg/use/page'; break; case 12: $api_name='/api/erp/msg/otherWare/page'; break; } $wdata['ParentClassNo'] = urlencode($parentclassno); $wdata['CName'] = urlencode($keywords); $accdb = tpCache("shop_info.ERPId", $stoid); $res = getApiData_java($api_name, $accdb, $wdata, $page, $pagenum); // $res = getApiData($api_name, $tk, null, $where, $page, $pagenum); $data = json_decode($res, true); $brandlist=$data['data']['pageData']; $count=0; if ($data['data']['total']) { $count = $data['data']['total']; } $Page = new AjaxPage($count, $pagenum); $show = $Page->show();//分页显示输出 $this->assign('page', $show);//赋值分页输出 $this->assign('brandlist', $brandlist); $this->assign('pager', $Page);//赋值分页输出 $this->assign('type', $type); return $this->fetch('', getAdmStoId()); } }