Goodsgift.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * 商品赠品模型
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. *
  13. * ----------------------------------------------------------------------------
  14. *
  15. * ============================================================================
  16. * 数据层模型
  17. */
  18. class Goodsgift extends BaseModel
  19. {
  20. /**
  21. * 插入数据
  22. * @access public
  23. * @author csdeshang
  24. * @param array $insert 插入内容
  25. * @return boolean
  26. */
  27. public function addGoodsgiftAll($insert)
  28. {
  29. return Db::name('goodsgift')->insertAll($insert);
  30. }
  31. /**
  32. * 查询赠品列表
  33. * @access public
  34. * @author csdeshang
  35. * @param array $condition 条件
  36. * @return array
  37. */
  38. public function getGoodsgiftList($condition)
  39. {
  40. return Db::name('goodsgift')->where($condition)->select()->toArray();
  41. }
  42. /**
  43. * 获取赠品列表根据商品ID
  44. * @access public
  45. * @author csdeshang
  46. * @param int $goods_id
  47. * @return array
  48. */
  49. public function getGoodsgiftListByGoodsId($goods_id)
  50. {
  51. $condition = array();
  52. $condition[] = array('goods_id', '=', $goods_id);
  53. $list = $this->_rGoodsgiftCache($goods_id);
  54. if (empty($list)) {
  55. $gift_list = $this->getGoodsgiftList($condition);
  56. $list['gift'] = serialize($gift_list);
  57. $this->_wGoodsgiftCache($goods_id, $list);
  58. }
  59. $gift_list = unserialize($list['gift']);
  60. return $gift_list;
  61. }
  62. /**
  63. * 删除赠品
  64. * @access public
  65. * @author csdeshang
  66. * @param array $condition 条件
  67. * @return boolean
  68. */
  69. public function delGoodsgift($condition)
  70. {
  71. $gift_list = $this->getGoodsgiftList($condition);
  72. if (empty($gift_list)) {
  73. return true;
  74. }
  75. $result = Db::name('goodsgift')->where($condition)->delete();
  76. if ($result) {
  77. foreach ($gift_list as $val) {
  78. $this->_dGoodsgiftCache($val['goods_id']);
  79. }
  80. }
  81. return $result;
  82. }
  83. /**
  84. * 读取商品公共缓存
  85. * @access public
  86. * @author csdeshang
  87. * @param int $goods_id 商品ID
  88. * @return array
  89. */
  90. private function _rGoodsgiftCache($goods_id)
  91. {
  92. return rcache($goods_id, 'goods_gift');
  93. }
  94. /**
  95. * 写入商品公共缓存
  96. * @access public
  97. * @author csdeshang
  98. * @param int $goods_id 商品ID
  99. * @param array $list 列表
  100. * @return boolean
  101. */
  102. private function _wGoodsgiftCache($goods_id, $list)
  103. {
  104. return wcache($goods_id, $list, 'goods_gift');
  105. }
  106. /**
  107. * 删除商品公共缓存
  108. * @access public
  109. * @author csdeshang
  110. * @param int $goods_id 商品ID
  111. * @return boolean
  112. */
  113. private function _dGoodsgiftCache($goods_id)
  114. {
  115. return dcache($goods_id, 'goods_gift');
  116. }
  117. }