Quellcode durchsuchen

上传文件至 ''

青鱼1233 vor 6 Jahren
Ursprung
Commit
edc95b1dc5
1 geänderte Dateien mit 530 neuen und 0 gelöschten Zeilen
  1. 530 0
      User.php

+ 530 - 0
User.php

@@ -0,0 +1,530 @@
+<?php
+namespace app\index\controller;
+use think\Controller;
+use think\db;
+use Jst\Jst;
+
+class User extends Controller{
+
+	//添加发票
+	public function addInvoice(){
+		$data=$this->request->param();
+
+		$data['time']=time();
+		if(db::name('invoice')->insert($data)){
+			$rdata['code']=200;
+			$rdata['mess']='添加成功';
+		}else{
+			$rdata['code']=400;
+			$rdata['mess']='添加失败';
+		}
+		return json($rdata);
+	}
+
+	//显示全部发票
+	public function showInvoice(){
+		$openid=$this->request->param('openid');
+
+		if(!$openid){
+            return json(['code'=>401,'mess'=>'请先登录']);
+        }
+
+		$data=db::name('invoice')->where('openid',$openid)->select();
+		if($data){
+			$rdata['code']=200;
+			$rdata['mess']=$data;
+		}else{
+			$rdata['code']=400;
+			$rdata['mess']='查看错误';
+		}
+		return json($rdata);
+	}
+
+    //查看发票
+    public function catInvoice(){
+        $id=$this->request->param('id');
+
+        if(!$id){
+            return json(['code'=>401,'mess'=>'发票id为空']);
+        }
+
+        $data=db::name('invoice')->find($id);
+        if($data){
+            $rdata['code']=200;
+            $rdata['mess']=$data;
+        }else{
+            $rdata['code']=400;
+            $rdata['mess']='查看错误';
+        }
+        return json($rdata);
+    }
+
+    //修改发票
+    public function editInvoice(){
+        $data=$this->request->param();
+        if(!$data['id']){
+            return json(['code'=>401,'mess'=>'发票id为空']);
+        }
+
+        if(db::name('invoice')->update($data)){
+            $rdata['code']=200;
+            $rdata['mess']='修改成功';
+        }else{
+            $rdata['code']=400;
+            $rdata['mess']='修改失败';
+        }
+        return json($rdata);
+    }
+
+	//删除发票
+	public function delInvoice(){
+		$res=$this->request->param();
+		$data=db::name('invoice')->where($res)->delete();
+		if($data){
+			$rdata['code']=200;
+			$rdata['mess']='删除成功';
+		}else{
+			$rdata['code']=400;
+			$rdata['mess']='删除失败';
+		}
+		return json($rdata);
+	}
+
+	//支付订单列表
+	public function my_order(){
+		$res=$this->request->param();
+
+		if(!$res['openid']){
+            return json(['code'=>401,'mess'=>'请先登录']);
+        }
+
+		$zhekou=GetPrice($res['openid']);  //计算用户折扣
+		$openid=$res['openid'];
+		//退款的订单id
+		$order_info_refund=db::name('order_info_refund')->field('id,order_info_true_id')->where('state','<>','1')->where('openid',$openid)->select();
+
+		$ids=array_column($order_info_refund,'order_info_true_id');
+
+		if($res['state']==0){
+			$data=db::name('order_info_true')
+				->field('id,kuaidi,code,state,totprice')
+				->where('id','NOT IN',$ids)
+				->where('openid',$openid)
+				->where('isdel','<>',1)
+				->order("id",'desc')
+				->select();
+		}elseif($res['state']==5){
+			//退款的订单
+			$data=db::name('order_info_refund')->alias('r')
+				->join('order_info_true t',"r.order_info_true_id=t.id")
+				->where('r.openid',$openid)
+				->where('r.state','<>','1')
+				->where('r.isdel','<>','1')
+				->field('r.state,r.id,t.kuaidi,t.code,t.totprice')
+				->order('r.id','desc')
+				->select();
+		}else{
+			$data=db::name('order_info_true')
+				->field('id,kuaidi,code,state,totprice')
+				->where('id','NOT IN',$ids)
+				->where($res)
+				->where('isdel','<>',1)
+				->order("id",'desc')
+				->select();
+		}
+
+		if(!isset($data)){
+			return json(['code'=>400,'mess'=>'没有订单']);
+		}	
+
+		foreach($data as $key=>$val){
+			$code=$val['code'];
+			$tmp=db::name("order")->alias('o')
+				->join('goods_inventory i',"o.inventory_id=i.id")
+				->join('goods g','o.goods_id=g.id')
+				->field('g.id,g.img1,g.name,o.nums,o.price,o.cangku,g.xinghao,i.fenlei')
+				->where('o.code',$val['code'])
+				->select();
+
+			$tmpnums=0;
+			$tmpprice=0;
+			foreach($tmp as $key1=>$val1){
+				$tmp[$key1]['price']=round($val1['price']*$zhekou,1);
+				$cangku=$val1['cangku'];
+
+				$tmpnums=$tmpnums+$val1['nums'];
+				$tmpprice=$tmpprice+round($val1['nums']*$val1['price']*$zhekou,1);
+
+				if(db::name('evaluate')->where(['goods_id'=>$val1['id'],'code'=>$code])->find()){
+					$tmp[$key1]['evaluate']=1;
+				}else{
+					$tmp[$key1]['evaluate']=0;
+				}
+			}
+
+			$data[$key]['goods']=$tmp;
+			$data[$key]['cangku']=$cangku;
+			$data[$key]['nums']=$tmpnums;
+			// $data[$key]['tot_money']=$tmpprice;
+			$data[$key]['tot_money']=$val['totprice'];
+		}
+
+		return json($data);
+
+	}
+
+	//删除订单
+	public function delOrder(){
+		$res=$this->request->param();
+		if(!isset($res['openid']) || !isset($res['id'])){
+			return json(['code'=>401,'mess'=>'参数错误']);
+		}
+
+		if(db::name("order_info_refund")->where($res)->update(['isdel'=>'1'])){
+			$response['code']=200;
+			$response['mess']='删除成功';
+		}else{
+			$response['code']=400;
+			$response['mess']='删除失败';
+		}
+		return json($response);
+	}
+
+	//删除订单
+	public function delOrderReald(){
+		$res=$this->request->param();
+		if(!isset($res['openid']) || !isset($res['id'])){
+			return json(['code'=>401,'mess'=>'参数错误']);
+		}
+
+		if(db::name("order_info_true")->where($res)->update(['isdel'=>'1'])){
+			$response['code']=200;
+			$response['mess']='删除成功';
+		}else{
+			$response['code']=400;
+			$response['mess']='删除失败';
+		}
+		return json($response);
+	}
+
+	//确认收货
+	public function trueOrder(){
+		$res=$this->request->param();
+		if(!isset($res['openid']) || !isset($res['id'])){
+			return json(['code'=>401,'mess'=>'参数错误']);
+		}
+		if(db::name("order_info_true")->where($res)->update(['state'=>4])){
+			//收益的金额
+			$order_info_true=db::name("order_info_true")->where($res)->field('code,time,openid,totprice,kuaidifei,crsNo')->find();
+			$totpricezhe=round($order_info_true['totprice']*0.05,2);
+			//得到收益人的openid  计算收益
+			$generalize=db::name('generalize')->field('popenid,rank')->where('openid',$res['openid'])->find();
+
+            //存入临时数据库7天进入账号
+            if($generalize){
+                $generalize_price_tmp['openid']=$generalize['popenid'];
+                $generalize_price_tmp['price']=$totpricezhe;
+                $generalize_price_tmp['time']=time();
+                $generalize_price_tmp['code']=$order_info_true['code'];
+                // $zeng=json_encode($generalize_price_tmp);
+                db::name('generalize_price_tmp')->insert($generalize_price_tmp); 
+            }
+               
+
+			//给总收益累计
+			db::name('user')->where('openid',$res['openid'])->setInc('cumulative',$order_info_true['totprice']);
+
+			//修改erp订单状态
+            $jst=new Jst();
+            $orderInfo=db::name("order")->alias('o')
+                ->join('goods_inventory g',"o.inventory_id=g.id")
+                ->join('goods s','o.goods_id=s.id')
+                ->field('g.shop_i_id,o.province,o.city,o.district,o.address,o.price,o.name,o.phone,o.inventory_id,o.nums,g.fenlei,s.name sname')
+                ->where('o.code',$order_info_true['code'])
+                ->select();
+            // $this->intext(json_encode($orderInfo));
+            foreach($orderInfo as $infokey=>$infoval){
+                $items[$infokey]=[
+                    'sku_id'=>$infoval['shop_i_id'],
+                    'properties_value'=>$infoval['fenlei'],
+                    'amount'=>$infoval['price'],
+                    'base_price'=>$infoval['price'],
+                    'qty'=>$infoval['nums'],
+                    'name'=>$infoval['sname'],
+                    'outer_oi_id'=>'zidingdanhao1'
+                ];
+                
+            }
+            // $this->intext(json_encode($items));
+            $jstData=[
+                [
+                    'shop_id'=>'10223774', //店铺编号
+                    'so_id'=>$order_info_true['code'],   //订单id
+                    'order_date'=>date("Y-m-d H:i:s",$order_info_true['time']),   //下单时间
+                    'shop_status'=>'TRADE_FINISHED',   //0:不启用,1:启用
+                    'shop_buyer_id'=>$order_info_true['openid'],  //卖家昵称
+                    'receiver_state'=>$orderInfo[0]['province'],  //收货省份
+                    'receiver_city'=>$orderInfo[0]['city'],  //收货城市
+                    'receiver_district'=>$orderInfo[0]['district'],  //收货区域
+                    'receiver_address'=>$orderInfo[0]['address'],  //详细地址
+                    'receiver_name'=>$orderInfo[0]['name'],  //收货人姓名
+                    'receiver_mobile'=>$orderInfo[0]['phone'],  //收货手机号
+                    'pay_amount'=>$order_info_true['totprice'],  //卖家昵称
+                    'freight'=>$order_info_true['kuaidifei'],  //卖家昵称
+                    'items'=>$items,
+                    'pay'=>[
+                        'outer_pay_id'=>$order_info_true['crsNo'],
+                        'pay_date'=>date("Y-m-d H:i:s",$order_info_true['time']),
+                        'payment'=>'微信支付',
+                        'seller_account'=>'援邦消防',
+                        'buyer_account'=>$order_info_true['openid'],
+                        'amount'=>$order_info_true['totprice']
+                    ]
+                ]
+            ];
+            $jstData=json_encode($jstData);
+            $res=$jst->queryData('orders.upload',$jstData);
+            // $this->intext($res);
+                    
+			$response['code']=200;
+			$response['mess']='操作成功';
+		}else{
+			$response['code']=400;
+			$response['mess']='操作失败';
+		}
+		return json($response);
+	}
+
+	    //写入文件操作
+    public function intext($data){
+        $myfile = fopen("a.txt", "a+");
+        fwrite($myfile, $data);
+        fclose($myfile);
+    }
+
+
+	//申请退款
+	public function refund(){
+		$openid=$this->request->param('openid');
+		$id=$this->request->param('id');
+		$reason=$this->request->param('reason');
+
+		if(!isset($id) || !isset($openid) || !isset($reason)){
+			return json(['code'=>400,'mess'=>'缺少参数']);
+		}
+
+		//退款订单信息
+		$order_info_true=db::name('order_info_true')->field('id,code,totprice,crsNo,state,card,openid,time,kuaidifei')->where('id',$id)->find();   
+
+		//退款订单的总金额
+		$totprice=db::name('order_info_true')->field("sum(totprice) stotprice")->where("crsNo",$order_info_true['crsNo'])->find();
+		// dump($totprice['stotprice']);
+
+		//判断是否已经申请过退款
+		$isrefund=db::name('order_info_refund')->where('code',$order_info_true['code'])->find();
+
+		if(isset($isrefund)){
+			return json(['code'=>401,'mess'=>'退款审核失败']);
+		}
+
+		$refundDdata['openid']=$openid;
+		$refundDdata['reason']=$reason;
+		$refundDdata['time']=time();
+		$refundDdata['order_info_true_id']=$order_info_true['id'];
+		$refundDdata['code']=$order_info_true['code'];
+		$refundDdata['out_trade_no']=$order_info_true['crsNo'];
+		$refundDdata['total_fee']=$totprice['stotprice'];
+		$refundDdata['state']='6';
+		$refundDdata['card']=$order_info_true['card'];
+		$refundDdata['refund_fee']=$order_info_true['totprice'];  //退款的金额
+		
+		if(db::name('order_info_refund')->insert($refundDdata)){
+
+			//修改erp订单状态
+            $jst=new Jst();
+            $orderInfo=db::name("order")->alias('o')
+                ->join('goods_inventory g',"o.inventory_id=g.id")
+                ->join('goods s','o.goods_id=s.id')
+                ->field('g.shop_i_id,o.province,o.city,o.district,o.address,o.price,o.name,o.phone,o.inventory_id,o.nums,g.fenlei,s.name sname')
+                ->where('o.code',$order_info_true['code'])
+                ->select();
+            // $this->intext(json_encode($orderInfo));
+            foreach($orderInfo as $infokey=>$infoval){
+                $items[$infokey]=[
+                    'sku_id'=>$infoval['shop_i_id'],
+                    'properties_value'=>$infoval['fenlei'],
+                    'amount'=>$infoval['price'],
+                    'base_price'=>$infoval['price'],
+                    'qty'=>$infoval['nums'],
+                    'name'=>$infoval['sname'],
+                    'refund_status'=>'waiting',
+                    'refund_qty'=>$infoval['nums'],
+                    'outer_oi_id'=>'zidingdanhao1'
+                ];
+                
+            }
+            // $this->intext(json_encode($items));
+            //判断订单原始装填
+            switch($order_info_true['state']){
+                case 1:
+                    $shop_status='WAIT_BUYER_PAY';
+                    break;
+                case 2:
+                    $shop_status='WAIT_SELLER_SEND_GOODS';
+                    break;
+                case 3:
+                    $shop_status='WAIT_BUYER_CONFIRM_GOODS';
+                    break;
+                case 4:
+                    $shop_status='TRADE_FINISHED';
+                    break;
+            }
+
+            $jstData=[
+                [
+                    'shop_id'=>'10223774', //店铺编号
+                    'so_id'=>$order_info_true['code'],   //订单id
+                    'order_date'=>date("Y-m-d H:i:s",$order_info_true['time']),   //下单时间
+                    'shop_status'=>$shop_status,   //订单状态
+                    'shop_buyer_id'=>$order_info_true['openid'],  //卖家昵称
+                    'receiver_state'=>$orderInfo[0]['province'],  //收货省份
+                    'receiver_city'=>$orderInfo[0]['city'],  //收货城市
+                    'receiver_district'=>$orderInfo[0]['district'],  //收货区域
+                    'receiver_address'=>$orderInfo[0]['address'],  //详细地址
+                    'receiver_name'=>$orderInfo[0]['name'],  //收货人姓名
+                    'receiver_mobile'=>$orderInfo[0]['phone'],  //收货手机号
+                    'pay_amount'=>$order_info_true['totprice'],  //卖家昵称
+                    'freight'=>$order_info_true['kuaidifei'],  //卖家昵称
+                    'items'=>$items,
+                    'pay'=>[
+                        'outer_pay_id'=>$order_info_true['crsNo'],
+                        'pay_date'=>date("Y-m-d H:i:s",$order_info_true['time']),
+                        'payment'=>'微信支付',
+                        'seller_account'=>'援邦消防',
+                        'buyer_account'=>$order_info_true['openid'],
+                        'amount'=>$order_info_true['totprice']
+                    ]
+                ]
+            ];
+            $jstData=json_encode($jstData);
+            $res=$jst->queryData('orders.upload',$jstData);
+            // $this->intext($res);
+            
+			return json(['code'=>200,'mess'=>'OK']);
+		}
+
+		// if(db::name('order_info_true')->where(['id'=>$id,'openid'=>$openid])->update(['state'=>5,'reason'=>$reason])){
+			
+		// }
+		
+	}
+
+
+	//我的推广码
+	public function myCode(){
+		$openid=$this->request->param('openid');
+
+		if(!$openid){
+            return json(['code'=>401,'mess'=>'请先登录']);
+        }
+
+		$data=db::name('generalize')->where('openid',$openid)->field('selfcode')->find()['selfcode'];
+
+		if(!isset($data)){
+			return json(['code'=>400,'mess'=>'缺少参数']);
+		}else{
+			return json(['code'=>200,'mess'=>$data]);
+		}
+	}
+
+	//订单详情
+	public function orderInfo(){
+		$openid=$this->request->param('openid');
+        
+		$code=$this->request->param('code');   //订单号
+
+		$data=db::name('order_info_true')->alias('t')
+			->join('order o',"o.code=t.code")
+			->join("goods g","g.id=o.goods_id")
+			->join('goods_inventory i',"i.id=o.inventory_id")
+			->field('t.id,t.code,t.kuaidi,t.state,t.totprice,t.kuaidifei,t.vipprice,o.province,o.city,o.district,o.address,o.phone,o.name,o.nums,o.price,i.fenlei,g.name gname,g.xinghao,i.img')
+			->where("t.code",$code)
+			->select();
+
+		foreach($data as $key=>$val){
+			$rdata['name']=$val['name'];
+			$rdata['state']=$val['state'];
+			$rdata['province']=$val['province'];
+			$rdata['city']=$val['city'];
+			$rdata['district']=$val['district'];
+			$rdata['address']=$val['address'];
+			$rdata['phone']=$val['phone'];
+			$rdata['id']=$val['id'];
+			$rdata['code']=$val['code'];
+			$rdata['kuaidi']=$val['kuaidi'];
+			$rdata['totprice']=$val['totprice'];
+			$rdata['kuaidifei']=$val['kuaidifei'];
+			$rdata['vipprice']=$val['vipprice'];
+			unset($data[$key]['name']);
+			unset($data[$key]['state']);
+			unset($data[$key]['province']);
+			unset($data[$key]['city']);
+			unset($data[$key]['district']);
+			unset($data[$key]['address']);
+			unset($data[$key]['phone']);
+			unset($data[$key]['id']);
+			unset($data[$key]['code']);
+			unset($data[$key]['kuaidi']);
+			unset($data[$key]['totprice']);
+			unset($data[$key]['kuaidifei']);
+			unset($data[$key]['vipprice']);
+		}
+
+		if($data){
+			$rdata['goods']=$data;
+			$rdata['return_code']=200;
+		}else{
+			$rdata['return_code']=400;
+			$rdata['mess']='信息有误';
+		}
+		return json($rdata);
+	}
+
+
+	//查询快递
+	public function express(){
+		
+		$code=$this->request->param('code');
+
+		$no=db::name('order_info_true')->where('code',$code)->field('no')->find()['no'];	
+		// http_request
+		if(!isset($no)){
+			return json(['status'=>501,'msg'=>'订单错误']);
+		}else{
+			$url="https://kdwlcxf.market.alicloudapi.com/kdwlcx?no=".$no;
+
+			$appcode='ef02a75b81334e119245ed999275047b';
+
+			$headers = array();
+
+			array_push($headers, "Authorization:APPCODE " . $appcode);
+
+			$data=http_request($url,'',$headers);
+
+			return $data;
+		}
+	}
+
+    //意见反馈
+    public function msg(){
+        $data=$this->request->param();
+        $data['time']=time();
+        if(db::name('msg')->insert($data)){
+            $req['code']=200;
+        }else{
+            $req['code']=400;
+        }
+
+        return json($req);
+    }
+}