Goodsgift.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * 商品赠品模型
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 数据层模型
  19. */
  20. class Goodsgift extends BaseModel
  21. {
  22. /**
  23. * 插入数据
  24. * @access public
  25. * @author csdeshang
  26. * @param array $insert 插入内容
  27. * @return boolean
  28. */
  29. public function addGoodsgiftAll($insert) {
  30. return Db::name('goodsgift')->insertAll($insert);
  31. }
  32. /**
  33. * 查询赠品列表
  34. * @access public
  35. * @author csdeshang
  36. * @param array $condition 条件
  37. * @return array
  38. */
  39. public function getGoodsgiftList($condition) {
  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. $condition = array();
  51. $condition[] = array('goods_id','=',$goods_id);
  52. $list = $this->_rGoodsgiftCache($goods_id);
  53. if (empty($list)) {
  54. $gift_list = $this->getGoodsgiftList($condition);
  55. $list['gift'] = serialize($gift_list);
  56. $this->_wGoodsgiftCache($goods_id, $list);
  57. }
  58. $gift_list = unserialize($list['gift']);
  59. return $gift_list;
  60. }
  61. /**
  62. * 删除赠品
  63. * @access public
  64. * @author csdeshang
  65. * @param array $condition 条件
  66. * @return boolean
  67. */
  68. public function delGoodsgift($condition) {
  69. $gift_list = $this->getGoodsgiftList($condition);
  70. if (empty($gift_list)) {
  71. return true;
  72. }
  73. $result = Db::name('goodsgift')->where($condition)->delete();
  74. if ($result) {
  75. foreach ($gift_list as $val) {
  76. $this->_dGoodsgiftCache($val['goods_id']);
  77. }
  78. }
  79. return $result;
  80. }
  81. /**
  82. * 读取商品公共缓存
  83. * @access public
  84. * @author csdeshang
  85. * @param int $goods_id 商品ID
  86. * @return array
  87. */
  88. private function _rGoodsgiftCache($goods_id) {
  89. return rcache($goods_id, 'goods_gift');
  90. }
  91. /**
  92. * 写入商品公共缓存
  93. * @access public
  94. * @author csdeshang
  95. * @param int $goods_id 商品ID
  96. * @param array $list 列表
  97. * @return boolean
  98. */
  99. private function _wGoodsgiftCache($goods_id, $list) {
  100. return wcache($goods_id, $list, 'goods_gift');
  101. }
  102. /**
  103. * 删除商品公共缓存
  104. * @access public
  105. * @author csdeshang
  106. * @param int $goods_id 商品ID
  107. * @return boolean
  108. */
  109. private function _dGoodsgiftCache($goods_id) {
  110. return dcache($goods_id, 'goods_gift');
  111. }
  112. }