123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace app\data\controller\api;
- use app\data\model\ShopGoods;
- use app\data\model\ShopGoodsCart;
- use app\data\model\ShopGoodsCate;
- use app\data\model\ShopGoodsCollection;
- use app\data\model\ShopGoodsMark;
- use app\data\service\ExpressService;
- use app\data\service\GoodsService;
- use think\admin\Controller;
- use hg\apidoc\annotation\Title;
- use hg\apidoc\annotation\Method;
- use hg\apidoc\annotation\Param;
- use hg\apidoc\annotation\Returned;
- /**
- * 商品数据接口
- * Class Goods
- * @package app\data\controller\api
- */
- class Goods extends Auth
- {
- /**
- * @Title ("获取分类数据")
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getCate()
- {
- $this->success('获取分类成功', ShopGoodsCate::treeData());
- }
- /**
- * 获取标签数据
- */
- public function getMark()
- {
- $this->success('获取标签成功', ShopGoodsMark::items());
- }
- /**
- * @Title ("name",desc="商品数据展示")
- * @Param ("cateids",desc = ”商品分类id")
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getGoods()
- {
- // 更新访问统计
- $map = $this->_vali(['code.default' => '']);
- if ($map['code']) ShopGoods::mk()->where($map)->inc('num_read')->update([]);
- // 商品数据处理
- $query = ShopGoods::mQuery()->like('name,marks,cateids,payment')->equal('code,vip_entry');
- $result = $query->where(['deleted' => 0, 'status' => 1])->order('sort desc,id desc')->page(true, false, false, 10);
- if (count($result['list']) > 0) GoodsService::bindData($result['list']);
- $this->success('获取商品数据', $result);
- }
- /**
- * 获取配送区域
- */
- public function getRegion()
- {
- $this->success('获取区域成功', ExpressService::region(3, 1));
- }
- /**
- * @Title("购物车添加")
- * @return void
- */
- public function cart_add()
- {
- $user = $this->getUser();
- $data = $this->_vali([
- 'admin_id.default'=>'',
- 'item_id.default' => '',
- 'num.default' => '',
- 'goods_id.default' =>'',
- 'admin_id.require' =>'店铺不能为空',
- 'item_id.require' => '选择商品规格不能为空!',
- 'num.require' => '数量不能为空!',
- 'goods_id.require' =>'商品不能为空'
- ]);
- $add_data=[
- 'admin_id'=>$data['admin_id'],
- 'goods_id'=>$data['goods_id'],
- 'item_id'=>$data['item_id'],
- 'user_id'=>$user['id'],
- 'num'=>$data['num'],
- 'create_time'=>date('Y-m-d H:i:s')
- ];
- ShopGoodsCart::mk()->insert($add_data);
- $this->success('成功加入购物车!');
- }
- /**
- * @Title ("购物车列表")
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- *
- */
- public function goods_cart_list(){
- $user = $this->getUser();
- $cart_list = ShopGoodsCart::mk()->alias('cart')
- ->join('shop_goods_item item','cart.item_id=item.id')
- ->join('shop_goods goods','item.goods_code=goods.code')
- ->join('system_user admin','admin.id=item.admin_id')
- ->where('cart.user_id',$user['id'])
- ->field('cart.*,item.goods_spec,goods.cover')
- ->paginate();
- $this->success('我的购物车列表',$cart_list);
- }
- /**
- * @Title ("修改购物车")
- * @Param ("cart_id",desc="购物车id")
- * @Param ("num",desc="数量")
- */
- public function goods_cart_save(){
- $user = $this->getUser();
- $cart_id= input('cart_id');
- $num = input('num');
- ShopGoodsCart::mk()->where(array('id'=>$cart_id,'user_id'=>$user['id']))->save(['num'=>$num]);
- $this->success('购物车修改完成');
- }
- /**
- * @Title ("删除购物车")
- * @Param ("cart_ids",desc="购物车id")
- */
- public function goods_cart_del(){
- $user = $this->getUser();
- $cart_id= input('cart_ids');
- ShopGoodsCart::mk()->whereIn('id',$cart_id)->where('user_id',$user['id'])->delete();
- $this->success('购物车已删除');
- }
- /**
- * @Title ("添加我的收藏")
- * @Param ("goods_id",desc="商品id")
- */
- public function collection(){
- $user =$this->getUser();
- $goods_id = input('goods_id');
- ShopGoodsCollection::mk()->insertGetId(['uuid'=>$user['id'],'goods_id'=>$goods_id,'create_at'=>date('Y-m-d H:i:s')]);
- $this->success('商品收藏成功');
- }
- /**
- * @Title ("删除我的收藏")
- * @Param ("coll_ids",desc="收藏id")
- */
- public function del_collection(){
- $user = $this->getUser();
- $coll_ids = input('coll_ids');
- ShopGoodsCollection::mk()->whereIn('id',$coll_ids)->where('uuid',$user['id'])->delete();
- $this->success('商品收藏已取消');
- }
- /**
- * @Title ("我的收藏列表")
- */
- public function collection_list(){
- $user = $this->getUser();
- $list = ShopGoodsCollection::mk()->where('uuid',$user['id'])->order('id','desc')->paginate();
- $this->success('我的收藏列表',$list);
- }
- }
|