123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- use think\facade\Db;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Memberfavorites extends BaseMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberfavorites.lang.php');
- }
- /**
- * 增加商品收藏
- */
- public function favoritesgoods()
- {
- $fav_id = intval(input('param.fid'));
- if ($fav_id <= 0) {
- echo json_encode(array('done' => false, 'msg' => lang('favorite_collect_fail')));
- die;
- }
- $favorites_model = model('favorites');
- //判断是否已经收藏
- $favorites_info = $favorites_model->getOneFavorites(array(
- 'fav_id' => "$fav_id", 'fav_type' => 'goods',
- 'member_id' => session('member_id')
- ));
- if (!empty($favorites_info)) {
- echo json_encode(array(
- 'done' => false, 'msg' => lang('favorite_already_favorite_goods')
- ));
- die;
- }
- //判断商品是否为当前会员所有
- $goods_model = model('goods');
- $goods_info = $goods_model->getGoodsInfoByID($fav_id);
- if ($goods_info['store_id'] == session('store_id')) {
- echo json_encode(array('done' => false, 'msg' => lang('favorite_no_my_product')));
- die;
- }
- //添加收藏
- $insert_arr = array();
- $insert_arr['member_id'] = session('member_id');
- $insert_arr['member_name'] = session('member_name');
- $insert_arr['fav_id'] = $fav_id;
- $insert_arr['fav_type'] = 'goods';
- $insert_arr['fav_time'] = TIMESTAMP;
- $result = $favorites_model->addFavorites($insert_arr);
- if ($result) {
- //增加收藏数量
- $goods_model->editGoodsById(array('goods_collect' => Db::raw('goods_collect+1')), $fav_id);
- echo json_encode(array('done' => true, 'msg' => lang('favorite_collect_success')));
- die;
- } else {
- echo json_encode(array('done' => false, 'msg' => lang('favorite_collect_fail')));
- die;
- }
- }
- /**
- * 增加店铺收藏
- */
- public function favoritesstore()
- {
- $fav_id = intval(input('param.fid'));
- if ($fav_id <= 0) {
- echo json_encode(array('done' => false, 'msg' => lang('favorite_collect_fail')));
- die;
- }
- $favorites_model = model('favorites');
- //判断是否已经收藏
- $favorites_info = $favorites_model->getOneFavorites(array(
- 'fav_id' => "$fav_id", 'fav_type' => 'store',
- 'member_id' => session('member_id')
- ));
- if (!empty($favorites_info)) {
- echo json_encode(array(
- 'done' => false, 'msg' => lang('favorite_already_favorite_store')
- ));
- die;
- }
- //判断店铺是否为当前会员所有
- if ($fav_id == session('store_id')) {
- echo json_encode(array('done' => false, 'msg' => lang('favorite_no_my_store')));
- die;
- }
- //添加收藏
- $insert_arr = array();
- $insert_arr['member_id'] = session('member_id');
- $insert_arr['member_name'] = session('member_name');
- $insert_arr['fav_id'] = $fav_id;
- $insert_arr['fav_type'] = 'store';
- $insert_arr['fav_time'] = TIMESTAMP;
- $result = $favorites_model->addFavorites($insert_arr);
- if ($result) {
- //增加收藏数量
- $store_model = model('store');
- $store_model->editStore(array('store_collect' => Db::raw('store_collect+1')), array('store_id' => $fav_id));
- echo json_encode(array('done' => true, 'msg' => lang('favorite_collect_success')));
- die;
- } else {
- echo json_encode(array('done' => false, 'msg' => lang('favorite_collect_fail')));
- die;
- }
- }
- /**
- * 商品收藏列表
- *
- * @param
- * @return
- */
- public function fglist()
- {
- $favorites_model = model('favorites');
- $show_type = 'favorites_goods_picshowlist'; //默认为图片横向显示
- $show = input('param.show');
- $store_array = array(
- 'list' => 'favorites_goods_index', 'pic' => 'favorites_goods_picshowlist',
- 'store' => 'favorites_goods_shoplist'
- );
- if (array_key_exists($show, $store_array))
- $show_type = $store_array[$show];
- $favorites_list = $favorites_model->getGoodsFavoritesList(array(array('member_id', '=', session('member_id'))), '*', 20);
- View::assign('show_page', $favorites_model->page_info->render());
- $store_favorites = array(); //店铺收藏信息
- $store_goods_list = array(); //店铺为分组的商品
- if (!empty($favorites_list) && is_array($favorites_list)) {
- $favorites_id = array(); //收藏的商品编号
- foreach ($favorites_list as $key => $favorites) {
- $fav_id = $favorites['fav_id'];
- $favorites_id[] = $favorites['fav_id'];
- $favorites_key[$fav_id] = $key;
- }
- $goods_model = model('goods');
- $field = 'goods.goods_id,goods.goods_name,goods.store_id,goods.goods_image,goods.goods_price,goods.evaluation_count,goods.goods_salenum,goods.goods_collect,store.store_name,store.member_id,store.member_name,store.store_qq,store.store_ww';
- $goods_list = $goods_model->getGoodsStoreList(array(array('goods_id', 'in', $favorites_id)), $field);
- $store_array = array(); //店铺编号
- if (!empty($goods_list) && is_array($goods_list)) {
- foreach ($goods_list as $key => $fav) {
- $fav_id = $fav['goods_id'];
- $fav['goods_member_id'] = $fav['member_id'];
- $key = $favorites_key[$fav_id];
- $favorites_list[$key]['goods'] = $fav;
- $store_id = $fav['store_id'];
- if (!in_array($store_id, $store_array))
- $store_array[] = $store_id;
- $store_goods_list[$store_id][] = $favorites_list[$key];
- }
- }
- if (!empty($store_array) && is_array($store_array)) {
- $store_list = $favorites_model->getStoreFavoritesList(array(
- array('member_id', '=', session('member_id')),
- array('fav_id', 'in', $store_array)
- ));
- if (!empty($store_list) && is_array($store_list)) {
- foreach ($store_list as $key => $val) {
- $store_id = $val['fav_id'];
- $store_favorites[] = $store_id;
- }
- }
- }
- }
- $this->setMemberCurMenu('member_favorites');
- $this->setMemberCurItem('fav_goods');
- View::assign('favorites_list', $favorites_list);
- View::assign('store_favorites', $store_favorites);
- View::assign('store_goods_list', $store_goods_list);
- return View::fetch($this->template_dir . $show_type);
- }
- /**
- * 店铺收藏列表
- *
- * @param
- * @return
- */
- public function fslist()
- {
- $favorites_model = model('favorites');
- $favorites_list = $favorites_model->getStoreFavoritesList(array(array('member_id', '=', session('member_id'))), '*', 10);
- if (!empty($favorites_list) && is_array($favorites_list)) {
- $favorites_id = array(); //收藏的店铺编号
- foreach ($favorites_list as $key => $favorites) {
- $fav_id = $favorites['fav_id'];
- $favorites_id[] = $favorites['fav_id'];
- $favorites_key[$fav_id] = $key;
- }
- $store_model = model('store');
- $store_list = $store_model->getStoreList(array(array('store_id', 'in', $favorites_id)));
- if (!empty($store_list) && is_array($store_list)) {
- foreach ($store_list as $key => $fav) {
- $fav_id = $fav['store_id'];
- $key = $favorites_key[$fav_id];
- $favorites_list[$key]['store'] = $fav;
- }
- }
- }
- $this->setMemberCurMenu('membergavorites');
- $this->setMemberCurItem('fav_store');
- View::assign('favorites_list', $favorites_list);
- View::assign('show_page', $favorites_model->page_info->render());
- return View::fetch($this->template_dir . "favorites_store_index");
- }
- /**
- * 删除收藏
- *
- * @param
- * @return
- */
- public function delfavorites()
- {
- if (!input('param.fav_id') || !input('param.type')) {
- ds_json_encode(10001, lang('favorite_del_fail'));
- }
- if (!preg_match_all('/^[0-9,]+$/', input('param.fav_id'), $matches)) {
- ds_json_encode(10001, lang('param_error'));
- }
- $fav_id = trim(input('param.fav_id'), ',');
- if (!in_array(input('param.type'), array('goods', 'store'))) {
- ds_json_encode(10001, lang('param_error'));
- }
- $type = input('param.type');
- $favorites_model = model('favorites');
- $fav_arr = explode(',', $fav_id);
- if (!empty($fav_arr) && is_array($fav_arr)) {
- $favorites_list = $favorites_model->getFavoritesList(array(array('fav_id', 'in', $fav_arr), array('fav_type', '=', "$type"), array('member_id', '=', session('member_id'))));
- if (!empty($favorites_list) && is_array($favorites_list)) {
- $fav_arr = array();
- foreach ($favorites_list as $k => $v) {
- $fav_arr[] = $v['fav_id'];
- }
- $result = $favorites_model->delFavorites(array(
- array('fav_id', 'in', $fav_arr), array('fav_type', '=', "$type"),
- array('member_id', '=', session('member_id'))
- ));
- if (!empty($fav_arr) && $result) {
- //更新商品收藏数量
- if ($type == 'store') {
- $store_model = model('store');
- $store_model->editStore(array('store_collect' => Db::raw('store_collect-1'),), array(array('store_id', '=', $fav_id), array('store_collect', '>', 0),));
- } else {
- $goods_model = model('goods');
- $goods_model->editGoodsById(array('goods_collect' => Db::raw('goods_collect-1')), $fav_arr);
- }
- ds_json_encode(10000, lang('favorite_del_success'));
- }
- } else {
- ds_json_encode(10001, lang('favorite_del_fail'));
- }
- } else {
- ds_json_encode(10001, lang('favorite_del_fail'));
- }
- }
- /**
- * 店铺新上架的商品列表
- *
- * @param
- * @return
- */
- public function store_goods()
- {
- $store_id = intval(input('param.store_id'));
- if ($store_id > 0) {
- $condition = array();
- $add_time_from = TIMESTAMP - 60 * 60 * 24 * 30; //30天
- $condition[] = array('store_id', '=', $store_id);
- $condition[] = array('goods_addtime', 'between', $add_time_from . ',' . TIMESTAMP);
- $goods_model = model('goods');
- $goods_list = $goods_model->getGoodsOnlineList($condition, 'goods_id,goods_name,store_id,goods_image,goods_price', 0, 'goods_id desc', 50);
- View::assign('goods_list', $goods_list);
- echo View::fetch($this->template_dir . 'favorites_store_goods');
- }
- }
- /**
- * 用户中心右边,小导航
- *
- * @param string $menu_type 导航类型
- * @param string $menu_key 当前导航的menu_key
- * @return
- */
- protected function getMemberItemList()
- {
- $menu_array = array(
- array(
- 'name' => 'fav_goods', 'text' => lang('ds_member_path_collect_list'),
- 'url' => (string)url('Memberfavorites/fglist')
- ), array(
- 'name' => 'fav_store', 'text' => lang('ds_member_path_collect_store'),
- 'url' => (string)url('Memberfavorites/fslist')
- )
- );
- if (config('ds_config.flea_isuse')) {
- $menu_array[] = array(
- 'name' => 'fav_flea', 'text' => lang('collection_idle'), 'url' => (string)url('Memberflea/favorites')
- );
- }
- return $menu_array;
- }
- }
|