public function exchange_commodity($com_id, $mobile, $address, $name) { $comsrv = new CommodityService(); $com = $comsrv->get_by_id($com_id); if ($com->count <= 0) { return GOOD_IS_ZERO; } $user_info = $this->get_by_uuid($this->user->uuid); if ($com->price > $user_info->scores) { return USER_ERR_SCORE_NOT_ENOUGH; } // 插入兑换记录 $result = $comsrv->add_exch_record($com_id, $this->user->uuid, $mobile, $address, $name); if ($result) { $umod = new UserModule($this->user->uuid); $score = 0 - $com->price; $rs = $umod->sub_score($this->user->uuid, $score); $comsrv->dec_com($com_id); } return $result; }