/**
  * 提现佣金
  * @author zhengqian@dajiayao.cc
  */
 public function postApplyDraw()
 {
     $inputData = $this->inputData->all();
     $validator = Validator::make($inputData, []);
     $applyCommissionNum = date("YmdHis") . rand(0, 9);
     $drawCommission = new WithDrawCommission();
     $drawCommission->withdraw_number = $applyCommissionNum;
     $drawCommission->seller_id = $this->sellerId;
     $drawCommission->amount = $inputData['amount'];
     $drawCommission->account_name = $this->seller->realname;
     $drawCommission->account_number = $this->seller->account_number;
     $drawCommission->opening_bank = $this->seller->opening_bank;
     $drawCommission->status = WithDrawCommission::STATUS_DRAWEDING;
     $drawCommission->save();
 }
 public function applyList()
 {
     $input = $this->inputData;
     if (!array_key_exists('status', $input)) {
         $drawCommissionList = WithDrawCommission::paginate(20);
     } else {
         $drawCommissionList = WithDrawCommission::where('status', $input['status'])->paginate(20);
     }
     $cacheArr = array();
     foreach ($drawCommissionList as $k => $rawDrawCommission) {
         if (!array_key_exists($rawDrawCommission->seller_id, $cacheArr)) {
             $sellerId = $rawDrawCommission->seller_id;
             //所有佣金
             $sellerCommissions = SellerCommission::where('seller_id', $sellerId)->get();
             $commisionTotal = 0;
             foreach ($sellerCommissions as $rowCommission) {
                 $commisionTotal += $rowCommission->amount;
             }
             //已经确认的佣金
             $sellerConfirmedCommissions = SellerCommission::where('seller_id', $sellerId)->where('status', SellerCommission::STATUS_CONFIRMED)->get();
             $commisionConfirmTotal = 0;
             foreach ($sellerConfirmedCommissions as $rowCommission) {
                 $commisionConfirmTotal += $rowCommission->amount;
             }
             //已经提取的佣金
             $drawedCommissions = WithDrawCommission::where('seller_id', $sellerId)->where('status', WithDrawCommission::STATUS_DRAWED)->get();
             $drawedCommissionTotal = 0;
             foreach ($drawedCommissions as $drawedCommission) {
                 $drawedCommissionTotal += $drawedCommission->amount;
             }
             //可以提取的佣金
             $rawDrawCommission->availableCommission = $commisionConfirmTotal - $drawedCommissionTotal;
             $rawDrawCommission->commissionTotal = $commisionTotal;
             $cacheArr[$rawDrawCommission->seller_id] = $rawDrawCommission;
         } else {
             $drawCommissionList[$k] = $cacheArr[$rawDrawCommission->seller_id];
         }
     }
     return view('admin.commission.apply_list')->with('draw_lists', $drawCommissionList)->with('input', $input);
 }