public function index() { $result = []; $applications = ShopCardApplication::where('authorized', 0)->with('customer')->get(); foreach ($applications as $application) { $result[] = ['require_id' => $application->id, 'id' => $application->customer_id, 'name' => $application->customer->nickname, 'phone' => $application->customer->phone, 'num' => $application->amount, 'beans_total' => $application->customer->beans_total]; } return view('backend.order.gift-card')->with(['applications' => json_encode($result)]); }
public function askForCard(Request $request) { $customer = \Helper::getCustomerOrFail(); $amount = $request->input('amount'); $card_type_id = $request->input('card_type_id', 1); $card_type = CardType::find($card_type_id); if (ShopCardApplication::where('customer_id', '=', $customer->id)->where('authorized', '=', 0)->first()) { return '您已有申请正在处理中,不能重复申请。'; } if ($customer->beans_total < $card_type->beans_value * $amount) { return '迈豆不足,不能申请兑换。'; } ShopCardApplication::create(['customer_id' => $customer->id, 'amount' => $amount, 'authorized' => 0, 'card_type_id' => $card_type_id]); return '申请成功,待管理员审核!'; }
/** * @return \App\Models\ShopCardApplication; * 返回shopcardapplication的卡券总数 */ public function getShopCardApplication() { try { $user = self::getSessionCachedUser(); $customer = Customer::where('openid', $user['openid'])->firstOrFail(); $shopCardApplication = ShopCardApplication::where('customer_id', $customer['id'])->get(); if (empty($shopCardApplication)) { return 0; } else { return $shopCardApplication; } } catch (\Exception $e) { abort('404'); } }