sns_goods.model.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * SNS功能商品
  4. *
  5. */
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class sns_goodsModel extends Model{
  8. public function __construct(){
  9. parent::__construct('sns_goods');
  10. }
  11. /**
  12. * 查询SNS商品详细
  13. *
  14. * @param array $condition
  15. * @param string $field
  16. * @return array
  17. */
  18. public function getSNSGoodsInfo($condition, $field = '*'){
  19. $result = $this->field($field)->where($condition)->find();
  20. return $result;
  21. }
  22. /**
  23. * 新增SNS商品
  24. *
  25. * @param $param 添加信息数组
  26. * @return 返回结果
  27. */
  28. public function goodsAdd($param){
  29. if (empty($param)){
  30. return false;
  31. }
  32. if (is_array($param)){
  33. $result = Db::insert('sns_goods',$param);
  34. return $result;
  35. }else {
  36. return false;
  37. }
  38. }
  39. /**
  40. * 查询SNS商品详细
  41. *
  42. * @param $condition 查询条件
  43. * @param $field 查询字段
  44. */
  45. public function getGoodsInfo($condition,$field='*'){
  46. $param = array();
  47. $param['table'] = 'sns_goods';
  48. $param['field'] = array_keys($condition);
  49. $param['value'] = array_values($condition);
  50. return Db::getRow($param,$field);
  51. }
  52. /**
  53. * 更新SNS商品信息
  54. * @param $param 更新内容
  55. * @param $condition 更新条件
  56. */
  57. public function editGoods($param,$condition) {
  58. if(empty($param)) {
  59. return false;
  60. }
  61. //得到条件语句
  62. $condition_str = $this->getCondition($condition);
  63. $result = Db::update('sns_goods',$param,$condition_str);
  64. return $result;
  65. }
  66. /**
  67. * 将条件数组组合为SQL语句的条件部分
  68. *
  69. * @param array $condition_array
  70. * @return string
  71. */
  72. private function getCondition($condition_array){
  73. $condition_sql = '';
  74. //商品ID
  75. if ($condition_array['snsgoods_goodsid'] != '') {
  76. $condition_sql .= " and `sns_goods`.snsgoods_goodsid = '{$condition_array['snsgoods_goodsid']}'";
  77. }
  78. return $condition_sql;
  79. }
  80. }