| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195 |
- <?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'],
- '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['nums'],'status'=>3]);
- $res2=db('goods')->where(['id'=>$tradeinfo['goodsid']])->update(['userid'=>$tradeinfo['relevant_userid'],'update_time'=>time(),'price1'=>$endprice,'pre_price'=> $endprice-$tradeinfo['nums']]);
- 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("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');
- }
- 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()
- {
- $times=strtotime('today')-60*60*24*2;
- $map['ctime']=['gt',$times];
- $map['status']=['not in','0,-2'];
- $map['userid|relevant_userid'] = $this->auth->id;
- $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? $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 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('本商家今日预约已达上限');
- }
- #价格区间
- 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 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++)
- {
- if($i < (int)$goodsinfo['son_nums'])
- {
- $price=round(($goodsinfo['price1']/$goodsinfo['son_nums']),0);
- $preprice=round(($goodsinfo['pre_price']/$goodsinfo['son_nums']),0);
- $sum+=$price;
- $sumpreprice+=$preprice;
- }else{
- $price=$goodsinfo['price1']-$sum;
- $preprice=$goodsinfo['pre_price']-$sumpreprice;
- }
- $data=[
- 'catid'=>$goodsinfo['catid'],
- 'title'=>$goodsinfo['title'].$i,
- 'description'=>$goodsinfo['description'].'-'.$i,
- 'content'=>$goodsinfo['content'],
- 'image'=>$goodsinfo['image'],
- 'images'=>$goodsinfo['images'],
- 'on_sale'=>1,
- 'price'=>$price-$preprice,
- 'price1'=>$price,
- '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]);
- db('trade')->where(['goodsid'=>$goodsinfo['id'],'status'=>3])->update(['isout'=>1]);
- // }
-
- $this->success('拆分成功');
-
- }
- }
|