Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     Log::info('Begin the check-cycle-bill command.');
     $now = Carbon::now();
     $cycleBillList = CompanyCycleBill::where('next_date', '>=', $now->format('Y-m-01 00:00:00'))->where('next_date', '<=', $now->format('Y-m-31 23:59:59'))->get();
     foreach ($cycleBillList as $cycleBill) {
         $companyBill = new CompanyBill();
         $item = $cycleBill->item;
         if ($cycleBill->rule = '1m') {
             $item = $item . "(" . $now->month . "月)";
         } elseif ($cycleBill->rule = '3m') {
             $item = $item . "(" . (int) ($now->month / 4 + 1) . "季度)";
         } elseif ($cycleBill->rule = '12m') {
             $item = $item . "(" . $now->year . "年)";
         }
         $companyBill->item = $item;
         $companyBill->user_id = $cycleBill->user_id;
         $companyBill->remarks = $cycleBill->remarks;
         $companyBill->company_id = $cycleBill->company_id;
         $companyBill->operator_id = $cycleBill->operator_id;
         $companyBill->grand_total = $cycleBill->grand_total;
         $companyBill->deadline = $cycleBill->next_date;
         $companyBill->cycle_bill_id = $cycleBill->id;
         $companyBill->save();
         $cycleBill->next_date = $cycleBill->next_date->addMonth(intval($cycleBill->rule));
         $cycleBill->save();
     }
     Log::info('End the check-cycle-bill command.');
 }
Exemplo n.º 2
0
 /**
  * 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.');
 }
Exemplo n.º 3
0
 /**
  * 获得当前客户对于当前代账公司的待付款项目数
  * @param $userId
  * @return mixed
  */
 public function countUnpaidBill($userId)
 {
     return CompanyBill::where('user_id', $userId)->where('is_paid', CompanyBill::IS_PAID_NO)->where('company_id', $this->id)->count();
 }
Exemplo n.º 4
0
 public function deleteCycleBill(Request $request, $companyId, $id)
 {
     $map = ['user_id' => (int) Session::get('company_id'), 'company_id' => (int) $companyId, 'id' => (int) $id];
     try {
         $cycleBill = CompanyCycleBill::where($map)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         Session::flash('error', '任务不存在,非法操作');
         return redirect()->back()->withInput($request->all());
     }
     $cycleBill->delete();
     CompanyBill::where('cycle_bill_id', $id)->where('is_paid', CompanyBill::IS_PAID_NO)->where('deadline', '>', Carbon::now())->delete();
     Session::flash('success', '删除收款项成功');
     return redirect()->back()->withInput($request->all());
 }