示例#1
0
 public function search($input)
 {
     $query = CardType::query();
     $columns = Schema::getColumnListing('cardTypes');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
示例#2
0
 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 '申请成功,待管理员审核!';
 }