/** * 获取税务信息 * @return mixed * @param Request $request * @author AndyLee <*****@*****.**> */ public function getTaxList(Request $request) { $company = Company::find($request->session()->get('customer_id')); $start = new \DateTime($company->created_at); $end = new DateTime(); $interval = DateInterval::createFromDateString('1 month'); $period = new DatePeriod($start, $interval, $end); $card = []; foreach ($period as $dt) { $map = ['user_id' => $request->session()->get('company_id'), 'company_id' => $request->session()->get('customer_id'), 'flag' => $dt->format("Ym")]; $tax = Tax::where($map)->first(); if (empty($tax)) { $record = new Tax(); $record->user_id = $request->session()->get('company_id'); $record->company_id = $request->session()->get('customer_id'); $record->operator_id = Auth::user()->id; $record->card_name = $dt->format("Ym") . '税务申报单'; $record->finish_time = strtotime($dt->format('Y-m') . '-15'); $record->uuid = Uuid::uuid1(); $record->guoshui_status = 0; $record->dishui_status = 0; $record->flag = $dt->format("Ym"); $record->save(); $card[] = $record->toArray(); } else { $card[] = $tax->toArray(); } } $card = array_reverse($card); return view('customer.tax.index')->with('cards', $card); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($request->segment(2) == '') { $request->session()->flash('error', '您访问的公司不存在!'); return redirect()->back(); } $map = ['id' => $request->segment(2), 'user_id' => $request->session()->get('company_id')]; try { $company = Company::where($map)->firstOrFail(); } catch (ModelNotFoundException $e) { $request->session()->flash('error', '您访问的公司不存在!'); return redirect()->back(); } $company->last_active_time = time(); $company->save(); view()->share('customer', $company); $request->session()->put('customer_id', $company->id); view()->share('customer_id', $company->id); return $next($request); }
/** * 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.'); }
/** * 上传证件 * @param Request $request * @return mixed * @author AndyLee <*****@*****.**> */ public function postUploadCertificate(Request $request) { $input = $request->file('file'); $param = $request->only('name', 'id'); $rules = array('file' => 'image|max:3000'); $validation = \Validator::make(['file' => $input], $rules); if ($validation->fails()) { return \Response::make($validation->errors->first(), 400); } $extension = $input->getClientOriginalExtension(); /** * 获取公司信息 */ $customer = CustomerCompany::find(Session::get('customer_id')); /** * 设置存储目录 * 存储目录结构 = uploads / sha1加密的公司id /客户公司uuid */ $directory = public_path('uploads') . '/' . sha1(Session::get('company_id')) . '/' . $customer->uuid; $filename = sha1(time() . time()) . ".{$extension}"; $upload_success = $input->move($directory, $filename); $message = ['file_path' => asset('uploads/' . sha1(Session::get('company_id')) . '/' . $customer->uuid) . '/' . $filename]; /** * 用户相关证件一键上传 */ if (!empty($param['name']) and !empty($param['id'])) { $param['company_id'] = Session::get('customer_id'); try { $certificate = Certificate::where($param)->firstOrFail(); } catch (ModelNotFoundException $e) { return \Response::json(['state' => 'denied'], 200); } $certificate->certificate_path = serialize([$message['file_path']]); $certificate->save(); } if ($upload_success) { $message['status'] = 'success'; return \Response::json($message, 200); } else { $message['status'] = 'error'; return \Response::json($message, 400); } }
/** * 修改公司信息操作 * @param Request $request * @return mixed * @param integer $id * @author AndyLee <*****@*****.**> */ public function postModifyCompany(Request $request, $id) { $company = Company::where(['id' => $id, 'user_id' => Session::get('company_id')])->first(); if (empty($company)) { Session::flash('error', '公司不存在,无法编辑'); return redirect()->back(); } $input = $request->only('full_name', 'name', 'leader', 'address', 'registion_type', 'registed_funds', 'registed_funds_type', 'register_time', 'end_time', 'register_number', 'scope'); $rules = ['full_name' => 'required', 'name' => 'required', 'registion_type' => 'required', 'address' => 'required', 'registed_funds' => 'required', 'register_time' => 'date', 'end_time' => 'date']; $v = Validator::make($input, $rules); if ($v->fails()) { Session::flush('error', $v->messages()->first()); return redirect()->back(); } $company->full_name = $input['full_name']; $company->name = $input['name']; $company->leader = $input['leader']; $company->location = $input['address']; $company->registion_type = $input['registion_type']; $company->registed_funds = $input['registed_funds']; $company->funds_type = $input['registed_funds_type']; if (!empty($input['register_time'])) { $company->register_time = strtotime($input['register_time']); } if (!empty($input['end_time'])) { $company->end_time = strtotime($input['end_time']); } $company->register_number = $input['register_number']; $company->scope = $input['scope']; $company->save(); Session::flash('success', '更新公司信息成功'); return redirect()->to(action('CustomerController@getCustomerCompanyInfo', Session::get('customer_id'))); }
/** * 仪表盘 * @param Request $request * @return mixed * @author AndyLee <*****@*****.**> */ public function getDashBoard(Request $request) { if (!$request->session()->has('company_id')) { $request->session()->flash('error', '请先选择一个代帐公司'); return redirect()->to('/'); } $today_start = strtotime(date('Y-m-d', time()) . ' 00:00:00'); $today_end = strtotime(date('Y-m-d', time()) . ' 23:59:59'); /** * 获取公司 */ $customers = CustomerCompany::where('user_id', $request->session()->get('company_id')); $count = $customers->count(); $new_customer = CustomerCompany::where('user_id', $request->session()->get('company_id'))->whereBetween('create_time', array($today_start, $today_end))->count(); $month_begin = mktime(0, 0, 0, date('m'), 1, date('Y')); $month_end = mktime(23, 59, 59, date('m'), date('t'), date('Y')); /** * 获取todo */ $count_task = Task::where('user_id', $request->session()->get('company_id'))->count(); $finish = Task::whereRaw('user_id = ? and is_finish = ?', [$request->session()->get('company_id'), 1])->whereBetween('finish_time', array($month_begin, $month_end))->count(); $order = $customers->orderBy('last_active_time', 'desc')->take(10)->get(); return view('dashboard')->with('count', $count)->with('new', $new_customer)->with('tasks', $count_task)->with('order', $order)->with('finish', $finish); }
/** * 短信催款 * @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()); }