app/Http/Controllers/admin/OrdersController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $data = $request -> all();
        $gid = $data['gid'];
        $goods = Goods::where('id',$gid)->first();
        $num = (($goods['discount'])*($data['num']));
        $time= date('YmdHis',time());
        $sj = $data['s_sf'];
        $sq = $data['s_sq'];
        $xj = $data['s_xj'];
        $jt = $data['address'];
        $address = $sj.$sq.$xj.$jt;
        $res1= Goods::find($data['gid']);
        if(!empty($res1))
        {
            $orders = new Orders;
            $orders -> uid = $data['uid'];
            $orders -> gid = $data['gid'];
            $orders -> ordersnum = $time;
            $orders -> recipients = $data['recipients'];
            $orders -> phone = $data['phone'];
            $orders -> address = $address;
            $orders -> num = $data['num'];
            $orders -> total = $num;
            $orders -> status = $data['status'];
            $res2 = $orders -> save();
            if ($res2) {
                return redirect('/admin/orders/index')-> with('success','添加成功');
            }else{
                return back()->with('error','添加失败');
            }
       }else{
            return back()->with('error','请核对商品ID');
       }
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; $ gid = $ data [ 'gid' ] ; $ goods = Goods :: where ( 'id' , $ gid ) -> first ( ) ; $ num = ( ( $ goods [ 'discount' ] ) * ( $ data [ 'num' ] ) ) ; $ time = date ( 'YmdHis' , time ( ) ) ; $ sj = $ data [ 's_sf' ] ; $ sq = $ data [ 's_sq' ] ; $ xj = $ data [ 's_xj' ] ; $ jt = $ data [ 'address' ] ; $ address = $ sj . $ sq . $ xj . $ jt ; $ res1 = Goods :: find ( $ data [ 'gid' ] ) ; if ( ! empty ( $ res1 ) ) { $ orders = new Orders ; $ orders -> uid = $ data [ 'uid' ] ; $ orders -> gid = $ data [ 'gid' ] ; $ orders -> ordersnum = $ time ; $ orders -> recipients = $ data [ 'recipients' ] ; $ orders -> phone = $ data [ 'phone' ] ; $ orders -> address = $ address ; $ orders -> num = $ data [ 'num' ] ; $ orders -> total = $ num ; $ orders -> status = $ data [ 'status' ] ; $ res2 = $ orders -> save ( ) ; if ( $ res2 ) { return redirect ( '/admin/orders/index' ) -> with ( 'success' , '添加成功'); } else { return back ( ) -> with ( 'error' , '添加失败'); } } else { return back ( ) -> with ( 'error' , '请核对商品ID'); } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//获取上传的订单信息 // dump($data); //获取添加订单的商品ID //查询商品表中对应的购买商品id的价格 //计算商品总价 // dd($num); //生成订单号 //获取市级 //拼接收货地址 //查询商品表中有没有添加的商品ID //判断商品中有没有要添加具体商品 //对得到的用户订单进行添加到数据库 //判断添加订单是否成功