123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace app\common\model;
- use think\facade\Db;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 数据层模型
- */
- class Goodsclassstaple extends BaseModel
- {
- /**
- * 常用分类列表
- * @access public
- * @author csdeshang
- * @param array $condition 条件
- * @param string $order 排序
- * @param string $field 字段
- * @param int $limit 限制
- * @return array 二维数组
- */
- public function getGoodsclassstapleList($condition, $field = '*', $order = 'staple_counter desc', $limit = 20)
- {
- $result = Db::name('goodsclassstaple')->field($field)->where($condition)->order($order)->limit($limit)->select()->toArray();
- return $result;
- }
- /**
- * 一条记录
- * @access public
- * @author csdeshang
- * @param array $condition 检索条件
- * @param string $field 字段
- * @return array 一维数组结构的返回结果
- */
- public function getGoodsclassstapleInfo($condition, $field = '*')
- {
- $result = Db::name('goodsclassstaple')->field($field)->where($condition)->find();
- return $result;
- }
- /**
- * 添加常用分类,如果已存在计数器+1
- * @access public
- * @author csdeshang
- * @param type $data 参数内容
- * @param type $member_id 会员ID
- * @return boolean
- */
- public function autoIncrementStaple($data, $member_id)
- {
- $where = array(
- 'gc_id_1' => intval($data['gc_id_1']),
- 'gc_id_2' => intval($data['gc_id_2']),
- 'gc_id_3' => intval($data['gc_id_3']),
- 'member_id' => $member_id
- );
- $staple_info = $this->getGoodsclassstapleInfo($where);
- if (empty($staple_info)) {
- $insert = array(
- 'staple_name' => $data['gctag_name'],
- 'gc_id_1' => intval($data['gc_id_1']),
- 'gc_id_2' => intval($data['gc_id_2']),
- 'gc_id_3' => intval($data['gc_id_3']),
- 'type_id' => $data['type_id'],
- 'member_id' => $member_id
- );
- $this->addGoodsclassstaple($insert);
- } else {
- $update = array('staple_counter' => Db::raw('staple_counter+1'));
- $where = array('staple_id' => $staple_info['staple_id']);
- $this->editGoodsclassstaple($update, $where);
- }
- return true;
- }
- /**
- * 新增
- * @access public
- * @author csdeshang
- * @param array $data 参数内容
- * @return boolean 布尔类型的返回结果
- */
- public function addGoodsclassstaple($data)
- {
- $result = Db::name('goodsclassstaple')->insertGetId($data);
- return $result;
- }
- /**
- * 更新
- * @access public
- * @author csdeshang
- * @param array $update 更新内容
- * @param array $where 条件
- * @return boolean
- */
- public function editGoodsclassstaple($update, $where)
- {
- $result = Db::name('goodsclassstaple')->where($where)->update($update);
- return $result;
- }
- /**
- * 删除常用分类
- * @access public
- * @author csdeshang
- * @param array $condition 条件
- * @return boolean
- */
- public function delGoodsclassstaple($condition)
- {
- $result = Db::name('goodsclassstaple')->where($condition)->delete();
- return $result;
- }
- }
|