Beispiel #1
0
  private function wxJsPay($request)
  {
    $state = $request->input('state');

    $decodeObject = json_decode($state);

    $user = Auth::user();

    $order_code = $decodeObject->order_code;

    $order = Order::where('code', '=', $order_code)->first();

    if (empty($order->id)) {
    
      //todo
    
    } else if ($order->status > 0) {
    
      return view('mobile/payed');
    
    }

    $good = Good::where('id', '=', $order->gid)->first();

    $orderPrice = OrderPrice::where('oid', '=', $order->id)->first();

    $receiver = ReceiverInfo::find($order->rid);

    require_once "lib/WxPay.Api.php";  

    require_once "lib/WxPay.JsApiPay.php";

    $notify_url = $this->debug ? "http://www.51linpai.com:8000/order/wxpay/" : "http://www.51linpai.com/order/wxpay/";

    $tools = new \JsApiPay();

    $openId = $tools->GetOpenid("", null);

    $input = new \WxPayUnifiedOrder();
    $input->SetBody($good->name);
    $input->SetAttach($good->code);
    $input->SetOut_trade_no($order->code);
    $input->SetTotal_fee($orderPrice->final_price * 100);
    $input->SetTime_start(date("YmdHis"));
    $input->SetTime_expire(date("YmdHis", time() + 600));
    $input->SetGoods_tag($good->code);
    $input->SetNotify_url($notify_url);
    $input->SetTrade_type("JSAPI");
    $input->SetOpenid($openId);
    $jsWxOrder = \WxPayApi::unifiedOrder($input);
    $jsApiParameters = $tools->GetJsApiParameters($jsWxOrder);

    //获取共享收货地址js函数参数
    $editAddress = $tools->GetEditAddressParameters();

    $data = [

        'editAddress' => $editAddress,

        'jsApiParameters' => $jsApiParameters,

        'order_code' => $order->code,

        'price' => $orderPrice->final_price,

        'address' =>  $receiver->city . ' ' . $receiver->district . ' ' . $receiver->address,

        'step' => 4,

        'header' => '支付订单'
      
      ];
    
    return view('mobile/wechat_js_pay', $data);
  
  }
  public function postEdit (Request $request)
  {
    $validate = $this->receiverValidate($request->input());

    if ($validate->fails()) {
    
      return $this->validateFail($validate);
    
    }

    $rid = $request->input('rid');

    if (empty($rid)) {
    
      return $this->failResponse('no_rid');
    
    }

    $input = $request->input();

    $receiver = ReceiverInfo::find($rid);

    $attributes = $receiver->getAttributes();

    foreach ($input as $key => $value) {
    
      if (array_key_exists($key, $attributes)) {

        $receiver->$key = $value;
      
      }
    
    }

    $res = $receiver->save();

    if ($res) {

      $html = $this->htmlTemplate($receiver);
    
      return $this->successResponse('result', $html);
    
    } else {

      /*
       * todo
       */
    
      return $this->failResponse();
    
    }

  }