| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\CoinRate;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use app\common\model\Config;
- use fast\Random;
- use think\Session;
- use think\Validate;
- /**
- * 互助接口
- */
- class Trade extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- }
- function getfunsorder()
- {
- $map['status']=3;
- $user=get_user_data($this->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('指派失败');
- }
- }
- }
|