public static function bootUserTrait() { //自动创建extra等数据 static::created(function ($user) { UserFinance::create(['id' => $user->getKey()]); }); }
public function create() { //帐户余额 $amount = UserFinance::findOrNew($this->agent->getKey())->money; //查找当前用户冻结金额 取出7天奖金 $freeze_money = Bill::whereRaw("uid = ? and is_dealt = ? and created_at>='?' and event in( 'commission' , 'income')", array($this->agent->getKey(), 1, date("Y-m-d 00:00:00", strtotime('-7 days'))))->sum('value') ?: 0; //可取资金 $usable_money = intval(($amount - $freeze_money) / ($this->site['withdraw_counter_percent'] + 1)); $this->_user_money = compact('amount', 'freeze_money', 'usable_money'); //查找银行卡信息 $this->_bank_cards = (new UserBankcard())->with('bank_name')->newQuery()->where('uid', $this->agent->getKey())->get(); $keys = 'money,card_id'; $this->_data = []; $this->_validates = $this->getScriptValidate('withdraw.store', $keys); return $this->view('agent-backend.withdraw.create'); }
public function edit($id) { $withdraw = Withdraw::find($id); //帐户余额 $amount = UserFinance::findOrNew($withdraw->uid)->money; //查找当前用户冻结金额 $freeze_money = Bill::whereRaw("uid = ? and is_dealt = ? and created_at>='?' and event in( 'commission' , 'income')", array($withdraw->uid, 1, date("Y-m-d 00:00:00", strtotime('-7 days'))))->sum('value') ?: 0; //可取资金 $usable_money = intval(($amount - $freeze_money) / ($this->site['withdraw_counter_percent'] + 1)); $this->_user_money = compact('amount', 'freeze_money', 'usable_money'); $withdraw = Withdraw::with(['bankcards'])->find($id); if (empty($withdraw)) { return $this->failure_noexists(); } $keys = 'audit,note'; $this->_validates = $this->getScriptValidate('withdraw.audit', $keys); $this->_data = $withdraw; return $this->view('admin.withdraw.edit'); }