/** * @param \App\Models\Customer $customer * @param string $action * @param int $beans_changed */ protected function update(Customer $customer, $action, $beans_changed) { if ($action == AppConstant::BEAN_ACTION_CONSUME or $action == AppConstant::BEAN_ACTION_TRANSFER_CASH) { if ($beans_changed >= $customer->beans_total) { \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_BEAN, -$customer->beans_total); $customer->beans_total = 0; } else { \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_BEAN, -$beans_changed); $customer->beans_total -= $beans_changed; } } else { \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_BEAN, $beans_changed); $customer->beans_total += $beans_changed; } $customer->save(); }
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'); }
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']); }
/** * */ protected function updateStatistics() { foreach ($this->commodities()->get(['id'])->pluck('id') as $commodity_id) { \Analyzer::updateCommodityStatistics($this->customer_id, $commodity_id); \Analyzer::updateBasicStatistics($this->customer_id, AnalyzerConstant::CUSTOMER_COMMODITY); \EnterpriseAnalyzer::updateCommodityStatistics($commodity_id); } \Analyzer::updateBasicStatistics($this->customer_id, AnalyzerConstant::CUSTOMER_ORDER); \Analyzer::updateBasicStatistics($this->customer_id, AnalyzerConstant::CUSTOMER_MONEY_COST, $this->cash_payment); \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_ORDER); \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_COMMODITY, $this->commodities()->count()); \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_INCOME, $this->cash_payment); \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_BEAN, $this->beans_payment); }
/** * @return \Closure */ public function subscribeEventCallback() { return function ($event) { // \Log::info('yijian:0831::---' . $event); \Log::info('subscribe' . $event); $openId = $event['FromUserName']; $eventKey = $event['EventKey']; $customer = Customer::where('openid', $openId)->first(); if ($customer) { if ($eventKey == 'qrscene_25011') { \Log::info('test 1:::---' . $event); $this->moveUserToGroup($openId, 103); //移动用户分组 return Message::make('text')->content("嗨!欢迎关注小易,我们有全面及时的糖尿病教育资讯和便捷丰富的在线商城。首次注册即赠送价值10元的迈豆,持续学习迈豆享不停,快来尽情换购吧\n\n<a target=\"_blank\" href=\"http://www.ohmate.cn/questionnaire2/\">点击此处,快来1元换购胰岛素针头!</a>"); } elseif ($eventKey == 'qrscene_25005') { return Message::make('text')->content("亲爱的用户:欢迎您关注易康伴侣,为普及糖尿病知识,提高大众对糖尿病认知水平,易康伴侣现发起全民“斗糖大赛”活动,邀您参与。每次5道题,答对3题及以上即可开启换购,支付1到3元不等即可换购对应商品,易折棉棒、低糖卫士、胰岛素针头等您领取。<a target=\"_blank\" href=\"http://www.ohmate.cn/questionnaire3/\">点击此处</a>,立即斗起来!"); } else { \Log::info('test 2:::---' . $event); return Message::make('text')->content('欢迎您回来!'); } } $customer = new Customer(); $customer->openid = $openId; $typeId = CustomerType::where('type_en', AppConstant::CUSTOMER_COMMON)->first()->id; $customer->type_id = $typeId; if (is_array($eventKey) && 0 == count($eventKey)) { \Log::info('test 3:::---' . $event); $customer->referrer_id = 0; } else { \Log::info('test 4:::---' . $event); $referrer_str = substr($eventKey, 8); if (strlen($referrer_str) > 10) { //假如是32位随机数,则为瞬联的旧版用户 $referrer = Customer::where('old_id', $referrer_str)->first(); } else { $referrerId = (int) $referrer_str; $referrer = Customer::where('id', $referrerId)->first(); } if (!$referrer || !$referrer->is_registered) { $customer->referrer_id = 0; } else { $customer->referrer_id = $referrer->id; } /*else>*/ } $customer->save(); \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_FOCUS); if ($eventKey == 'qrscene_25011') { $this->moveUserToGroup($openId, 103); //移动用户分组 \Log::info('test 5:::---' . $event); return Message::make('text')->content("嗨!欢迎关注小易,我们有全面及时的糖尿病教育资讯和便捷丰富的在线商城。首次注册即赠送价值10元的迈豆,持续学习迈豆享不停,快来尽情换购吧\n\n<a target=\"_blank\" href=\"http://www.ohmate.cn/questionnaire2/\">点击此处,快来1元换购胰岛素针头!</a>"); } elseif ($eventKey == 'qrscene_25005') { return Message::make('text')->content("亲爱的用户:欢迎您关注易康伴侣,为普及糖尿病知识,提高大众对糖尿病认知水平,易康伴侣现发起全民“斗糖大赛”活动,邀您参与。每次5道题,答对3题及以上即可开启换购,支付1到3元不等即可换购对应商品,易折棉棒、低糖卫士、胰岛素针头等您领取。<a target=\"_blank\" href=\"http://www.ohmate.cn/questionnaire3/\">点击此处</a>,立即斗起来!"); } $upper = $customer->getReferrer(); if ($upper && $upper->doctorType() == 'A') { return Message::make('news')->items(function () { return [Message::make('news_item')->title('问卷有礼')->description('问卷有礼')->url(url('/questionnaire'))->picUrl('http://7xrlyr.com1.z0.glb.clouddn.com/填调查问卷.jpg')]; }); } $content = '嗨!欢迎关注易康伴侣!' . '在此您能任性享用新鲜实用的糖尿病资讯。' . '您学习,我送礼;' . '您消费,我奖励。' . '一大波迈豆等您拿,注册立奖10元!'; return Message::make('text')->content($content); }; }