Goodsclassstaple.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Goodsclassstaple extends BaseModel
  12. {
  13. /**
  14. * 常用分类列表
  15. * @access public
  16. * @author csdeshang
  17. * @param array $condition 条件
  18. * @param string $order 排序
  19. * @param string $field 字段
  20. * @param int $limit 限制
  21. * @return array 二维数组
  22. */
  23. public function getGoodsclassstapleList($condition, $field = '*', $order = 'staple_counter desc', $limit = 20)
  24. {
  25. $result = Db::name('goodsclassstaple')->field($field)->where($condition)->order($order)->limit($limit)->select()->toArray();
  26. return $result;
  27. }
  28. /**
  29. * 一条记录
  30. * @access public
  31. * @author csdeshang
  32. * @param array $condition 检索条件
  33. * @param string $field 字段
  34. * @return array 一维数组结构的返回结果
  35. */
  36. public function getGoodsclassstapleInfo($condition, $field = '*')
  37. {
  38. $result = Db::name('goodsclassstaple')->field($field)->where($condition)->find();
  39. return $result;
  40. }
  41. /**
  42. * 添加常用分类,如果已存在计数器+1
  43. * @access public
  44. * @author csdeshang
  45. * @param type $data 参数内容
  46. * @param type $member_id 会员ID
  47. * @return boolean
  48. */
  49. public function autoIncrementStaple($data, $member_id)
  50. {
  51. $where = array(
  52. 'gc_id_1' => intval($data['gc_id_1']),
  53. 'gc_id_2' => intval($data['gc_id_2']),
  54. 'gc_id_3' => intval($data['gc_id_3']),
  55. 'member_id' => $member_id
  56. );
  57. $staple_info = $this->getGoodsclassstapleInfo($where);
  58. if (empty($staple_info)) {
  59. $insert = array(
  60. 'staple_name' => $data['gctag_name'],
  61. 'gc_id_1' => intval($data['gc_id_1']),
  62. 'gc_id_2' => intval($data['gc_id_2']),
  63. 'gc_id_3' => intval($data['gc_id_3']),
  64. 'type_id' => $data['type_id'],
  65. 'member_id' => $member_id
  66. );
  67. $this->addGoodsclassstaple($insert);
  68. } else {
  69. $update = array('staple_counter' => Db::raw('staple_counter+1'));
  70. $where = array('staple_id' => $staple_info['staple_id']);
  71. $this->editGoodsclassstaple($update, $where);
  72. }
  73. return true;
  74. }
  75. /**
  76. * 新增
  77. * @access public
  78. * @author csdeshang
  79. * @param array $data 参数内容
  80. * @return boolean 布尔类型的返回结果
  81. */
  82. public function addGoodsclassstaple($data)
  83. {
  84. $result = Db::name('goodsclassstaple')->insertGetId($data);
  85. return $result;
  86. }
  87. /**
  88. * 更新
  89. * @access public
  90. * @author csdeshang
  91. * @param array $update 更新内容
  92. * @param array $where 条件
  93. * @return boolean
  94. */
  95. public function editGoodsclassstaple($update, $where)
  96. {
  97. $result = Db::name('goodsclassstaple')->where($where)->update($update);
  98. return $result;
  99. }
  100. /**
  101. * 删除常用分类
  102. * @access public
  103. * @author csdeshang
  104. * @param array $condition 条件
  105. * @return boolean
  106. */
  107. public function delGoodsclassstaple($condition)
  108. {
  109. $result = Db::name('goodsclassstaple')->where($condition)->delete();
  110. return $result;
  111. }
  112. }