コード例 #1
0
ファイル: SendBillNotice.php プロジェクト: n0th1n9/daizhang
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     Log::info('Begin the send-bill-notice command.');
     $now = Carbon::now();
     $beforeDay = \Config::get('app.day_before_send_bill_notice');
     $billList = CompanyBill::where('deadline', '=', $now->addDay($beforeDay)->format('Y-m-d 00:00:00'))->where('is_paid', CompanyBill::IS_PAID_NO)->select('company_id', 'user_id')->distinct()->get();
     foreach ($billList as $bill) {
         $map = ['user_id' => $bill->user_id, 'id' => $bill->company_id];
         $customerCompany = CustomerCompany::where($map)->first();
         if (!$customerCompany) {
             Log::error('send-bill-notice:Not find company.');
             continue;
         }
         $contact = $customerCompany->getDefaultContact();
         if (!$contact) {
             Log::error('send-bill-notice:Not find company contact.');
             continue;
         }
         $company = Company::where('id', $bill->user_id)->first();
         if (!$company) {
             Log::error('send-bill-notice:Not find daizhang user.');
             continue;
         }
         $sql = "SELECT sum(cb.grand_total) as grand_total, count(cb.id) as total_item FROM company_bills cb  where cb.is_paid=0 and cb.user_id={$bill->user_id} and cb.company_id={$bill->company_id}";
         $unpaidResult = DB::select($sql);
         if (count($unpaidResult) == 0) {
             continue;
         }
         $totalItem = $unpaidResult[0]->total_item;
         $grandTotal = $unpaidResult[0]->grand_total;
         $sms = new Sms();
         $text = "【代账通】尊敬的客户,贵公司尚有未支付费用 {$totalItem} 项,共计 ¥{$grandTotal} 元 。请及时联系 {$company->name} 缴纳。";
         $result = $sms->sendMessage($text, $contact->mobile);
         if ($result->code != 0) {
             Log::error('send-bill-notice:Send SMS error.' . $result->detail);
             continue;
         }
     }
     Log::info('End the send-bill-notice command.');
 }
コード例 #2
0
ファイル: AuthController.php プロジェクト: n0th1n9/daizhang
 /**
  * 获取验证码
  * @param Request $request
  * @return json
  * @author AndyLee <*****@*****.**>
  */
 public function getCaptcha(Request $request)
 {
     $input = $request->get('mobile');
     if (!preg_match("/^13[0-9]{1}[0-9]{8}\$|15[056189732]{1}[0-9]{8}\$|17[056189732]{1}[0-9]{8}\$|18[012356789]{1}[0-9]{8}\$/", $input)) {
         return Response::json(['message' => '手机号码格式不正确', 'message_code' => -1]);
     }
     $ip = $request->ip();
     $time = new \DateTime();
     $count = Cache::get($ip . '-' . $time->format('Y-m-d'));
     if ($count > 10) {
         return Response::json(['message' => '发送验证码次数超出阀值', 'message_code' => -2]);
     }
     Cache::increment($ip . '-' . $time->format('Y-m-d'));
     Cache::put($input, 'aa', 3);
     $user = User::where('mobile', $input)->first();
     if (!empty($user)) {
         return Response::json(['message' => '手机号码已经注册', 'message_code' => -3]);
     }
     $captcha = mt_rand(100000, 999999);
     $sms = new Sms();
     $text = "【白羽软件】您的验证码是" . $captcha . ' ,请于3分钟内填写。';
     $result = $sms->sendMessage($text, $input);
     if ($result->code < 0) {
         //@see http://www.yunpian.com/api/retcode.html
         return Response::json(['message' => '验证码发送失败, 网关异常', 'message_code' => -4]);
     }
     Cache::increment($ip . '-' . $time->format('Y-m-d'));
     Cache::put($input, $captcha, 3);
     return Response::json(['message' => '验证码发送成功, 请检查您的手机', 'message_code' => 1]);
 }
コード例 #3
0
 /**
  * 短信催款
  * @param Request $request
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function sendBillNotice(Request $request)
 {
     $input = $request->only('companyId', 'grand_total', 'total_item');
     $rules = ['companyId' => 'required', 'grand_total' => 'required|numeric|min:0', 'total_item' => 'required|numeric|min:0'];
     $v = Validator::make($input, $rules);
     if ($v->fails()) {
         Session::flash('error', $v->messages()->first());
         return redirect()->back()->with($input);
     }
     $map = ['user_id' => Session::get('company_id'), 'id' => $input['companyId']];
     $customerCompany = CustomerCompany::where($map)->first();
     if (!$customerCompany) {
         Session::flash('error', '公司不存在,非法操作');
         return redirect()->back()->withInput($request->all());
     }
     $contact = $customerCompany->getDefaultContact();
     if (!$contact) {
         Session::flash('error', '公司联系人不存在,无法发送短信');
         return redirect()->back()->withInput($request->all());
     }
     $company = Company::where('id', Session::get('company_id'))->first();
     if (!$company) {
         Session::flash('error', '代账用户不存在');
         return redirect()->back()->withInput($request->all());
     }
     $grandTotal = $input['grand_total'];
     $totalItem = $input['total_item'];
     $sms = new Sms();
     //TODO 不存在短信模板,需要增加模板才可发送。
     $text = "【代账通】尊敬的客户,贵公司尚有未支付费用 {$totalItem} 项,共计 ¥{$grandTotal} 元 。请及时联系 {$company->name} 缴纳。";
     $result = $sms->sendMessage($text, $contact->mobile);
     if ($result->code != 0) {
         Session::flash('error', '发送失败, 网关异常');
         return redirect()->back()->withInput($request->all());
     }
     Session::flash('success', '催款短信发送成功');
     return redirect()->back()->withInput($request->all());
 }