/** * 迈豆充值 * * @param \App\Models\Customer $customer * @param string $action * @param int $value * @return bool */ protected function recharge(Customer $customer, $action, $value = 1) { $beanRate = BeanRate::where('action_en', $action)->firstOrFail(); $result = $beanRate->rate * $value; $this->update($customer, $action, $result); $bean = new CustomerBean(); $bean->customer_id = $customer->id; $bean->bean_rate_id = $beanRate->id; $bean->value = $value; $bean->result = $beanRate->rate * $value; return $bean->save(); }
protected function persist() { $bean_rate = BeanRate::where('action_en', '=', $this->name)->firstOrFail(); $this->customer->beans()->create(['bean_rate_id' => $bean_rate->id, 'value' => 1, 'result' => $this->beans, 'before' => $this->before, 'after' => $this->after]); }