| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <?php
- namespace app\api\controller\service;
- use app\api\model\service\JoinShop;
- use app\common\controller\Api;
- use think\Db;
- use think\Exception;
- use think\Loader;
- /**
- * 首页接口
- */
- class Shop extends Api
- {
- protected $noNeedLogin = ['searchShop','shopDetail','getCodeShop','getSampleShop','searchShopGoods'];
- protected $noNeedRight = ['*'];
- /**
- * 申请成为商家
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function apply()
- {
- $uid = $this->auth->id;
- $userInfo = model('app\api\model\service\UserInfo')->where(['user_id'=>$uid])->field('id,is_shop')->find();
- $info = model('app\api\model\service\ApplyShop')->where(['user_id'=>$uid])->find();
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
- $types = input('types','');
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $applyShop = new \app\api\model\service\ApplyShop();
- $post['user_id'] = $uid;
- $post['updatetime'] = time();
- if(in_array($types,['add','edit']))
- {
- $validate = Loader::validate('service.ApplyShop');
- if(!$validate->scene($types)->check($post)){
- $this->error($validate->getError());
- }
- }
- if($types == 'add')
- {
- unset($post['types']);
- $applyShop->data($post)->save();
- $this->success('申请已提交,等待审核');
- }elseif($types == 'edit') {
- unset($post['types']);
- if($userInfo['is_shop'] == 1)
- {
- $post['applytype'] = 1;
- }
- $post['state'] = 0;
- $applyShop->allowField(true)->save($post,['id'=>$info['id']]);
- $this->success('申请已提交,等待审核');
- }
- $this->success('信息返回成功',$info);
- }
- /**
- * 查询商家列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function searchShop()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $post = input('post.','','trim,strip_tags');
- !$post['city'] && $this->error('城市信息缺失');
- (!$post['lng'] || !$post['lat']) && $this->error('定位信息异常');
- $list = \app\api\model\service\Shop::searchShop($post);
- $this->success('信息列表返回成功',$list);
- }
- public function searchShopGoods()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $shopId = input('shop_id','');
- $shopGoodsIds = \app\api\model\service\Shop::where('id',$shopId)->value('goods_ids');
- $list = \app\api\model\service\Goods::getNewShopGoods($shopGoodsIds,1);
- $this->success('信息返回成功',$list);
- }
- /**
- * 简单商户列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function shopList()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $skillCity = \app\api\model\service\Skill::where('user_id',$uid)->value('city');
- $page = input('page/d',1);
- $limit = 10;
- $list = \app\api\model\service\Shop::where(['state'=>1,'city'=>$skillCity])->field('id,code,logo_image,intro,user_id,name,abbr,leader_name,leader_mobile')->order('weigh desc')->page($page)->limit($limit)->select();
- foreach ($list as &$value)
- {
- $value['followNum'] = \app\api\model\service\Follow::getCount(['follow_id'=>$value['id'],'state'=>1]);
- $value['commentScore'] = \app\api\model\service\Comment::getCommentScore(['shop_id'=>$value['id'],'state'=>1]);
- }
- $this->success('信息返回成功',$list);
- }
- public function getSampleShop()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $id = input('id/d','');
- $shop = \app\api\model\service\Shop::where(['id'=>$id])->field('id,code,logo_image,intro,user_id,name,abbr,license_image')->find();
- $shop['followNum'] = \app\api\model\service\Follow::getCount(['follow_id'=>$shop['id'],'state'=>1]);
- $shop['commentScore'] = \app\api\model\service\Comment::getCommentScore(['shop_id'=>$shop['id'],'state'=>1]);
- $this->success('信息返回成功',$shop);
- }
- public function shopDetail()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $id = input('id/d','');
- $page = input('page/d',1);
- $info = \app\api\model\service\Shop::getShopDetail(['id'=>$id,'page'=>$page]);
- $uid = $this->auth->isLogin()?$this->auth->id:'';
- !$info && $this->error('商家信息异常');
- $info['followNum'] = \app\api\model\service\Follow::getCount(['follow_id'=>$info['id'],'state'=>1]);
- $info['commentScore'] = \app\api\model\service\Comment::getCommentScore(['shop_id'=>$info['id'],'state'=>1]);
- $info['followState'] = $uid?\app\api\model\service\Follow::getState(['user_id'=>$uid,'follow_id'=>$id]):0;
- $this->success('信息返回成功',$info);
- }
- /**
- * 商户处理服务人员申请
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function joinShopList()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $startTime = strtotime(date("Y-m-d",time()));
- $shop = \app\api\model\service\Shop::where(['user_id'=>$uid])->field('id,accept_nums,service_nums,already_service_nums,percent')->find();
- $shop['already_accept_nums'] = \app\api\model\service\Order::where(['shop_id'=>$shop['id'],'status'=>['>',1],'starttime'=>['>=',$startTime]])->count();
- $type = input('type','');
- if($type == 'check')
- {
- $post = input('post.','');
- ($post['state'] == 1 && $post['percent']>$shop['percent']) && $this->error('订单分成请勿超出商户分成');
- ($post['state'] == 1 && $shop['already_service_nums']>=$shop['service_nums']) && $this->error('商户服务者数量已达到上限');
- $re = \app\api\model\service\JoinShop::check($post);
- !$re && $this->error('审核失败');
- $this->success('已审核');
- }
- $state = input('state/d',0);
- $page = input('page/d','');
- $list = \app\api\model\service\JoinShop::getApplyShop(['shop_id'=>$shop['id'],'state'=>$state,'page'=>$page]);
- $this->success('信息返回成功',$list);
- }
- public function allocationOrder()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shop_id = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $post = input('post.','');
- $post['shop_id'] = $shop_id;
- try{
- \app\api\model\service\Order::allocationOrder($post);
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('订单已分配');
- }
- public function getShopSkill()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shop_id = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $id = input('id/d','');
- $orderAddress = \app\api\model\service\OrderAddress::where(['order_id'=>$id])->field('lng,lat')->find();
- $goodsId = \app\api\model\service\Order::where(['id'=>$id])->value('goods_id');
- $page = input('page/d','');
- $where['shop_id'] = $shop_id;
- $where['state'] = 1;
- $where[] =['exp',Db::raw("FIND_IN_SET('$goodsId',goods_ids)")];
- $list = \app\api\model\service\Skill::getShopSkill($where,$page);
- foreach ($list as $key=>$value)
- {
- $list[$key]['distance'] = \addons\service\library\Common::distance($value['lng'],$value['lat'],$orderAddress['lng'],$orderAddress['lat']);
- }
- $this->success('信息返回成功',$list);
- }
- public function getShopSkillInfo()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $post = input('post.','','trim,strip_tags');
- $uid = $this->auth->id;
- $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $skill = \app\api\model\service\Skill::where(['id'=>$post['id'],'shop_id'=>$shopId])->field('id,ensure_price,is_rest,image,percent,name,sex,city,user_id')->find();
- $post['shop_id'] = $shopId;
- $skill['orderList'] = \app\api\model\service\Order::getShopSkillOrder($post);
- if(isset($post['page']))
- {
- unset($post['page']);
- }
- $skill['skillDetail'] = \app\api\model\service\Skill::skillShopDetail(['shop_id'=>$shopId,'id'=>$skill['id'],'user_id'=>$skill['user_id']]);
- $skill['starttime'] = $post['starttime'] ?? '';
- $skill['endtime'] = $post['endtime'] ?? '';
- $this->success('信息返回成功',$skill);
- }
- /**
- * 商户项目列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function shopGoods()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shop = \app\api\model\service\Shop::where(['user_id'=>$uid])->field('id,to_shop,name,intro,logo_image')->find();
- $page = input('page/d',1);
- $shop_state = input('shop_state/d',0);
- $list = \app\api\model\service\Goods::where(['shop_id'=>$shop['id'],'shop_state'=>$shop_state])->field('id,name,cost_seconds,to_shop,note,image,tag_name,price,shop_state,status')->page($page)->limit(10)->select();
- $data['list'] = $list;
- $data['shop'] = $shop;
- $this->success('信息返回成功',$data);
- }
- /**
- * 商户个人中心
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function shopIndex()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $data['userInfo'] = \app\api\model\service\UserInfo::where(['user_id'=>$uid])->field('shop_user_money,money')->find();
- $shopInfo = \app\api\model\service\Shop::where(['user_id'=>$uid])->field('id,ensure_price,category_ids,to_shop,goods_ids,accept_nums,already_service_nums,service_nums,name,abbr,code,logo_image')->find();
- $shopInfo['already_accept_nums'] = \app\api\model\service\Order::where(['shop_id'=>$shopInfo['id'],'status'=>['>',1],'starttime'=>['>=',strtotime("Y-m-d",time())]])->count();
- $data['skillCount'] = \app\api\model\service\Skill::getCount(['shop_id'=>$shopInfo['id']]);
- $shopInfo['goodsList'] = explode(',',$shopInfo['goods_ids']);
- $data['goodsCount'] = count(\app\api\model\service\Goods::getShopPlatformGoods($shopInfo['goods_ids'],$uid));
- $data['shopInfo'] = $shopInfo;
- $data['shopGoodsCount'] = \app\api\model\service\Goods::getCount(['shop_id'=>$shopInfo['id'],'shop_state'=>1]);
- $data['applyCount'] = \app\api\model\service\JoinShop::getCount(['shop_id'=>$shopInfo['id']]);
- $this->success('信息返回成功',$data);
- }
- /**
- * 商户端首页
- * @return void
- * @throws \think\Exception
- */
- public function shopHome()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $post = input('post.','','trim,strip_tags');
- $post['shop_id'] = $shopId;
- //筛选时间,订单数量,订单金额
- $starttime = strtotime(date("Y-m-d",time()));
- $data['dayNum'] = \app\api\model\service\Rebate::getNum(['user_id'=>$uid,'type'=>1,'createtime'=>['>',$starttime]]);
- $data['poolNum'] = \app\api\model\service\Order::getOrderCount(['is_pool'=>1,'status'=>1,'is_service'=>['in',[0,-1]]]);
- $data['dayNewCount'] = \app\api\model\service\Order::getOrderCount(['shop_id'=>$shopId,'createtime'=>['>',$starttime],'is_service'=>['in',[0,-1]]]);
- $data['dayFinishCount'] = \app\api\model\service\Order::getOrderCount(['shop_id'=>$shopId,'status'=>['>',5],'finishtime'=>['>',$starttime],'is_service'=>['in',[0,-1]]]);
- $data['dayDispatchCount'] = \app\api\model\service\Order::getOrderCount(['shop_id'=>$shopId,'status'=>1,'to_shop'=>'door','is_service'=>['in',[0,-1]],'skill_id'=>['null','']]);
- $data['dayServiceList'] = \app\api\model\service\Order::getDayServiceList(['shop_id'=>$shopId,'status'=>['in','1,2,3,4,5'],'is_service'=>['in',[0,-1]]]);
- $data['form'] = \app\api\model\service\Order::getForm($post);
- $this->success('信息返回成功',$data);
- }
- /**
- * 商户下服务者列表
- * @return void
- */
- public function shopSkillList()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $page = input('page/d',1);
- $list = \app\api\model\service\Skill::getShopSkillList(['shop_id'=>$shopId],$page);
- $this->success('信息返回成功',$list);
- }
- public function updateShopInfo()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shop = \app\api\model\service\Shop::where(['user_id'=>$uid])->field('id,withdrawtype,day')->find();
- $type = input('type','','trim,strip_tags');
- if($type == 'update')
- {
- $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
- model('app\api\model\service\Shop')->allowField('withdrawtype,day')->save($post,['user_id'=>$uid]);
- $this->success('信息已更新');
- }
- $this->success('信息返回成功',$shop);
- }
- public function shopCoupon()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $post = input('post.','','trim,strip_tags');
- $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $post['shop_id'] = $shopId;
- $list = \app\api\model\service\Coupon::getCouponList($post);
- $this->success('信息返回成功',$list);
- }
- public function getCodeShop()
- {
- $code = input('code','');
- $shop = \app\api\model\service\Shop::where(['code'=>$code,'state'=>1])->field('id,name,abbr,intro,logo_image')->find();
- !$shop && $this->error('未获取到相关商户信息');
- $this->success('信息返回成功',$shop);
- }
- public function editCoupon()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $types = input('types','');
- if($types == 'add')
- {
- $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
- $goodsList = \app\api\model\service\Goods::where(['shop_id'=>$shopId])->column('id');
- ($post['type'] == 3 && !in_array($post['goods_id'],$goodsList)) && $this->error('商品信息不符');
- $post['shop_id'] = $shopId;
- $post['state'] = 0;
- $coupon = new \app\api\model\service\Coupon($post);
- $coupon->allowField(true)->save();
- $this->success('信息已提交,等待管理员审核');
- }elseif ($types == 'edit')
- {
- $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
- $coupon = \app\api\model\service\Coupon::where(['id'=>$post['id'],'shop_id'=>$shopId])->find();
- !$coupon && $this->error('优惠券信息异常');
- $coupon = new \app\api\model\service\Coupon();
- $post['is_check'] = 0;
- $coupon->allowField(true)->save($post,['id'=>$post['id']]);
- $this->success('已提交,等待管理员审核');
- }elseif ($types == 'info')
- {
- $id = input('id/d','');
- $coupon = \app\api\model\service\Coupon::where(['id'=>$id,'shop_id'=>$shopId])->find();
- !$coupon && $this->error('优惠券信息异常');
- $this->success('信息返回成功',$coupon);
- }
- $this->error('接口信息异常');
- }
- }
|