ConfigModel.class.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. class ConfigModel{
  16. public function update($data)
  17. {
  18. foreach($data as $name => $value)
  19. {
  20. $info = M('lionfish_comshop_config')->where( array('name' => $name) )->find();
  21. $value = htmlspecialchars($value);
  22. if( empty($info) )
  23. {
  24. $ins_data = array();
  25. $ins_data['name'] = $name;
  26. $ins_data['value'] = $value;
  27. M('lionfish_comshop_config')->add($ins_data);
  28. }else{
  29. $rs = M('lionfish_comshop_config')->where( array('id' => $info['id']) )->save( array('value' => $value) );
  30. }
  31. }
  32. $this->get_all_config(true);
  33. }
  34. public function get_all_config($is_parse = false)
  35. {
  36. $data = S('_get_all_config');
  37. if (empty($data) || $is_parse) {
  38. $all_list = M('lionfish_comshop_config')->select();
  39. if (empty($all_list)) {
  40. $data = array();
  41. }else{
  42. $data = array();
  43. foreach($all_list as $val)
  44. {
  45. $data[$val['name']] = htmlspecialchars_decode( $val['value'] );
  46. }
  47. }
  48. S('_get_all_config', $data);
  49. }
  50. return $data;
  51. }
  52. /**
  53. * 删除满减配置项
  54. * @param $data
  55. */
  56. public function delete_config($data){
  57. foreach($data as $name => $value)
  58. {
  59. $info = M('lionfish_comshop_config')->where( array('name' => $name) )->find();
  60. $rs = M('lionfish_comshop_config')->where( array('id' => $info['id']) )->delete();
  61. }
  62. $this->get_all_config(true);
  63. }
  64. }
  65. ?>