Goodsclassstaple.php 3.7 KB

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