看看这段代码回出现什么问题,如何优化,谢谢大家,来者有分
Alisa 2006-08-22 04:07:44 <?php
class cartstore{
var $ownerid;
function cartstore($ownerid){
$this->ownerid = $ownerid;
}
function add($extendobj){
$a = new avatar_cart_store();
$a->set('componentid', $extendobj->componentid);
$a->set('ownerid', $this->ownerid);
$a->set('flag', $extendobj->isinuse);
$n = $a->selectby();
if (count($n) > 0){
$n[0]->set('count', $n[0]->get('count') + 1);
return $n[0]->update();
}else{
$a->set('count', 1);
return $a->insert();
}
}
function del($id){
$a = new avatar_cart_store();
$a->set('id', $id);
return $a->delete();
}
function emptycartstore($ownerid, $typeid){
$a = new avatar_cart_store();
$a->set('typeid', $typeid);
$a->set('ownerid', $ownerid);
$a->deleteby();
}
function changetype($ownerid, $otypeid, $ntypeid){
$a = new avatar_cart_store();
$a->set('ownerid', $ownerid);
$a->set('typeid', $otypeid);
$n = $a->selectby();
if (count($n) == 0){
return false;
}else{
foreach ($n as $row){
$temp = new avatar_cart_store();
$temp->set('ownerid', $ownerid);
$temp->set('componentid', $row->get('componentid'));
$temp->set('typeid', $ntypeid);
$k = $temp->selectby();
if (count($k) > 0){
$k[0]->set('count', $k[0]->get('count') + $row->get('count'));
$k[0]->update();
$row->delete();
}else{
$row->set('typeid', $ntypeid);
$row->update();
}
}
}
}
function getall($ownerid, $typeid){
$a = new avatar_cart_store();
$a->set('ownerid', $ownerid);
$a->set('typeid', $typeid);
$array = $a->selectby();
$ra = array();
foreach ($array as $row){
$c = new cbme_component();
$c->set('id', $row->get('componentid'));
$c = $c->select();
$o = new extendobj();
$o->id = $row->get('id');
$o->componentid = $row->get('componenetid');
$o->count = $row->get('count');
$o->name = $c->get('name');
$o->sexid = $c->get('sexid');
$o->price1 = $c->get('price1');
$o->price2 = $c->get('price2');
$o->jpglocation = $c->get('jpglocation');
$ra[] = $o;
}
return $ra;
}
}
?>