SpecModel.class.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 SpecModel{
  16. public function update($data,$spec_type = 'normal')
  17. {
  18. $ins_data = array();
  19. $ins_data['name'] = $data['name'];
  20. $ins_data['spec_type'] = $spec_type;
  21. $ins_data['value'] = serialize(array_filter($data['value']));
  22. $ins_data['addtime'] = time();
  23. $id = $data['id'];
  24. if( !empty($id) && $id > 0 )
  25. {
  26. M('lionfish_comshop_spec')->where( array('id' => $id) )->save($ins_data);
  27. $id = $data['id'];
  28. }else{
  29. M('lionfish_comshop_spec')->add($ins_data);
  30. $id = M('lionfish_comshop_spec')->getLastInsID();
  31. }
  32. }
  33. public function get_all_spec($spec_type = 'normal')
  34. {
  35. $specs = M('lionfish_comshop_spec')->where(' spec_type="'.$spec_type.'"')->order('id asc')->select();
  36. foreach($specs as $key => $val)
  37. {
  38. $val['value'] = unserialize($val['value']);
  39. if( !empty($val['value']) )
  40. {
  41. $val['value_str'] = implode('@', $val['value']);
  42. }else{
  43. $val['value_str'] = '';
  44. }
  45. $specs[$key] = $val;
  46. }
  47. return $specs;
  48. }
  49. }
  50. ?>