'float', 'commission' => 'float', 'parent_commission' => 'float', 'settle_time' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; // 获取所属代理商 public function agent() { return $this->belongsTo('app\manager\model\Agent', 'agent_id'); } // 获取激活码信息 public function code() { return $this->belongsTo('app\manager\model\ActivationCode', 'code_id'); } // 结算佣金 public function settle() { if ($this->status == 1) { return false; } // 开启事务 $this->startTrans(); try { // 更新代理商余额 $this->agent->updateBalance($this->commission); // 如果有上级佣金,更新上级代理商余额 if ($this->parent_commission > 0 && $this->agent->parent) { $this->agent->parent->updateBalance($this->parent_commission); } // 更新结算状态 $this->status = 1; $this->settle_time = date('Y-m-d H:i:s'); $this->save(); $this->commit(); return true; } catch (\Exception $e) { $this->rollback(); return false; } } }