GoodsCollect.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\model\goods;
  13. use app\model\BaseModel;
  14. use app\model\system\Stat;
  15. /**
  16. * 商品收藏
  17. */
  18. class GoodsCollect extends BaseModel
  19. {
  20. /**
  21. * 添加收藏
  22. * @param array $data
  23. */
  24. public function addCollect($data)
  25. {
  26. $res = model('goods_collect')->getInfo([ [ 'member_id', '=', $data['member_id'] ], [ 'goods_id', '=', $data['goods_id'] ] ], 'site_id, collect_id');
  27. if (empty($res)) {
  28. $data['create_time'] = time();
  29. $collect_id = model('goods_collect')->add($data);
  30. if ($collect_id) {
  31. model("goods_sku")->setInc([ [ 'goods_id', '=', $data['goods_id'] ] ], 'collect_num', 1);
  32. }
  33. //添加统计
  34. $stat = new Stat();
  35. $stat->addShopStat([ 'collect_goods' => 1, 'site_id' => $data['site_id'] ]);
  36. return $this->success($collect_id);
  37. } else {
  38. return $this->error();
  39. }
  40. }
  41. /**
  42. * 取消收藏
  43. * @param int $member_id
  44. * @param int $goods_id
  45. */
  46. public function deleteCollect($member_id, $goods_id)
  47. {
  48. $res = model('goods_collect')->delete([ [ 'member_id', '=', $member_id ], [ 'goods_id', '=', $goods_id ] ]);
  49. if ($res) {
  50. model("goods_sku")->setDec([ [ 'goods_id', '=', $goods_id ] ], 'collect_num', 1);
  51. }
  52. return $this->success($res);
  53. }
  54. /**
  55. * 检测商品是否收藏
  56. * @param unknown $goods_id
  57. * @param unknown $member_id
  58. */
  59. public function getIsCollect($goods_id, $member_id)
  60. {
  61. $res = model('goods_collect')->getInfo([ [ 'member_id', '=', $member_id ], [ 'goods_id', '=', $goods_id ] ], 'collect_id');
  62. if (!empty($res)) {
  63. return $this->success(1);
  64. } else {
  65. return $this->success(0);
  66. }
  67. }
  68. /**
  69. * 获取收藏列表
  70. * @param array $condition
  71. * @param string $field
  72. * @param string $order
  73. * @param string $limit
  74. */
  75. public function getCollectList($condition = [], $field = 'collect_id, member_id, goods_id, sku_id, category_id, sku_name, sku_price, sku_image, create_time', $order = '', $limit = null)
  76. {
  77. $list = model('goods_collect')->getList($condition, $field, $order, '', '', '', $limit);
  78. return $this->success($list);
  79. }
  80. /**
  81. * 获取收藏分页列表
  82. * @param array $condition
  83. * @param number $page
  84. * @param string $page_size
  85. * @param string $order
  86. * @param string $field
  87. */
  88. public function getCollectPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = 'collect_id, member_id, goods_id, sku_id, category_id, sku_name, sku_price, sku_image, create_time')
  89. {
  90. $list = model('goods_collect')->pageList($condition, $field, $order, $page, $page_size);
  91. return $this->success($list);
  92. }
  93. }