dlh_test_server/app/api/controller/Index.php
2024-11-19 10:52:45 +08:00

273 lines
9.4 KiB
PHP
Executable File

<?php
namespace app\api\controller;
use app\api\logic\DistributionLogic;
use app\api\logic\IndexLogic;
use app\common\basics\Api;
use app\common\enum\MenuEnum;
use app\common\logic\ChatLogic;
use app\common\logic\RegionLogic;
use app\common\model\MenuDecorate;
use app\common\model\user\User;
use app\common\model\user\UserAuth;
use app\common\server\JsonServer;
use think\facade\Config;
use think\facade\Db;
use weixin\Getopenid;
class Index extends Api
{
public $like_not_need_login = ['index', 'indexCategory', 'config', 'copyright', 'city', 'geocoder', 'setHome'];
// 首页
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);
$divide_state = 0;
$regional_state = 0;
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_second_user_id = 0;
$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['divide_role_user_id'] !== 0) {
$divide_role_user_id = $firend_msg['divide_role_user_id'];
$divide_state = 1;
}
// else {
// if ($firend_msg['first_leader'] != 0) {
// $divide_role_user_id = $firend_msg['first_leader'];
// } else {
// $divide_role_user_id = $firend_id;
// }
// }
if ($firend_msg['regional_state'] === 1) {
$divide_second_user_id = $firend_msg['id'];
$regional_state = 1;
} elseif ($firend_msg['divide_second_user_id'] !== 0) {
$divide_second_user_id = $firend_msg['divide_second_user_id'];
$regional_state = 1;
}
}
$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,
'divide_second_user_id' => $divide_second_user_id,
'divide_state' => $divide_state,
'regional_state'=>$regional_state
];
$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($this->user_id);
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()
{
$local = Db::name("local_store")
->where([
'user_id' => $this->user_id,
'store_state' => 1,
'is_delete' => 0,
])->count();
$list = MenuDecorate::where(['decorate_type' => 3, 'del' => 0, 'is_show' => 1])
->field('name,image,link_type,link_address')
->order('sort desc')
->select()
->toArray();
$company = array();
if ($local > 0) {
$company[] = array(
"image" => 'https://zjeloong.oss-cn-hangzhou.aliyuncs.com/uniapp/all_service.png?t=1',
"name" => '企业服务',
"is_tab" => 0,
"link" => '/bundle_b/pages/local_shop/local_shop',
"link_type" => 1,
"is_set" => 0
);
}
$data = array();
if ($list) {
foreach ($list as &$v) {
$menu_content = MenuEnum::getMenu('local', $v['link_address']);
$v['link'] = $menu_content['link'];
}
$data = array_merge($company, $list);
}
if (empty($data) && $company) {
$data = $company;
}
return JsonServer::success('查询成功', $data);
}
public function getLocalMenu()
{
$arr = array(
array(
"image" => Config::get('aliyunoss.domain') . 'uniapp/bundle_b/local_shop/store_manager.png?t=1',
"name" => '商家信息',
"is_tab" => 0,
"link" => '/bundle_b/pages/local_shop/local_shop',
"link_type" => 1,
"is_set" => 0
),
array(
"image" => Config::get('aliyunoss.domain') . 'uploads/images/2024081216470092b229906.png',
"name" => '商家入驻',
"is_tab" => 0,
"link" => '/bundle_b/pages/local_settled/index',
"link_type" => 1,
"is_set" => 0
)
);
return JsonServer::success('查询成功', $arr);
}
}