Exemple #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.');
 }
 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());
 }