dlhmaster/app/api/controller/Index.php
2024-07-26 10:45:36 +08:00

209 lines
7.1 KiB
PHP

<?php
namespace app\api\controller;
use app\api\logic\DistributionLogic;
use app\common\basics\Api;
use app\api\logic\IndexLogic;
use app\common\logic\ChatLogic;
use app\common\logic\RegionLogic;
use app\common\model\user\User;
use app\common\model\user\UserAuth;
use app\common\server\JsonServer;
use weixin\Getopenid;
use think\facade\Db;
class Index extends Api
{
public $like_not_need_login = ['index', 'indexCategory', 'config','copyright','city','geocoder'];
// 首页
public function index()
{
$terminal = $this->request->get('terminal', 'nmp');
$city = $this->request->get('city_id', '');
$p_id = $this->request->get('p_id',0);
$set_id = $this->request->get('set',0);
// $firend_invite_code = $this->request->get('firend_invite_code',0);
$code = $this->request->get('code');
$invite_code = $this->request->get('invite_code');
// file_put_contents('log.txt', '1invite_code= ' . $invite_code . '; code='. $code);
// die;
// echo $code;
// echo $invite_code;
// Log::record('测试日志信息');
// trace('invite_code', $invite_code.'-'.$code);
// $data = $this->request->param();
// echo $data;die;
// if(isset($invite_code)){
// if($invite_code != 0){
// $firend_invite_code = $invite_code;
// }
// }
$open=new Getopenid();
$info=$open->getAcc($code);
if(isset($info['openid'])) {
$openid = $info['openid'];
$user_msg = UserAuth::where("openid",$openid)->find();
$firend_msg = User::where("distribution_code",$invite_code)->find();
if($user_msg==null){
$divide_role_user_id = 0;
$firend_id = 0;
$is_d = Db::name("distribution")->where('user_id', $firend_msg['id'] )->where('is_distribution', 1 )->find();
if($is_d != null){
$firend_id = $firend_msg['id'];
if($firend_msg['first_leader'] !=0){
$divide_role_user_id = $firend_msg['first_leader'];
}else{
$divide_role_user_id = $firend_id;
}
}
$data = [
'sn' => create_user_sn(),
'create_time' => time(),
"first_leader" => $firend_id,
'distribution_code' => generate_invite_code(),//分销邀请码
'is_distribution' => DistributionLogic::isDistributionMember(),
'client' => 1,
'is_new_user' => 1,
'user_ad_cret' => 1,
'divide_role_user_id' => $divide_role_user_id
];
$user = User::create($data);
$user_id = $user->id;
$UserAuth = UserAuth::create([
"user_id"=>$user_id,
"openid"=>$openid,
"create_time"=>time(),
"client"=>1
]);
if($is_d != null){
$firend_id = $firend_msg['id'];
$dat['f_user_id'] = $firend_id;
$dat['user_id'] = $user_id;
$dat['ditme'] = date("Y-m-d H:i:s");
Db::name("user_firster")->save($dat);
}
//生成会员分销扩展表
DistributionLogic::createUserDistribution($user_id);
// 生成分销基础信息表
\app\common\logic\DistributionLogic::add($user_id);
}
}
$data = IndexLogic::index($this->user_id,$terminal,$city,$p_id,$set_id);
return JsonServer::success('获取成功', $data);
}
// 首页分类
public function indexCategory()
{
$platform_category_id = $this->request->get('platform_category_id', '', 'intval');
$p_id = $this->request->get('p_id',0);
$set_id = $this->request->get('set',0);
if(empty($platform_category_id)) {
return JsonServer::error('平台分类id不能为空');
}
$data = IndexLogic::indexCategory($platform_category_id,$p_id,$set_id);
return JsonServer::success('获取成功', $data);
}
// 通用配置
public function config()
{
$data = IndexLogic::config();
return JsonServer::success('获取成功', $data);
}
/**
* @notes 客服配置
* @return \think\response\Json
* @author 段誉
* @date 2021/12/15 17:16
*/
public function chatConfig()
{
$shop_id = $this->request->get('shop_id/d');
$result = ChatLogic::getConfig($shop_id);
return JsonServer::success($result['msg'], [], $result['code']);
}
/**
* @notes 版权资质
* @return \think\response\Json
* @author ljj
* @date 2022/2/22 10:16 上午
*/
public function copyright()
{
$shop_id = $this->request->get('shop_id/d');
$result = IndexLogic::copyright($shop_id);
return JsonServer::success('', $result);
}
/**
* @notes 地级市
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2022/9/20 5:51 下午
*/
public function city()
{
$result = RegionLogic::city();
return JsonServer::success('', $result);
}
/**
* @notes 腾讯地图逆地址解析(坐标位置描述)
* @return \think\response\Json
* @author ljj
* @date 2022/9/21 2:37 下午
* 经纬度到文字地址及相关位置信息的转换
*/
public function geocoder()
{
$get = $this->request->get();
if (!isset($get['location']) || $get['location'] == '') {
return JsonServer::error('经纬度缺失');
}
$result = IndexLogic::geocoder($get);
if ($result['status'] !== 0) {
return JsonServer::error($result['message']);
}
return JsonServer::success('',$result);
}
// 控制显示本地生活
public function setHome(){
$arr = array(
array(
"image"=>'https://zjeloong.oss-cn-hangzhou.aliyuncs.com/uniapp/bundle_b/local_shop/store_manager.png',
"name"=>'商家信息',
"is_tab"=> 0,
"link"=>'/bundle_b/pages/local_shop/local_shop',
"link_type"=>1,
"is_set"=>0
),
array(
"image"=>'https://zjeloong.oss-cn-hangzhou.aliyuncs.com/uniapp/bundle_b/local_shop/store_settled.png',
"name"=>'商家入驻',
"is_tab"=> 0,
"link"=>'/bundle_b/pages/local_settled/index',
"link_type"=>1,
"is_set"=>0
)
);
return JsonServer::success('查询成功', $arr);
// return JsonServer::success('查询成功', []);
}
}