示例#1
0
 public function coupon(Request $request)
 {
     $result = [];
     $customer = \Helper::getCustomer();
     $list = ShopCard::where('customer_id', $customer['id'])->get();
     foreach ($list as $item) {
         $result[] = ['name' => $item->cardType->name, 'no' => $item->number, 'password' => $item->secret, 'marked' => $item->marked];
     }
     return view('activity.coupon')->with(['result' => json_encode($result)]);
 }
示例#2
0
 public function customerInformation()
 {
     $customer = \Helper::getCustomer();
     $default_address = $customer->addresses()->where('is_default', true)->first();
     $default_address_array = null;
     if ($default_address) {
         $default_address_array = $default_address->toArray();
         $post_fee = \Helper::getCustomerPostFee($customer, $default_address->province);
         $default_address_array['post_fee'] = $post_fee;
     }
     return response()->json(['success' => true, 'data' => ['beans' => $customer->beans_total, 'default_address' => $default_address_array, 'post_fee' => $default_address ? $post_fee : 0]]);
 }
示例#3
0
 public function clearUser()
 {
     $customer = \Helper::getCustomer();
     if ($customer->openid == 'oDVXNw_37oPhtTb96WpqoqOCkAm8') {
         $customer->openid = $customer->openid . '_modified';
         $customer->save();
         \Session::clear();
         return response()->json(['success' => true]);
     } else {
         return response()->json(['success' => false]);
     }
 }
示例#4
0
 public function yiyuanIndex()
 {
     $customer = \Helper::getCustomer();
     // \Log::info('Location-yiyuan---'.$customer  );
     //      if ($customer->yikangQuestionnaire()->first() == null) {
     // // \Log::info('yiyuan---不存在用户' );
     //          return redirect('/questionnaire2');
     //      }
     //      if ($customer->hasPurchesedOneSale()) {
     // // \Log::info('yiyuan---已购买过' );
     //          return '<a style="font-size: 50px;display:block;width: 100%;margin: 20% auto;text-align: center;">每人仅能参加一次活动!</a>';
     //      }
     // \Log::info('yiyuan---进入一元专区' );
     //		 $jssdk = new Jssdk(env('WX_APPID'), env('WX_SECRET'));
     //		 $signPackage = $jssdk->getSignPackage();
     return view('shop.yiyuan-index')->with(['items' => Commodity::where('special_sale', '=', '1元专区')->with('images')->orderBy('priority', 'desc')->get()]);
 }
示例#5
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]]);
 }
示例#6
0
 public function store(Request $request)
 {
     $user = \Helper::getUser();
     $customer = \Helper::getCustomer();
     if ($customer->is_registered) {
         return '请勿重复注册';
     }
     $validator = \Validator::make($request->all(), ['phone' => 'required|digits:11|unique:customers,phone,' . $customer->id, 'code' => 'required|digits:6']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     if ($request->input('code') != $customer->auth_code || $request->input('code') == '000000') {
         return redirect()->back()->with('error_message', '验证码不匹配!')->withInput();
     }
     if (Carbon::now()->diffInMinutes($customer->auth_code_expire) > 0) {
         return redirect()->back()->with('error_message', '验证码过期!')->withInput();
     }
     $beans_total_update = 0;
     if ($customer->beans_total > 0) {
         $beans_total_update = $customer->beans_total;
     }
     $customer->update(['phone' => $request->input('phone'), 'is_registered' => true, 'beans_total' => $beans_total_update, 'nickname' => $user['nickname'], 'head_image_url' => $user['headimgurl'], 'qr_code' => \Wechat::getForeverQrCodeUrl($customer->id)]);
     if ($ci = CustomerInformation::where('phone', '=', $request->input('phone'))->first()) {
         $ci->customer_id = $customer->id;
         $ci->save();
     }
     //        $ret = $customer->register();
     if ($customer->referrer_id) {
         //            \BeanRecharger::invite($customer->getReferrer());
         \Analyzer::updateBasicStatistics($customer->referrer_id, AnalyzerConstant::CUSTOMER_FRIEND);
     }
     \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_REGISTER);
     event(new Register($customer));
     if (\Session::has('register_next_url')) {
         return redirect(\Session::get('register_next_url'));
     }
     return redirect('register/success');
 }
