Example #1
0
 /**
  * 依据前台post消息创建订单
  *
  * @param Request $request
  * @return \Response
  */
 public function generateConfig(Request $request)
 {
     $validator = \Validator::make($request->all(), ['address_id' => 'required|exists:addresses,id', 'cart' => 'required']);
     if ($validator->fails()) {
         return response()->json($validator->errors()->getMessages());
     }
     $customer = \Helper::getCustomer();
     $items = $request->input('cart');
     $sale = $request->input('sale', null);
     if ($sale != null && !$this->checkSaleCredential($customer, $sale)) {
         return response()->json(['success' => false, 'error_message' => '你不具有参加特卖资格!']);
     }
     $order = new Order();
     $address = Address::findOrFail($request->input('address_id'));
     $order->initWithCustomerAndAddress($customer, $address, $sale);
     $order->save();
     $order->addCommodities($items);
     $order->calculate();
     $order->save();
     $result = \Wechat::generatePaymentConfig($order, $customer);
     return response()->json(['success' => true, 'data' => ['result' => $result, 'order_id' => $order->id]]);
 }