private function updateprop($client, $clid) { $it = TmpXml::model()->findAll("ctype=:ctype AND ckey=:ckey AND user=:user", array(':ctype' => 11, ':ckey' => $client, ':user' => Yii::app()->user->uid)); if (!($it === null)) { foreach ($it as $valu) { if (!($prop = ClientProp::model()->findByPk(array('id' => $clid, '_key' => $valu->cname)))) { $prop = new ClientProp(); } $prop->id = $clid; $prop->_key = $valu->cname; $prop->_value = $valu->lname; $prop->save(); } } }
private function updatesimple($typic, $grtype, $result, &$info) { if ($typic == 2) { $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid " . " FROM tmp_xml a WHERE a.user="******" AND a.ctype=" . $typic; } else { $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid," . " b.id AS g_id, b.ckey AS g_key, b.cname AS g_name, b.lid as g_lid " . " FROM tmp_xml a LEFT JOIN tmp_xml b ON a.cgr=b.ckey AND b.user="******" AND b.ctype=" . $grtype . " WHERE a.user="******" AND a.ctype=" . $typic; } $recs = Yii::app()->db->createCommand($sql)->query(); $i = 0; $j = 0; $jj = 0; if (count($recs) > 0) { foreach ($recs as $value) { $doprod = 0; $doprodid = 0; $edid = 0; if ($value['p_lid'] === null) { if ($result[$value['p_id']] === null) { $doprod = -1; $doprodid = 1; } else { $edid = (int) $result[$value['p_id']]; if ($edid > 0) { $doprodid = 2; $doprod = $edid; } else { $doprod = -1; $doprodid = 1; } } } else { if ($result[$value['p_id']] === null) { $doprod = $value['p_lid']; } else { $edid = $result[$value['p_id']]; if ($edid > 0) { $doprodid = 3; $doprod = $edid; } else { $doprod = -1; $doprodid = 4; } } } $grid = 0; if ($doprod < 0) { if ($typic != 2) { if ($value['g_lid'] === null) { if ($typic == 0) { $prodid = ProductgroupId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1)); } else { $prodid = CountryId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1)); } if ($prodid === null) { if ($typic == 0) { $group = new ProductGroup(); $group->tnam = $value['g_name']; $group->save(); $grid = $group->ckey; $groupid = new ProductgroupId(); } else { $group = new Country(); $group->name = $value['g_name']; $group->save(); $grid = $group->id; $groupid = new CountryId(); } $groupid->ckey = $value['g_key']; $groupid->db = 1; $groupid->id = $grid; $groupid->save(); $i++; } else { $grid = $prodid->id; } } else { $grid = $value['g_lid']; } } else { $grid = 1; } if ($grid > 0) { if ($typic == 0) { $prod = new Product(); $prod->tnam = $value['p_name']; $prod->cgr = $grid; $it = TmpXml::model()->find('ctype=:ctype AND ckey=:ckey AND user=:user', array(':ctype' => 10, ':ckey' => $value['p_key'], ':user' => Yii::app()->user->uid)); if ($it) { $prod->it = (int) $it->cname; } $prod->save(); $grid = $prod->ckey; } else { if ($typic == 1) { $prod = new Client(); $prod->name = $value['p_name']; $prod->country_id = $grid; $prod->save(); $grid = $prod->id; $it = TmpXml::model()->findAll("ctype=:ctype AND ckey=:ckey AND user=:user", array(':ctype' => 11, ':ckey' => $value['p_key'], ':user' => Yii::app()->user->uid)); if (!($it === null)) { foreach ($it as $valu) { $prop = new ClientProp(); $prop->id = $grid; $prop->_key = $valu->cname; $prop->_value = $valu->lname; $prop->save(); } } } else { $prod = new Department(); $prod->name = $value['p_name']; $prod->save(); $grid = $prod->id; } } $j++; if ($doprodid == 1) { if ($typic == 0) { $prodid = new ProductId(); } else { if ($typic == 1) { $prodid = new ClientId(); } else { $prodid = new DepartmentId(); } } $prodid->ckey = $value['p_key']; $prodid->db = 1; $prodid->id = $grid; $prodid->save(); } else { if ($typic == 0) { $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1)); } else { if ($typic == 1) { $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1)); } else { $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1)); } } if (!($prodid === null)) { $prodid->id = $grid; $prodid->save(); } } } } if ($doprodid == 2) { if ($typic == 0) { $prodid = new ProductId(); } else { if ($typic == 1) { $prodid = new ClientId(); } else { $prodid = new DepartmentId(); } } $prodid->ckey = $value['p_key']; $prodid->db = 1; $prodid->id = $edid; $prodid->save(); } else { if ($doprodid == 3) { if ($typic == 0) { $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1)); } else { if ($typic == 1) { $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1)); } else { $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1)); } } if (!($prodid === null)) { $prodid->id = $edid; $prodid->save(); } } } if ($doprod > 0) { if ($typic == 0) { $prod = Product::model()->findByPk($doprod); if (!($prod === null)) { if ($prod->tnam != $value['p_name']) { $prod->tnam = $value['p_name']; $prod->save(); $jj = 0; } } } else { if ($typic == 1) { $prod = Client::model()->findByPk($doprod); if (!($prod === null)) { if ($prod->name != $value['p_name']) { $prod->name = $value['p_name']; $prod->save(); $jj = 0; } $it = TmpXml::model()->findAll("ctype=:ctype AND ckey=:ckey AND user=:user", array(':ctype' => 11, ':ckey' => $value['p_key'], ':user' => Yii::app()->user->uid)); if ($it) { foreach ($it as $valu) { if (!($prop = ClientProp::model()->findByPk(array('id' => $prod->id, '_key' => $valu->cname)))) { $prop = new ClientProp(); } $prop->id = $prod->id; $prop->_key = $valu->cname; $prop->_value = $valu->lname; $prop->save(); } } } } else { if (!($prop = DepartmentProp::model()->findByPk(array('id' => $doprod, '_key' => 'stop')))) { $prod = Department::model()->findByPk($doprod); if (!($prod === null)) { if ($prod->name != $value['p_name']) { $prod->name = $value['p_name']; $prod->save(); $jj = 0; } } } } } } } } if ($typic == 0) { $info[] = 'Создано новых групп товаров:' . $i; $info[] = 'Создано новых товаров:' . $j; $info[] = 'Обновлено товаров:' . $jj; } else { if ($typic == 1) { $info[] = 'Создано новых групп клиентов:' . $i; $info[] = 'Создано новых клиентов:' . $j; $info[] = 'Обновлено клиентов:' . $jj; } else { $info[] = 'Создано новых фирм:' . $j; $info[] = 'Обновлено фирм:' . $jj; } } return; }