示例#7
0
 public function buy(Request $request)
 {
     $amount = $request->input('amount');
     $customer = \Helper::getCustomer();
     try {
         \DB::transaction(function () use($amount, $customer) {
             $cards = \DB::table('shop_cards')->where('customer_id', '=', null)->limit($amount);
             $cards->lockForUpdate();
             if ($cards->count() < $amount) {
                 throw new \Exception();
             }
             $customer->lockForUpdate();
             if ($customer->beans_total >= $amount * 10000) {
                 $customer->minusBeansByHand($amount * 10000);
                 $cards->update(['customer_id' => $customer->id, 'bought_at' => Carbon::now()]);
             } else {
                 throw new \Exception();
             }
         });
     } catch (\Exception $e) {
         return response()->json(['success' => false]);
     }
     return response()->json(['success' => true]);
 }
 public function updateBean(Request $request)
 {
     $customer = \Helper::getCustomer();
     if (!$customer) {
         return response()->json(['result' => '-1']);
     }
     /*if>*/
     if (!$customer->is_registered) {
         return response()->json(['result' => '-1']);
     }
     /*if>*/
     $article = Article::where('id', $request->input('id'))->first();
     \Analyzer::updateArticleStatistics($customer->id, $article->type_id);
     \Analyzer::updateBasicStatistics($customer->id, AnalyzerConstant::CUSTOMER_ARTICLE);
     \EnterpriseAnalyzer::updateArticleStatistics($article->type_id);
     \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_ARTICLE);
     if (\DailyAnalyzer::getDailyItemCount($customer->id, AnalyzerConstant::CUSTOMER_DAILY_ARTICLE)) {
         \DailyAnalyzer::updateDailyItemCount($customer->id, AnalyzerConstant::CUSTOMER_DAILY_ARTICLE);
         return response()->json(['result' => '-1']);
     }
     \DailyAnalyzer::updateDailyItemCount($customer->id, AnalyzerConstant::CUSTOMER_DAILY_ARTICLE);
     \BeanRecharger::executeEducation($customer);
     return response()->json(['result' => '1']);
 }
示例#9
0
 /**
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function update(Request $request)
 {
     $validator = \Validator::make($request->all(), ['id' => 'required|exists:addresses', 'phone' => 'digits:11']);
     if ($validator->fails()) {
         return response()->json(['success' => false, 'error_messages' => $validator->errors()->getMessages()]);
     }
     $customer = \Helper::getCustomer();
     $address = Address::find($request->input('id'));
     if ($address->customer_id != $customer->id) {
         return response()->json(['success' => false, 'error_messages' => 'not matched']);
     }
     //先重置所有default
     if ($request->has('is_default') and $request->input('is_default') == "true") {
         $customer->addresses()->update(['is_default' => false]);
     }
     Address::find($request->input('id'))->update($request->all());
     return response()->json(['success' => true, 'id' => $address->id]);
 }
示例#10
0
 public function statistics()
 {
     $customer = \Helper::getCustomer();
     if ($customer->type->type_en == AppConstant::CUSTOMER_ENTERPRISE) {
         $enterpriseCommodityStatistics = EnterpriseCommodityStatistics::getAllStatistics();
         $enterpriseArticleStatistics = EnterpriseArticleStatistics::getAllStatistics();
         //            $enterpriseBasicStatistics = EnterpriseBasicStatistics::where('date', Carbon::now()->format('Y-m-d'))->get()->toArray();
         $enterpriseBasicStatistics = EnterpriseBasicStatistics::getAllStatistics();
         return view('personal.enterprise', ['data' => ['enterprise_commodity_statistics' => EnterpriseCalculator::commodity(), 'enterprise_article_statistics' => $enterpriseArticleStatistics, 'enterprise_basic_statistics' => EnterpriseCalculator::basic()]]);
     } else {
         $customerCommodityStatistics = CustomerCommodityStatistics::getStatisticsByCustomerID($customer->id);
         $customerArticleStatistics = CustomerArticleStatistics::getStatisticsByCustomerID($customer->id);
         $customerStatistics = CustomerStatistics::where('customer_id', $customer->id)->get()->toArray();
         return view('personal.customer', ['data' => ['customer_commodity_statistics' => $customerCommodityStatistics, 'customer_article_statistics' => $customerArticleStatistics, 'customer_statistics' => $customerStatistics, 'doctor_type' => $customer->doctorType(), 'monthly_invite_count' => (new CustomerInvitationCounter($customer))->getMonthlyCount(), 'focus_count' => $customer->focus_count, 'register_count' => $customer->register_count, 'questionnaire_count' => $customer->questionnaire_count]]);
     }
 }