| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509 |
- <?php
- namespace app\shop\controller;
- use app\common\controller\Frontend;
- use app\common\library\CoinRate;
- use app\common\model\Config;
- class Trade extends Frontend{
-
- protected $noNeedLogin = [''];
- protected $noNeedRight = '*';
- protected $layout = '';
-
- public function _initialize()
- {
- parent::_initialize();
- }
- /* 分类 */
- function index()
- {
- $info=db('user')->where(['id'=>$this->auth->id])->find();
- $total1=0;$total2=0;
- $total1=db('detailed_bonus')->where(['userid'=>$info['id'],'type'=>['in','16,17,18']])->sum('money');
- $total2=db('detailed_bonus')->where(['userid'=>$info['id'],'type'=>19])->sum('money');
- $this->view->assign([
- "user"=>$info,
- 'total1'=>$total1,
- 'total2'=>$total2
- ]);
- return $this->fetch();
- }
- function orders()
- {
- return $this->fetch();
- }
- function editorder()
- {
- $id=input('id');
- $trade=db('trade')->where(['id'=>$id])->find();
- $this->view->assign([
- "trade"=>$trade,
- ]);
- return $this->fetch();
- }
- /*全部*/
- function tradelist()
- {
- $config = Config::getConfigByGroup('trade');
- $releaseRate = isset($config['release_rate'])? floatval($config['release_rate']['value']) : 0;
- $this->view->assign('release_rate', $releaseRate);
- return $this->fetch();
- }
- /*待付款订单*/
- function trade1()
- {
- $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find();
- $stuid = isset($loginStu['id'])? $loginStu['id'] : 0;
- $list=db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>1,'stuid'=>$stuid])->select();
- foreach ($list as &$v)
- {
- $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
- $v['goods']=$goods;
- $v['flag']=0;
- $v['selluser']=get_user_info($v['userid'],'nickname','mobile');
- $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile');
- if($v['userid']== $this->auth->id)
- {
- $v['flag']=1;
- }else{
- $v['flag']=2;
- }
- }
- $this->view->assign([
- 'list'=>$list,
- ]);
- return $this->fetch();
- }
- /*待确认*/
- function trade2()
- {
- $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find();
- $stuid = isset($loginStu['id'])? $loginStu['id'] : 0;
- $list=db('trade')->where(['userid'=>$this->auth->id,'status'=>2,'stuid'=>$stuid])->select();
- foreach ($list as &$v)
- {
- $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
- $v['goods']=$goods;
- $v['flag']=0;
- $v['selluser']=get_user_info($v['userid'],'nickname','mobile');
- $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile');
- if($v['userid']== $this->auth->id)
- {
- $v['flag']=1;
- }else{
- $v['flag']=2;
- }
- }
- $this->view->assign([
- 'list'=>$list,
- ]);
- return $this->fetch();
- }
- function trade4()
- {
- return $this->fetch();
- }
- function trade5()
- {
- $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find();
- $stuid = isset($loginStu['id'])? $loginStu['id'] : 0;
- $list=db('trade')->where(['userid|relevant_userid'=>$this->auth->id,'status'=>-1,'stuid'=>$stuid])->select();
- foreach ($list as &$v)
- {
- $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
- $v['goods']=$goods;
- $v['flag']=0;
- $v['selluser']=get_user_info($v['userid'],'nickname','mobile');
- $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile');
- if($v['userid']== $this->auth->id)
- {
- $v['flag']=1;
- }elseif($v['relevant_userid'] == $this->auth->id)
- {
- $v['flag']=2;
- }
- }
- $this->view->assign([
- 'list'=>$list,
- ]);
- return $this->fetch();
- }
- /**/
- function trade3()
- {
- $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find();
- $stuid = isset($loginStu['id'])? $loginStu['id'] : 0;
- $list=db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>3,'issell'=>[['egt',0],['elt',2]],'stuid'=>$stuid])->order('issell asc,ctime desc')->select();
- foreach ($list as &$v)
- {
- $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
- $v['goods']=$goods;
- $v['flag']=0;
- $v['selluser']=get_user_info($v['userid'],'nickname','mobile');
- $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile');
- if($v['userid']== $this->auth->id)
- {
- $v['flag']=1;
- }elseif($v['relevant_userid'] == $this->auth->id)
- {
- $v['flag']=2;
- }
- }
- $config = Config::getConfigByGroup('trade');
- $releaseRate = isset($config['release_rate'])? floatval($config['release_rate']['value']) : 0;
- $this->view->assign([
- 'list'=>$list,
- 'release_rate'=> $releaseRate
- ]);
- return $this->fetch();
- }
- function tj()
- {
- $list=db('studio')->where(['refereeid'=>$this->auth->stuid,'status'=>1])
- ->whereOrRaw('id='. $this->auth->stuid.' and status = 1')
- ->select();
- $sid=input('sid');
- if($sid>0)
- {
- $map['stuid']=$sid;
- }else{
- $map['stuid']=0;
- }
- $time=input('starttime');
- if(empty($time))
- {
- $start=strtotime('today')-60*60*24*5;
- $map['ctime']=['gt',$start];
- }else{
- $start=strtotime($time);
- $end=$start+60*60*24;
- $map['ctime']=[['egt',$start],['lt',$end]];
- }
- ##订单数
- $total=db('trade')->where($map)->count();
- #总金额
- $totalnums=db('trade')->where($map)->sum('nums');
- #总上架费
- $totalfee=db('trade')->where($map)->sum('fee');
- $this->view->assign([
- 'list'=>$list,
- 'sid'=>$sid,
- 'starttime'=>$time,
- 'total'=>$total,
- 'totalnums'=>$totalnums,
- 'totalfee'=>$totalfee,
- ]);
- return $this->fetch();
- }
- /*导出*/
- function toexport()
- {
- $name=date('Y-m-d-H-i-s');
- $sid=input('sid');
- if($sid>0)
- {
- $map['stuid']=$sid;
- }
- $time=input('starttime');
- if(empty($time))
- {
- $start=strtotime('today')-60*60*24*5;
- $map['ctime']=['gt',$start];
- }else{
- $start=strtotime($time);
- $end=$start+60*60*24;
- $map['ctime']=[['egt',$start],['lt',$end]];
- }
- ##订单数
- $data_list=db('trade')->where($map)->where('status','>',0)->order('id asc')->select();
- Vendor('PHPExcel.PHPExcel.IOFactory');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getActiveSheetIndex(0);
- $objPHPExcel->getActiveSheet()->setTitle(iconv('gbk', 'utf-8', 'Sheet'));
- // 设置默认字体和大小
- $objPHPExcel->getDefaultStyle()->getFont()->setName(iconv('gbk', 'utf-8', ''));
- $objPHPExcel->getDefaultStyle()->getFont()->setSize(11);
- $styleArray = array(
- 'font' => array(
- 'bold' => true,
- 'color'=>array(
- 'argb' => 'ffffffff',
- )
- ),
- 'borders' => array (
- 'outline' => array (
- 'style' => \PHPExcel_Style_Border::BORDER_THIN,
- 'color' => array ('argb' => 'FF000000'), //设置border颜色
- )
- )
- );
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
- $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFill()->getStartColor()->setARGB('333399');
- $objPHPExcel->getActiveSheet()
- ->setCellValue('A1', '产品名称')
- ->setCellValue('B1', '产品编号')
- ->setCellValue('C1', '茶室')
- ->setCellValue('D1', '出售人')
- ->setCellValue('E1', '购买人')
- ->setCellValue('F1', '订单金额')
- ->setCellValue('G1', '上架费')
- ->setCellValue('H1', '状态')
- ->setCellValue('I1', '抢单时间')
- ->setCellValue('J1', '支付时间')
- ->setCellValue('K1', '确认时间');
- $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->applyFromArray($styleArray);
- foreach ($data_list as $k=>$v){
- $i=$k+2;//注意表头
- $objPHPExcel->getActiveSheet()
- ->setCellValue('A'.$i,get_table_column('goods',$v['goodsid'],'title'))
- ->setCellValue('B'.$i, get_table_column('goods',$v['goodsid'],'description'))
- ->setCellValue('C'.$i, get_table_column('studio',$v['stuid'],'name'))
- ->setCellValue('D'.$i, get_user_info($v['userid'],'nickname','mobile'))
- ->setCellValue('E'.$i, get_user_info($v['relevant_userid'],'nickname','mobile'))
- ->setCellValue('F'.$i, $v['nums'])
- ->setCellValue('G'.$i, $v['fee'])
- ->setCellValue('H'.$i, '已完成')
- ->setCellValue('I'.$i, date('Y-m-d H:i:s',$v['ctime']))
- ->setCellValue('J'.$i, date('Y-m-d H:i:s',$v['pay_time']))
- ->setCellValue('K'.$i, date('Y-m-d H:i:s',$v['confirm_time']));
- }
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel5');
- // 从浏览器直接输出$filename
- header('Content-Type:application/csv;charset=UTF-8');
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
- header("Content-Type:application/force-download");
- header("Content-Type:application/vnd.ms-excel;");
- header("Content-Type:application/octet-stream");
- header("Content-Type:application/download");
- header('Content-Disposition: attachment;filename="'.$name.'.xlsx"');
- header("Content-Transfer-Encoding:binary");
- $objWriter->save('php://output');
- }
- function ownchange()
- {
- $goodsid=input('goodsid');
- $goodsinfo=db('goods')->where(['id'=>$goodsid])->find();
- $owner=db('user')->where(['id'=>$goodsinfo['userid']])->find();
- $this->view->assign([
- 'goodsinfo'=>$goodsinfo,
- 'owner'=>$owner,
- ]);
- return $this->fetch();
- }
- function changestudio()
- {
- $goodsid=input('goodsid');
- $goodsinfo=db('goods')->where(['id'=>$goodsid])->find();
- $studiolist=db('studio')->where(['status'=>1])->select();
- $this->view->assign([
- 'goodsinfo'=>$goodsinfo,
- 'slist'=>$studiolist,
- ]);
- return $this->fetch();
- }
- function changelist()
- {
- $type=input('type');
- if(empty($type))
- {
- $type=1;
- }
- $this->view->assign([
- 'type'=>$type,
- ]);
- return $this->fetch();
- }
- function yuyue()
- {
- $sid=input('sid');
- $sinfo=db('studio')->where(['id'=>$sid])->find();
- if(time()>strtotime(date("Y-m-d {$sinfo['start']}")) && time()< strtotime(date("Y-m-d {$sinfo['end']}")) )
- {
- $status='营业中';
- }elseif(time()< strtotime(date("Y-m-d {$sinfo['start']}"))){
- $status='停业中';
- }elseif(time() > strtotime(date("Y-m-d {$sinfo['end']}"))){
- $status='停业中';
- }
- $this->view->assign([
- 'sid'=>$sid,
- 'studio'=>$sinfo,
- 'status'=>$status
- ]);
- return $this->fetch();
- }
- function yuyuecode()
- {
- $list=db('trade')->alias('a')
- ->join('user b','b.id=a.userid','left')
- ->join('user c','c.id=a.relevant_userid','left')
- ->where(['a.relevant_userid'=>$this->auth->id,'a.status'=>0])
- ->field('a.*,b.nickname,b.mobile,c.nickname as c_nickname,c.mobile as c_mobile')
- ->select();
- foreach ($list as &$v)
- {
- $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
- $v['goods']=$goods;
- }
- $this->view->assign([
- 'list'=>$list,
- ]);
- return $this->fetch();
- }
- function hostgoods()
- {
- return $this->fetch();
- }
- function hostappoint()
- {
- $list=db('trade')->alias('a')
- ->join('user b','b.id=a.userid','left')
- ->join('user c','c.id=a.relevant_userid','left')
- ->where(['a.stuid'=>$this->auth->stuid,'a.status'=>0])
- ->field('a.*,b.nickname,b.mobile,c.nickname as c_nickname,c.mobile as c_mobile')
- ->order('a.yuyue_status asc,a.ctime desc')
- ->select();
- foreach ($list as &$v)
- {
- $goods=db('goods')->where(['id'=>$v['goodsid']])->find();
- $v['goods']=$goods;
- }
- $this->view->assign([
- 'list'=>$list,
- ]);
- return $this->fetch();
- }
- function sethost()
- {
- $sinfo=db('studio')->where(['title'=>$this->auth->login_studio])->find();
- $this->view->assign([
- 'studio'=>$sinfo,
- ]);
- return $this->fetch();
- }
- function managergoods()
- {
- $this->view->assign([
- 'type'=>input('type')==''?1:input('type'),
- ]);
- return $this->fetch();
- }
- function setuserappoint()
- {
- $sinfo=db('studio')->where(['id'=>$this->auth->stuid])->find();
- $this->view->assign([
- 'studio'=>$sinfo,
- ]);
- return $this->fetch();
- }
- function viewonsale()
- {
- $type=input('type');
- if(empty($type))
- {
- $type=0;
- }
- $this->view->assign('type',$type);
- return $this->fetch();
- }
- /*交易详情*/
- function showtrade()
- {
- $id=input('id');
- $trade=db('trade')->where(['id'=>$id])->find();
- $goods= db('goods')->where(['id'=>$trade['goodsid']])->find();
- $selluser=db('user')->where(['id'=>$trade['userid']])->find();
- $buyuser=db('user')->where(['id'=>$trade['relevant_userid']])->find();
- $this->view->assign([
- 'selluser'=>$selluser,
- 'info'=>$trade,
- 'goods'=>$goods,
- 'buyuser'=>$buyuser,
- ]);
- return $this->fetch();
- }
- function mydraw()
- {
- $type=input('type');
- $this->view->assign([
- 'type'=>$type]);
- return $this->fetch();
- }
- /*申诉*/
- function appeal()
- {
- $id=input('id');
- $this->view->assign('id',$id);
- return $this->fetch();
- }
- /*待支付*/
- function topay()
- {
- $id=input('id');
- $trade=db('trade')->where(['id'=>$id])->find();
- $goods= db('goods')->where(['id'=>$trade['goodsid']])->find();
- if(empty($goods)){
- $this->error('商品信息错误');
- }
- $selluser=db('user')->where(['id'=>$trade['userid']])->find();
- $level=get_user_data($this->auth->id,'level');
- $feeCf=db('bonus_config')->where(['config_type'=>3,'user_level'=>$level])->find();
- $bcf=db('bonus_config')->where(['id'=>1])->find();
- $rtx=$bcf['value'];
- $goods['price_usdt'] = round(CoinRate::transfer($goods['price1']),2);
- $goods['pre_price_usdt'] = round(CoinRate::transfer($trade['pre_price']),2);
- $goods['price_thb'] = round(CoinRate::transfer($goods['price1'],'CNY','THB'),2);
- $goods['pre_price_thb'] = round(CoinRate::transfer($trade['pre_price'],'CNY','THB'),2);
- $goods['price_idr'] = round(CoinRate::transferRp($goods['price1'],'CNY','IDR'),2);
- $goods['pre_price_idr'] = round(CoinRate::transferRp($trade['pre_price'],'CNY','IDR'),2);
- $selluser['usdt_address_text'] = $selluser['usdt_address']? substr($selluser['usdt_address'],0,6).'***'.substr($selluser['usdt_address'],-6,6) : '';
- $this->view->assign([
- 'selluser'=>$selluser,
- 'info'=>$trade,
- 'goods'=>$goods,
- 'rtx'=>$rtx,
- ]);
- return $this->fetch();
- }
- /*冻结goods*/
- function djgoods()
- {
- $list=db('goods')->where(['userid'=>$this->auth->id,'isdj'=>1,'istj'=>1])->order('id asc')->select();
- $this->view->assign([
- 'list'=>$list,
- ]);
- return $this->fetch();
- }
- /*冻结goods*/
- function djedgoods()
- {
- $list=db('goods')->where(['userid'=>$this->auth->id,'isdj'=>0,'istj'=>1])->order('id desc')->select();
- $this->view->assign([
- 'list'=>$list,
- ]);
- return $this->fetch();
- }
- }
|