Favorites.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Favorites extends BaseModel
  17. {
  18. public $page_info;
  19. /**
  20. * 收藏列表
  21. * @access public
  22. * @author csdeshang
  23. * @param array $condition 查询条件
  24. * @param string $field 查询字段
  25. * @param int $pagesize 分页信息
  26. * @param string $order 排序
  27. * @return array
  28. */
  29. public function getFavoritesList($condition, $field = '*', $pagesize = 0, $order = 'favlog_id desc')
  30. {
  31. if ($pagesize) {
  32. $res= Db::name('favorites')->where($condition)->field($field)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  33. $this->page_info=$res;
  34. return $res->items();
  35. } else {
  36. return Db::name('favorites')->where($condition)->field($field)->order($order)->select()->toArray();
  37. }
  38. }
  39. /**
  40. * 收藏商品列表
  41. * @access public
  42. * @author csdeshang
  43. * @param array $condition 检索条件
  44. * @param string $field 字段
  45. * @param int $pagesize 分页信息
  46. * @param string $order 排序
  47. * @return array
  48. */
  49. public function getGoodsFavoritesList($condition, $field = '*', $pagesize = 0, $order = 'favlog_id desc')
  50. {
  51. $condition[]=array('fav_type','=','goods');
  52. return $this->getFavoritesList($condition, $field, $pagesize, $order);
  53. }
  54. /**
  55. * 收藏店铺列表
  56. * @access public
  57. * @author csdeshang
  58. * @param array $condition 查询条件
  59. * @param string $field 字段
  60. * @param int $pagesize 分页信息
  61. * @param string $order 排序
  62. * @return array
  63. */
  64. public function getStoreFavoritesList($condition, $field = '*', $pagesize = 0, $order = 'favlog_id desc')
  65. {
  66. $condition[]=array('fav_type','=','store');
  67. return $this->getFavoritesList($condition, $field, $pagesize, $order);
  68. }
  69. /**
  70. * 取单个收藏的内容
  71. * @access public
  72. * @author csdeshang
  73. * @param array $condition 查询条件
  74. * @return array 数组类型的返回结果
  75. */
  76. public function getOneFavorites($condition)
  77. {
  78. return Db::name('favorites')->where($condition)->find();
  79. }
  80. /**
  81. * 获取店铺收藏数
  82. * @access public
  83. * @author csdeshang
  84. * @param int $storeId 店铺ID
  85. * @param int $memberId 会员ID
  86. * @return int
  87. */
  88. public function getStoreFavoritesCountByStoreId($storeId, $memberId = 0)
  89. {
  90. $condition = array();
  91. $condition[] = array('fav_type','=','store');
  92. $condition[] = array('fav_id','=',$storeId);
  93. if ($memberId > 0) {
  94. $condition[] = array('member_id','=',$memberId);
  95. }
  96. return Db::name('favorites')->where($condition)->count();
  97. }
  98. /**
  99. * 获取商品收藏数
  100. * @access public
  101. * @author csdeshang
  102. * @param int $goodsId 商品ID
  103. * @param int $memberId 会员ID
  104. * @return int
  105. */
  106. public function getGoodsFavoritesCountByGoodsId($goodsId, $memberId = 0)
  107. {
  108. $condition = array();
  109. $condition[] = array('fav_type','=','goods');
  110. $condition[] = array('fav_id','=',$goodsId);
  111. if ($memberId > 0) {
  112. $condition[] = array('member_id','=',$memberId);
  113. }
  114. return Db::name('favorites')->where($condition)->count();
  115. }
  116. /**
  117. * 新增收藏
  118. * @access public
  119. * @author csdeshang
  120. * @param array $data 参数内容
  121. * @return bool 布尔类型的返回结果
  122. */
  123. public function addFavorites($data)
  124. {
  125. if (empty($data)) {
  126. return false;
  127. }
  128. if ($data['fav_type'] == 'store') {
  129. $store_id = intval($data['fav_id']);
  130. $store_model = model('store');
  131. $store = $store_model->getStoreInfoByID($store_id);
  132. $data['store_name'] = $store['store_name'];
  133. $data['store_id'] = $store['store_id'];
  134. $data['storeclass_id'] = $store['storeclass_id'];
  135. }
  136. if ($data['fav_type'] == 'goods') {
  137. $goods_id = intval($data['fav_id']);
  138. $goods_model = model('goods');
  139. $goods = $goods_model->getGoodsInfoByID($goods_id);
  140. $data['goods_name'] = $goods['goods_name'];
  141. $data['goods_image'] = $goods['goods_image'];
  142. $data['favlog_price'] = $goods['goods_promotion_price'];//商品收藏时价格
  143. $data['favlog_msg'] = $goods['goods_promotion_price'];//收藏备注,默认为收藏时价格,可修改
  144. $data['gc_id'] = $goods['gc_id'];
  145. $store_id = intval($goods['store_id']);
  146. $store_model = model('store');
  147. $store = $store_model->getStoreInfoByID($store_id);
  148. $data['store_name'] = $store['store_name'];
  149. $data['store_id'] = $store['store_id'];
  150. $data['storeclass_id'] = $store['storeclass_id'];
  151. }
  152. return Db::name('favorites')->insertGetId($data);
  153. }
  154. /**
  155. * 修改记录
  156. * @access public
  157. * @author csdeshang
  158. * @param type $condition 修改条件
  159. * @param type $data 修改数据
  160. * @return boolean
  161. */
  162. public function editFavorites($condition, $data)
  163. {
  164. if (empty($condition)) {
  165. return false;
  166. }
  167. if (is_array($data)) {
  168. $result = Db::name('favorites')->where($condition)->update($data);
  169. return $result;
  170. }
  171. else {
  172. return false;
  173. }
  174. }
  175. /**
  176. * 删除
  177. * @access public
  178. * @author csdeshang
  179. * @param array $condition 查询条件
  180. * @return bool 布尔类型的返回结果
  181. */
  182. public function delFavorites($condition)
  183. {
  184. if (empty($condition)) {
  185. return false;
  186. }
  187. return Db::name('favorites')->where($condition)->delete();
  188. }
  189. /**
  190. * 获取店铺收藏数
  191. * @access public
  192. * @author csdeshang
  193. * @param int $id 会员ID
  194. * @return int
  195. */
  196. public function getStoreFavoritesCountByMemberId($member_id)
  197. {
  198. $condition = array();
  199. $condition[] = array('fav_type','=','store');
  200. if ($member_id > 0) {
  201. $condition[] = array('member_id','=',$member_id);
  202. }
  203. return Db::name('favorites')->where($condition)->count();
  204. }
  205. /**
  206. * 获取商品收藏数
  207. * @access public
  208. * @author csdeshang
  209. * @param int $id 会员ID
  210. * @return int
  211. */
  212. public function getGoodsFavoritesCountByMemberId($member_id)
  213. {
  214. $condition = array();
  215. $condition[] = array('fav_type','=','goods');
  216. if ($member_id > 0) {
  217. $condition[] = array('member_id','=',$member_id);
  218. }
  219. return Db::name('favorites')->where($condition)->count();
  220. }
  221. }