goods_class_staple.model.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * 常用商品分类模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined ( 'InShopNC' ) or exit ( 'Access Invalid!' );
  10. class goods_class_stapleModel extends Model {
  11. public function __construct(){
  12. parent::__construct('goods_class_staple');
  13. }
  14. /**
  15. * 常用分类列表
  16. *
  17. * @param array $condition 条件
  18. * @param string $order 排序
  19. * @param string $field 字段
  20. * @param int $limit 限制
  21. * @return array 二维数组
  22. */
  23. public function getStapleList($condition, $field = '*', $order = 'counter desc', $limit = 20) {
  24. $result = $this->field($field)->where($condition)->order($order)->limit($limit)->select();
  25. return $result;
  26. }
  27. /**
  28. * 一条记录
  29. *
  30. * @param array $condition 检索条件
  31. * @param object $page
  32. * @return array 一维数组结构的返回结果
  33. */
  34. public function getStapleInfo($condition, $field = '*') {
  35. $result = $this->field($field)->where($condition)->find();
  36. return $result;
  37. }
  38. /**
  39. * 添加常用分类,如果已存在计数器+1
  40. *
  41. * $param array $patam 参数
  42. * $param int $member_id 成员id
  43. */
  44. public function autoIncrementStaple($param, $member_id) {
  45. $where = array(
  46. 'gc_id_1' => intval($param['gc_id_1']),
  47. 'gc_id_2' => intval($param['gc_id_2']),
  48. 'gc_id_3' => intval($param['gc_id_3']),
  49. 'member_id' => $member_id
  50. );
  51. $staple_info = $this->getStapleInfo($where);
  52. if (empty($staple_info)) {
  53. $insert = array(
  54. 'staple_name' => $param['gc_tag_name'],
  55. 'gc_id_1' => intval($param['gc_id_1']),
  56. 'gc_id_2' => intval($param['gc_id_2']),
  57. 'gc_id_3' => intval($param['gc_id_3']),
  58. 'type_id' => $param['type_id'],
  59. 'member_id' => $member_id
  60. );
  61. $this->addStaple($insert);
  62. } else {
  63. $update = array('counter' => array('exp', 'counter + 1'));
  64. $where = array('staple_id' => $staple_info['staple_id']);
  65. $this->updateStaple($update, $where);
  66. }
  67. return true;
  68. }
  69. /**
  70. * 新增
  71. *
  72. * @param array $param 参数内容
  73. * @return boolean 布尔类型的返回结果
  74. */
  75. public function addStaple($param) {
  76. $result = $this->insert($param);
  77. return $result;
  78. }
  79. /**
  80. * 更新
  81. *
  82. * @param array $update 更新内容
  83. * @param array $where 条件
  84. * @return boolean
  85. */
  86. public function updateStaple($update, $where) {
  87. $result = $this->where($where)->update($update);
  88. return $result;
  89. }
  90. /**
  91. * 删除常用分类
  92. *
  93. * @param array $condtion 条件
  94. * @return boolean
  95. */
  96. public function delStaple($condtion) {
  97. $result = $this->where($condtion)->delete();
  98. return $result;
  99. }
  100. }