Goodsclassstaple.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Goodsclassstaple extends BaseModel {
  17. /**
  18. * 常用分类列表
  19. * @access public
  20. * @author csdeshang
  21. * @param array $condition 条件
  22. * @param string $order 排序
  23. * @param string $field 字段
  24. * @param int $limit 限制
  25. * @return array 二维数组
  26. */
  27. public function getGoodsclassstapleList($condition, $field = '*', $order = 'staple_counter desc', $limit = 20) {
  28. $result = Db::name('goodsclassstaple')->field($field)->where($condition)->order($order)->limit($limit)->select()->toArray();
  29. return $result;
  30. }
  31. /**
  32. * 一条记录
  33. * @access public
  34. * @author csdeshang
  35. * @param array $condition 检索条件
  36. * @param string $field 字段
  37. * @return array 一维数组结构的返回结果
  38. */
  39. public function getGoodsclassstapleInfo($condition, $field = '*') {
  40. $result = Db::name('goodsclassstaple')->field($field)->where($condition)->find();
  41. return $result;
  42. }
  43. /**
  44. * 添加常用分类,如果已存在计数器+1
  45. * @access public
  46. * @author csdeshang
  47. * @param type $data 参数内容
  48. * @param type $member_id 会员ID
  49. * @return boolean
  50. */
  51. public function autoIncrementStaple($data, $member_id) {
  52. $where = array(
  53. 'gc_id_1' => intval($data['gc_id_1']),
  54. 'gc_id_2' => intval($data['gc_id_2']),
  55. 'gc_id_3' => intval($data['gc_id_3']),
  56. 'member_id' => $member_id
  57. );
  58. $staple_info = $this->getGoodsclassstapleInfo($where);
  59. if (empty($staple_info)) {
  60. $insert = array(
  61. 'staple_name' => $data['gctag_name'],
  62. 'gc_id_1' => intval($data['gc_id_1']),
  63. 'gc_id_2' => intval($data['gc_id_2']),
  64. 'gc_id_3' => intval($data['gc_id_3']),
  65. 'type_id' => $data['type_id'],
  66. 'member_id' => $member_id
  67. );
  68. $this->addGoodsclassstaple($insert);
  69. } else {
  70. $update = array('staple_counter' => Db::raw('staple_counter+1'));
  71. $where = array('staple_id' => $staple_info['staple_id']);
  72. $this->editGoodsclassstaple($update, $where);
  73. }
  74. return true;
  75. }
  76. /**
  77. * 新增
  78. * @access public
  79. * @author csdeshang
  80. * @param array $data 参数内容
  81. * @return boolean 布尔类型的返回结果
  82. */
  83. public function addGoodsclassstaple($data) {
  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. $result = Db::name('goodsclassstaple')->where($where)->update($update);
  97. return $result;
  98. }
  99. /**
  100. * 删除常用分类
  101. * @access public
  102. * @author csdeshang
  103. * @param array $condition 条件
  104. * @return boolean
  105. */
  106. public function delGoodsclassstaple($condition) {
  107. $result = Db::name('goodsclassstaple')->where($condition)->delete();
  108. return $result;
  109. }
  110. }
  111. ?>