".$start_time; if($end_time) $where0.=" and a.billdate<".$end_time; $is_usererp = I('is_usererp/s'); if ($is_usererp !=""){ if($is_usererp==1) { $where['a.erpid']=array('neq',''); } else { $where['a.erpid']=array('exp','is null'); } } $count = M('storage_recharge')->alias('a') ->join('storage_renew b','a.store_id=b.store_id and a.type=4 and a.id=b.rec_id','left') ->join('store s','a.store_id=s.store_id','left') ->where($where)->where($where0)->count('a.id'); $sumbuy_money = M('storage_recharge')->alias('a') ->join('storage_renew b','a.store_id=b.store_id and a.type=4 and a.id=b.rec_id','left') ->join('store s','a.store_id=s.store_id','left') ->where($where)->where($where0)->sum('a.buy_money'); $Page = $pager = new Page($count, 10); $show = $Page->show(); $list = M('storage_recharge')->alias('a') ->join('storage_renew b','a.store_id=b.store_id and a.type=4 and a.id=b.rec_id','left') ->join('store s','a.store_id=s.store_id','left') ->join('distri_price c','a.distri_price_id=c.id','left') ->where($where)->where($where0)->limit($Page->firstRow . ',' . $Page->listRows) ->field('a.*,b.pernum,b.add_time as b_time,b.end_time as e_time,c.user_num,s.reg_mobile') ->order('a.id desc') ->select(); foreach ($list as $k=>$v){ if($v['dj_price_id']>0) { $r4 = M('dj_price')->where('id',$v['dj_price_id'])->find(); $list[$k]['dj_num']=$r4['user_num']; }else{ $list[$k]['dj_num']=0; } } $old_url=U('Manager/Payment/index',array( 'no' => $no, 'type' => $type, 'erp' => $erp, 'start'=>$start, 'end'=>$end, 'p'=>I('p/d') )); $this->assign([ 'list' => $list, 'page' => $show, 'sumbuy_money' => $sumbuy_money, 'pager' => $pager, 'no' => $no, 'type' => $type, 'erp' => $erp, 'start'=>$start, 'end'=>$end, 'old_url'=>urlencode($old_url) ]); return $this->fetch(); } public function recharge_info() { if (IS_POST) { $data = I('post.'); $stoid=$data['store_id']; $gettimetype=I('timetype/d',1); $gettimevalue=I('timevalue/d',1); $manager_id = session('manager_id'); $name = M('manager_admin')->where('manager_id', $manager_id)->field('manager_name')->find()['manager_name']; $time = time(); $data['billdate'] = $time; $data['admin_id'] = $manager_id; $data['admin_man'] = $name; $addtime='+'.$gettimevalue.' year'; switch ($gettimetype) { case 1: $addtime='+'.$gettimevalue.' year'; break; case 2: $addtime='+'.$gettimevalue.' month'; break; case 3: $addtime='+'.$gettimevalue.' day'; break; case 4: $addtime='+'.$gettimevalue.' hour'; break; default: break; } $ttyy=$data['type'] ; if ($ttyy == 2) { $data['add_time'] = $time; $data['end_time'] = strtotime($addtime); $data['month_num'] = 0; } if($ttyy == 1 ){ $data['distri_price_id'] = I("moneytype"); //把到期时间弄到模块到期时间表 $stoid=$data['store_id']; $rs0=M("store_module_endtime") ->where('store_id',$stoid)->where('type',2)->find(); if($rs0){ $time2=0; if($rs0['end_time']>time()){ $time2=strtotime($addtime,$rs0['end_time']); }else{ $time2=strtotime($addtime,time()); } $data['end_time']=$time2; }else{ $time2=$addtime; $data['end_time']=$time2; } } if($ttyy == 5 ){ $data['type']=8; $data['dj_price_id'] = I("moneytype"); //把到期时间弄到模块到期时间表 $stoid=$data['store_id']; $rs0=M("store_module_endtime") ->where('store_id',$stoid)->where('type',3)->find(); if($rs0){ $time2=0; if($rs0['end_time']>time()){ $time2=strtotime($addtime,$rs0['end_time']); }else{ $time2=strtotime($addtime,time()); } $data['end_time']=$time2; }else{ $time2=strtotime($addtime); $data['end_time']=$time2; } } if($ttyy == 3 || $ttyy == 4 || $ttyy == 6 || $ttyy == 7){ $tyy=0; if($ttyy==3) $tyy=0; //自定义模板 if($ttyy==4) $tyy=1; //送礼神器 if($ttyy==6) $tyy=4; //京东到家 if($ttyy==7) $tyy=5; //京东到家 $rr=M('store_module_endtime')->where(array('store_id'=>$stoid,'type'=>$tyy,'is_sy'=>0))->find(); if($rr){ $data['add_time'] = $time; $data['end_time'] = strtotime($addtime,$rr['end_time']); }else{ $data['add_time'] = $time; $data['end_time'] = strtotime($addtime); } if ($data['type']==4) { $data['type']=7; } else if ($data['type']==6){ $data['type']=10; } else if ($data['type']==7){ $data['type']=11; } else { $data['type']=6; } $data['distri_price_id'] = I("moneytype"); } $id = M('storage_recharge')->add($data); if($ttyy==1){ $rss= M('store_distribut')->where('store_id',$data['store_id'])->find(); if($rss) { M('store_distribut')->where('store_id', $data['store_id'])->save(['switch' => 1]);//自动开启分销 }else{ M('store_distribut')->save(['switch' => 1,'store_id'=>$data['store_id']]); } $u = M('distri_price')->where('id', I("moneytype"))->find(); $num = $u['user_num']; $map = [ 'store_id' => $data['store_id'], ]; $r2 = M('store_distribut') ->where($map) ->save(['distribut_num' => $num]); //把到期时间弄到模块到期时间表 $where='type=2'; //0自定义模板 1送礼 2分销 $rh=M("store_module_endtime")->where('store_id',$stoid)->where($where)->find(); if($rh){ $dd['end_time']=$data['end_time']; $dd['is_sy']=0; M("store_module_endtime")->where('store_id',$stoid)->save($dd); }else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = $data['end_time']; $data0['is_sy'] = 0; $data0['type'] = 2; //2是分销 $rh=M("store_module_endtime")->save($data0); } } //当是等级卡的时候 if($ttyy==5){ $map = ['store_id'=> $data['store_id'],]; $r2 = M('store_config')->where($map)->field('dj_num')->find(); //开启接口 if(empty($r2['dj_num'])){ //开启erp开关 $tk = M("store")->where("store_id", $data['store_id'])->field("api_token")->find(); $data['IsMem']=1; $mrs = getApiData("wxd.base.sys.edit", $tk['api_token'],array($data)); $rank_switch=json_decode($r2['switch_list'],true);; $rank_switch['rank_switch']=2; $rs2 = M('store_config')->where($map) ->save(['switch_list' => json_encode($rank_switch)]); } $u=M('dj_price')->where('id',I("moneytype"))->find(); $num = $u['user_num']; $r2 = M('store_config')->where($map) ->save(['dj_num' => $num]); //把到期时间弄到模块到期时间表 $where='type=3'; //0自定义模板 1送礼 2分销 3等级卡 $rh=M("store_module_endtime")->where('store_id',$stoid)->where($where)->find(); if($rh){ $dd['end_time']=$data['end_time']; $dd['is_sy']=0; M("store_module_endtime")->where('store_id',$stoid)->save($dd); }else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = $data['end_time']; $data0['is_sy'] = 0; $data0['type'] = 3; //2是分销 3等级卡 $rh=M("store_module_endtime")->save($data0); } } if ($ttyy == 2) { $da['erpid'] = $data['erpid']; $da['store_id'] = $data['store_id']; $da['store_name'] = $data['store_name']; $da['add_time'] = $time; $da['end_time'] = $data['end_time']; $da['fromid'] = $id; $da['per_money'] = $data['buy_money']/$data['buy_num'] ; for ($i = 0; $i < $data['buy_num']; $i++) { $detail[] = $da; } M('storage_recharge_detail')->insertAll($detail); } //自定义模板和送礼神器 if ($ttyy==3 || $ttyy==4 || $ttyy==6 || $ttyy==7){ $tyy=0; if($ttyy==3){ $tyy=0; }else if($ttyy==4){ $tyy=1; } else if($ttyy==6){ $tyy=4; } else if($ttyy==7){ $tyy=5; } //自定义模板收费 $stoid=$data['store_id']; $rh=M("store_module_endtime")->where('store_id',$stoid)->where('type',$tyy)->find(); if($rh){ $dd['is_sy']=0; $et=$rh['end_time']; if($et>time()) $dd['end_time']=strtotime($addtime,$et); else $dd['end_time']=strtotime($addtime); M("store_module_endtime")->where('store_id',$stoid)->save($dd); }else { $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] =strtotime('+1 year'); $data0['is_sy'] = 0; $data0['type'] = $tyy; $rh=M("store_module_endtime")->save($data0); } } if ($id) { $this->success('操作成功', U('payment/index')); /*--- $wareid=""; if($ttyy==1){ $wareid="76D69994-6077-4D84-AAE6-F1331AC75066"; //分销 }else if($ttyy==2){ $wareid="124C8E53-5933-4C69-924A-154545DFAB6C"; //在线客服 }else if($ttyy==3){ $wareid='45D4CE52-E1DF-4E2F-90B9-C9078B2CE140'; //模板 } //待入OA接口 $pd['number']=$cs[0]['recharge_no']; $pd['billdate']=$cs[0]['recharge_no']; $pd['alipay_trade_no']=$cs[0]['recharge_no']; $pd['Operator']=urlencode('支付完成'); $pd['CustId']=$cs[0]['erpid']; $pd['WareId']=$wareid; //接口要带入的商品ID $pd['Serial']=1; //序列 $pd['Qty']=$cs[0]['buy_num']; //购买数量 $pd['price']=$cs[0]['buy_money'];//购买金额 $pd['ExpMan']='';//购买金额 $pd['Exptel']='';//购买金额 $pd['ExpAddress']='';//购买金额 $pd['remark']='';//购买金额 $pdd[]=$pd; mlog('post:'.json_encode($pdd),'notify/'.$cs[0]['erpid']); $url="http://em.it250.cn:6081/data/exec?access_token=wxdoa.trade.add&token=CE4416DC64C6C5B9A4247579555A2FF1"; http_post_json($url,json_encode($pdd));---*/ } else { $this->error('操作失败'); } } $url=urldecode(urldecode(urldecode(I('url')))); $this->assign('url',$url); return $this->fetch(); } public function select_store() { $erp = I('erp_id'); $time = time(); $store = M('store')->where('ERPId', $erp)->field('store_id,store_name')->find(); if (empty($store)) { return json(['code' => 0, 'msg' => '请输入正确的账套']); } $recharge = M('storage_recharge')->where(['store_id' => $store['store_id']])->field('type,end_time')->select(); $is_distr = 0;//是否开通过分销 $is_cust = 0;//是否开通过客服 if ($recharge) { foreach ($recharge as $v) { if ($v['type'] == 1) { $is_distr = 1; } if ($v['type'] == 2 && $v['end_time'] > $time) { $is_cust = 1; } } } return json(['code' => 1, 'msg' => '操作成功', 'is_dist' => $is_distr, 'is_cust' => $is_cust, 'store' => $store]); } //分销价格列表 public function distri_price_list(){ $rs=M("distri_price")->order('sort')->select(); $this->assign('list', $rs); $this->assign('count', count($rs)); return $this->fetch(); } //分销价格设置 public function distri_price_info(){ $id=I('id'); $ajax=I("ajax"); if($ajax==1){ $date=input('post.'); unset($date['id']); $manager_id=session('manager_id'); $usr=M('manager_admin')->where("manager_id = " . $manager_id)->find(); if(empty($id)) { $date['add_time']=time(); $date['edit_man']=$usr['manager_name']; $date['edit_ip']=getIP(); M("distri_price")->save($date); }else{ $date['edit_time']=time(); $date['edit_man']=$usr['manager_name']; $date['edit_ip']=getIP(); M("distri_price")->where('id',$id)->save($date); } $this->error("设置成功",U('payment/distri_price_list')); exit(); } if(empty($id)) { $maxsort = M('distri_price')->max('sort'); if ($maxsort>0) $maxsort++; else $maxsort = 1; $this->assign('maxsort', $maxsort); }else{ $info=M('distri_price')->where('id',$id)->find(); $this->assign('info', $info); } return $this->fetch(); } //分销价格删除 public function distri_price_del(){ $id=I('id'); M("distri_price")->where('id',$id)->delete(); $this->error("删除成功",U('payment/distri_price_list')); } //获取价格列表 public function select_price(){ $store_id=I('stoid'); $yy=M("storage_recharge")->where("store_id",$store_id)->where('recharge_state',1) ->where("distri_price_id>0")->field('distri_price_id')->select(); $ucount=M('users')->where("store_id",$store_id)->where('is_distribut',1)->count(); $aarr = M("distri_price")->order('type desc,money desc')->select(); $barr = null; if($yy) { // $idarr = get_arr_column($yy, 'distri_price_id'); // $aarr0 = M("distri_price")->order('type desc,money desc')->where('id', 'in', $idarr)->find(); // foreach ($aarr as $k => $v) { // if($v['id']!=$aarr0['id']){ // $barr[]=$v; // }else{ // break; // } // } foreach ($aarr as $k => $v) { if($v['user_num']>$ucount && $v['type']==0){ if($v['money']<=0) break; else{} $barr[]=$v; }else{ if($v['type']==1) $barr[]=$v; else break; } } }else{ $barr=$aarr; } if($barr) return json(['code'=>1,'data'=>$barr]); return json(['code'=>-1]); } //等级价格列表 public function dj_price_list(){ $rs=M("dj_price")->order('sort')->select(); $this->assign('list', $rs); $this->assign('count', count($rs)); return $this->fetch(); } //等级价格设置 public function dj_price_info(){ $id=I('id'); $ajax=I("ajax"); if($ajax==1){ $date=input('post.'); unset($date['id']); $manager_id=session('manager_id'); $usr=M('manager_admin')->where("manager_id = " . $manager_id)->find(); if(empty($id)) { $date['add_time']=time(); $date['edit_man']=$usr['manager_name']; $date['edit_ip']=getIP(); M("dj_price")->save($date); }else{ $date['edit_time']=time(); $date['edit_man']=$usr['manager_name']; $date['edit_ip']=getIP(); M("dj_price")->where('id',$id)->save($date); } $this->error("设置成功",U('payment/dj_price_list')); exit(); } if(empty($id)) { $maxsort = M('dj_price')->max('sort'); if ($maxsort>0) $maxsort++; else $maxsort = 1; $this->assign('maxsort', $maxsort); }else{ $info=M('dj_price')->where('id',$id)->find(); $this->assign('info', $info); } return $this->fetch(); } //等级价格删除 public function dj_price_del(){ $id=I('id'); M("dj_price")->where('id',$id)->delete(); $this->error("删除成功",U('payment/dj_price_list')); } //获取等级价格列表 public function select_dj_price(){ $store_id=I('stoid'); $yy=M("storage_recharge")->where("store_id",$store_id)->where('recharge_state',1) ->where("dj_price_id>0")->field('dj_price_id')->select(); $ucount=M('users')->where("store_id",$store_id) ->where("card_field<>''")->count(); $aarr = M("dj_price")->order('type desc,money desc')->select(); $barr = null; if($yy) { // $idarr = get_arr_column($yy, 'dj_price_id'); // $aarr0 = M("dj_price")->order('type desc,money desc')->where('id', 'in', $idarr)->find(); // foreach ($aarr as $k => $v) { // if($v['id']!=$aarr0['id']){ // $barr[]=$v; // }else{ // break; // } // } foreach ($aarr as $k => $v) { if($v['user_num']>$ucount && $v['type']==0){ if($v['money']<=0) break; else{} $barr[]=$v; }else{ if($v['type']==1) $barr[]=$v; else break; } } }else{ $barr=$aarr; } if($barr) return json(['code'=>1,'data'=>$barr]); return json(['code'=>-1]); } public function tongji(){ $allmoney=M('storage_recharge')->where('recharge_state=1 and admin_type=0')->sum('buy_money'); $weeksele=Db::query('SELECT FROM_UNIXTIME(billdate,\'%Y年-第%u周\') weeks,sum(buy_money) sum FROM wxd_storage_recharge where recharge_state=1 and admin_type=0 GROUP BY weeks order by weeks desc limit 10;'); $monthsele=Db::query('SELECT FROM_UNIXTIME(billdate,\'%Y年%m月\') months,sum(buy_money) sum FROM wxd_storage_recharge where recharge_state=1 and admin_type=0 GROUP BY months order by months desc limit 10'); $yearsele=Db::query('SELECT FROM_UNIXTIME(billdate,\'%Y年\') years,sum(buy_money) sum FROM wxd_storage_recharge where recharge_state=1 and admin_type=0 GROUP BY years order by years desc limit 10'); $erpsele=Db::query('SELECT erpid,SUM(buy_money) sum FROM wxd_storage_recharge where recharge_state=1 and admin_type=0 GROUP BY erpid order by sum desc limit 10'); $this->assign('allmoney',$allmoney); $this->assign('erpsele',$erpsele); $this->assign('daysele',$daysele); $this->assign('weeksele',$weeksele); $this->assign('monthsele',$monthsele); $this->assign('yearsele',$yearsele); return $this->fetch(); } public function recharge_detail(){ $id=I("id"); $detail= M('storage_recharge')->alias('a') ->join('storage_renew b','a.store_id=b.store_id and a.type=4 and a.id=b.rec_id','left') ->join('store s','a.store_id=s.store_id','left') ->join('distri_price c','a.distri_price_id=c.id','left') ->where("a.id",$id) ->field('a.*,b.pernum,b.add_time as b_time,b.end_time as e_time,c.user_num,s.reg_mobile') ->find(); $this->assign('detail',$detail); return $this->fetch(); } //---小程序价格--- public function wxapp_price_list(){ $rs=M("wxapp_price")->order('sort')->select(); $this->assign('list', $rs); $this->assign('count', count($rs)); return $this->fetch(); } //---小程序价格--- public function wxapp_price_info(){ $id=I('id'); $ajax=I("ajax"); if($ajax==1){ $date=input('post.'); unset($date['id']); $manager_id=session('manager_id'); $usr=M('manager_admin')->where("manager_id = " . $manager_id)->find(); if(empty($id)) { $date['add_time']=time(); $date['edit_man']=$usr['manager_name']; $date['edit_ip']=getIP(); M("wxapp_price")->save($date); }else{ $date['edit_time']=time(); $date['edit_man']=$usr['manager_name']; $date['edit_ip']=getIP(); M("wxapp_price")->where('id',$id)->save($date); } $this->error("设置成功",U('payment/wxapp_price_list')); exit(); } if(empty($id)) { $maxsort = M('wxapp_price')->max('sort'); if ($maxsort>0) $maxsort++; else $maxsort = 1; $this->assign('maxsort', $maxsort); }else{ $info=M('wxapp_price')->where('id',$id)->find(); $this->assign('info', $info); } return $this->fetch(); } //等级价格删除 public function wxapp_price_del(){ $id=I('id'); M("wxapp_price")->where('id',$id)->delete(); $this->error("删除成功",U('payment/dj_price_list')); } //获取等级价格列表 public function select_wxapp_price(){ $store_id=I('stoid'); $yy=M("storage_recharge")->where("store_id",$store_id)->where('recharge_state',1) ->where("wxapp_price_id>0")->field('wxapp_price_id')->select(); $ucount=M('users')->where("store_id",$store_id) ->where("card_field<>''")->count(); $aarr = M("wxapp_price")->order('type desc,money desc')->select(); $barr = null; if($yy) { // $idarr = get_arr_column($yy, 'dj_price_id'); // $aarr0 = M("dj_price")->order('type desc,money desc')->where('id', 'in', $idarr)->find(); // foreach ($aarr as $k => $v) { // if($v['id']!=$aarr0['id']){ // $barr[]=$v; // }else{ // break; // } // } foreach ($aarr as $k => $v) { if($v['user_num']>$ucount && $v['type']==0){ if($v['money']<=0) break; else{} $barr[]=$v; }else{ if($v['type']==1) $barr[]=$v; else break; } } }else{ $barr=$aarr; } if($barr) return json(['code'=>1,'data'=>$barr]); return json(['code'=>-1]); } }