123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <?php
- namespace app\data\controller\api;
- use app\data\model\DataMerchants;
- 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\model\ShopOrder;
- use app\data\model\ShopOrderItem;
- use app\data\model\ShopOrderPay;
- 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;
- use hg\apidoc\annotation\Header;
- use app\data\model\SystemUser;
- /**
- * 商品数据接口
- * Class Goods
- * @package app\data\controller\api
- */
- class Goods extends Auth
- {
- /**
- * @Title ("用户信息")
- * @Method ("get")
- * @Param ("admin_id",desc="商家端id")
- * @Returned("merchant.head_img",desc="商家头像")
- * @Returned("merchant.name",desc="商家名称")
- * @Returned("merchant.full_address",desc="详细地址")
- * @Returned("merchant.contact_name",desc="联系人")
- * @Returned("merchant.contact_phone",desc="联系电话")
- * @Returned("merchant.intro",desc="商家简介")
- * @Returned("merchant.imgs_videos",desc="图片及视频")
- * @Returned("merchant.business_img",desc="营业执照")
- * @Returned("merchant.longitude",desc="经度")
- * @Returned("merchant.latitude",desc="纬度")
- */
- public function user_info(){
- $admin_id = $this->_vali(['admin_id.require'=>'商家id不能空']);
- $merchant=DataMerchants::getByAdmin($admin_id['admin_id']);
- $this->success('用户信息',$merchant);
- }
- /**
- * @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 ("商品数据展示")
- * @Header("api-name",type="string",require=1,default="",desc="访问类型")
- * @Header("api-token",type="string",require=1,default="",desc="token")
- * @Param ("cateids",desc="商品分类id")
- * @Param ("name",desc="搜索名称模糊查询")
- * @Param ("sales_order",desc="销量排序 asc desc")
- * @Param ("price_order",desc="价格排序 asc desc")
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getGoods()
- {
- $sales_order = input('sales_order','desc');
- $price_order = input('price_order','desc');
- // 更新访问统计
- $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,'examine'=>1])
- ->when($sales_order,function ($quer) use ($sales_order){
- $quer->order('stock_sales '.$sales_order);
- })
- ->when($price_order,function ($quer) use ($price_order){
- $quer->order('price_market '.$price_order);
- })
- //->order('sort desc,id desc')
- ->page(true, false, false, 10);
- if (count($result['list']) > 0) GoodsService::bindData($result['list']);
- $this->success('获取商品数据', $result);
- }
- /**
- * @Title ("商品详情")
- * @Param ("goods_id",desc="商品id")
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function Goods_info(){
- $id = input('goods_id');
- $query = ShopGoods::mQuery()->where('id',$id);
- $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']);
- $result['list'][0]['admin_name']=SystemUser::mk()->where('id',$result['list'][0]['admin_id'])->value('username');
- $result['list'][0]['is_collection']=0;
- if(ShopGoodsCollection::mk()->where('goods_id',$result['list'][0]['id'])->where('uuid',$this->uuid)->find()){
- $result['list'][0]['is_collection']=1;
- }
- $this->success('获取商品数据详情', $result['list'][0]);
- }
- /**
- * 获取配送区域
- */
- public function getRegion()
- {
- $this->success('获取区域成功', ExpressService::region(3, 1));
- }
- /**
- * @Title ("购物车数量")
- * @Method ("get")
- * @return void
- * @throws \think\db\exception\DbException
- */
- public function cart_number(){
- $user = $this->getUser();
- $count = ShopGoodsCart::mk()->where('user_id',$user['id'])->count();
- $this->success('购物车数量!',$count);
- }
- /**
- * @Title("购物车添加")
- * @Param ("admin_id",desc="商家id")
- * @Param ("goods_id",desc="商品id")
- * @Param ("item_id",desc="规格id")
- * @Param ("num",desc="数量")
- * @return void
- */
- public function cart_add()
- {
- $user = $this->getUser();
- $data = $this->_vali([
- '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')
- ];
- $is_have = ShopGoodsCart::mk()->where(['admin_id'=>$data['admin_id'],'goods_id'=>$data['goods_id'],'item_id'=>$data['item_id'],'user_id'=>$user['id']])->find();
- if($is_have){
- $add_data['num']=$is_have['num']+$data['num'];
- ShopGoodsCart::mk()->where('id',$is_have['id'])->save($add_data);
- }
-
- else {
- 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();
- $query = ShopGoodsCart::mQuery()->alias('cart');
- $cart_list = $query ->join('system_user admin','admin.id=cart.admin_id')
- ->where('cart.user_id',$user['id'])
- ->group('cart.admin_id')
- ->field('cart.admin_id,admin.nickname')
- ->page(true, false, false, 10);
- foreach ($cart_list['list'] as $k=>$v){
- $cart_list['list'][$k]['goods_item']= ShopGoodsCart::mk()->alias('cart')
- ->join('shop_goods goods','cart.goods_id=goods.id')
- ->join('shop_goods_item item','cart.item_id=item.id')
- ->join('system_user admin','admin.id=cart.admin_id')
- ->where('cart.user_id',$user['id'])
- ->where('cart.admin_id',$cart_list['list'][$k]['admin_id'])
- ->field('cart.*,goods.cover,goods.name,item.price_selling,item.goods_spec')
- ->select();
- }
- $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 ("详情取消收藏")
- * @Param ("goods_id",desc="商品id")
- */
- public function cancel_collection(){
- $user = $this->getUser();
- $coll_ids = input('goods_id');
- ShopGoodsCollection::mk()->where('goods_id',$coll_ids)->where('uuid',$user['id'])->delete();
- $this->success('商品收藏已取消');
- }
- /**
- * @Title ("我的收藏列表")
- */
- public function collection_list(){
- $user = $this->getUser();
- $list = ShopGoodsCollection::mk()->alias('c')->join('shop_goods g','c.goods_id=g.id')->where('c.uuid',$user['id'])->order('c.id','desc')->field('c.*,g.name,g.cover,g.price_selling')->paginate();
- $this->success('我的收藏列表',$list);
- }
- }
|