Update.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <?php namespace Manage\Api\Page;
  2. use Dever;
  3. use Manage\Lib\Page;
  4. ini_set("memory_limit", -1);
  5. set_time_limit(0);
  6. # 更新页
  7. class Update extends Page
  8. {
  9. public function __construct($load = '', $input = true)
  10. {
  11. parent::__construct('update', $load, $input);
  12. }
  13. public function get(&$value = array(), &$option = array())
  14. {
  15. $func = $this->checkFunc();
  16. $remote = $show = $spec = $source = $default = array();
  17. $data['update'] = $data['field'] = $data['option'] = array();
  18. $this->setting('field', $data['update'], true, 'text');
  19. foreach ($data['update'] as $k => $v) {
  20. if ($v['type'] == 'tree' || $v['type'] == 'upload' || $v['type'] == 'cascader' || $v['type'] == 'checkbox' || isset($v['multiple'])) {
  21. $v['value'] = array();
  22. }
  23. if (isset($v['source'])) {
  24. $source[$v['key']] = $v['source'];
  25. }
  26. if (isset($v['remote'])) {
  27. $remote[$v['key']] = array($k, $v['remote'], $v['key']);
  28. if (isset($v['remote_default']) && !$v['remote_default']) {
  29. unset($remote[$v['key']][2]);
  30. }
  31. }
  32. if (isset($v['spec_data'])) {
  33. $spec[$v['key']] = array($k, $v['spec_data'], $v['key'] . '_spec', $v['spec'], $v['spec_field']);
  34. }
  35. if (isset($v['show']) && is_string($v['show'])) {
  36. $show[$v['key']] = array($k, $v['show']);
  37. }
  38. if (isset($v['default']) && is_string($v['default']) && strstr($v['default'], '{')) {
  39. $default[$v['key']] = array($k, $v['default']);
  40. }
  41. $data['field'][$v['key']] = $v['value'];
  42. if ($v['type'] == 'sku') {
  43. $data['field'][$v['key'] . '_spec'] = [];
  44. }
  45. if (isset($v['option'])) {
  46. $data['option'][$v['key']] = $v['option'];
  47. unset($data['update'][$k]['option']);
  48. }
  49. }
  50. $active = $this->column($data);
  51. $data['info_id'] = false;
  52. if (!$this->info && $active) {
  53. $this->info = $this->db->find($active);
  54. if ($this->info) {
  55. $data['info_id'] = $this->info['id'];
  56. if (!$func) {
  57. $func = $this->getFunc('edit', '编辑', 1);
  58. if (!$func && $this->menu && $this->menu['show'] == 1) {
  59. Dever::error('无操作权限');
  60. }
  61. }
  62. }
  63. } elseif (!$func) {
  64. $func = $this->getFunc('update', '更新', 1);
  65. if (!$func && $this->menu && $this->menu['show'] == 1) {
  66. Dever::error('无操作权限');
  67. }
  68. }
  69. if ($this->info) {
  70. $info = $this->info;
  71. $this->setInfo($info, $data, $remote, $show, $source, $default, 1, $this->config['field']);
  72. if ($spec) {
  73. foreach ($spec as $k => $v) {
  74. $data['update'][$spec[$k][0]]['remote'] = Dever::url($spec[$k][1]);
  75. $result = Dever::call($spec[$k][1], array($spec[$k][3], $spec[$k][4], $this->info['id']));
  76. if ($result) {
  77. $data['field'][$spec[$k][2]] = $result;
  78. }
  79. }
  80. }
  81. } elseif ($value) {
  82. $field = array();
  83. if (isset($this->config['field']) && $this->config['field']) {
  84. foreach ($this->config['field'] as $k => $v) {
  85. if (isset($v['field'])) {
  86. $field[$v['field']] = $v;
  87. if (!isset($field[$v['field']]['index'])) {
  88. $field[$v['field']]['index'][] = $k;
  89. }
  90. } else {
  91. $field[$k] = $v;
  92. }
  93. }
  94. }
  95. foreach ($value as $k => &$v) {
  96. $this->setInfo($v, $data, $remote, $show, $source, $default, 2, $field);
  97. $option[$k] = $data['option'];
  98. }
  99. if (isset($data['reset'])) {
  100. foreach ($data['reset'] as $k1 => $v1) {
  101. if (isset($data['option'][$k1])) {
  102. unset($data['option'][$k1]);
  103. $data['field'][$k1] = $v1;
  104. }
  105. }
  106. }
  107. } else {
  108. if ($remote) {
  109. $info = array();
  110. foreach ($remote as $k => $v) {
  111. $data['update'][$v[0]]['remote'] = Dever::url($v[1]);
  112. if (isset($v[2]) && isset($data['option'][$v[2]]) && $data['option'][$v[2]] && $m = Dever::issets($data['option'][$v[2]][0], 'id')) {
  113. $result = Dever::call($v[1], array($m), 'api');
  114. if ($result) {
  115. $this->setUpdate($info, $data, $result);
  116. }
  117. }
  118. }
  119. }
  120. if ($show) {
  121. foreach ($show as $k => $v) {
  122. $data['update'][$v[0]]['show'] = true;
  123. }
  124. }
  125. }
  126. $data['desc'] = $this->config['desc'] ?? '';
  127. $data['drag'] = $this->config['drag'] ?? false;
  128. $this->layout($data);
  129. $this->control($data);
  130. $this->tab($data, 'step');
  131. if (!$data['step']) {
  132. $this->tab($data);
  133. }
  134. return $data;
  135. }
  136. private function setInfo(&$info, &$data, $remote, $show, $source, $default, $type = 1, $field = array())
  137. {
  138. if ($source) {
  139. foreach ($source as $k => $v) {
  140. $t = array();
  141. foreach ($v as $v1) {
  142. $t[] = $info[$v1] ?? '';
  143. }
  144. $info[$k] = implode(',', $t);
  145. }
  146. }
  147. foreach ($info as $k => $v) {
  148. if ($v == null) {
  149. $v = '';
  150. }
  151. if (isset($data['field'][$k])) {
  152. if (is_array($data['field'][$k])) {
  153. if ($v) {
  154. $v = explode(',', $v);
  155. foreach ($v as $k1 => $v1) {
  156. if (is_numeric($v1)) {
  157. $v[$k1] = (float) $v1;
  158. }
  159. }
  160. } else {
  161. $v = array();
  162. }
  163. $info[$k] = $v;
  164. }
  165. if (isset($field[$k]) && isset($field[$k]['update'])) {
  166. $v = $field[$k]['update'];
  167. }
  168. if ($k == 'cdate') {
  169. $field[$k]['type'] = 'date';
  170. }
  171. if (isset($field[$k]) && isset($field[$k]['type']) && $field[$k]['type'] == 'date' && $v) {
  172. $v = date('Y-m-d H:i:s', $v);
  173. }
  174. if ($type == 1) {
  175. $data['field'][$k] = $v;
  176. }
  177. if (isset($remote[$k])) {
  178. $data['update'][$remote[$k][0]]['remote'] = Dever::url($remote[$k][1]);
  179. if ($field[$k]['type'] == 'cascader' && !isset($field[$k]['option'])) {
  180. } else {
  181. $result = Dever::call($remote[$k][1], array($v), 'api');
  182. if ($result) {
  183. $this->setUpdate($info, $data, $result);
  184. }
  185. }
  186. }
  187. if (isset($show[$k])) {
  188. $data['update'][$show[$k][0]]['show'] = $this->getShow($show[$k][1], $info);
  189. $info[$k] = $data['update'][$show[$k][0]]['show'];
  190. }
  191. }
  192. if (isset($field[$k]) && isset($field[$k]['index'])) {
  193. foreach ($field[$k]['index'] as $v1) {
  194. $info[$v1] = $v;
  195. }
  196. }
  197. }
  198. if ($default) {
  199. foreach ($default as $k => $v) {
  200. $data['update'][$v[0]]['value'] = $this->getShow($v[1], $info);
  201. $info[$k] = $data['field'][$k] = $data['update'][$v[0]]['value'];
  202. }
  203. }
  204. }
  205. private function setUpdate(&$info, &$data, $result, $remote = array())
  206. {
  207. foreach ($data['update'] as $k => $v) {
  208. if (isset($result[$v['key']])) {
  209. # 批量更新时,默认数据需要重置
  210. if (!isset($data['reset'][$v['key']])) {
  211. $data['reset'][$v['key']] = $data['field'][$v['key']];
  212. }
  213. if (isset($result[$v['key']]['option'])) {
  214. $data['option'][$v['key']] = $result[$v['key']]['option'];
  215. unset($result[$v['key']]['option']);
  216. }
  217. if (empty($data['field'][$v['key']]) && isset($result[$v['key']]['value'])) {
  218. if (is_array($data['field'][$v['key']]) && !is_array($result[$v['key']]['value'])) {
  219. $data['field'][$v['key']] = explode(',', $result[$v['key']]['value']);
  220. } else {
  221. $data['field'][$v['key']] = $result[$v['key']]['value'];
  222. }
  223. }
  224. if (isset($result[$v['key']]['set']) && $info) {
  225. $info = array_merge($info, $result[$v['key']]['set']);
  226. }
  227. $data['update'][$k] = array_merge($data['update'][$k], $result[$v['key']]);
  228. }
  229. }
  230. }
  231. private function control(&$data)
  232. {
  233. $data['control'] = array();
  234. if (isset($this->config['control']) && $data['control'] = $this->config['control']) {
  235. foreach ($data['control'] as $k => $v) {
  236. foreach ($data['update'] as $k1 => $v1) {
  237. if ($v1['key'] == $k) {
  238. $show = true;
  239. foreach ($v as $k2 => $v2) {
  240. if (is_array($v2)) {
  241. $temp = false;
  242. foreach ($v2 as $k3 => $v3) {
  243. if (is_array($data['field'][$k2]) && in_array($v3, $data['field'][$k2])) {
  244. $temp = true;
  245. } elseif ($data['field'][$k2] == $v3) {
  246. $temp = true;
  247. }
  248. }
  249. $show = $temp;
  250. } else {
  251. if (is_array($data['field'][$k2]) && !in_array($v2, $data['field'][$k2])) {
  252. $show = false;
  253. } elseif ($data['field'][$k2] != $v2) {
  254. $show = false;
  255. }
  256. }
  257. }
  258. $data['update'][$k1]['show'] = $show;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. private function tab(&$data, $type = 'tab')
  265. {
  266. $field = $this->input('field', '');
  267. $data[$type] = array();
  268. //if (empty($data['layout']) && !$field && isset($this->config[$type])) {
  269. if (empty($data['layout']) && isset($this->config[$type])) {
  270. foreach ($this->config[$type] as $k => $v) {
  271. if (is_string($v)) {
  272. $field = array();
  273. $data[$type][] = array
  274. (
  275. 'name' => $k,
  276. 'update' => $this->getUpdate($v, $data['update'], $field),
  277. 'field' => $field,
  278. );
  279. } else {
  280. $field = array();
  281. $result = array();
  282. $result['name'] = $k;
  283. foreach ($v as $v1) {
  284. $result['layout'][] = $this->getUpdate($v1, $data['update'], $field);
  285. }
  286. $result['field'] = $field;
  287. $data[$type][] = $result;
  288. }
  289. }
  290. $data['update'] = array();
  291. }
  292. }
  293. private function layout(&$data)
  294. {
  295. $field = $this->input('field', '');
  296. $data['layout'] = array();
  297. if (!$field && isset($this->config['layout'])) {
  298. foreach ($this->config['layout'] as $k => $v) {
  299. $field = array();
  300. $data['layout'][] = $this->getUpdate($v, $data['update'], $field);
  301. }
  302. $data['update'] = array();
  303. }
  304. }
  305. private function getUpdate($set, $update, &$field)
  306. {
  307. $result = array();
  308. if (is_string($set)) {
  309. $set = explode(',', $set);
  310. foreach ($set as $k => $v) {
  311. foreach ($update as $value) {
  312. if ($value['key'] == $v) {
  313. $result[] = $value;
  314. $field[] = $v;
  315. }
  316. }
  317. }
  318. } else {
  319. foreach ($set as $k => $v) {
  320. foreach ($update as $value) {
  321. if ($value['key'] == $k) {
  322. $result[] = array('span' => $v, 'update' => array($value));
  323. $field[] = $k;
  324. }
  325. }
  326. }
  327. }
  328. return $result;
  329. }
  330. public function do_commit(){}
  331. public function do()
  332. {
  333. $this->checkFunc();
  334. $update = array();
  335. $this->setting('field', $update, true, 'text');
  336. if ($update) {
  337. $data = $other = $sku = array();
  338. $input = Dever::input();
  339. $id = false;
  340. if (isset($input['id']) && $input['id'] > 0) {
  341. $id = $input['id'];
  342. }
  343. foreach ($update as $k => $v) {
  344. if (isset($input[$v['key']])) {
  345. if (isset($v['rules'])) {
  346. $this->checkRules($v, $input[$v['key']]);
  347. }
  348. if ($v['type'] == 'sku') {
  349. if (isset($input[$v['key'] . '_spec']) && isset($input[$v['key']])) {
  350. $sku[$v['key']] = array($v['where'], $v['content']['field'], $v['spec'], $v['spec_field'], $input[$v['key'] . '_spec'], $input[$v['key']]);
  351. }
  352. } elseif (strpos($v['key'], '/') && $v['type'] != 'hidden') {
  353. if (isset($v['field'])) {
  354. $value = $input[$v['key']] ?? false;
  355. if (strpos($v['key'], '#')) {
  356. $v['key'] = str_replace('#', '', $v['key']);
  357. }
  358. $other_id = $input[$v['key'] . '_id'] ?? 0;
  359. $value = array
  360. (
  361. 0 => array('id' => $other_id, $v['field'] => $value)
  362. );
  363. if (isset($other[$v['key']])) {
  364. $other[$v['key']][3][0] += $value[0];
  365. } else {
  366. $other[$v['key']] = array($v['where'], false, false, $value);
  367. }
  368. } else {
  369. $other[$v['key']] = array($v['where'], $v['content']['field'], $v['content']['drag'], $input[$v['key']]);
  370. }
  371. } else {
  372. $this->doData($data, $v['key'], $input[$v['key']], $this->config['field']);
  373. }
  374. } elseif ($id) {
  375. $data[$v['key']] = '';
  376. }
  377. if (isset($data[$v['key']]) && !$data[$v['key']] && isset($v['empty']) && !$v['empty']) {
  378. unset($data[$v['key']]);
  379. }
  380. }
  381. if (!$data && !$other && !$sku) {
  382. Dever::error('无效数据');
  383. }
  384. if ($data) {
  385. $this->exists($id, $data, $this->config['field']);
  386. $this->start($id, $data);
  387. if ($id) {
  388. $info = $this->db->find($id);
  389. if ($info) {
  390. $state = $this->db->update($info['id'], $data);
  391. if ($state) {
  392. $id = $info['id'];
  393. }
  394. } else {
  395. $data['id'] = $id;
  396. $id = $this->db->insert($data);
  397. }
  398. } else {
  399. $id = $this->db->insert($data);
  400. }
  401. }
  402. if (!$id) {
  403. Dever::error('操作失败');
  404. }
  405. $this->other($id, $data, $other);
  406. $this->sku($id, $data, $sku);
  407. $this->end($id, $data);
  408. return '操作成功';
  409. }
  410. }
  411. private function doData(&$data, $key, $value, $field = array())
  412. {
  413. if (is_array($value)) {
  414. if (isset($value[0])) {
  415. $value = ltrim(implode(',', $value), ',');
  416. } else {
  417. $value = Dever::json_encode($value);
  418. }
  419. }
  420. if (isset($field[$key]) && isset($field[$key]['field'])) {
  421. $key = $field[$key]['field'];
  422. }
  423. if ($value && isset($field[$key]) && $handle = Dever::issets($field[$key], 'handle')) {
  424. $value = Dever::call($handle, array($value));
  425. if (is_array($value) && isset($value[$key])) {
  426. foreach ($value as $k => $v) {
  427. $data[$k] = trim($v);
  428. }
  429. return;
  430. }
  431. } elseif (isset($field[$key]) && isset($field[$key]['type']) && $field[$key]['type'] == 'date' && $value) {
  432. $value = \Dever\Helper\Date::mktime($value);
  433. }
  434. $data[$key] = trim($value);
  435. }
  436. private function exists($id, $data, $field)
  437. {
  438. if (isset($this->config['check']) && $this->config['check']) {
  439. $check = explode(',', $this->config['check']);
  440. $where = array();
  441. $name = array();
  442. foreach ($check as $k => $v) {
  443. if (isset($data[$v]) && $data[$v]) {
  444. if (isset($field[$v]) && isset($field[$v]['name'])) {
  445. $n = $field[$v]['name'];
  446. } elseif (isset($this->db->config['struct'][$v])) {
  447. $n = $this->db->config['struct'][$v]['name'];
  448. } else {
  449. $n = $v;
  450. }
  451. $where[$v] = $data[$v];
  452. $name[] = $n;
  453. }
  454. }
  455. if ($where) {
  456. if ($id) {
  457. $where['id'] = array('!=', $id);
  458. }
  459. $info = $this->db->find($where);
  460. if ($info) {
  461. $name = implode('、', $name);
  462. Dever::error($name . '已存在');
  463. }
  464. }
  465. }
  466. }
  467. private function start($id, &$data)
  468. {
  469. if (isset($this->config['start']) && $this->config['start']) {
  470. $data['id'] = $id;
  471. if (is_array($this->config['start'])) {
  472. $result = $data;
  473. foreach ($this->config['start'] as $k => $v) {
  474. $result = Dever::call($v, array($this->db, $result));
  475. }
  476. } else {
  477. $result = Dever::call($this->config['start'], array($this->db, $data));
  478. }
  479. if ($result) {
  480. $data = $result;
  481. }
  482. }
  483. }
  484. private function end($id, $data)
  485. {
  486. if (isset($this->config['end']) && $this->config['end']) {
  487. $data['id'] = $id;
  488. if (is_array($this->config['end'])) {
  489. foreach ($this->config['end'] as $k => $v) {
  490. Dever::call($v, array($this->db, $data));
  491. }
  492. } else {
  493. Dever::call($this->config['end'], array($this->db, $data));
  494. }
  495. }
  496. }
  497. private function other($rid, $data, $other)
  498. {
  499. if ($other) {
  500. foreach ($other as $k => $v) {
  501. if (strpos($k, '#')) {
  502. $k = str_replace('#', '', $k);
  503. }
  504. $set = new Update($k, false);
  505. $common = $v[0];
  506. $update = $v[1];
  507. $drag = $v[2];
  508. $input = $v[3];
  509. $value = array();
  510. foreach ($input as $k1 => $v1) {
  511. if (isset($v1['id']) && $v1['id']) {
  512. $value['id'] = $v1['id'];
  513. }
  514. foreach ($common as $k2 => $v2) {
  515. if (!is_array($v2)) {
  516. if ($v2 == 'id') {
  517. $value[$k2] = $rid;
  518. } elseif (isset($data[$v2])) {
  519. $value[$k2] = $data[$v2];
  520. } else {
  521. $value[$k2] = $v2;
  522. }
  523. }
  524. }
  525. if ($update) {
  526. foreach ($update as $k2 => $v2) {
  527. if (isset($v1[$k2])) {
  528. $this->doData($value, $k2, $v1[$k2], $set->config['field']);
  529. } else {
  530. $value[$k2] = '';
  531. }
  532. }
  533. } else {
  534. $value += $v1;
  535. }
  536. if ($drag) {
  537. $value[$drag] = $k1+1;
  538. }
  539. if (isset($value['id']) && $value['id'] > 0) {
  540. $id = $value['id'];
  541. unset($value['id']);
  542. Dever::db($k)->update($id, $value);
  543. } else {
  544. Dever::db($k)->insert($value);
  545. }
  546. }
  547. }
  548. }
  549. }
  550. private function sku($rid, $data, $sku)
  551. {
  552. if ($sku) {
  553. if (isset($data['spec_type']) && $data['spec_type'] <= 2) {
  554. return;
  555. }
  556. foreach ($sku as $k => $v) {
  557. if (strpos($k, '#')) {
  558. $k = str_replace('#', '', $k);
  559. }
  560. $common = $v[0];
  561. $update = $v[1];
  562. $spec_table = $v[2];
  563. $spec_value_table = $spec_table . '_value';
  564. $spec_field = $v[3];
  565. $spec = $v[4];
  566. $input = $v[5];
  567. $value = $spec_value = array();
  568. Dever::db($spec_table)->update(array($spec_field => $rid), array('state' => 2));
  569. Dever::db($spec_value_table)->update(array($spec_field => $rid), array('state' => 2));
  570. foreach ($spec as $k1 => &$v1) {
  571. $spec_data = array();
  572. $spec_data['state'] = 1;
  573. $spec_data[$spec_field] = $rid;
  574. $spec_data['name'] = $v1['name'];
  575. $spec_data['sort'] = $k1+1;
  576. if (isset($v1['id']) && $v1['id']) {
  577. Dever::db($spec_table)->update($v1['id'], $spec_data);
  578. } else {
  579. $v1['id'] = Dever::db($spec_table)->insert($spec_data);
  580. }
  581. if ($v1['id']) {
  582. foreach ($v1['value'] as $k2 => &$v2) {
  583. $spec_value_data = array();
  584. $spec_value_data['state'] = 1;
  585. $spec_value_data[$spec_field] = $rid;
  586. $spec_value_data['spec_id'] = $v1['id'];
  587. $spec_value_data['value'] = $v2['value'] ?? $v2['name'];
  588. $spec_value_data['sort'] = $k2+1;
  589. $spec_value_data['is_checked'] = $v2['checked'] == 'true' ? 1 : 2;
  590. if (isset($v2['id']) && $v2['id']) {
  591. Dever::db($spec_value_table)->update($v2['id'], $spec_value_data);
  592. } else {
  593. $v2['id'] = Dever::db($spec_value_table)->insert($spec_value_data);
  594. }
  595. $spec_value[$v1['key']][$spec_value_data['value']] = array($v2['id'], $spec_data['sort']);
  596. }
  597. }
  598. }
  599. Dever::db($spec_table)->delete(array($spec_field => $rid, 'state' => 2));
  600. Dever::db($spec_value_table)->delete(array($spec_field => $rid, 'state' => 2));
  601. Dever::db($k)->update(array($spec_field => $rid), array('state' => 2));
  602. foreach ($input as $k1 => $v1) {
  603. if (isset($v1['id'])) {
  604. $value['id'] = $v1['id'];
  605. }
  606. foreach ($common as $k2 => $v2) {
  607. if (!is_array($v2)) {
  608. if ($v2 == 'id') {
  609. $value[$k2] = $rid;
  610. } elseif (isset($data[$v2])) {
  611. $value[$k2] = $data[$v2];
  612. } else {
  613. $value[$k2] = $v2;
  614. }
  615. }
  616. }
  617. foreach ($update as $k2 => $v2) {
  618. if (isset($v1[$k2])) {
  619. $value[$k2] = $v1[$k2];
  620. }
  621. }
  622. $value['key'] = array();
  623. foreach ($v1 as $k2 => $v2) {
  624. if (isset($spec_value[$k2]) && isset($spec_value[$k2][$v2])) {
  625. $value['key'][$spec_value[$k2][$v2][1]] = $spec_value[$k2][$v2][0];
  626. }
  627. }
  628. if ($value['key']) {
  629. $value['key'] = implode(',' , $value['key']);
  630. }
  631. $value['state'] = 1;
  632. if (isset($value['id']) && $value['id'] > 0) {
  633. $id = $value['id'];
  634. unset($value['id']);
  635. Dever::db($k)->update($id, $value);
  636. } else {
  637. Dever::db($k)->insert($value);
  638. }
  639. }
  640. Dever::db($k)->delete(array($spec_field => $rid, 'state' => 2));
  641. }
  642. }
  643. }
  644. }