error("请先上传微信商户平台API证书",U("admin/Wechat/setting")); } //没有校验成功 $wx_user=M('wx_user')->where(array('store_id'=>$id))->field('check_json')->find(); if (empty($wx_user)) { $this->error("请选配置微信信息",U("admin/Wechat/setting")); exit(); } if (empty($wx_user['check_json'])) { $this->error("API证书未校验,请去校验",U("admin/Wechat/setting")); exit(); } $getcheck_json=json_decode($wx_user['check_json'],true); if ($getcheck_json['code']!=1) { $this->error("API证书校验不成功,请去更新",U("admin/Wechat/setting")); exit(); } $this->updategoodstype(); $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')); $kttype = I('kttype'); $where="1=1"; if ($begin) { $where.=' and a.start_time>'.$begin; } if ($end) { $where.=' and a.start_time<'.$end; } if ($kttype) { $condition['a.kttype'] = $kttype; } $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('teamlist')->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) ->where($where) ->count(); $Page = new Page($count, $pagenum); $show = $Page->show(); $res = M('teamlist')->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) ->where($where) ->limit($Page->firstRow . ',' . $Page->listRows) ->field('a.*,c.goods_sn,c.sku') ->order('a.ordid')->select(); foreach ($res as $kj=>$vj){ $w['store_id']=getAdmStoId(); $w['team_id']=$vj['id']; $tu=M('teamgroup')->where($w)->count(); $res[$kj]['kt_num']=$tu; if($vj['start_time']time()) $res[$kj]['state']='正在进行'; else $res[$kj]['state']='已经结束'; }else{ $res[$kj]['state']='还未开始'; } if( $res[$kj]['is_show']==0){$res[$kj]['state']='未启用';} } $this->assign('list', $res); $show = $Page->show(); $this->assign('page', $show); $this->assign('pager', $Page); $this->assign('pagenum', $pagenum); return $this->fetch('', getAdmStoId()); } //增加/修改 public function addinfo() { $id = getAdmStoId(); $dir=ROOT_PATH.'/public/cert/'.$id.'/apiclient_cert.pem'; //创建目录失败 if(!file_exists($dir)){ $this->error("请先上传微信商户平台API证书",U("admin/Wechat/setting")); } //没有校验成功 $wx_user=M('wx_user')->where(array('store_id'=>$id))->field('check_json')->find(); if (empty($wx_user)) { $this->error("请选配置微信信息",U("admin/Wechat/setting")); exit(); } if (empty($wx_user['check_json'])) { $this->error("API证书未校验,请去校验",U("admin/Wechat/setting")); exit(); } $getcheck_json=json_decode($wx_user['check_json'],true); if ($getcheck_json['code']!=1) { $this->error("API证书校验不成功,请去更新",U("admin/Wechat/setting")); exit(); } $act = I('GET.act', 'add'); $infoid = I('get.id'); $info = array(); $info['start_time'] = date('Y-m-d H:i:s'); $info['end_time'] = date('Y-m-d H:i:s', time() + 3600 * 365); $info['store_id'] = getAdmStoId(); $info["kttype"] = 1; $info["tz_yhjgtype"] = 1; $info["is_show"] = 1; if ($infoid) { $info = M('teamlist')->where(" store_id=" . getAdmStoId() . " and id=" . $infoid)->find(); $is_start=$info['start_time']assign('is_start', $is_start); $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']); $info['show_time'] = date('Y-m-d H:i:s', $info['show_time']); $act = 'edit'; $rt = M("goods")->where(array('store_id'=>getAdmStoId(),'goods_id'=>$info['goods_id']))->find(); if ($rt) { $info['goods_price']=$rt['shop_price']; $this->assign('storecount', $rt['store_count']); } } else { $maxinfo = M('teamlist')->where(" store_id=" . getAdmStoId())->field("IFNULL(max(ordid),0)+1 ordid,IFNULL(max(actno),1000000)+1 actno")->find(); if ($maxinfo) { $info["ordid"] = $maxinfo['ordid']; $info["actno"] = $maxinfo['actno']; } } if (IS_POST) { $data = I('post.'); $data_list = $data['data']; unset($data['data']); if ($data['kttype']==3) //阶梯团 { $data['ct_rylist']=json_encode($data_list); $data['price']=$data_list[0]['price']; $data['ct_num']=$data_list[0]['rynum']; } if ($data['show_time']) { $data['show_time'] = strtotime($data['show_time']); } else { $data['show_time'] = strtotime($data['start_time'] . " -1 day"); } $admid = getAdminId(); $amdinfo = getAdminInfo($admid); $data['end_time'] = strtotime($data['end_time']); $data['start_time'] = strtotime($data['start_time']); $data['store_id'] = getAdmStoId(); /*---操作活动总表---*/ $adata['edit_man'] = $amdinfo['ERPName']; $adata['prom_type'] = 6; $adata['prom_price'] = $data['price']; $adata['goods_listid'] = "," . $data['goods_id'] . ","; $adata['is_show'] = 1; $adata['is_end'] = 0; $adata['warm_uptime'] = $data['show_time']; $adata['s_time'] = $data['start_time']; $adata['e_time'] = $data['end_time']; $adata['prom_integral'] = 0; $adata['store_id'] = getAdmStoId(); $data['remark'] = nl2br($data['remark']); if (empty($data['id'])) { //--开启事务--- Db::startTrans(); try { $data['add_time'] = time(); $data['add_ip'] = getIP(); $adata['add_time'] = time(); $adata['add_ip'] = getIP(); $r = M('teamlist')->add($data); M('goods')->where("goods_id=" . $data['goods_id'])->save(array('prom_id' => $r, 'prom_type' => 6)); $adata['act_id'] = $r; M('activitylist')->save($adata); /*--- $count=M('users')->where('store_id',getAdmStoId())->count(); if($count>50000){ $email=C('s_email'); $sname=tpCache('shop_info.store_name',getAdmStoId()); $str_start=date('Y-m-d H:i:s', $data['start_time']); $str_end=date('Y-m-d H:i:s', $data['end_time']); $txt="商家名称:".$sname."
会员数量:".$count."
活动类型:天天拼单
活动名称:".$data['title']."
活动数量:".$data['goods_num']."件
活动时间:".$str_start." 到 ".$str_end; sendmail($email, '活动通知', $txt); }---*/ //先建拼单活动就设置队列 $redis = get_redis_handle(); $name = get_redis_name($r, 6, getAdmStoId()); $namec = $name . ":c"; $len = $redis->lLen($name); for ($i = 0; $i < ($data['goods_num']); $i++) { $redis->lPush($name, "pt" . $i); } F($namec, 1); Db::commit(); }catch(\Exception $e) { // 回滚事务 Db::rollback(); $this->error('添加活动失败', U('Team/index')); exit(); } $this->success('添加成功', U('Team/index')); exit(); } else { //如果保存前是开始时间大于当前时间 $rrp0 = M('teamlist')->where("id=" . $data['id']) ->where('store_id', getAdmStoId())->field('buy_num,start_time')->find(); /*---设置活动是秒杀销售量,当活动还没有开始的时候---*/ if($rrp0['start_time']>time()) { //$redis = new \Redis(); //$redis->connect(redisip, 6379); $redis=get_redis_handle(); //$name='pind'.$data['id'].'-'.getAdmStoId(); //$namec='pind'.$data['id'].'-'.getAdmStoId().'c'; $name=get_redis_name($data['id'],6,getAdmStoId()); $namec=$name.":c"; $len = $redis->lLen($name); if (empty($len)) { for ($i = 0; $i < ($data['goods_num'] - $rrp0['buy_num']); $i++) { $redis->lPush($name, "pt" . $i); } F($namec, 1); } else if ($len != ($data['goods_num'] - $rrp0['buy_num'])) { //$redis->delete($name); del_redis($redis,$name); for ($i = 0; $i < ($data['goods_num'] - $rrp0['buy_num']); $i++) { $redis->lPush($name, "pt" . $i); } F($namec, 1); } } $data['edit_time'] = time(); $data['edit_mark'] = "编辑抢购活动"; $data['edit_ip'] = getIP(); $adata['edit_time'] = $data['edit_time']; $adata['edit_ip'] = $data['edit_ip']; M('activitylist')->where('act_id', $data['id'])->where('prom_type', 6)->save($adata); $r = M('teamlist')->where("id=" . $data['id'])->save($data); M('goods')->where("prom_type=6 and prom_id=" . $data['id'])->save(array('prom_id' => 0, 'prom_type' => 0)); M('goods')->where("goods_id=" . $data['goods_id'])->save(array('prom_id' => $data['id'], 'prom_type' => 6)); $this->success('编辑成功', U('Team/index')); exit(); } } $this->assign('erpid', getERPId()); $this->assign('info', $info); $this->assign('list', json_decode($info['ct_rylist'],true)); $this->assign('act', $act); $this->assign('qclurl', QCLOUD_IMGURL); return $this->fetch('', getAdmStoId()); } //删除 public function info_del() { $prom_id = I('del_id/d'); $team0= M('teamlist')->where('id',$prom_id)->field('kttype')->find(); //--开启事务--- 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' => 6])->save($adata); M("goods")->where("store_id=" . getAdmStoId() . " and prom_id=$prom_id and prom_type=6") ->save(array('prom_id' => 0, 'prom_type' => 0)); M('teamlist')->where("store_id=" . getAdmStoId() . " and id=$prom_id")->save($data); Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); $this->error('删除活动失败', U('Team/index')); exit(); } ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $name='pind'.$prom_id.'-'.getAdmStoId(); $namec='pind'.$prom_id.'-'.getAdmStoId().'c'; /*---删除拼单活动缓存---*/ //$redis = new \Redis(); //$redis->connect(redisip, 6379); $redis=get_redis_handle(); //if($redis->exists($name)) $redis->delete($name); del_redis($redis,$name); m_clearC($namec); //会员团要清空团redis if($team0['kttype']==2){ $tg= M('teamgroup')->where('store_id',getAdmStoId())->where('team_id',$prom_id)->select(); foreach ($tg as $k1=>$v1){ //$name2 = 'pind'.$prom_id.'-'.$v1['actno'].getAdmStoId(); $name2 = get_redis_name($prom_id,6,getAdmStoId()).":".$v1['actno']; //$redis->delete($name2); del_redis($redis,$name2); } } $this->success('删除活动成功', U('Team/index')); } //开团列表 public function grouplist() { $this->updategoodstype(); $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); $actname = I('actname'); $teamid = I('teamid'); $state=I('state'); $where = " a.store_id=" . getAdmStoId(); $fytype=0; $fymoney=0; if ($teamid) { $where .= " and a.team_id=".$teamid; $ac=M("teamlist")->where('id',$teamid)->field('kttype,tz_yhjgtype,tz_yyhjg')->find(); if($ac){ $this->assign("ktty",$ac['kttype']); $fytype=$ac['tz_yhjgtype']; $fymoney=$ac['tz_yyhjg']; } } if ($actname) { $condition['a.listno'] =$actname; } if($state) { $condition['a.state'] =$state; } $qdrecord = M('teamgroup'); $count = $qdrecord->alias('a') ->where($where) ->where($condition) ->count(); $Page = $pager = new Page($count, $pagenum);// 实例化分页类 传入总记录数和每页显示的记录数 $grouplist = $qdrecord->alias('a') ->where($where) ->where($condition) ->limit($Page->firstRow . ',' . $Page->listRows) ->order('a.addtime desc') ->select();// 查询满足要求的总记录数 foreach ($grouplist as $kk=>$vv){ if($vv['openvipid']){ $usr=M("users")->where('user_id',$vv['openvipid'])->field('nickname')->find(); $grouplist[$kk]['openvipname']=$usr['nickname']; } else{ $grouplist[$kk]['openvipname']="商家团开团"; } //阶梯团和会员团都要显示 if($ac['kttype']==2 || $ac['kttype']==3 ){ $tz_odr = M('order')->alias('a') ->where('user_id',$vv['openvipid']) ->where('a.store_id', getAdmStoId()) ->where('a.pt_prom_id', $vv['team_id']) ->where('a.pt_listno', $vv['listno']) ->where('a.is_pt_tz', 1) ->field('a.order_amount,a.user_money,a.is_pt_rebate,a.order_status,a.pt_status,a.shipping_price') ->find(); } if($ac['kttype']==2) { if ($tz_odr) { switch ($fytype) { case 0: case 1: $grouplist[$kk]['fymoney'] = "无"; $grouplist[$kk]['fystate'] = "无"; break; case 2://免单处理 if ($tz_odr['order_status'] <> 3 && $tz_odr['order_status'] <> 5 && $tz_odr['order_status'] <> 6) { $grouplist[$kk]['fymoney'] = $tz_odr['order_amount'] + $tz_odr['user_money']-$tz_odr['shipping_price']; if ($tz_odr['is_pt_rebate']) $grouplist[$kk]['fystate'] = "已返佣"; else $grouplist[$kk]['fystate'] = "待返佣"; } break; case 3://返佣 if ($tz_odr['order_status'] <> 3 && $tz_odr['order_status'] <> 5 && $tz_odr['order_status'] <> 6) { $grouplist[$kk]['fymoney'] = $fymoney; if ($tz_odr['is_pt_rebate']) $grouplist[$kk]['fystate'] = "已返佣"; else $grouplist[$kk]['fystate'] = "待返佣"; } break; } }else{ $grouplist[$kk]['fymoney'] = "无"; $grouplist[$kk]['fystate'] = "无"; } }else{ $grouplist[$kk]['fymoney'] = "无"; $grouplist[$kk]['fystate'] = "无"; } $count=M('order') ->where('store_id',getAdmStoId()) ->where('pt_prom_id',$vv['team_id']) ->where('pt_listno',$vv['listno']) ->count(); $grouplist[$kk]['buynum']=$count; $str=""; switch($vv['state']){ case 1:$str= "拼团失败";break; case 2: if($ac['kttype']==1){ $str = "拼团进行中"; }else { if ($tz_odr['pt_status'] == 0) { $str = "待支付"; } else { $str = "拼团进行中"; } } break; case 3: $str="拼团成功";break; case 4: $str="拼团成功";break; case 5: $str="拼团成功";break; } $grouplist[$kk]['statestr']=$str; } $show = $Page->show(); $this->assign('page', $show); $this->assign('pager', $Page); $this->assign('pagenum', $pagenum); $this->assign('teamid', $teamid); $this->assign('grouplist', $grouplist); $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 updategoodstype() { $time = time(); $data = M("teamlist")->where(array('store_id' => getAdmStoId(), 'is_end' => 0, 'end_time' => ['<', $time])) ->select(); if($data) { //--开启事务--- Db::startTrans(); try { $pid = get_arr_column($data, 'id'); M("teamlist") ->where("id", 'in', $pid) ->where(array('store_id' => getAdmStoId(), 'is_end' => 0)) ->save(array('is_end' => 1)); M("activitylist")->where(array('store_id' => getAdmStoId(), 'prom_type' => 6)) ->where("act_id", 'in', $pid)->save(array('is_end' => 1)); if (!empty($data)) { foreach ($data as $val) { M('goods')->where(array('store_id' => getAdmStoId(), 'prom_type' => 6, 'prom_id' => $val['id'])) ->save(array('prom_type' => 0, 'prom_id' => 0)); //$name = 'pind' . $val['id'] . '-' . getAdmStoId(); //$namec = 'pind' . $val['id'] . '-' . getAdmStoId() . 'c'; $name = get_redis_name($val['id'], 6, getAdmStoId()); $namec = $name . ":c"; /*---删除秒杀活动缓存---*/ //$redis = new \Redis(); //$redis->connect(redisip, 6379); $redis = get_redis_handle(); //if ($redis->exists($name)) $redis->delete($name); del_redis($redis, $name); m_clearC($namec); //会员团要清空团redis if ($val['kttype'] == 2) { $tg = M('teamgroup')->where('store_id', getAdmStoId())->where('team_id', $val['id'])->select(); foreach ($tg as $k1 => $v1) { //$name2 = 'pind' . $val['id'] . '-' . $v1['actno'] . getAdmStoId(); $name2 = get_redis_name($val['id'], 6, getAdmStoId()) . ":" . $v1['actno']; //$redis->delete($name2); del_redis($redis, $name2); } } } } Db::commit(); } catch (\Exception $e) { mlog("错误".$e->getMessage(),"updategoodstype/".getAdmStoId()); // 回滚事务 Db::rollback(); } } } //拼单购买列表 public function buylist(){ $pid=I("pid"); $qh=I("qh"); $olist=M('order')->alias('a')->join('order_goods b','a.order_id=b.order_id') ->join('users c','a.user_id=c.user_id') ->where('a.store_id',getAdmStoId()) ->where('a.pt_prom_id',$pid) ->where('a.pt_listno',$qh) ->field('c.nickname,c.mobile,c.head_pic,a.order_sn,a.pay_sn,a.order_amount,a.user_money,a.tail_pay_type,a.pt_tail_money, a.pickup_id,a.address,a.province,a.city,a.district,a.twon,a.order_status,a.shipping_status,a.pay_status,a.pt_status,a.exp_type,a.order_id,a.pt_status,a.is_zsorder,a.pt_pay_time') ->select(); if($olist){ /*---获取地区---*/ $region_list = get_region_list(); foreach ($olist as $k=>$v){ $pk=M("pick_up")->where('store_id',getAdmStoId())->where('pickup_id',$v['pickup_id']) ->field('pickup_name')->find(); $olist[$k]['pickup_name']=$pk['pickup_name']; if($v['exp_type']==0){ $v['provicename'] = $region_list[$v['province']]['name']; $v['cityname'] = $region_list[$v['city']]['name']; $v['districtname'] = $region_list[$v['district']]['name']; $v['twonname'] = $region_list[$v['twon']]['name']; $olist[$k]['address']= $v['provicename']. $v['cityname'].$v['districtname'].$v['twonname'].$v['address']; } $u=M('return_goods')->where('order_id',$v['order_id'])->where('store_id',getAdmStoId())->find(); if($u){ $olist[$k]['rt']=$u; $olist[$k]['rt_state']=$u['status']; } } $this->assign('olist',$olist); } return $this->fetch('',getAdmStoId()); } //门店汇总 public function 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('teamid');//ID //$picksle=trim(I('picksle')); //$pstype=I('picksle_type'); $pickup_id=I("pickup_id"); $where = " a.store_id=" . getAdmStoId(); $where .= " and a.prom_type=6 and a.prom_id=" . $flashsaleid; $team=M('teamlist')->where('id',$flashsaleid)->where('store_id',getAdmStoId()) ->field('kttype')->find(); if($team){ $this->assign("kttype",$team['kttype']); } /*--- if($picksle){ if($pstype) $where .= " AND c.pickup_name='".$picksle."'"; else $where .= " AND c.pickup_no='".$picksle."'"; }---*/ if($pickup_id){ $where .= " AND c.pickup_id='".$pickup_id."'"; } 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: //已退款 $where.=" and (b.is_back=1 or b.order_status=6)"; break; case 13: //已付款 $where.=" and b.pay_time>0 and b.order_status<>3 and b.order_status<>5"; break; case 7: //待成团 $condition['b.pt_status'] =1; $condition['b.order_status'] = ['in','0,1']; break; case 8: //待支付尾款 $condition['b.pt_status'] =2; $condition['b.order_status'] = ['in','0,1']; $condition['b.is_zsorder'] = 4; 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(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('teamlist')->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('teamlist')->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 historylist(){ $this->updategoodstype(); $condition = array(); $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['a.is_end'] = 1; $condition['a.is_his_end'] = 0; $model = M('teamlist'); $count = $model->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(); $prom_list = $model ->alias('a') ->join('(select goods_id,goods_sn,sku from wxd_goods where store_id='.getAdmStoId().') c',' c.goods_id=a.goods_id','left') ->join('(select sum(a.goods_num) as sum_goods_num,a.prom_id from wxd_order_goods a left join wxd_order b on a.order_id=b.order_id where a.store_id='.getAdmStoId().' and a.prom_type=1 and b.pay_status=1 group by a.prom_id) b','a.id=b.prom_id','left') ->where($condition)->order("id desc")->limit($Page->firstRow . ',' . $Page->listRows) ->field('a.*,b.sum_goods_num,c.goods_sn,c.sku') ->select(); $this->assign('prom_list', $prom_list); $this->assign('page', $show);// 赋值分页输出 $this->assign('pager', $Page); $this->assign('pagenum', $pagenum); //upload_ylp_log('历史'); return $this->fetch('', getAdmStoId()); } public function search_goods() { $GoodsLogic = new GoodsLogic; $brandList = $GoodsLogic->getSortBrands(); $this->assign('brandList', $brandList); $categoryList = $GoodsLogic->getSortCategory(); $this->assign('categoryList', $categoryList); $where=""; $type = I('type', ''); if (!empty($type)) { $gift_list=M('gift')->where('is_end',0)->getfield('goods_id',true); if($gift_list) $where = 'is_on_sale = 1 and is_mainshow=1 and prom_type not in (1,2,4) and store_count>0 and store_id=' . getAdmStoId() . ' and goods_id not in ('.implode(',',$gift_list).')';//赠品的搜索条件 else $where = 'is_on_sale = 1 and is_mainshow=1 and prom_type not in (1,2,4) and store_count>0 and store_id=' . getAdmStoId();//赠品的搜索条件 } else { $where = 'is_on_sale = 1 and is_mainshow=1 and prom_type=0 and store_count>0 and store_id=' . getAdmStoId() . '';//搜索条件 } $intro = I('intro'); if (!empty($intro)) { $where = "$where and " . I('intro') . " = 1"; $this->assign('intro', $intro); } if (I('cat_id')) { $this->assign('cat_id', I('cat_id')); $grandson_ids = getCatGrandson(I('cat_id')); $where = " $where and cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件 } if (I('brand_id')) { $this->assign('brand_id', I('brand_id')); $where = "$where and brand_id = " . I('brand_id'); } $kword = urldecode(urldecode(I('keywords/s'))); if (!empty($kword)) { $this->assign('keywords', $kword); $where = "$where and (goods_sn like '%" . $kword . "%' or goods_name like '%" . $kword . "%' or keywords like '%" . $kword . "%' or sku = '" . $kword . "')"; } $t=time(); $where.=" and on_time<".$t." and (down_time>".$t." or down_time=0 or down_time='' or down_time is null)"; $count = M('goods')->where($where)->count(); $Page = new Page($count, 10); $goodsList = M('goods')->where($where)->order('goods_id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->select(); $show = $Page->show();//分页显示输出 $this->assign('page', $show);//赋值分页输出 $this->assign('goodsList', $goodsList); $this->assign('pager', $Page);//赋值分页输出 $tpl = "select_goods"; return $this->fetch($tpl, getAdmStoId()); } //拼单失败记录 public function fail_list(){ return $this->fetch("", getAdmStoId()); } public function ajax_fail_list(){ $stoid=getAdmStoId(); $where="1=1"; $timegap = I('timegap'); if($timegap){ $gap = explode('-', $timegap); $begin = strtotime($gap[0]); $end = strtotime($gap[1]); } if (I('add_time_begin') && I('add_time_end')) { //@new 新后台UI参数 $begin = strtotime(I('add_time_begin')); $end = strtotime(I('add_time_end')); } if($begin && $end){ $condition['a.add_time'] = array('between',"$begin,$end"); } $condition['a.store_id']= $stoid; $condition['a.order_status']= 3; //都是拼单失败的单 $where.=" and a.is_zsorder>1"; //是拼单订单的 $where.=" and a.pay_time>0"; //有支付的 $keywords = I('keywords','','trim'); if($keywords){ $where.=" and (a.order_sn like '%".$keywords."%' or b.mobile like '%".$keywords."%' or b.nickname like '%".$keywords."%')"; } $team_name=I("team_name"); if($team_name){$where.=" and (c.title like '%".$team_name."%')";} $qh=I("qh"); if($qh){ $condition['a.pt_listno']= $qh;} $money=I("money"); if($money){ $where.=" and (a.pt_tail_money+a.order_amount+a.user_money)=".$money; } $team_type=I("team_type"); if($team_type){ $where.=" and a.is_zsorder=".($team_type+1); } $pay_type=I("pay_type"); if($pay_type==1){$where.=" and a.order_amount>0";} if($pay_type==2){$where.=" and a.user_money>0";} $back_status=I('back_status'); if($back_status==1){ $where.=" and a.is_zsorder=4 and a.is_back=0 and back_err_json=''"; } if($back_status==2){ $where.=" and ((a.is_zsorder<4 and a.order_status=3) or a.is_back=1) and back_err_json=''"; } if($back_status==3){ $where.=" and back_err_json<>''"; } $count = M('order')->alias('a') ->join('(select nickname,mobile,head_pic,user_id from wxd_users where store_id='.$stoid.') b','a.user_id=b.user_id','left') ->join('(select id,title,actno from wxd_teamlist where store_id='.$stoid.') c','a.pt_prom_id=c.id','left') ->where($condition)->where($where)->count('a.order_id'); $Page = new AjaxPage($count,10); $sort_order="a.order_id desc"; //获取订单列表 $show = $Page->show(); $start=$Page->firstRow; $page_size=$Page->listRows; $orderList= M('order')->alias('a') ->join('(select nickname,mobile,head_pic,user_id from wxd_users where store_id='.$stoid.') b','a.user_id=b.user_id','left') ->join('(select id,title,actno from wxd_teamlist where store_id='.$stoid.') c','a.pt_prom_id=c.id','left') ->where($condition)->where($where) ->limit("$start,$page_size") ->order($sort_order) ->field('a.order_sn,a.add_time,a.order_amount,a.user_money,(a.order_amount+a.user_money+a.pt_tail_money) as buy_num,a.pay_status,a.order_status,a.is_zsorder,a.pt_status,a.pt_listno,a.is_back,a.back_err_json,b.mobile,b.nickname,b.head_pic,c.title,c.actno') ->select(); foreach ($orderList as $k=>$v){ $count=M('order_goods')->where('order_sn',$v['order_sn'])->sum('goods_num'); $orderList[$k]['goods_num']= $count; } $this->assign('orderList',$orderList); $this->assign('page',$show);// 赋值分页输出 $this->assign('pager',$Page); return $this->fetch("", getAdmStoId()); } //给未支付尾款的退钱 function return_order(){ $odr_sn=I('order_sn'); $od=M("order")->where('store_id',getAdmStoId()) ->where('order_sn',$odr_sn)->find(); if($od){ if($od['is_back']==1){ return json(['code'=>-1,'msg'=>'该订单已退过款']); } //如果是退款失败的订单 if($od['back_err_json']){ return $this->back_err_order($od,$od['back_err_json']); } //以下是拼单退款处理 include_once "plugins/payment/weixin/weixin.class.php"; $wx=new \weixin(); $uy=M("order")->where('store_id',getAdmStoId()) ->where('order_sn',$odr_sn) ->where('is_back<>1')->save(['is_back'=>1]); if($uy){ $v = $od; $stoid = $od['store_id']; $refund_type = tpCache('basic.refund_type', $stoid); $dd=null; //退到余额 if ($refund_type == 0) { $user_money = $v['order_amount'] + $v['user_money']; $sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id']; $rs1 = Db::execute($sql); if ($rs1) { if ($user_money > 0) { $odata['user_id'] = $v['user_id']; $odata['create_time'] = time(); $odata['money'] = $user_money; $odata['remark'] = "退款"; $odata['store_id'] = $v['store_id']; $odata['order_sn'] = $v['order_sn']; $odata['status'] = 1; $odata['type'] = 1; M('withdrawals')->save($odata); } } else { mlog($v['order_sn']."退款到余额失败,", 'refund/' . $stoid); $dd['user_money']=$user_money; } } //原路返回 else if ($refund_type == 1) { if ($v['order_amount'] > 0) { $ordno = $v['order_sn']; $total_fee = $v['order_amount']; $refund_fee = $total_fee; //$erpid = tpCache('shop_info.ERPId', $stoid); $path = BASE_PATH . 'public/cert/' . $stoid . '/'; try { $rs = $wx->refund2($ordno, $total_fee, $refund_fee, $path,$v['store_id'],null,$v['source_type']); if ($rs['return_code'] == 'FAIL') { $dd['weixin_err']=$rs['return_msg']; $dd['weixin']=$v['order_amount']; } } catch (\Exception $e) { mlog($v['order_sn']."退款签名失败," . $e->getMessage(), 'refund/' . $stoid); $dd['weixin_err']=$e->getMessage(); $dd['weixin']=$v['order_amount']; } } if ($v['user_money'] > 0) { $user_money = $v['user_money']; $sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id']; $rs1 = Db::execute($sql); if ($rs1) { if ($user_money > 0) { $odata['user_id'] = $v['user_id']; $odata['create_time'] = time(); $odata['money'] = $user_money; $odata['remark'] = "退款"; $odata['store_id'] = $v['store_id']; $odata['order_sn'] = $v['order_sn']; $odata['status'] = 1; $odata['type'] = 1; M('withdrawals')->save($odata); } } else { mlog($v['order_sn']."退款到余额失败,", 'refund/' . $stoid); $dd['user_money']=$v['user_money']; } } } if($dd) { $jsontxt=json_encode($dd); M("order")->where('order_id',$v['order_id'])->save(['back_err_json'=>$jsontxt]); $msg="退款失败"; if($dd['weixin_err']) $msg=$msg.$dd['weixin_err']; return json(['code'=>-1,'msg'=>$msg]); }else{ return json(['code'=>1,'msg'=>'退款成功']); } }else{ return json(['code'=>-1,'msg'=>'退款失败']); } }else{ return json(['code'=>-1,'msg'=>'未找到订单']); } } //拼单失败记录导出 public function fail_export(){ $stoid=getAdmStoId(); $where="1=1"; $timegap = I('timegap'); if($timegap){ $gap = explode('-', $timegap); $begin = strtotime($gap[0]); $end = strtotime($gap[1]); } if (I('add_time_begin') && I('add_time_end')) { //@new 新后台UI参数 $begin = strtotime(I('add_time_begin')); $end = strtotime(I('add_time_end')); } if($begin && $end){ $condition['a.add_time'] = array('between',"$begin,$end"); } $condition['a.store_id']= $stoid; $condition['a.order_status']= 3; //都是拼单失败的单 $where.=" and a.is_zsorder>1"; //是拼单订单的 $where.=" and a.pay_time>0"; //有支付的 $keywords = I('keywords','','trim'); if($keywords){ $where.=" and (a.order_sn like '%".$keywords."%' or b.mobile like '%".$keywords."%' or b.nickname like '%".$keywords."%')"; } $team_name=I("team_name"); if($team_name){$where.=" and (c.title like '%".$team_name."%')";} $qh=I("qh"); if($qh){ $condition['a.pt_listno']= $qh;} $money=I("money"); if($money){ $where.=" and (a.pt_tail_money+a.order_amount+a.user_money)=".$money; } $team_type=I("team_type"); if($team_type){ $where.=" and a.is_zsorder=".($team_type+1); } $pay_type=I("pay_type"); if($pay_type==1){$where.=" and a.order_amount>0";} if($pay_type==2){$where.=" and a.user_money>0";} $back_status=I('back_status'); if($back_status==1){ $where.=" and a.is_zsorder=4 and a.is_back=0"; } if($back_status==2){ $where.=" and ((a.is_zsorder<4 and a.order_status=3) or a.is_back=1)"; } $count = M('order')->alias('a') ->join('(select nickname,mobile,head_pic,user_id from wxd_users where store_id='.$stoid.') b','a.user_id=b.user_id','left') ->join('(select id,title,actno from wxd_teamlist where store_id='.$stoid.') c','a.pt_prom_id=c.id','left') ->where($condition)->where($where)->count('a.order_id'); $Page = new AjaxPage($count,10); $sort_order="a.order_id desc"; //获取订单列表 $show = $Page->show(); $start=$Page->firstRow; $page_size=$Page->listRows; $orderList= M('order')->alias('a') ->join('(select nickname,mobile,head_pic,user_id from wxd_users where store_id='.$stoid.') b','a.user_id=b.user_id','left') ->join('(select id,title,actno from wxd_teamlist where store_id='.$stoid.') c','a.pt_prom_id=c.id','left') ->where($condition)->where($where) ->limit("$start,$page_size") ->order($sort_order) ->field('a.order_sn,a.add_time,a.order_amount,a.user_money,(a.order_amount+a.user_money+a.pt_tail_money) as buy_num,a.pay_status,a.order_status,a.is_zsorder,a.pt_status,a.pt_listno,a.is_back,b.mobile,b.nickname,b.head_pic,c.title,c.actno') ->select(); foreach ($orderList as $k=>$v){ $count=M('order_goods')->where('order_sn',$v['order_sn'])->sum('goods_num'); $orderList[$k]['goods_num']= $count; } $strTable = ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; if (is_array($orderList)) { foreach ($orderList as $k => $val) { $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $ptye=""; if($val['order_amount']>0 && $val['user_money']> 0){ $ptye="微支付+余额"; } if($val['order_amount']>0 && $val['user_money']<=0){ $ptye="微支付"; } if($val['order_amount']<=0 && $val['user_money']> 0){ $ptye="余额"; } $strTable .= ''; $strTable .= ''; $dtype="已退款"; if($val['is_back']==0 && $val['is_zsorder']==4){ $dtype="未支付尾款"; } $strTable .= ''; $strTable .= ''; } } $strTable .= '
会员活动名称/编号团期编号订单号/微流水号金额/数量支付类型付款时间处理状态
' . $val['nickname'] . '
'. $val['mobile'].'
' . $val['title'] . '
'. $val['actno'].'
' . $val['pt_listno'] . '' . $val['order_sn'] . '
'. $val['pay_sn'].'
' . $val['buy_num'] . '
('. $val['goods_num'].'件)
' . $ptye . '' . date('Y-m-d H:i:s',$val['add_time']) . '' . $dtype . '
'; echo $strTable; unset($goodsList); downloadExcel($strTable, 'order'); exit(); } //拼单失败记录导出 public function export_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('teamid');//ID $picksle=trim(I('picksle')); $pstype=I('picksle_type'); $where = " a.store_id=" . getAdmStoId(); $where .= " and a.prom_type=6 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(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 .= ''; $strTable .= ''; if (is_array($redmoneylist)) { foreach ($redmoneylist as $k => $val) { $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; $strTable .= ''; } } $strTable .= '
门店编号门店名称订单数(笔)购买总件数(件)应收总金额实收总金额
$nbsp;' .$val['pickup_no'].'' . $val['pickup_name'] .' ' . $val['ordernum'] . '' . $val['warenum'] .'' . $val['all_total_amount']. '' . $val['all_order_amount']. '
'; echo $strTable; unset($goodsList); downloadExcel($strTable, 'order'); exit(); } //重新再退那些订单退款失败的订单 public function back_err_order($od,$back_err_json){ $uy=M("order")->where('store_id',getAdmStoId()) ->where('order_id',$od['order_id']) ->where("back_err_json<>''")->save(['back_err_json'=>'']); if($uy) { $v = $od; $ddstr = json_decode($back_err_json, true); $stoid = $v['store_id']; if ($ddstr['weixin']) { include_once "plugins/payment/weixin/weixin.class.php"; $wx = new \weixin(); $ordno = $v['order_sn']; $total_fee = $ddstr['weixin']; $refund_fee = $total_fee; $path = BASE_PATH . 'public/cert/' . $stoid . '/'; try { $rs = $wx->refund2($ordno, $total_fee, $refund_fee, $path, $stoid,null,$v['source_type']); if ($rs['return_code'] == 'FAIL') { $dd['weixin_err'] = $rs['return_msg']; $dd['weixin'] = $ddstr['weixin']; } } catch (\Exception $e) { mlog($v['order_sn'] . "退款签名失败," . $e->getMessage(), 'refund/' . $stoid); $dd['weixin_err'] = $e->getMessage(); $dd['weixin'] = $ddstr['weixin']; } } if ($ddstr['user_money']) { $user_money = $ddstr['user_money']; $sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id']; $rs1 = Db::execute($sql); if ($rs1) { if ($user_money > 0) { $odata['user_id'] = $v['user_id']; $odata['create_time'] = time(); $odata['money'] = $user_money; $odata['remark'] = "退款"; $odata['store_id'] = $v['store_id']; $odata['order_sn'] = $v['order_sn']; $odata['status'] = 1; $odata['type'] = 1; M('withdrawals')->save($odata); } } else { mlog($v['order_sn'] . "退款到余额失败,", 'refund/' . $stoid); $dd['user_money'] = $user_money; } } //如果退款失败要进行记录 if($dd) { M("order")->where('order_id', $v['order_id'])->save(['back_err_json' => json_encode($dd)]); $msg="退款失败"; if($dd['weixin_err']) $msg=$msg.$dd['weixin_err']; return json(['code'=>-1,'msg'=>$msg]); }else{ return json(['code'=>1,'msg'=>"退款成功"]); } } } //秒杀历史记录删除按钮 public function his_pt_buy_del() { $id = I('del_id'); if ($id) { $data['is_his_end'] = 1; $admid = getAdminId(); $amdinfo = getAdminInfo($admid); $data['edit_man'] = $amdinfo['ERPName']; $data['edit_time'] = time(); $data['edit_mark'] = "删除历史团购活动"; $data['edit_ip'] = getIP(); M('teamlist')->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)); } } }