PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/new88li/core/model/trading/mdl.deliveryarea.php

http://phpfor.googlecode.com/
PHP | 217 lines | 192 code | 6 blank | 19 comment | 19 complexity | 452231ec9d9d40f93debd26b68013889 MD5 | raw file
  1. <?php
  2. require_once('shopObject.php');
  3. class mdl_deliveryarea extends shopObject{
  4. var $idColumn = 'area_id'; //??id??
  5. var $textColumn = 'area_id';
  6. var $defaultCols = 'name,ordernum';
  7. var $adminCtl = 'trading/deliveryarea';
  8. var $defaultOrder = array('ordernum','desc');
  9. var $tableName = 'sdb_dly_area';
  10. var $IdGroup=array();//?????
  11. function getTreeSize(){
  12. $sql="select count(region_id) as rcount from sdb_regions";
  13. $row=$this->db->selectrow($sql);
  14. if ($row['rcount']>100)
  15. return true;
  16. else
  17. return false;
  18. }
  19. function getById($regionId=''){
  20. return $this->db->selectrow("select local_name from sdb_regions where region_id=".intval($regionId));
  21. }
  22. function getRegionById($regionId=''){
  23. $sql='select region_id,p_region_id,local_name,ordernum,region_path from sdb_regions as r where r.p_region_id'.($regionId?('='.intval($regionId)):' is null').' order by ordernum asc,region_id asc';
  24. $aTemp=$this->db->select($sql);
  25. if (is_array($aTemp)&&count($aTemp)>0){
  26. foreach($aTemp as $key => $val){
  27. $aTemp[$key]['p_region_id']=intval($val['p_region_id']);
  28. $aTemp[$key]['step'] = intval(substr_count($val['region_path'],','))-1;
  29. $aTemp[$key]['child_count'] = $this->getChildCount($val['region_id']);
  30. }
  31. }
  32. return $aTemp;
  33. }
  34. function getChildCount($region_id){
  35. $row = $this->db->selectrow('select count(*) as childCount from sdb_regions where p_region_id='.intval($region_id));
  36. return $row['childCount'];
  37. }
  38. function getRegionByParentId($parentId){
  39. $sql="select region_id,local_name from sdb_regions where region_id=".intval($parentId);
  40. return $this->db->selectrow($sql);
  41. }
  42. function toRemoveArea($regionId){
  43. /*
  44. $this->getAllChild($regionId);
  45. if (count($this->IdGroup)>0){
  46. foreach($this->IdGroup as $key => $val){
  47. $this->db->exec('DELETE FROM sdb_regions where region_id='.intval($val));
  48. }
  49. } */
  50. $tmpRow = $this->db->selectrow("select region_path from sdb_regions where region_id=".intval($regionId));
  51. $this->db->exec("DELETE FROM sdb_regions where region_id=".intval($regionId));
  52. $this->toRemoveSubArea($tmpRow['region_path']);
  53. return true;
  54. }
  55. function toRemoveSubArea($path){
  56. if ($path)
  57. return $this->db->exec("DELETE FROM sdb_regions where region_path LIKE '%".$path."%'");
  58. }
  59. function getAllChild_ex($regionId){
  60. $sql="select region_path from sdb_regions where region_id=".intval($regionId);
  61. $tmpRow=$this->db->selectrow($sql);
  62. $sql="select region_id from sdb_regions where region_path like '%".$tmpRow['region_path']."%'";
  63. $row=$this->db->select($sql);
  64. if (is_array($row)&&count($row)>0){
  65. foreach($row as $key => $val){
  66. $region_Id[]=$val['region_id'];
  67. }
  68. }
  69. return $region_Id;
  70. }
  71. function getAllChild($regionId){
  72. /*
  73. $sql="select region_id from sdb_regions where p_region_id=".intval($regionId);
  74. $aTemp=$this->db->select($sql);
  75. if (is_array($aTemp)&&count($aTemp)>0){
  76. foreach($aTemp as $key => $val){
  77. $this->getAllChild($val['region_id']);
  78. }
  79. }
  80. $this->IdGroup[]=$regionId; */
  81. unset($this->IdGroup);
  82. $sql="select region_path from sdb_regions where region_id=".intval($regionId);
  83. $tmpRow=$this->db->selectrow($sql);
  84. $sql="select region_id from sdb_regions where region_path like '%".$tmpRow['region_path']."%'";
  85. $row=$this->db->select($sql);
  86. if (is_array($row)&&count($row)>0){
  87. foreach($row as $key => $val){
  88. $this->IdGroup[]=$val['region_id'];
  89. }
  90. }
  91. }
  92. function updateOrderNum($param){
  93. if (is_array($param)&&count($param)>0){
  94. foreach($param as $key => $val){
  95. $val=$val?$val:'50';
  96. $this->db->exec('UPDATE sdb_regions set ordernum='.intval($val).' where region_id='.intval($key));
  97. }
  98. }
  99. return true;
  100. }
  101. function insertDlArea($aData,&$msg){
  102. if(!trim($aData['local_name'])){
  103. $msg = __('?????????');
  104. return false;
  105. }
  106. $aData['ordernum']=$aData['ordernum']?$aData['ordernum']:'50';
  107. if($this->checkDlArea($aData['local_name'],$aData['p_region_id'])){
  108. $msg = __('??????????');
  109. return false;
  110. }
  111. $tmp = $this->db->selectrow('select region_path from sdb_regions where region_id='.intval($aData['p_region_id']));
  112. if (!$tmp)
  113. $tmp['region_path'] = ",";
  114. $aData = array_filter($aData);
  115. $aRs = $this->db->query('SELECT * FROM sdb_regions WHERE 0');
  116. $sSql = $this->db->GetInsertSql($aRs,$aData);
  117. if ($this->db->exec($sSql)){
  118. $regionId = $this->db->lastInsertId();
  119. $tmp['region_path'] = $tmp['region_path'].$regionId.',';
  120. $tmp['region_grade'] = count(explode(",",$tmp['region_path']))-2;
  121. $this->db->exec($sql='UPDATE sdb_regions set region_path='.$this->db->quote($tmp['region_path']).',region_grade='.intval($tmp['region_grade']).' where region_id='.intval($regionId));
  122. return true;
  123. }
  124. else
  125. return false;
  126. }
  127. function getGroupRegionId($regionId){
  128. $row = $this->db->selectrow($sql='select region_path from sdb_regions where region_id='.intval($regionId));
  129. $path=$row['region_path'];
  130. $rows = $this->db->select($sql="select region_id from sdb_regions where region_path like '%".$path."%' and region_id<>".intval($regionId));
  131. if ($rows){
  132. foreach($rows as $key => $val){
  133. $idGroup[]=$val['region_id'];
  134. }
  135. return $idGroup;
  136. }
  137. }
  138. function updateDlArea($aData,&$msg){
  139. if ($aData['region_id']==$aData['p_region_id']){
  140. $msg = __('???????????');
  141. return false;
  142. }
  143. else{
  144. $idGroup = $this->getGroupRegionId($aData['region_id']);
  145. if (in_array($aData['p_region_id'],$idGroup)){
  146. $msg = __('???????????????');
  147. return false;
  148. }
  149. }
  150. if(!$aData['region_id']){
  151. $msg = __('?????');
  152. return false;
  153. }
  154. else{
  155. $cPath=$this->db->selectrow('select region_path from sdb_regions where region_id='.intval($aData['region_id']));
  156. }
  157. if(!trim($aData['local_name'])){
  158. $msg = __('?????????');
  159. return false;
  160. }
  161. if (intval($aData['p_region_id'])){
  162. $tmp = $this->db->selectrow('select region_path from sdb_regions where region_id='.intval($aData['p_region_id']));
  163. $aData['region_path'] = $tmp['region_path'].$aData['region_id'].",";
  164. }
  165. else{
  166. $aData['region_path'] = ",".$aData['region_id'].",";
  167. }
  168. $aData['ordernum']=$aData['ordernum']?$aData['ordernum']:'50';
  169. $aData['region_grade'] = count(explode(",",$aData['region_path']))-2;
  170. $aData = array_filter($aData);
  171. $aRs = $this->db->query('SELECT * FROM sdb_regions WHERE region_id='.$aData['region_id']);
  172. $sSql = $this->db->GetUpdateSql($aRs,$aData);
  173. $this->updateSubPath($cPath['region_path'],$aData['region_path']);
  174. return (!$sSql || $this->db->exec($sSql));
  175. }
  176. function updateSubPath($Opath,$Npath){
  177. $offset = count(explode(",",$Npath)) - count(explode(",",$Opath));
  178. return $this->db->exec("update sdb_regions set region_path=replace(region_path,".$this->db->quote($Opath)
  179. .",".$this->db->quote($Npath)."),region_grade=region_grade + "
  180. .intval($offset)." where region_path LIKE '%".$Opath."%'");
  181. }
  182. function getDlAreaById($aRegionId){
  183. /*return $this->db->selectrow('SELECT * FROM sdb_dly_area WHERE area_id='.intval($aAreaId));*/
  184. $sql='select c.region_id,c.local_name,c.p_region_id,c.ordernum,p.local_name as parent_name from sdb_regions as c LEFT JOIN sdb_regions as p ON p.region_id=c.p_region_id where c.region_id='.intval($aRegionId);
  185. return $this->db->selectrow($sql);
  186. }
  187. function checkDlArea($name,$p_region_id){
  188. /*$aTemp = $this->db->selectrow("SELECT area_id FROM sdb_dly_area WHERE name='".$sName."' order by ordernum desc");
  189. return $aTemp['area_id']; */
  190. $aTemp = $this->db->selectrow("SELECT region_id FROM sdb_regions WHERE local_name='".$name."' and p_region_id".($p_region_id?('='.intval($p_region_id)):' is null'));
  191. return $aTemp['region_id'];
  192. }
  193. function getMap($prId=''){
  194. if ($prId)
  195. $sql="select region_id,region_grade,local_name,ordernum,(select count(*) from sdb_regions where p_region_id=r.region_id) as child_count from sdb_regions as r where r.p_region_id=".intval($prId)." order by ordernum asc,region_id";
  196. else
  197. $sql="select region_id,region_grade,local_name,ordernum,(select count(*) from sdb_regions where p_region_id=r.region_id) as child_count from sdb_regions as r where r.p_region_id is null order by ordernum asc,region_id";
  198. $row = $this->db->select($sql);
  199. foreach($row as $key => $val){
  200. $this->regions[]=array(
  201. "local_name"=>$val['local_name'],
  202. "region_id"=>$val['region_id'],
  203. "region_grade"=>$val['region_grade'],
  204. "ordernum"=>$val['ordernum']
  205. );
  206. if ($val['child_count'])
  207. $this->getMap($val['region_id']);
  208. }
  209. }
  210. }
  211. ?>