auth->id); $uids=db('user')->where(['id'=>['like','%,'.$this->auth->id.',%'],'tdeep'=>['elt',$user['tdeep']+2]])->column('id'); if($uids) { $map['relevant_userid']=['in',$uids]; }else{ $map['relevant_userid']=0; } $p=$this->request->request('p'); if(empty($p)) { $this->error('缺少参数页码'); } $pagesize=10; $total=db('trade')->where($map)->count(); $totalPage=ceil($total/$pagesize); if($p>$totalPage && $total>0) { $this->error('页码有误'); } $list=db('trade')->where($map)->page($p,$pagesize)->order('id desc')->select(); foreach ($list as &$v) { $v['name']=get_table_column('goods',$v['goodsid'],'title'); $v['ctime']=date('Y-m-d H:i',$v['ctime']); $v['mobile']=get_user_data($v['userid'],'mobile'); } if(empty($list)) { $data['list']=[]; }else{ $data['list']=$list; } $data['total']=$totalPage; $this->success('',$data); } function match() { $goodsid=$this->request->request("goodsid"); $ginfo=db('goods')->where(['id'=>$goodsid])->find(); if($ginfo['istrade'] == 1) { $this->error('已结束'); }else{ $user=get_user_data($this->auth->id); if(empty($user['bank_number']) && empty($user['wxprc']) &&empty($user['alipayprc']) && empty($user['usdt_address']) && empty($user['thb_bank_number']) && empty($user['idr_bank_number'])) { $this->error('请至少完善一个收款账户信息,在交易'); } // if($user['isreal'] != 2) // { // $this->error('您还未实名~'); // } $addressCnt=db('user_address')->where(['userid'=>$user['id']])->count(); if($addressCnt == 0) { //$this->error('您还未添加地址~'); } if($ginfo['userid'] == $this->auth->id) { $this->error('您不能买自己的商品~'); } $topbcf=db('bonus_config')->where(['id'=>5])->find(); $studio=db('studio')->where(['title'=>$this->auth->login_studio])->find(); $topcnt=db('trade')->where(['relevant_userid'=>$user['id'],'stuid'=>$studio['id'],'iscancel'=>0,'create_time'=>strtotime('today'),'type'=>0 ])->count(); if($topcnt>=$topbcf['value']) { $this->error($topcnt.'您今日此分商家抢单次数已达上限'.$topbcf['value']); } $feeconfig=db('bonus_config')->where(['id'=>2])->find(); $fee=$feeconfig['value']*0.01*$ginfo['price1']; if ($ginfo['istrade'] == 0){ db()->startTrans(); $tradedata=[ 'orderNo'=>date('YmdHi').rand(100,999), 'userid'=>$ginfo['userid'], 'goodsid'=>$goodsid, 'nums'=>$ginfo['price1'], 'price'=>$ginfo['price'], 'ctime'=>time(), 'create_time'=>strtotime('today'), 'status'=>1, 'relevant_userid'=>$this->auth->id, 'fee'=>$fee, 'pre_price'=> $ginfo['pre_price'], 'remark'=>date('Y-m-d H:i:s'), 'catid'=>$ginfo['catid'], 'stuid'=>$ginfo['stuid'], 'type'=>0, ]; $tradeid=db('trade')->insertGetId($tradedata); $res1=db('goods')->where(['id'=>$goodsid])->update(['istrade'=>1]); if($tradeid && $res1) { db()->commit(); $this->success('成功',['id'=>$tradeid]); }else{ db()->rollback(); $this->error('抢购失败'); } }else{ $this->error('抢购结束'); } } } function topay() { $tradid=$this->request->request("id"); if(empty($tradid)) { $this->error('网络错误,请重试~'); } $prc=$this->request->request("prc"); if(empty($prc)) { $this->error('请上传凭证'); } $res=db('trade')->where(['id'=>$tradid])->update(['pay_time'=>time(),'status'=>2,'prc'=>$prc]); if($res) { $this->success('支付完成'); }else{ $this->error('支付失败'); } } function tocancelappeal() { $id=$this->request->request("id"); $trade=db('trade')->where(['id'=>$id,'userid'=>$this->auth->id,'isappeal'=>1,'status'=>-1])->find(); if($trade) { $res1=db('trade')->where(['id'=>$id])->update(['isappeal'=>0,'appeal_text'=>'','status'=>2]); if($res1) { $this->success('取消成功'); }else{ $this->error('取消失败'); } }else{ $this->error('订单不存在,或订单状态已发生改变'); } } function tocancel1() { $id=$this->request->post("id"); $trade=db('trade')->where(['id'=>$id,'status'=>0])->find(); if(empty($trade)) { $this->error('订单不存在,或以发生改变'); }else{ $res1=db('trade')->where(['id'=>$id])->update(['status'=>-2,'iscancel'=>1,'confirm_time'=>time()]); if($res1) { $selltrade=db('trade')->where(['goodsid'=>$trade['goodsid'],'status'=>3])->find(); if(empty($selltrade)) { $res2=db('goods')->where(['id'=>$trade['goodsid']])->update(['istrade'=>0]); } $this->success('取消成功'); }else{ $this->error('取消失败'); } } } function tocancel() { $id=$this->request->request("id"); $trade=db('trade')->where(['id'=>$id,'status'=>1])->find(); if(empty($trade)) { $this->error('订单不存在,或以发生改变'); }else{ db()->startTrans(); $res1=db('trade')->where(['id'=>$id])->update(['status'=>-2,'iscancel'=>1,'confirm_time'=>time()]); $res2=db('goods')->where(['id'=>$trade['goodsid']])->update(['istrade'=>0]); if($res1 && $res2) { db()->commit(); $this->success('取消成功'); }else{ db()->rollback(); $this->error('取消失败'); } } } function toeditorder() { $param=$this->request->request(); $trade=db('trade')->where(['id'=>$param['id']])->find(); if(empty($param['buyer']) && $param['status'] == $trade['status']) { $this->error('您并未修改订单'); } db()->startTrans(); if($param['buyer']) { $user=db('user')->where(['username|mobile'=>$param['buyer']])->find(); if($user['id'] == $trade['relevant_userid']) { unset($param['buyer']); $res1=1; $res2=1; }else{ $res1=db('trade')->where(['id'=>$param['id']])->update(['relevant_userid'=>$user['id']]); $res2=db('goods')->where(['id'=>$trade['goodsid']])->update(['userid'=>$user['id']]); } } if($param['status'] != $trade['status']) { if($param['status'] == 1) { $res3=db('trade')->where(['id'=>$param['id']])->update(['status'=>1,'pay_time'=>0,'confirm_time'=>0,'endnums'=>0]); $res4=1; }elseif($param['status'] == 2) { $res3=db('trade')->where(['id'=>$param['id']])->update(['status'=>2,'pay_time'=>time(),'confirm_time'=>0,'endnums'=>0]); $res4=1; }elseif($param['status'] == 3) { $bcf=db('bonus_config')->where(['id'=>1])->find(); $endprice=$trade['nums']*$bcf['value']*0.01+$trade['nums']; $res3=db('trade')->where(['id'=>$param['id']])->update(['status'=>3,'endnums'=>$endprice,'confirm_time'=>time()]); $res4=db('goods')->where(['id'=>$trade['goodsid']])->update(['userid'=>$trade['relevant_userid'],'price1'=>$endprice]); } }else{ $res3=1; $res4=1; } if($res1 && $res2 && $res3 && $res4) { db()->commit(); $this->success('修改成功'); }else{ db()->rollback(); $this->error('修改失败'); } } function toconfirm() { $id=$this->request->request("id"); $tradeinfo=db('trade')->where(['id'=>$id,'status'=>2])->find(); if(empty($tradeinfo)) { $this->error('订单不存在,或以发生改变'); }else{ $bcf=db('bonus_config')->where(['id'=>1])->find(); $endprice=$tradeinfo['nums']*$bcf['value']*0.01+$tradeinfo['nums']; db()->startTrans(); $res1=db('trade')->where(['id'=>$id])->update(['confirm_time'=>time(),'endnums'=>$endprice,'pre_price'=> $endprice-$tradeinfo['price'],'status'=>3]); $res2=db('goods')->where(['id'=>$tradeinfo['goodsid']])->update(['userid'=>$tradeinfo['relevant_userid'],'update_time'=>time(),'price1'=>$endprice,'pre_price'=> $endprice-$tradeinfo['price']]); if($res1 && $res2) { db()->commit(); $this->success('操作完成'); }else{ db()->rollback(); $this->error('操作失败'); } } } /*发货*/ function addorder() { $id=$this->request->post('id'); if(empty($id)) { $this->error('缺少参数'); } $addressinfo=db('user_address')->where(['userid'=>$this->auth->id])->order('isdefault desc')->find(); if(empty($addressinfo)) { $this->error("地址不存在,请添加地址"); } $info=db('trade')->where(['id'=>$id])->find(); if($info['issell']>0) { $this->error('不可重复操作'); } $goods=db('goods')->where(['id'=>$info['goodsid']])->find(); db()->startTrans(); $res=db('trade')->where(['id'=>$id])->update(['issell'=>-1,'ext'=>'发货']); $data=[ 'orderNo'=>date('YmdHis').rand(100,999), 'orderStatus'=>1, 'totalMoney'=>$info['nums'], 'deliverMoney'=>0, 'userid'=>$this->auth->id, 'userName'=>$addressinfo['userName'], 'userPhone'=>$addressinfo['userPhone'], 'userAddress'=>$addressinfo['area'].$addressinfo['address'], 'addressId'=>$addressinfo['id'], 'remark'=>'', 'createTime'=>date('Y-m-d H:i:s'), 'needPay'=>$info['nums'], 'utime'=>time(), 'type'=>0 ]; $oids=db('order')->insertGetId($data); $ordGod=[ 'orderid'=>$oids, 'goodsid'=>$info['goodsid'], 'nums'=>1, 'price'=>$info['nums'], 'attr'=>'', 'title'=>$goods['title'], 'image'=>$goods['image'], ]; $ogids=db('order_goods')->insertGetId($ordGod); $logid=db('order_log')->insertGetId(['orderid'=>$oids,'title'=>'订单消息','content'=>'您的订单已生成,请耐心等待发货','userid'=>$this->auth->id,'ctime'=>time()]); if($res && $oids && $ogids && $logid) { db()->commit(); $this->success('操作完成'); }else{ db()->rollback(); $this->error('操作失败'); } } /*代售*/ function tosell() { $id=$this->request->post('id'); if(empty($id)) { $this->error('缺少参数'); } $wtprc=$this->request->post('wtprc'); if(empty($wtprc)) { $this->error('请上传凭证'); } $user=get_user_data($this->auth->id); $info=db('trade')->where(['id'=>$id])->find(); if($info['issell']>0) { $this->error('不可重复操作'); } $res=db('trade')->where(['id'=>$id])->update(['issell'=>1,'wtprc'=>$wtprc]); if($res) { $this->success('操作完成,请耐心等待审核'); }else{ $this->error('操作失败'); } } function getonsale() { $type = $this->request->post('type'); if($type > 0) { $map['issell']=$type; if($type == 2) { $map['status']=['egt',3]; }else{ $map['status']=3; } }else{ $map['issell']=0; $map['status']=['in','1,2']; } $map['stuid']=get_user_data($this->auth->id,'stuid'); $p = $this->request->post('p'); $data_list = db('trade')->where($map)->page($p, 10)->order("id desc")->select(); foreach ($data_list as &$v) { $goods=db('goods')->where(['id'=>$v['goodsid']])->find(); $v['goods']=$goods; $v['ctime1']=date('Y-m-d H:i:s',$v['ctime']); $v['sendtime1']=$v['sendtime']>0?date('Y-m-d H:i:s',$v['sendtime']):''; $v['status_desc']=config('tradeStatus')[$v['status']]; $v['selluser']=get_user_info($v['userid'],'nickname','mobile'); $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile'); if($type == 1) { $v['desc']='待审核'; }elseif($type == 2) { $v['desc']='已审核'; }else{ $v['desc']='交易中'; } } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('trade' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } function getorders() { $map['stuid'] = $this->auth->stuid; $map['status'] = ['in','1,2,3']; $p = $this->request->post('p'); $data_list = db('trade')->where($map)->page($p, 10)->order("status asc,id desc")->select(); foreach ($data_list as &$v) { $goods=db('goods')->where(['id'=>$v['goodsid']])->find(); $v['goods']=$goods; $v['ctime1']=date('Y-m-d H:i:s',$v['ctime']); $v['pay_time1']=$v['pay_time']>0?date('Y-m-d H:i:s',$v['pay_time']):''; $v['confirm_time1']=$v['confirm_time']>0?date('Y-m-d H:i:s',$v['confirm_time']):''; $v['status_desc']=config('tradeStatus')[$v['status']]; $v['selluser']=get_user_info($v['userid'],'nickname','mobile'); $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile'); } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('trade' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } function gettj() { $sid = $this->request->post('sid'); if($sid>0) { $map['stuid']=$sid; }else{ $map['stuid']=0; } $time=$this->request->post('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]]; } $p = $this->request->post('p'); $data_list = db('trade')->where($map)->page($p, 10)->order("id desc")->select(); foreach ($data_list as &$v) { $goods=db('goods')->where(['id'=>$v['goodsid']])->find(); $v['goods']=$goods; $v['ctime1']=date('Y-m-d H:i:s',$v['ctime']); $v['confirm_time1']=date('Y-m-d H:i:s',$v['confirm_time']); $v['status_desc']=config('tradeStatus')[$v['status']]; $v['selluser']=get_user_info($v['userid'],'nickname','mobile'); $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile'); $v['stuname']=get_table_column('studio',$v['stuid'],'name'); } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('trade' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } /*我的挂卖*/ function gettradeout() { $times=strtotime('today')-60*60*24*2; $userId = $this->auth->id; $map['ctime']=['gt',$times]; // $map['userid'] = $this->auth->id; $map['status'] = ['egt',3]; $p = $this->request->post('p'); $data_list = db('trade')->where($map)->where(function($query) use($userId){ $query->where(['userid'=> $userId])->whereOr(function($query) use($userId){ $query->where(['relevant_userid'=> $userId,'on_resale'=>1]); }); })->page($p, 10)->order("id desc")->select(); //var_dump(db('trade')->getLastSql()); //$speedData = \app\common\model\Trade::getSpeedTotalByUser($userId); $config = Config::getConfigByGroup('trade'); $releaseRate = isset($config['release_rate'])? floatval($config['release_rate']['value']) : 0; foreach ($data_list as &$v) { $goods=db('goods')->where(['id'=>$v['goodsid']])->find(); $v['goods']=$goods; $v['ctime1']=date('Y-m-d H:i:s',$v['ctime']); $v['pay_time1']=date('Y-m-d H:i:s',$v['pay_time']); $v['confirm_time1']=date('Y-m-d H:i:s',$v['confirm_time']); $v['status_desc']=config('tradeStatus')[$v['status']]; $v['selluser']=get_user_info($v['userid'],'nickname','mobile'); $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile'); $v['release_rate']=$releaseRate; $v['flag']=0; if($v['userid']== $this->auth->id) { $v['flag']=1; }elseif($v['relevant_userid']== $this->auth->id) { $v['flag']=2; } } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('trade' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } function tochange() { $params=$this->request->post(); if($params['old'] == $params['new']) { $this->error('变更商家不可与原商家一致'); } /*转商家记录不可重复提交*/ $info=db('studio_code')->where(['goodsid'=>$params['goodsid'],'status'=>1])->find(); if($info) { $this->error('此商品新店长还未处理,不可重复操作'); } $params['userid']=$this->auth->id; $params['hostid']=$params['new']; $params['ctime']=time(); $params['status']=1; $ids=db('studio_code')->insertGetId($params); if($ids) { $this->success('已提交审核,请耐心等待'); }else{ $this->error('提交失败,请重新操作'); } } function tosethost() { $params=$this->request->post(); $studio=db('studio')->where(['id'=>$params['id']])->find(); if($studio['userid'] != $this->auth->id) { $this->error('你还不是店长不可设置商家参数'); } if($params['new_title']) { $params['title']=$studio['ident'].$params['new_title']; } unset($params['new_title']); $res=db('studio')->where(['id'=>$params['id']])->update($params); if($res) { if(isset($params['title']) && $params['title']){ \app\common\model\User::where(['id'=> $this->auth->id])->update(['login_studio'=> $params['title']]); } $this->success('设置成功'); }else{ $this->error('设置失败'); } } function todjgoods() { $id=$this->request->post('id'); $status=$this->request->post('status'); $info=db('goods')->where(['id'=>$id])->find(); if(empty($info)) { $this->error('要操作的信息不存在'); }else{ if($status == 1) { $res=db('goods')->where(['id'=>$id,'on_sale'=>-1])->update(['on_sale'=>1]); }else{ $res=db('goods')->where(['id'=>$id,'on_sale'=>1])->update(['on_sale'=>-1]); } if($res) { $this->success('操作完成'); }else{ $this->error('操作失败'); } } } function toviewchange() { $id=$this->request->post('id'); $status=$params=$this->request->post('status'); $info=db('studio_code')->where(['id'=>$id,'status'=>1])->find(); if(empty($info)) { $this->error('要操作的信息不存在'); } if($status == 1) { db()->startTrans(); $res1=db('studio_code')->where(['id'=>$id])->update(['status'=>2,'utime'=>time()]); $res2=db('goods')->where(['id'=>$info['goodsid']])->update(['stuid'=>$info['new']]); if($res1 && $res2) { db('trade')->where(['status'=>['neq',4],'goodsid'=>$info['goodsid']])->update(['stuid'=>$info['new']]); db()->commit(); $this->success('审核完成'); }else{ db()->rollback(); $this->error('审核失败'); } }else{ $res=db('studio_code')->where(['id'=>$id])->update(['status'=>-1]); if($res) { $this->success('审核完成'); }else{ $this->error('审核失败'); } } } function getmystdgoods() { $type = $this->request->post('type'); if($type) { $map['on_sale']=$type; } $studio=db('studio')->where(['title'=>$this->auth->login_studio])->find(); $map['stuid']=$studio['id']; $p = $this->request->post('p'); $data_list = db('goods')->where($map)->page($p, 10)->order("id desc")->select(); foreach ($data_list as &$v) { $info=db('studio_code')->where(['goodsid'=>$v['id'],'status'=>1])->find(); if($info) { $v['iszc']=1; }else{ $v['iszc']=0; } $v['username']=get_user_data($v['userid'],'mobile'); $v['nickname']=get_user_data($v['userid'],'nickname'); } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('goods' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } function gethostdraw() { $map['on_sale']=1; $map['on_resale']=2; $map['stuid'] = $this->auth->stuid; $p = $this->request->post('p'); $data_list = db('goods')->where($map)->page($p, 10)->order("id desc")->select(); foreach ($data_list as &$v) { $v['username']=get_user_data($v['userid'],'mobile'); } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('goods' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } function getchangedraw() { $status=$this->request->post('status'); if($status == 1) { $map['status']=1; $map['hostid'] = $this->auth->stuid; }elseif($status == 2) { $map['new'] = $this->auth->stuid; }else{ $map['old'] = $this->auth->stuid; } $p = $this->request->post('p'); $data_list = db('studio_code')->where($map)->page($p, 10)->order("id desc")->select(); foreach ($data_list as &$v) { $v['username']=get_user_data($v['userid'],'mobile'); $v['olds']=get_table_column('studio',$v['old'],'title'); $v['news']=get_table_column('studio',$v['new'],'title'); $v['time1']=date('Y-m-d H:i:s',$v['ctime']); $v['time2']=$v['utime']>0?date('Y-m-d H:i:s',$v['utime']):''; } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('studio_code' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } function getmydraw() { $type = $this->request->post('type'); if($type == 1) { $map['istrade']=0; }elseif($type == 2) { $map['istrade']=1; } $map['on_sale']=1; $map['on_resale']=2; $map['userid'] = $this->auth->id; $p = $this->request->post('p'); $data_list = db('goods')->where($map)->page($p, 10)->order("id desc")->select(); if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('goods' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } /*交易列表*/ function gettradelist() { $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find(); $times=strtotime('today')-60*60*24*2; $map['ctime']=['gt',$times]; $map['status']=['not in','0,-2']; $map['stuid'] = isset($loginStu['id'])? $loginStu['id'] : 0; $map['userid|relevant_userid'] = $this->auth->id; $p = $this->request->post('p'); $data_list = db('trade')->where($map)->page($p, 10)->order("status asc,id desc")->select(); foreach ($data_list as &$v) { $goods=db('goods')->where(['id'=>$v['goodsid']])->find(); $v['goods']=$goods? $goods : ['image'=>'']; $v['ctime1']=date('Y-m-d H:i:s',$v['ctime']); $v['pay_time1']=date('Y-m-d H:i:s',$v['pay_time']); $v['confirm_time1']=date('Y-m-d H:i:s',$v['confirm_time']); $v['selluser']=get_user_info($v['userid'],'nickname','mobile'); $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile'); $v['flag']=0; if($v['userid']== $this->auth->id) { $v['flag']=1; }elseif($v['relevant_userid']== $this->auth->id) { $v['flag']=2; } if($v['status'] == 3 && $v['issell'] == 0) { $v['status_desc']='待上架'; }elseif($v['status'] == 3 && $v['issell'] == 1){ $v['status_desc']='待茶室长确认'; }elseif($v['status'] == 3 && $v['issell'] == 2){ $v['status_desc']='已上架'; }else{ if($v['status'] == 1 && $v['flag']==1){ $v['status_desc']='等待买方支付'; }else if($v['status'] == 1 && $v['flag']==2){ $v['status_desc']='待付款'; } else if($v['status'] == 2 && $v['flag']==1){ $v['status_desc']='待收款'; } else if($v['status'] == 2 && $v['flag']==2){ $v['status_desc']='等待卖方确认'; }else{ $v['status_desc']=config('tradeStatus')[$v['status']]; } } } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('trade' )->where($map)->count(); $return['total'] = ceil($count / 10); return $return; } /*统计交易列表*/ function gettradelisttj() { $type = input('type', 0); $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find(); $times=strtotime('today')-60*60*24*2; $map['ctime']=['gt',$times]; $map['stuid'] = isset($loginStu['id'])? $loginStu['id'] : 0; if($type){ $map['status']= $type; if($type == 3){ $map['issell'] = [['egt',0],['elt',2]]; } }else{ $map['status']=['not in','0,-2']; } $p = $this->request->post('p'); $data_list = db('trade')->where($map)->page($p, 10)->order("status asc,id desc")->select(); foreach ($data_list as &$v) { $goods=db('goods')->where(['id'=>$v['goodsid']])->find(); $v['goods']=$goods? $goods : ['image'=>'']; $v['ctime1']=date('Y-m-d H:i:s',$v['ctime']); $v['pay_time1']=date('Y-m-d H:i:s',$v['pay_time']); $v['confirm_time1']=date('Y-m-d H:i:s',$v['confirm_time']); $v['selluser']=get_user_info($v['userid'],'nickname','mobile'); $v['buyuser']=get_user_info($v['relevant_userid'],'nickname','mobile'); $v['studio_name']= isset($loginStu['name'])? $loginStu['name'] : ''; $v['flag']=0; if($v['userid']== $this->auth->id) { $v['flag']=1; }elseif($v['relevant_userid']== $this->auth->id) { $v['flag']=2; } if($v['status'] == 3 && $v['issell'] == 0) { $v['status_desc']='待上架'; }elseif($v['status'] == 3 && $v['issell'] == 1){ $v['status_desc']='待茶室长确认'; }elseif($v['status'] == 3 && $v['issell'] == 2){ $v['status_desc']='已上架'; }else{ if($v['status'] == 1 && $v['flag']==1){ $v['status_desc']='等待买方支付'; }else if($v['status'] == 1 && $v['flag']==2){ $v['status_desc']='待付款'; } else if($v['status'] == 2 && $v['flag']==1){ $v['status_desc']='待收款'; } else if($v['status'] == 2 && $v['flag']==2){ $v['status_desc']='等待卖方确认'; }else{ $v['status_desc']=config('tradeStatus')[$v['status']]; } } } if ($data_list) { $return['data'] = $data_list; } else { $return['data'] = null; } $count = db('trade' )->where($map)->count(); $return['total'] = ceil($count / 10); $datetime = strtotime(date('Y-m-d')); $return['counts'] = [ 'today_count'=> db('trade' )->where($map)->where('ctime','>=', $datetime)->count(), 'today_total'=>db('trade' )->where($map)->where('ctime','>=', $datetime)->sum('nums') ]; return $return; } function toselltrade() { $id=$this->request->request('id'); $trade=db('trade')->where(['id'=>$id,'status'=>3,'issell'=>1])->find(); if(empty($trade)) { $this->error('订单不存在,或状态已发生改变'); } db()->startTrans(); $res1=db('goods')->where(['id'=>$trade['goodsid']])->update(['time1'=>time()]); $res=db('trade')->where(['id'=>$id,'status'=>3])->update(['issell'=>2,'create_time'=>strtotime('today'),'sendtime'=>time()]); if($res && $res1) { bonusorder($trade['relevant_userid'],$trade['nums']); addtrade($trade['goodsid']); db()->commit(); $this->success('审核完成'); }else{ db()->rollback(); $this->error('审核失败'); } } function toupdatetrade() { $id=$this->request->request('id'); $type=$this->request->request('type'); $isadd=$this->request->request('isadd'); $trade=db('trade')->where(['id'=>$id,'status'=>3,'issell'=>0])->find(); if(empty($trade)) { $this->error('订单不存在,或状态已发生改变'); } if($type == 1) {//代售 db()->startTrans(); $res=db('trade')->where(['id'=>$id,'status'=>3])->update(['issell'=>1]); $res1=db('goods')->where(['id'=>$trade['goodsid']])->update(['time1'=>time()]); if($res && $res1) { db()->commit(); $this->success('代售完成'); }else{ db()->rollback(); $this->error('代售失败'); } }else{ $addressinfo=db('user_address')->where(['userid'=>$this->auth->id])->order('isdefault desc')->find(); if(empty($addressinfo)) { $this->error("地址不存在,请添加地址"); } if($trade['issell']>0) { $this->error('已代售不可重复操作'); } $goods=db('goods')->where(['id'=>$trade['goodsid']])->find(); db()->startTrans(); $res=db('trade')->where(['id'=>$id])->update(['status'=>4,'issell'=>-1,'sendtime'=>time()]); $data=[ 'orderNo'=>date('YmdHis').rand(100,999), 'orderStatus'=>1, 'totalMoney'=>$trade['nums'], 'deliverMoney'=>0, 'userid'=>$this->auth->id, 'userName'=>$addressinfo['userName'], 'userPhone'=>$addressinfo['userPhone'], 'userAddress'=>$addressinfo['area'].$addressinfo['address'], 'addressId'=>$addressinfo['id'], 'remark'=>'', 'createTime'=>date('Y-m-d H:i:s'), 'needPay'=>0, 'utime'=>time(), 'type'=>0, 'tradeid'=>$id, ]; $oids=db('order')->insertGetId($data); $ordGod=[ 'orderid'=>$oids, 'goodsid'=>$trade['goodsid'], 'nums'=>1, 'price'=>$trade['nums'], 'attr'=>'', 'title'=>$goods['title'], 'image'=>$goods['image'], ]; $ogids=db('order_goods')->insertGetId($ordGod); $logid=db('order_log')->insertGetId(['orderid'=>$oids,'title'=>'订单消息','content'=>'您的订单已生成,请耐心等待发货','userid'=>$this->auth->id,'ctime'=>time()]); if($res && $oids && $ogids && $logid) { db('goods')->where(['id'=>$goods['id']])->update(['on_sale'=>0]); db()->commit(); $this->success('发货成功'); }else{ db()->rollback(); $this->error('发货失败'); } } } /*转售给平台 add by wes */ function resaletrade() { $id=$this->request->request('id'); $trade=db('trade')->where(['id'=>$id,'status'=>3,'issell'=>2])->find(); if(empty($trade)) { $this->error('订单商品不存在,或未上架无法转售'); } if($trade['on_resale'] == 1) { $this->error('订单商品已转售'); } $studio=db('studio')->where(['title'=>$this->auth->login_studio])->find(); $startTime = isset($studio['start'])? $studio['start'] : 0; $endTime = isset($studio['end'])? $studio['end'] : 0; $startTime = $startTime? strtotime(date('Y-m-d').' '.$startTime) : 0; $endTime = $endTime? strtotime(date('Y-m-d').' '.$endTime) : 0; $expired = $startTime > time()? $startTime - time() : 0; if(time()>= $startTime && time() <= $endTime){ $this->error('抱歉,请在营业时间以外转售'); } db()->startTrans(); $totalUsdt = CoinRate::transfer($trade['pre_price']); $res=db('trade')->where(['id'=>$id,'status'=>3])->update(['on_resale'=>1,'status'=>4,'release_total_usdt'=> $totalUsdt]); $res1=db('goods')->where(['id'=>$trade['goodsid']])->update(['time1'=>time(),'on_resale'=> 1]); if($res && $res1) { db()->commit(); $this->success('转售平台完成'); }else{ db()->rollback(); $this->error('转售平台失败'); } } /*申诉*/ function toappeal() { $id=$this->request->request('id'); $appeal_text=$this->request->request('appeal_text'); if(empty($appeal_text)) { $this->error('缺少参数'); } $res=db('trade')->where(['id'=>$id])->update(['status'=>-1,'isappeal'=>1,'appeal_text'=>$appeal_text]); if($res) { $this->success('申诉提交完成'); }else{ $this->error('申诉失败'); } } function toyuyue() { $type=$this->request->request('type'); if(empty($type)) { $this->error('请选择价值范围'); } $sid=$this->request->request('sid'); if(empty($sid)) { $this->error('请选择商家'); }else{ $map['stuid']=$sid; $gmap['stuid']=$sid; } $studio=db('studio')->where(['id'=>$sid])->find(); $isappoint=db('studio_user')->where(['sid'=>$studio['id'],'userid'=>$this->auth->id])->find(); if($isappoint) { $this->error('预约已关闭'); } $bcf=db('bonus_config')->where(['id'=>5])->find(); // $yuyue_count=db('trade')->where(['stuid'=>$sid,'type'=>1,'status'=>['neq',-2],'relevant_userid'=>$this->auth->id,'appoint_time'=>['gt',strtotime('today')]])->count(); // if($yuyue_count >= $bcf['cap']) // { // $this->error('本商家今日预约已达上限'); // } #价格区间 $appointPrice = ''; if($type == 5) { $map['endnums']=['egt',config('price_range')[$type]]; $gmap['price1']=['egt',config('price_range')[$type]]; $appointPrice = '大于'.config('price_range')[$type]; }else{ $price_range=explode('-',config('price_range')[$type]); $map['endnums'][]=['egt',$price_range[0]]; $map['endnums'][]=['lt',$price_range[1]]; $gmap['price1'][]=['egt',$price_range[0]]; $gmap['price1'][]=['lt',$price_range[1]]; $appointPrice = "¥{$price_range[0]}~$price_range[1]"; } /*下架的不算*/ $godis =[]; $ggids=db('goods')->where(['on_sale'=>['neq',1]])->column('id'); // 过滤自身已预约中和预约成功的订单商品 $ggids2=db('trade')->where(['status'=>0,'relevant_userid'=> $this->auth->id])->whereIn('yuyue_status',[1,2])->column('goodsid'); if($ggids) { if($ggids2) { $godis=array_merge($ggids,$ggids2); }else{ $godis=$ggids; } $map['goodsid']=['not in',$godis]; $gmap['id']=['not in',$godis]; }else{ if($ggids2) { $map['goodsid']=['not in',$ggids2]; $gmap['id']=['not in',$godis]; } } $map['relevant_userid']=['neq',$this->auth->id];/*不匹配自身订单*/ $map['status']=3; $map['issell']=2; $map['isout']=0; $info=db('trade')->where($map)->find(); if(empty($info)) { $gmap['on_sale']=1; $gmap['on_resale']=2; $gmap['istrade']=0; $gmap['userid']=['neq',$this->auth->id]; $goods=db('goods')->where($gmap)->find(); if(empty($goods)) { $this->error('没有商品可以预约,请更换价格范围'); }else{ db()->startTrans(); $feebcf=db('bonus_config')->where(['id'=>2])->find(); $tradedata=[ 'orderNo'=>date('YmdHi').rand(100,999), 'userid'=>$goods['userid'], 'goodsid'=>$goods['id'], 'nums'=>$goods['price1'], 'pre_price'=>$goods['pre_price'], 'ctime'=>time(), 'create_time'=>strtotime('today'), 'status'=>0, 'yuyue_status'=> 1, 'appoint_price'=> $appointPrice, 'relevant_userid'=>$this->auth->id, 'fee'=>$goods['price']*$feebcf['value']*0.01, 'remark'=>date('Y-m-d H:i:s'), 'catid'=>$goods['catid'], 'stuid'=>$goods['stuid'], 'appoint_time'=>time(), 'type'=>1, ]; $tradeid=db('trade')->insertGetId($tradedata); //$res1=db('goods')->where(['id'=>$goods['id']])->update(['istrade'=>1]); if($tradeid) { db()->commit(); $this->success('预约完成'); }else{ db()->rollback(); $this->error('预约失败'); } } }else{ $feebcf=db('bonus_config')->where(['id'=>2])->find(); $tradedata=[ 'orderNo'=>date('YmdHi').rand(100,999), 'userid'=>$info['relevant_userid'], 'goodsid'=>$info['goodsid'], 'nums'=>$info['endnums'], 'pre_price'=>$info['pre_price'], 'ctime'=>time(), 'create_time'=>strtotime('today'), 'status'=>0, 'yuyue_status'=> 1, 'appoint_price'=> $appointPrice, 'relevant_userid'=>$this->auth->id, 'fee'=>$info['endnums']*$feebcf['value']*0.01, 'remark'=>date('Y-m-d H:i:s'), 'catid'=>$info['catid'], 'stuid'=>$info['stuid'], 'appoint_time'=>time(), 'type'=>1, ]; $tradeid=db('trade')->insertGetId($tradedata); if($tradeid) { $this->success('预约完成'); }else{ $this->error('预约失败'); } } } function toyuyue1() { $this->error('功能未开放...'); $type=$this->request->request('type'); if(empty($type)) { $this->error('请选择价值范围'); } $sid=$this->request->request('sid'); if(empty($sid)) { $this->error('请选择商家'); }else{ $map['stuid']=$sid; $gmap['stuid']=$sid; } $studio=db('studio')->where(['id'=>$sid])->find(); $isappoint=db('studio_user')->where(['sid'=>$studio['id'],'userid'=>$this->auth->id])->find(); if($isappoint) { $this->error('预约已关闭'); } $bcf=db('bonus_config')->where(['id'=>5])->find(); // $yuyue_count=db('trade')->where(['stuid'=>$sid,'type'=>1,'status'=>['neq',-2],'relevant_userid'=>$this->auth->id,'appoint_time'=>['gt',strtotime('today')]])->count(); // if($yuyue_count >= $bcf['cap']) // { // $this->error('本商家今日预约已达上限'); // } #价格区间 if($type == 5) { $map['endnums']=['egt',config('price_range')[$type]]; $gmap['price1']=['egt',config('price_range')[$type]]; }else{ $price_range=explode('-',config('price_range')[$type]); $map['endnums'][]=['egt',$price_range[0]]; $map['endnums'][]=['lt',$price_range[1]]; $gmap['price1'][]=['egt',$price_range[0]]; $gmap['price1'][]=['lt',$price_range[1]]; } /*下架的不算*/ $godis =[]; $ggids=db('goods')->where(['on_sale'=>['neq',1]])->column('id'); $ggids2=db('trade')->where(['status'=>0])->column('goodsid'); if($ggids) { if($ggids2) { $godis=array_merge($ggids,$ggids2); }else{ $godis=$ggids; } $map['goodsid']=['not in',$godis]; $gmap['id']=['not in',$godis]; }else{ if($ggids2) { $map['goodsid']=['not in',$ggids2]; $gmap['id']=['not in',$godis]; } } $map['relevant_userid']=['neq',$this->auth->id];/*不匹配自身订单*/ $map['status']=3; $map['issell']=2; $map['isout']=0; $info=db('trade')->where($map)->find(); if(empty($info)) { $gmap['userid']=['neq',$this->auth->id]; $gmap['on_sale']=1; $gmap['on_resale']=2; $gmap['istrade']=0; $gmap['userid']=['neq',$this->auth->id]; $goods=db('goods')->where($gmap)->find(); if(empty($goods)) { $this->error('没有商品可以预约,请更换价格范围'); }else{ db()->startTrans(); $feebcf=db('bonus_config')->where(['id'=>2])->find(); $tradedata=[ 'orderNo'=>date('YmdHi').rand(100,999), 'userid'=>$goods['userid'], 'goodsid'=>$goods['id'], 'nums'=>$goods['price1'], 'ctime'=>time(), 'create_time'=>strtotime('today'), 'status'=>0, 'relevant_userid'=>$this->auth->id, 'fee'=>$goods['price']*$feebcf['value']*0.01, 'remark'=>date('Y-m-d H:i:s'), 'catid'=>$goods['catid'], 'stuid'=>$goods['stuid'], 'appoint_time'=>time(), 'type'=>1, ]; $tradeid=db('trade')->insertGetId($tradedata); $res1=db('goods')->where(['id'=>$goods['id']])->update(['istrade'=>1]); if($tradeid && $res1) { db()->commit(); $this->success('预约完成'); }else{ db()->rollback(); $this->error('预约失败'); } } }else{ $feebcf=db('bonus_config')->where(['id'=>2])->find(); $tradedata=[ 'orderNo'=>date('YmdHi').rand(100,999), 'userid'=>$info['relevant_userid'], 'goodsid'=>$info['goodsid'], 'nums'=>$info['endnums'], 'ctime'=>time(), 'create_time'=>strtotime('today'), 'status'=>0, 'relevant_userid'=>$this->auth->id, 'fee'=>$info['endnums']*$feebcf['value']*0.01, 'remark'=>date('Y-m-d H:i:s'), 'catid'=>$info['catid'], 'stuid'=>$info['stuid'], 'appoint_time'=>time(), 'type'=>1, ]; $tradeid=db('trade')->insertGetId($tradedata); if($tradeid) { $this->success('预约完成'); }else{ $this->error('预约失败'); } } } function toconfirmyuyue(){ $id=$this->request->request('id'); $status=$this->request->request('status'); $tradeinfo=db('trade')->where(['id'=>$id,'status'=>0])->find(); if(empty($tradeinfo)){ $this->error('预约记录不存在'); } if($tradeinfo['yuyue_status'] != 1){ $this->error('预约记录已处理'); } if(!in_array($status,[2,3])){ $this->error('操作类型错误'); } db()->startTrans(); $res = db('trade')->where(['id'=>$id,'status'=>0])->update(['yuyue_status'=> $status]); $res1=db('goods')->where(['id'=>$tradeinfo['goodsid']])->update(['istrade'=>1]); if($res && $res1){ db()->commit(); $this->error('审核成功'); }else{ db()->rollback(); $this->error('审核失败'); } } function toownchange() { $goodsid=$this->request->request('goodsid'); $goods=db('goods')->where(['id'=>$goodsid])->find(); if(empty($goods)) { $this->error('要操作的商品不存在'); } $username=$this->request->request('username'); if(empty($username)) { $this->error('请输入更改会员账户或手机号'); } $user=db('user')->where(['username|mobile'=>$username])->find(); if($user['id'] == $goods['userid']) { $this->error('更改的所属人不可与原所属人一致'); } $res=db('goods')->where(['id'=>$goodsid])->update(['userid'=>$user['id']]); if($res) { db('trade')->where(['goodsid'=>$goodsid,'status'=>['in','1,2,3']])->update(['relevant_userid'=>$user['id']]); $this->success('更改成功'); }else{ $this->error('更改失败'); } } // 拆分 function tosongoods() { $gid=input('id'); $goodsinfo=db('goods')->where(['id'=>$gid])->find(); $tradeinfo=db('trade')->where(['goodsid'=>$goodsinfo['id'],'status'=>['in','1,2,-1']])->find(); if($tradeinfo) { $this->error('此商品交易中,不可拆分'); } $tradeinfo1=db('trade')->where(['goodsid'=>$goodsinfo['id'],'status'=>3,'issell'=>0])->find(); if($tradeinfo) { $this->error('此商品还未代售,不可拆分'); } // if($goodsinfo['topprice']<=$goodsinfo['price1']) // { $sum=0; $sumpreprice=0; for($i=1;$i<=(int)$goodsinfo['son_nums'];$i++) { $prePrice = $goodsinfo['price1'] - $goodsinfo['price']; if($i < (int)$goodsinfo['son_nums']) { $price=round(($goodsinfo['price1']/$goodsinfo['son_nums']),0); $preprice=$prePrice>0?round(($prePrice/$goodsinfo['son_nums']),0):0; $sum+=$price; $sumpreprice+=$preprice; }else{ $price=$goodsinfo['price1']-$sum; $preprice=$prePrice>0?$prePrice-$sumpreprice:0; } $data=[ 'catid'=>$goodsinfo['catid'], 'title'=>$goodsinfo['title'].$i, 'description'=>$goodsinfo['description']? $goodsinfo['description'].'-'.$i : 'G'.$goodsinfo['id'].'-'.$i, 'content'=>$goodsinfo['content'], 'image'=>$goodsinfo['image'], 'images'=>$goodsinfo['images'], 'on_sale'=>1, 'price'=>$goodsinfo['price'], 'price1'=>$goodsinfo['price']+$preprice, 'pre_price'=>$preprice, 'topprice'=>$goodsinfo['topprice'], 'son_nums'=>$goodsinfo['son_nums'], 'utime'=>time(), 'isnew'=>1, 'istrade'=>0, 'stuid'=>$goodsinfo['stuid'], 'userid'=>$goodsinfo['userid'], ]; $ids=db('goods')->insertGetId($data); } db('goods')->where(['id'=>$goodsinfo['id']])->update(['on_sale'=>0,'price1'=>0,'price'=>0,'pre_price'=>0]); db('trade')->where(['goodsid'=>$goodsinfo['id'],'status'=>3])->update(['isout'=>1]); // } $this->success('拆分成功'); } function toassign(){ $gid=input('id'); $mobile=input('mobile',''); if(empty($mobile)){ $this->error('请填写指派用户手机账号'); } $studio=db('studio')->where(['title'=>$this->auth->login_studio])->find(); if(time()>=strtotime(date("Y-m-d {$studio['start']}")) && time()<=strtotime(date("Y-m-d {$studio['end']}"))){ $this->error('请在店铺营业时间外指派'); } $goods=db('goods')->where(['id'=>$gid])->find(); if(empty($goods) || $goods['on_sale'] != 1){ $this->error('此商品不存在或未上架,不可指派'); } if($goods['on_resale'] == 1){ $this->error('此商品已转售,不可指派'); } $tradeinfo=db('trade')->where(['goodsid'=>$gid,'status'=>['in','1,2,-1']])->find(); if($tradeinfo || $goods['istrade'] != 0 || $tradeinfo['on_resale'] == 1) { $this->error('此商品交易中,不可指派'); } $tradeinfo1=db('trade')->where(['goodsid'=>$gid,'status'=>3,'issell'=>0])->find(); if($tradeinfo1) { $this->error('此商品还未代售,不可指派'); } $userInfo = \app\common\model\User::where(['mobile'=> $mobile,'status'=>1])->find(); if(empty($userInfo)){ $this->error('指派用户不存在或不可用,请核对或更换账号'); } if($userInfo['id'] == $this->auth->id){ //$this->error('抱歉不能指派给自己'); } $feebcf=db('bonus_config')->where(['id'=>2])->find(); db()->startTrans(); $tradedata=[ 'orderNo'=>date('YmdHi').rand(100,999), 'userid'=>$goods['userid'], 'goodsid'=>$goods['id'], 'nums'=>$goods['price1'], 'pre_price'=>$goods['pre_price'], 'ctime'=>time(), 'create_time'=>strtotime('today'), 'status'=>1, 'relevant_userid'=> $userInfo['id'], 'fee'=>$goods['price1']*$feebcf['value']*0.01, 'remark'=>date('Y-m-d H:i:s'), 'catid'=>$goods['catid'], 'stuid'=>$goods['stuid'], 'appoint_time'=>time(), 'type'=>1, ]; $tradeid=db('trade')->insertGetId($tradedata); $res1=db('goods')->where(['id'=>$goods['id']])->update(['istrade'=>1]); if($tradeid && $res1) { db()->commit(); $this->success('指派成功',['id'=>$tradeid]); }else{ db()->rollback(); $this->error('指派失败'); } } }