123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <?php
- /**
- * Index.php
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: http://www.niushop.com.cn
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
- * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
- * =========================================================
- * @author : niuteam
- * @date : 2015.1.17
- * @version : v1.0.0.0
- */
- namespace app\api\controller;
- use app\model\shop\Shop as ShopModel;
- use app\model\web\WebSite;
- use think\facade\Db;
- class Shop extends BaseApi
- {
-
- /**
- * 基础信息
- */
- public function info()
- {
- $site_id = isset($this->params['site_id']) ? $this->params['site_id'] : 0;
- if (empty($site_id)) {
- return $this->response($this->error('', 'REQUEST_SITE_ID'));
- }
- $shop = new ShopModel();
- $field = 'site_id,expire_time,site_name,website_id,is_own,level_name,category_name,shop_status,start_time,end_time,logo,avatar,banner,
- seo_description,qq,ww,telephone,shop_desccredit,shop_servicecredit,shop_deliverycredit,workingtime,shop_baozh,shop_baozhopen,shop_baozhrmb,
- shop_qtian,shop_zhping,shop_erxiaoshi,shop_tuihuo,shop_shiyong,shop_shiti,shop_xiaoxie,shop_free_time,shop_sales,shop_adv,work_week,address,full_address,longitude,latitude,sub_num';
- $info = $shop->getShopInfo([ [ 'site_id', '=', $site_id ] ], $field);
- $info['data']['start_time'] = time_to_date($info['data']['start_time'],'H:i');
- $info['data']['end_time'] = time_to_date($info['data']['end_time'],'H:i');
- $count_evaluate = Db::table('v4goods_evaluate')->where(['site_id'=>$site_id])->count();
- $all_evaluate = Db::table('v4goods_evaluate')->where(['site_id'=>$site_id])->sum('scores');
- $info['data']['evaluate'] = bcdiv($all_evaluate,$count_evaluate,1);
- return $this->response($info);
- }
-
- public function page()
- {
- $page = isset($this->params['page']) ? $this->params['page'] : 1;
- $page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGE_LIST_ROWS;
- $keyword = isset($this->params['keyword']) ? $this->params['keyword'] : '';//关键词
- $order = isset($this->params['order']) ? $this->params['order'] : "site_id";//排序(综合、销量、信用)
- $sort = isset($this->params['sort']) ? $this->params['sort'] : "desc";//升序、降序
- $web_city = isset($this->params['web_city']) ? $this->params['web_city'] : "";
- $lat = isset($this->params['lat']) ? $this->params['lat'] : ""; // 纬度
- $lng = isset($this->params['lng']) ? $this->params['lng'] : ""; // 经度
- $is_recommend = isset($this->params['is_recommend']) ? $this->params['is_recommend'] : 0; // 是否推荐
- $shop = new ShopModel();
- $condition = [
- [ 'shop_status', '=', 1 ],
- [ 'cert_id', '<>', 0 ]
- ];
- $city_name = input('city_name/s','');
- if (!empty($city_name)){
- $condition[] = ['city_name','like','%'.$city_name.'%'];
- }
-
- if (!empty($keyword)) {
- $token = $this->checkToken();
- if ($this->member_id){
- $in_data['uid'] = $this->member_id;
- $in_data['keyword'] = $keyword;
- $is_history = Db::table('v4search_history')->where($in_data)->find();
- if ($is_history){
- Db::table('v4search_history')->where($in_data)->delete();
- }
- $in_data['create_time'] = date("Y-m-d H:i:s",time());
- Db::table('v4search_history')->insert($in_data);
- }
- $condition[] = [ 'site_name', 'like', '%' . $keyword . '%' ];
- }
- if (!empty($is_recommend)) {
- $condition[] = [ 'is_recommend', '=', $is_recommend ];
- }
-
- // 非法参数进行过滤
- if ($sort != "desc" && $sort != "asc") {
- $sort = "";
- }
-
- // 非法参数进行过滤
- if ($order != '') {
- if ($order != "shop_sales" && $order != "shop_desccredit") {
- $order = 'site_id';
- }
- $order_by = $order . ' ' . $sort;
- } else {
- $order_by = 'is_recommend desc,sort desc,site_id desc';
- }
-
- // 查询是否存在城市分站
- if (addon_is_exit('city') && !empty($web_city)) {
- $website_model = new WebSite();
- $website_info = $website_model->getWebSite([ [ 'site_area_id', '=', $web_city ] ], 'site_id');
- if (!empty($website_info['data'])) {
- $order_by = "INSTR('{$website_info['data']['site_id']}', website_id) desc," . $order_by;
- }
- }
- $list = $shop->getShopPageList($condition, $page, $page_size, $order_by, 'site_id,site_name,category_name,group_name,logo,avatar,banner,seo_description,shop_desccredit,shop_servicecredit,shop_deliverycredit,shop_sales,sub_num,is_own,longitude,latitude,telephone,address,full_address');
-
- if (!empty($list['data']['list'])) {
- foreach ($list['data']['list'] as $k => $item) {
- if ($item['longitude'] && $item['latitude'] && $lng && $lat) {
- $list['data']['list'][ $k ]['distance'] = round(getDistance((float) $item['longitude'], (float) $item['latitude'], (float) $lng, (float) $lat));
- } else {
- $list['data']['list'][ $k ]['distance'] = 0;
- }
- $count_evaluate = Db::table('v4goods_evaluate')->where(['site_id'=>$list['data']['list'][ $k ]['site_id']])->count();
- $all_evaluate = Db::table('v4goods_evaluate')->where(['site_id'=>$list['data']['list'][ $k ]['site_id']])->sum('scores');
- $list['data']['list'][ $k ]['evaluate'] = bcdiv($all_evaluate,$count_evaluate,1);
- $list['data']['list'][$k]['avatar'] = 'https://'.$_SERVER['HTTP_HOST'].'/'.$item['avatar'];
- }
- }
- return $this->response($list);
- }
-
- /**
- * 是否显示店铺相关功能,用于审核小程序
- */
- public function isShow()
- {
- $res = 1;// 0 隐藏,1 显示
- return $this->response($this->success($res));
- }
- /**
- * 活动列表
- * */
- public function activityList(){
- $page = isset($this->params['page']) ? $this->params['page'] : 1;
- $page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGE_LIST_ROWS;
- $order = isset($this->params['order']) ? $this->params['order'] : "id";//排序(综合、销量、信用)
- $sort = isset($this->params['sort']) ? $this->params['sort'] : "desc";//升序、降序
- $list = Db::table('v4shop_activity')->field('id,img,title,address,time')->page($page,$page_size)->order($order.' '.$sort)->select();
- return $this->response($this->success($list));
- }
- /**
- * 活动详情
- * */
- public function activityDetails(){
- $id = input('id/d',0);
- $info = Db::table('v4shop_activity')->field('id,img,title,address,time,content')->where(['id'=>$id])->find();
- return $this->response($this->success($info));
- }
- /**
- * 店铺入驻
- * */
- public function joinShop(){
- $token = $this->checkToken();
- if ($token['code'] < 0) return $this->response($token);
- $uid = $this->member_id;
- $data['shop_name'] = input('shop_name','');
- $data['telephone'] = input('telephone','');
- $data['address'] = input('address','');
- $data['do_business_date'] = input('do_business_date','');
- $data['business_license'] = input('business_license','');
- $data['id_front'] = input('id_front','');
- $data['id_behind'] = input('id_behind','');
- $username = input('username','');
- $is_join_shop = Db::table('v4shop_apply')->where(['member_id'=>$uid])->find();
- if ($is_join_shop){
- return $this->response($this->error('','请勿重复申请'));
- }
- if (empty($data['shop_name'])){
- return $this->response($this->error('店铺名称不能为空'));
- }
- if (empty($data['telephone'])){
- return $this->response($this->error('店铺手机号不能为空'));
- }
- if (empty($username)){
- return $this->response($this->error('店铺账号不能为空'));
- }
- if (empty($data['address'])){
- return $this->response($this->error('地址不能为空'));
- }
- if (empty($data['do_business_date'])){
- return $this->response($this->error('营业时间不能为空'));
- }
- if (empty($data['business_license'])){
- return $this->response($this->error('营业执照不能为空'));
- }
- if (empty($data['id_front'])){
- return $this->response($this->error('身份证正面照不能为空'));
- }
- if (empty($data['id_behind'])){
- return $this->response($this->error('身份证反面照不能为空'));
- }
- $member_info = Db::table('v4member')->where(['member_id'=>$uid])->find();
- $data['member_id'] = $uid;
- $data['uid'] = $uid;
- $data['member_name'] = $member_info['nickname'];
- $data['create_time'] = time();
- $result = Db::table('v4shop_apply')->insert($data);
- Db::table('v4member')->where('member_id',$uid)->update(['username'=>$username]);
- return $this->response($this->success($result));
- }
- /**
- * 自动发送红包
- * */
- public function courseWatchMoney(){
- $standard_watch = Db::table('v4config_md')->where(['type'=>'prize','name'=>'shop_watch'])->value('value');
- $money = Db::table('v4config_md')->where(['type'=>'prize','name'=>'shop_watch_money'])->value('value');
- if ($standard_watch > 0 && $money > 0){
- $list = Db::table('v4curriculum')->where([['see_num','>=',$standard_watch],['uid','<>','null'],['status','=',1],['is_reward','=',0]])->select()->toArray();
- //echo "<pre>";print_r($list);exit;
- foreach ($list as $k=>$v){
- $user_info = Db::table('v4member')->field('username,mobile,email')->where(['member_id'=>$v['uid']])->find();
- Db::table('v4curriculum')->where(['id'=>$v['id']])->update(['is_reward'=>1]);
- Db::table('v4member')->where(['member_id'=>$v['uid']])->inc('balance',$money)->update();
- $log_data['member_id'] = $v['uid'];
- $log_data['account_type'] = 'balance';
- $log_data['account_data'] = $money;
- $log_data['from_type'] = 'curriculum';
- $log_data['type_name'] = '课程浏览数达标奖励';
- $log_data['remark'] = '课程浏览数达标奖励送'.$money.'余额';
- $log_data['create_time'] = time();
- $log_data['username'] = $user_info['username'];
- $log_data['mobile'] = $user_info['mobile'];
- $log_data['email'] = $user_info['email'];
- Db::table('v4member_account')->insert($log_data);
- }
- }
- }
- /**
- * 商家列表
- * */
- public function shopList(){
- $page = isset($this->params['page']) ? $this->params['page'] : 1;
- $page_size = isset($this->params['page_size']) ? $this->params['page_size'] : 5;
- $city_name = input('city_name/s','');
- $lng = input('longitude','');//经度
- $lat = input('latitude','');//纬度
- $min_distance = input('min_distance/d',0);
- $max_distance = input('max_distance/d',0);
- $where = [['shop_status','=',1],['city_name','like','%'.$city_name.'%']];
- $EARTH=6378.137; //地球半径
- $PI=3.1415926535898; //PI值
- if (!empty($min_distance) && !empty($max_distance)){
- $list = Db::table('v4shop')
- ->field("site_id,site_name,avatar,address,(2 * $EARTH* ASIN(SQRT(POW(SIN($PI*(".$lat."-latitude)/360),2)+COS($PI*".$lat."/180)* COS(latitude * $PI/180)*POW(SIN($PI*(".$lng."-longitude)/360),2)))) as juli")
- ->where($where)
- ->having('juli >='.$min_distance)
- ->having('juli <='.$max_distance)
- ->order('juli asc')
- ->page($page,$page_size)->select()->toArray();
- }else{
- $list = Db::table('v4shop')
- ->field("site_id,site_name,avatar,address,(2 * $EARTH* ASIN(SQRT(POW(SIN($PI*(".$lat."-latitude)/360),2)+COS($PI*".$lat."/180)* COS(latitude * $PI/180)*POW(SIN($PI*(".$lng."-longitude)/360),2)))) as juli")
- ->where($where)
- ->order('juli asc')
- ->page($page,$page_size)->select()->toArray();
- }
- foreach ($list as $k => &$v) {
- $count_evaluate = Db::table('v4goods_evaluate')->where(['site_id'=>$v['site_id']])->count();
- $all_evaluate = Db::table('v4goods_evaluate')->where(['site_id'=>$v['site_id']])->sum('scores');
- $v['evaluate'] = bcdiv($all_evaluate,$count_evaluate,1);
- $v['avatar'] = 'https://'.$_SERVER['HTTP_HOST'].'/'.$v['avatar'];
- $v['good_num'] = Db::table('v4goods')->where(['site_id'=>$v['site_id'],'goods_state'=>1,'verify_state'=>1,'is_delete'=>0])->count();
- $v['juli'] = round($v['juli'],2);
- }
- return $this->response($this->success($list));
- }
- }
|