Goodsclassstaple.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Goodsclassstaple extends BaseModel {
  16. /**
  17. * 常用分类列表
  18. * @access public
  19. * @author csdeshang
  20. * @param array $condition 条件
  21. * @param string $order 排序
  22. * @param string $field 字段
  23. * @param int $limit 限制
  24. * @return array 二维数组
  25. */
  26. public function getGoodsclassstapleList($condition, $field = '*', $order = 'staple_counter desc', $limit = 20) {
  27. $result = Db::name('goodsclassstaple')->field($field)->where($condition)->order($order)->limit($limit)->select()->toArray();
  28. return $result;
  29. }
  30. /**
  31. * 一条记录
  32. * @access public
  33. * @author csdeshang
  34. * @param array $condition 检索条件
  35. * @param string $field 字段
  36. * @return array 一维数组结构的返回结果
  37. */
  38. public function getGoodsclassstapleInfo($condition, $field = '*') {
  39. $result = Db::name('goodsclassstaple')->field($field)->where($condition)->find();
  40. return $result;
  41. }
  42. /**
  43. * 添加常用分类,如果已存在计数器+1
  44. * @access public
  45. * @author csdeshang
  46. * @param type $data 参数内容
  47. * @param type $member_id 会员ID
  48. * @return boolean
  49. */
  50. public function autoIncrementStaple($data, $member_id) {
  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. $result = Db::name('goodsclassstaple')->insertGetId($data);
  84. return $result;
  85. }
  86. /**
  87. * 更新
  88. * @access public
  89. * @author csdeshang
  90. * @param array $update 更新内容
  91. * @param array $where 条件
  92. * @return boolean
  93. */
  94. public function editGoodsclassstaple($update, $where) {
  95. $result = Db::name('goodsclassstaple')->where($where)->update($update);
  96. return $result;
  97. }
  98. /**
  99. * 删除常用分类
  100. * @access public
  101. * @author csdeshang
  102. * @param array $condition 条件
  103. * @return boolean
  104. */
  105. public function delGoodsclassstaple($condition) {
  106. $result = Db::name('goodsclassstaple')->where($condition)->delete();
  107. return $result;
  108. }
  109. }
  110. ?>