optionModel.php 10 KB

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