optionModel.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /**
  3. * 来自:信呼开发团队
  4. * 作者:磐石(rainrock)
  5. * 网址:http://www.rockoa.com/
  6. * 系统文件
  7. */
  8. class optionClassModel extends Model
  9. {
  10. private $getypsarr = array();
  11. public function getval($num, $dev = '', $lx = 0)
  12. {
  13. $val = '';
  14. $rs = $this->getone("`num`='$num'", '`name`,`value`,`id`,`optdt`');
  15. if ($rs) {
  16. if ($lx == 0) $val = $rs['value'];
  17. if ($lx == 1) $val = $rs['name'];
  18. if ($lx == 2) $val = $rs['id'];
  19. if ($lx == 3) $val = $rs['optdt'];
  20. }
  21. if (isempt($val)) $val = $dev;
  22. return $val;
  23. }
  24. public function getpids($num)
  25. {
  26. if (!is_numeric($num)) {
  27. $id = (int)$this->getmou('id', "`num`='$num'");
  28. if ($id == 0) $id = -829;
  29. } else {
  30. $id = $num;
  31. }
  32. return $id;
  33. }
  34. public function getdata($num, $whe = '')
  35. {
  36. $pid = $this->getpids($num);
  37. return $this->getall("`pid`='$pid' and `valid`=1 $whe order by `sort`,`id`", '`id`,`name`,`value`,`num`,`receid`,`recename`,`pid`');
  38. }
  39. public function getmnum($num)
  40. {
  41. return $this->getdata($num);
  42. }
  43. public $getselectdatad;
  44. public function getselectdata($num, $tbo = false)
  45. {
  46. $this->getselectdatad = array();
  47. $this->getselectdatas($num, 0, $tbo);
  48. return $this->getselectdatad;
  49. }
  50. public function getselectdatas($num, $lev = 0, $tbo = false)
  51. {
  52. $pid = $this->getpids($num);
  53. $fied = '';
  54. if ($tbo) $fied = ',(select count(1) from `[Q]option` where `pid`=a.`id` and `valid`=1)as stotal';
  55. $arr = $this->db->getall("select a.`id`,a.`name`,a.`num`,a.`value`" . $fied . " from `[Q]option` a where a.`pid`='$pid' and a.`valid`=1 order by a.`sort`,a.id");
  56. foreach ($arr as $k => $rs) {
  57. $rs['nameo'] = $rs['name'];
  58. $strs = '';
  59. for ($i = 0; $i < $lev; $i++) $strs .= '&nbsp;&nbsp;&nbsp;&nbsp;';
  60. if ($lev > 0) $rs['name'] = '' . $strs . '├' . $rs['name'] . '';
  61. $rs['padding'] = $lev * 24;
  62. $this->getselectdatad[] = $rs;
  63. if ($tbo && $rs['stotal'] > 0) $this->getselectdatas($rs['id'], $lev + 1, $tbo);
  64. }
  65. }
  66. public function setval($num, $val = '', $name = null, $isub = true)
  67. {
  68. $numa = explode('@', $num);
  69. $num = $numa[0];
  70. $where = "`num`='$num'";
  71. $id = (int)$this->getmou('id', $where);
  72. if ($id == 0) $where = '';
  73. $arr = array('num' => $num, 'value' => $val, 'optid' => $this->adminid, 'comid' => m('admin')->getcompanyid(), 'optdt' => $this->rock->now);
  74. if (isset($numa[1])) $arr['pid'] = $numa[1];
  75. if ($name != null) $arr['name'] = $name;
  76. if ($id == 0 || $isub) $this->record($arr, $where);
  77. if ($id == 0) $id = $this->db->insert_id();
  78. return $id;
  79. }
  80. public function gettreedata($pid)
  81. {
  82. $rows = $this->getfoldrowsss($pid);
  83. return $rows;
  84. }
  85. public function getfoldrowsss($pid)
  86. {
  87. $rows = $this->db->getall("select `id`,`pid`,`name`,`optdt`,`sort`,`receid`,`recename` from [Q]option where `pid`='$pid' and `valid`=1 order by `sort`,`id`");
  88. foreach ($rows as $k => $rs) {
  89. $rows[$k]['expanded'] = true;
  90. $rows[$k]['children'] = $this->getfoldrowsss($rs['id']);
  91. }
  92. return $rows;
  93. }
  94. public function getnumtoid($num, $name = '', $isub = true)
  95. {
  96. $idd = $this->setval($num, '', $name, $isub);
  97. return $idd;
  98. }
  99. public function getpidarr($pid, $lx = 0)
  100. {
  101. $rows = $this->getall("`pid`='$pid'");
  102. $barr = array();
  103. foreach ($rows as $k => $rs) {
  104. $barr[$rs['num']] = $rs['value'];
  105. }
  106. return $barr;
  107. }
  108. public function getalldownid($id)
  109. {
  110. $str = $id;
  111. $rows = $this->getall('`pid`=' . $id . ' and `valid`=1', '`id`');
  112. foreach ($rows as $k => $rs) {
  113. $str1 = $this->getalldownid($rs['id']);
  114. $str .= ',' . $str1 . '';
  115. }
  116. return $str;
  117. }
  118. public function getreceiddownall($uid, $optid = 0, $type = 0)
  119. {
  120. $rstr = m('admin')->getjoinstr('`receid`', $uid, 1, 1);
  121. $whe = '';
  122. if ($optid > 0) $whe = ' and `optid`=' . $optid . '';
  123. $rows = $this->getall('`valid`=1 and `type`=' . $type . ' and (' . $rstr . ') ' . $whe . '', '`id`');
  124. $strs = '';
  125. foreach ($rows as $k => $rs) {
  126. $str1 = $this->getalldownid($rs['id']);
  127. $strs .= ',' . $str1 . '';
  128. }
  129. if ($strs != '') $strs = substr($strs, 1);
  130. return $strs;
  131. }
  132. public function gettypeid($djnum, $s)
  133. {
  134. if (isset($this->getypsarr[$s])) return $this->getypsarr[$s];
  135. $sid = 0;
  136. $s = str_replace(',', '/', $s);
  137. $djid = $this->getval($djnum, '0', 2);
  138. if (isempt($djid)) {
  139. $djid = $this->insert(array('name' => '分类', 'num' => $djnum, 'pid' => 0, 'valid' => 1));
  140. }
  141. $dsja = $djid;
  142. $sarr = explode('/', $s);
  143. foreach ($sarr as $safs) {
  144. $pid = $djid;
  145. $djid = (int)$this->getmou('id', "`pid`='$pid' and `name`='$safs'");
  146. if ($djid == 0) {
  147. $djid = $this->insert(array('name' => $safs, 'pid' => $pid, 'valid' => 1,));
  148. }
  149. }
  150. if ($djid != $dsja) $sid = $djid;
  151. $this->getypsarr[$s] = $sid;
  152. return $sid;
  153. }
  154. public function delpid($pid)
  155. {
  156. $this->delete("`pid` in($pid)");
  157. }
  158. public function getcnumdata($num)
  159. {
  160. if (ISMORECOM && $cnum = m('admin')->getcompanynum()) $num .= '_' . $cnum . '';
  161. $rows = $this->getselectdata($num, true);
  162. $arr = array();
  163. foreach ($rows as $k => $rs) {
  164. $arr[] = array('value' => $rs['id'], 'name' => $rs['name'], 'padding' => $rs['padding'],);
  165. }
  166. return $arr;
  167. }
  168. public function addoption($name, $num, $pid = 0, $down = array(), $arr = array())
  169. {
  170. $id = (int)$this->getmou('id', "`num`='$num'");
  171. if (!$id) $id = 0;
  172. if ($id > 0) return $id;
  173. if (!is_numeric($pid)) $pid = (int)$this->getmou('id', "`num`='$pid'");
  174. if ($pid == 0) $pid = 1;
  175. $uarr = array('num' => $num, 'pid' => $pid, 'name' => $name,);
  176. foreach ($arr as $k => $v) $uarr[$k] = $v;
  177. $id = $this->insert($uarr);
  178. if ($down && is_string($down)) {
  179. $downa = explode(',', $down);
  180. $down = array();
  181. foreach ($downa as $k2) $down[] = array('name' => $k2);
  182. }
  183. if ($down) foreach ($down as $k => $rs) {
  184. $iarr = $rs;
  185. $iarr['pid'] = $id;
  186. $idown = arrvalue($rs, 'down');
  187. if ($idown) {
  188. unset($iarr['down']);
  189. $sid = $this->insert($iarr);
  190. foreach ($idown as $k1 => $rs1) {
  191. $isarr = $rs1;
  192. $isarr['pid'] = $sid;
  193. $this->insert($isarr);
  194. }
  195. } else {
  196. $this->insert($iarr);
  197. }
  198. }
  199. return $id;
  200. }
  201. public function authercheck()
  202. {
  203. $rows = $this->getall('pid=-101', '`num`,`value`');
  204. $authkey = $yuming = $enddt = '';
  205. foreach ($rows as $k1 => $rs1) {
  206. if ($rs1['num'] == 'auther_authkey') $authkey = $rs1['value'];
  207. if ($rs1['num'] == 'auther_yuming') $yuming = $rs1['value'];
  208. if ($rs1['num'] == 'auther_enddt') $enddt = $rs1['value'];
  209. }
  210. if (isempt($yuming) || isempt($enddt) || isempt($authkey)) return $this->rock->jm->base64decode('57O757uf5pyq562!5o6I5LiN6IO95L2.55So77yM562!5o6I5piv5YWN6LS555qE77yMPGEgaHJlZj0iaHR0cDovL3d3dy5yb2Nrb2EuY29tL3ZpZXdfYXV0aGVyLmh0bWwiPueci!W4ruWKqeiuvue9rjwvYT4:');
  211. if ($this->rock->jm->uncrypt($enddt) < $this->rock->date) return $this->rock->jm->base64decode('57O757uf562!5o6I5bey5Yiw5pyf');
  212. $ym = $this->rock->jm->uncrypt($yuming);
  213. $mym = HOST;
  214. $ho1 = ',' . $mym . ',';
  215. $yma = explode(',', $ym);
  216. $bool = false;
  217. foreach ($yma as $ym1) {
  218. if ($ym1 == $mym) $bool = true;
  219. if (substr($ym1, 0, 2) == '*.' && contain($mym, substr($ym1, 1))) $bool = true;
  220. }
  221. if (substr($mym, 0, 7) == $this->rock->jm->base64decode('MTkyLjE2OA::')) $bool = true;
  222. if (!$bool) return str_replace('1', $mym, $this->rock->jm->base64decode('MeWfn!WQjeacquetvuaOiOS4jeiDveS9v!eUqA::'));
  223. return array('star' => 'rock', 'authkey' => $authkey, 'yuming' => $ym);
  224. }
  225. public function strsste()
  226. {
  227. }
  228. }