Goodsgift.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * 商品赠品模型
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 数据层模型
  18. */
  19. class Goodsgift extends BaseModel
  20. {
  21. /**
  22. * 插入数据
  23. * @access public
  24. * @author csdeshang
  25. * @param array $insert 插入内容
  26. * @return boolean
  27. */
  28. public function addGoodsgiftAll($insert) {
  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. return Db::name('goodsgift')->where($condition)->select()->toArray();
  40. }
  41. /**
  42. * 获取赠品列表根据商品ID
  43. * @access public
  44. * @author csdeshang
  45. * @param int $goods_id
  46. * @return array
  47. */
  48. public function getGoodsgiftListByGoodsId($goods_id) {
  49. $condition = array();
  50. $condition[] = array('goods_id','=',$goods_id);
  51. $list = $this->_rGoodsgiftCache($goods_id);
  52. if (empty($list)) {
  53. $gift_list = $this->getGoodsgiftList($condition);
  54. $list['gift'] = serialize($gift_list);
  55. $this->_wGoodsgiftCache($goods_id, $list);
  56. }
  57. $gift_list = unserialize($list['gift']);
  58. return $gift_list;
  59. }
  60. /**
  61. * 删除赠品
  62. * @access public
  63. * @author csdeshang
  64. * @param array $condition 条件
  65. * @return boolean
  66. */
  67. public function delGoodsgift($condition) {
  68. $gift_list = $this->getGoodsgiftList($condition);
  69. if (empty($gift_list)) {
  70. return true;
  71. }
  72. $result = Db::name('goodsgift')->where($condition)->delete();
  73. if ($result) {
  74. foreach ($gift_list as $val) {
  75. $this->_dGoodsgiftCache($val['goods_id']);
  76. }
  77. }
  78. return $result;
  79. }
  80. /**
  81. * 读取商品公共缓存
  82. * @access public
  83. * @author csdeshang
  84. * @param int $goods_id 商品ID
  85. * @return array
  86. */
  87. private function _rGoodsgiftCache($goods_id) {
  88. return rcache($goods_id, 'goods_gift');
  89. }
  90. /**
  91. * 写入商品公共缓存
  92. * @access public
  93. * @author csdeshang
  94. * @param int $goods_id 商品ID
  95. * @param array $list 列表
  96. * @return boolean
  97. */
  98. private function _wGoodsgiftCache($goods_id, $list) {
  99. return wcache($goods_id, $list, 'goods_gift');
  100. }
  101. /**
  102. * 删除商品公共缓存
  103. * @access public
  104. * @author csdeshang
  105. * @param int $goods_id 商品ID
  106. * @return boolean
  107. */
  108. private function _dGoodsgiftCache($goods_id) {
  109. return dcache($goods_id, 'goods_gift');
  110. }
  111. }