Goodscombo.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 Goodscombo extends BaseModel
  21. {
  22. /**
  23. * 插入数据
  24. * @access public
  25. * @author csdeshang
  26. * @param array $data 参数内容
  27. * @return boolean
  28. */
  29. public function addGoodscomboAll($data) {
  30. $result = Db::name('goodscombo')->insertAll($data);
  31. if ($result) {
  32. foreach ((array)$data as $v) {
  33. if ($v['goods_id']) $this->_dGoodscomboCache($v['goods_id']);
  34. }
  35. }
  36. return $result;
  37. }
  38. /**
  39. * 查询组合商品列表
  40. * @access public
  41. * @author csdeshang
  42. * @param array $condition 查询条件
  43. * @return boolean
  44. */
  45. public function getGoodscomboList($condition) {
  46. return Db::name('goodscombo')->where($condition)->select()->toArray();
  47. }
  48. /**
  49. * 查询组合商品列表
  50. * @access public
  51. * @author csdeshang
  52. * @param type $condition 查询条件
  53. * @return boolean
  54. */
  55. public function delGoodscombo($condition) {
  56. $list = $this->getGoodscomboList($condition, 'goods_id');
  57. if (empty($list)) {
  58. return true;
  59. }
  60. $result = Db::name('goodscombo')->where($condition)->delete();
  61. if ($result) {
  62. foreach ($list as $v) {
  63. $this->_dGoodscomboCache($v['goods_id']);
  64. }
  65. }
  66. return $result;
  67. }
  68. /**
  69. * 获取商品组合缓存
  70. * @access public
  71. * @author csdeshang
  72. * @param type $goods_id 商品ID
  73. * @return array
  74. */
  75. public function getGoodscomboCacheByGoodsId($goods_id) {
  76. $array = $this->_rGoodscomboCache($goods_id);
  77. if (empty($array)) {
  78. $gcombo_list = array();
  79. $combo_list = $this->getGoodscomboList(array('goods_id' => $goods_id));
  80. if (!empty($combo_list)) {
  81. $comboid_array= array();
  82. foreach ($combo_list as $val) {
  83. $comboid_array[] = $val['combo_goodsid'];
  84. }
  85. $gcombo_list = model('goods')->getGeneralGoodsList(array(array('goods_id','in', $comboid_array)));
  86. }
  87. $array = array('gcombo_list' => serialize($gcombo_list));
  88. $this->_wGoodscomboCache($goods_id, $array);
  89. }
  90. return $array;
  91. }
  92. /**
  93. * 读取商品推荐搭配缓存
  94. * @access public
  95. * @author csdeshang
  96. * @param int $goods_id 商品id
  97. * @return array
  98. */
  99. private function _rGoodscomboCache($goods_id) {
  100. return rcache($goods_id, 'goods_combo');
  101. }
  102. /**
  103. * 写入商品推荐搭配缓存
  104. * @access public
  105. * @author csdeshang
  106. * @param int $goods_id 商品ID
  107. * @param array $array 数组内容
  108. * @return boolean
  109. */
  110. private function _wGoodscomboCache($goods_id, $array) {
  111. return wcache($goods_id, $array, 'goods_combo', 60);
  112. }
  113. /**
  114. * 删除商品推荐搭配缓存
  115. * @access public
  116. * @author csdeshang
  117. * @param int $goods_id 商品第
  118. * @return boolean
  119. */
  120. private function _dGoodscomboCache($goods_id) {
  121. return dcache($goods_id, 'goods_combo');
  122. }
  123. }