// +----------------------------------------------------------------------
namespace app\controller\api\v1;
use app\jobs\integral\IntegralJob;
use app\jobs\order\ShareOrderJob;
use app\jobs\supplier\SupplierFinanceJob;
use app\listener\order\Pay;
use app\model\order\StoreOrder;
use app\model\user\AwardIntegral;
use app\model\user\UserExtract;
use app\model\user\UserIntegral;
use app\model\user\User;
use app\services\activity\combination\StorePinkServices;
use app\services\diy\DiyServices;
use app\services\message\service\StoreServiceServices;
use app\services\order\StoreOrderServices;
use app\services\store\DeliveryServiceServices;
use app\services\other\CacheServices;
use app\services\product\category\StoreProductCategoryServices;
use app\services\product\product\StoreProductServices;
use app\services\other\ExpressServices;
use app\services\other\SystemCityServices;
use app\services\supplier\finance\SupplierFlowingWaterServices;
use app\services\system\attachment\SystemAttachmentServices;
use app\services\system\config\SystemConfigServices;
use app\services\store\SystemStoreServices;
use app\services\store\SystemStoreStaffServices;
use app\services\user\AwardIntegralServices;
use app\services\user\level\UserLevelServices;
use app\services\user\UserAwardIntegralServices;
use app\services\user\UserBillServices;
use app\services\user\UserInvoiceServices;
use app\services\user\UserServices;
use app\services\wechat\WechatUserServices;
use app\webscoket\SocketPush;
use crmeb\services\AliAuthService;
use crmeb\services\WithdrawService;
use Joypack\Tencent\Map\Bundle\Location;
use Joypack\Tencent\Map\Bundle\LocationOption;
use app\Request;
use crmeb\services\CacheService;
use crmeb\services\UploadService;
use crmeb\basic\BaseController;
use think\facade\Cache;
use think\facade\Log;
/**
* 公共类
* Class PublicController
* @package app\controller\api
*/
class PublicController extends BaseController
{
public function version()
{
$version = sys_config('app_version', '');
$apk = sys_config('app_apk', '');
return app('json')->successful(compact('version', 'apk'));
}
public function test()
{
event('user.cancelUser', [4]);
event('user.cancelUser', [5]);
event('user.cancelUser', [6]);
event('user.cancelUser', [7]);
event('user.cancelUser', [8]);
event('user.cancelUser', [9]);
event('user.cancelUser', [10]);
$max_id = CacheService::redisHandler()->get('max_id', 0);
$list = UserIntegral::where('type', 0)->where('status', 0)->order('id asc')->where('id', '>', $max_id)->limit(300)->select();
$last_time = CacheService::redisHandler()->get('last_time', 0);
$service = app()->make(AwardIntegralServices::class);
echo date('Y-m-d', $list[0]['add_time']) . '
';
foreach ($list as $v) {
if (date('Y-m-d', $v['add_time']) != date('Y-m-d', $last_time) && $last_time > 0) {
echo date('Y-m-d', $v['add_time']) . '
';
$days = (strtotime(date('Y-m-d', $v['add_time'])) - strtotime(date('Y-m-d', $last_time))) / (24 * 3600);
echo '时间间隔' . $days . '天
';
for ($i = 0; $i < $days; $i++) {
$service->daySend(true);
}
}
$this->dealOrderIntegral($v['link_id'], $v['uid'], $v['order_price'], $v['add_time']);
$last_time = $v['add_time'];
$max_id = $v['id'];
}
CacheService::redisHandler()->set('max_id', $max_id);
CacheService::redisHandler()->set('last_time', $last_time);
if (count($list) < 300 && strtotime(date('Y-m-d', $last_time)) < strtotime(date('Y-m-d'))) {
echo date('Y-m-d') . '
';
$days = (strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', $last_time))) / (24 * 3600);
echo '时间间隔' . $days . '天
';
for ($i = 0; $i < $days; $i++) {
$service->daySend(true);
}
}
// $main_orders = $service->getIntegralList(['uid' => 1, 'link_id' => 0, 'order_price_elt' => 2500, 'valid' => 2]);//满足复投条件的主单
// var_dump($main_orders);
// var_dump(AwardIntegral::getLastSql());
// $service->daySend(true);
}
public function dealOrderIntegral($order_id, $uid, $order_price, $add_time)
{
Log::debug(date('Y-m-d H:i:s') . '开始处理' . $order_id . '积分');
/** @var AwardIntegralServices $awardIntegralService */
$awardIntegralService = app()->make(AwardIntegralServices::class);
/** @var UserServices $userService */
$userService = app()->make(UserServices::class);
$user = $userService->getUserInfo($uid);
$total_price = $order_price;
return $awardIntegralService->transaction(function () use ($awardIntegralService, $userService, $user, $total_price, $order_id, $add_time) {
try {
$rate = sys_config('static_integral_rate', 3);
$give_static_integral = bcmul($total_price, $rate);
if ($give_static_integral > 0) {
$mark = '购买商品,获得参考分';
$integral_info = $awardIntegralService->incIntegral($user['uid'], $give_static_integral, $total_price, $order_id, $mark, $add_time);
}
//TODO 加动态积分
//推荐奖
$spread = $userService->getUserInfo($user['spread_uid']);
if ($spread && $spread['is_promoter']) {
if ($awardIntegralService->getPaySum($spread['uid']) > 0) {
$award_ratio = sys_config('recommend_speed_integral', 0);
$give_action_integral = bcdiv(bcmul($total_price, $award_ratio), 100, 2);
if ($give_action_integral > 0) {
$first = $awardIntegralService->getFirstStaticIntegral($spread['uid']);
if ($first) {
$awardIntegralService->upSpeedIntegral($first['id'], $give_action_integral);
}
}
}
}
Log::debug(date('Y-m-d H:i:s') . '结束处理' . $order_id . '积分');
return true;
} catch (\Throwable $e) {
Log::error('处理积分奖池失败,失败原因:' . $e->getMessage());
Log::debug(date('Y-m-d H:i:s') . '结束处理' . $order_id . '积分');
return false;
}
});
}
// public function send_test()
// {
// $service = app()->make(AwardIntegralServices::class);
// $service->daySend(true);
// return app('json')->successful('已释放');
// }
/**
* 主页获取
* @param Request $request
* @return mixed
*/
public function index(Request $request)
{
$uid = $request->hasMacro('uid') ? (int)$request->uid() : 0;
$banner = sys_data('routine_home_banner') ?: [];// 首页banner图
$menus = sys_data('routine_home_menus') ?: [];// 首页按钮
$roll = sys_data('routine_home_roll_news') ?: [];// 首页滚动新闻
$activity = sys_data('routine_home_activity', 3) ?: [];// 首页活动区域图片
$explosive_money = sys_data('index_categy_images') ?: [];// 首页超值爆款
$site_name = sys_config('site_name');
$routine_index_page = sys_data('routine_index_page');
$info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';// 快速选择简介
$info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';// 精品推荐简介
$info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';// 首发新品简介
$info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';// 促销单品简介
$logoUrl = sys_config('routine_index_logo');// 促销单品简介
if (strstr($logoUrl, 'http') === false && $logoUrl) {
$logoUrl = sys_config('site_url') . $logoUrl;
}
$logoUrl = str_replace('\\', '/', $logoUrl);
$fastNumber = (int)sys_config('fast_number', 0);// 快速选择分类个数
$bastNumber = (int)sys_config('bast_number', 0);// 精品推荐个数
$firstNumber = (int)sys_config('first_number', 0);// 首发新品个数
$promotionNumber = (int)sys_config('promotion_number', 0);// 首发新品个数
/** @var StoreProductCategoryServices $categoryService */
$categoryService = app()->make(StoreProductCategoryServices::class);
$info['fastList'] = $fastNumber ? $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic') : [];// 快速选择分类个数
/** @var StoreProductServices $storeProductServices */
$storeProductServices = app()->make(StoreProductServices::class);
$info['bastList'] = $bastNumber ? $storeProductServices->getRecommendProduct($uid, ['is_best' => 1], $bastNumber) : [];// 精品推荐个数
$info['firstList'] = $firstNumber ? $storeProductServices->getRecommendProduct($uid, ['is_new' => 1], $firstNumber) : [];// 首发新品个数
$info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];// 首页精品推荐图片
$benefit = $promotionNumber ? $storeProductServices->getRecommendProduct($uid, ['is_benefit' => 1], $promotionNumber) : [];// 首页促销单品
$lovely = sys_data('routine_home_new_banner') ?: [];// 首发新品顶部图
$likeInfo = $storeProductServices->getRecommendProduct($uid, ['is_hot' => 1], 3);// 热门榜单 猜你喜欢
if ($uid) {
/** @var WechatUserServices $wechatUserService */
$wechatUserService = app()->make(WechatUserServices::class);
$subscribe = (bool)$wechatUserService->value(['uid' => $uid], 'subscribe');
} else {
$subscribe = true;
}
$newGoodsBananr = sys_config('new_goods_bananr');
$tengxun_map_key = sys_config('tengxun_map_key');
$award_integral_service = app()->make(UserAwardIntegralServices::class);
$award_lack = $award_integral_service->getLake();
$integral_price = $award_integral_service->getPrice();
return app('json')->successful(compact('award_lack', 'integral_price', 'banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key', 'explosive_money'));
}
/**
* 获取分享配置
* @return mixed
*/
public function share()
{
$data['img'] = sys_config('wechat_share_img');
if (strstr($data['img'], 'http') === false) {
$data['img'] = sys_config('site_url') . $data['img'];
}
$data['img'] = str_replace('\\', '/', $data['img']);
$data['title'] = sys_config('wechat_share_title');
$data['synopsis'] = sys_config('wechat_share_synopsis');
return app('json')->successful($data);
}
/**
* 获取网站配置
* @return mixed
*/
public function getSiteConfig()
{
$data['record_No'] = sys_config('record_No');
return app('json')->success($data);
}
/**
* 获取个人中心菜单
* @param Request $request
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function menu_user(Request $request)
{
$menusInfo = sys_data('routine_my_menus') ?? [];
$uid = 0;
$userInfo = [];
if ($request->hasMacro('user')) $userInfo = $request->user();
if ($request->hasMacro('uid')) $uid = $request->uid();
$vipOpen = sys_config('member_func_status');
$brokerageFuncStatus = sys_config('brokerage_func_status');
$balanceFuncStatus = sys_config('balance_func_status');
$vipCard = sys_config('member_card_status', 0);
$svipOpen = (bool)sys_config('member_card_status');
$userService = $invoiceStatus = $deliveryUser = $isUserPromoter = $userVerifyStatus = $userOrder = $isStaff = $isDelivery = true;
if ($uid && $userInfo) {
/** @var StoreServiceServices $storeService */
$storeService = app()->make(StoreServiceServices::class);
$userService = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1, 'account_status' => 1]);
$userOrder = $storeService->checkoutIsService(['uid' => $uid, 'account_status' => 1, 'customer' => 1]);
/** @var SystemStoreStaffServices $systemStoreStaff */
$systemStoreStaff = app()->make(SystemStoreStaffServices::class);
/** @var UserServices $user */
$user = app()->make(UserServices::class);
/** @var UserInvoiceServices $userInvoice */
$userInvoice = app()->make(UserInvoiceServices::class);
$invoiceStatus = $userInvoice->invoiceFuncStatus(false);
/** @var DeliveryServiceServices $deliveryService */
$deliveryService = app()->make(DeliveryServiceServices::class);
$deliveryUser = $deliveryService->checkoutIsService($uid);
$isUserPromoter = $user->checkUserPromoter($uid, $userInfo);
$userVerifyStatus = $systemStoreStaff->verifyStatus($uid);
try {
$isStaff = $systemStoreStaff->getStaffInfoByUid($uid);
} catch (\Throwable $e) {
$isStaff = false;
}
try {
$isDelivery = $deliveryService->getDeliveryInfoByUid($uid);
} catch (\Throwable $e) {
$isDelivery = false;
}
}
$auth = [];
$auth['/pages/users/user_vip/index'] = !$vipOpen;
$auth['/pages/users/user_spread_user/index'] = !$brokerageFuncStatus || !$isUserPromoter || $uid == 0;
$auth['/pages/users/user_money/index'] = !$balanceFuncStatus;
$auth['/pages/admin/order/index'] = !$userOrder || $uid == 0;
$auth['/pages/admin/order_cancellation/index'] = (!$userVerifyStatus && !$deliveryUser) || $uid == 0;
$auth['/pages/users/user_invoice_list/index'] = !$invoiceStatus;
$auth['/pages/annex/vip_paid/index'] = !$vipCard || !$svipOpen;
$auth['/kefu/mobile_list'] = !$userService || $uid == 0;
$auth['/pages/admin/store/index'] = $uid == 0 || !$isStaff;
$auth['/pages/admin/distribution/index'] = $uid == 0 || !$isDelivery;
$auth['/pages/store_spread/index'] = $uid == 0 || !$isStaff;
foreach ($menusInfo as $key => &$value) {
$value['pic'] = set_file_url($value['pic'] ?? '');
$value['url'] = $value['url'] ?? '';
if (isset($auth[$value['url']]) && $auth[$value['url']]) {
unset($menusInfo[$key]);
continue;
}
if ($value['url'] == '/kefu/mobile_list') {
$value['url'] = sys_config('site_url') . $value['url'];
if ($request->isRoutine()) {
$value['url'] = str_replace('http://', 'https://', $value['url']);
}
}
}
/** @var SystemConfigServices $systemConfigServices */
$systemConfigServices = app()->make(SystemConfigServices::class);
$bannerInfo = $systemConfigServices->getSpreadBanner() ?? [];
$my_banner = sys_data('routine_my_banner');
$routine_contact_type = sys_config('routine_contact_type', 0);
/** @var DiyServices $diyServices */
$diyServices = app()->make(DiyServices::class);
$diy_data = $diyServices->cacheRemember('diy_data_member_3', function () use ($diyServices) {
$diy_data = $diyServices->get(['template_name' => 'member', 'type' => 3], ['value', 'status', 'order_status', 'my_banner_status', 'menu_status', 'service_status']);
$diy_data = $diy_data ? $diy_data->toArray() : [];
return $diy_data;
});
if ($diy_data) {
$diy_value = json_decode($diy_data['value'], true);
$new_value = [];
if (is_int($diy_value)) {
$new_value['status'] = $diy_value;
$new_value['vip_type'] = 1;
$new_value['newcomer_status'] = 1;
$new_value['newcomer_style'] = 1;
} else {
$new_value = $diy_value;
}
$diy_data = array_merge($diy_data, $new_value);
$diy_data['order_status'] = (int)$diy_data['order_status'];
}
unset($diy_data['value']);
return app('json')->successful(['routine_my_menus' => array_merge($menusInfo), 'routine_my_banner' => $my_banner, 'routine_spread_banner' => $bannerInfo, 'routine_contact_type' => $routine_contact_type, 'diy_data' => $diy_data]);
}
/**
* 热门搜索关键字获取
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function search()
{
$routineHotSearch = sys_data('routine_hot_search') ?? [];
$searchKeyword = [];
if (count($routineHotSearch)) {
foreach ($routineHotSearch as $key => &$item) {
array_push($searchKeyword, $item['title'] ?? '');
}
}
return app('json')->successful($searchKeyword);
}
/**
* 图片上传
* @param Request $request
* @return mixed
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function upload_image(Request $request, SystemAttachmentServices $services)
{
$data = $request->postMore([
['filename', 'file'],
]);
if (!$data['filename']) return app('json')->fail('参数有误');
if (CacheService::has('start_uploads_' . $request->uid()) && CacheService::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail('非法操作');
$upload = UploadService::init();
$info = $upload->to('store/comment')->validate()->move($data['filename']);
if ($info === false) {
return app('json')->fail($upload->getError());
}
$res = $upload->getUploadInfo();
$services->attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, (int)sys_config('upload_type', 1), $res['time'], 3);
if (CacheService::has('start_uploads_' . $request->uid()))
$start_uploads = (int)CacheService::get('start_uploads_' . $request->uid());
else
$start_uploads = 0;
$start_uploads++;
CacheService::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
$res['dir'] = path_to_url($res['dir']);
if (strpos($res['dir'], 'http') === false) $res['dir'] = sys_config('site_url') . $res['dir'];
return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
}
/**
* 物流公司
* @return mixed
*/
public function logistics(Request $request, ExpressServices $services)
{
[$status] = $request->getMore([
['status', ''],
], true);
if ($status == 1) $data['status'] = $status;
$data['is_show'] = 1;
$expressList = $services->expressList($data);
return app('json')->successful($expressList ?? []);
}
/**
* 反向解析地址
* @param Request $request
* @return mixed
*/
public function geoLbscoder(Request $request)
{
[$data] = $request->getMore([
['location', '']
], true);
$locationOption = new LocationOption(sys_config('tengxun_map_key'));
$data = explode(',', $data);
$locationOption->setLocation($data[0] ?? '', $data[1] ?? '');
$location = new Location($locationOption);
$res = $location->request();
if ($res->error) {
return app('json')->fail($res->error);
}
if ($res->status) {
return app('json')->fail($res->message);
}
if (!$res->result) {
return app('json')->fail('获取失败');
}
return app('json')->success($res->result);
}
/**
* 短信购买异步通知
*
* @param Request $request
* @return mixed
*/
public function sms_pay_notify(Request $request)
{
[$order_id, $price, $status, $num, $pay_time, $attach] = $request->postMore([
['order_id', ''],
['price', 0.00],
['status', 400],
['num', 0],
['pay_time', time()],
['attach', 0],
], true);
if ($status == 200) {
try {
SocketPush::admin()->type('PAY_SMS_SUCCESS')->data(['price' => $price, 'number' => $num])->push();
} catch (\Throwable $e) {
}
return app('json')->successful();
}
return app('json')->fail();
}
/**
* 记录用户分享
* @param Request $request
* @param UserBillServices $services
* @return mixed
*/
public function user_share(Request $request, UserBillServices $services)
{
$uid = (int)$request->uid();
return app('json')->successful($services->setUserShare($uid));
}
/**
* 获取图片base64
* @param Request $request
* @return mixed
*/
public function get_image_base64(Request $request)
{
[$imageUrl, $codeUrl] = $request->postMore([
['image', ''],
['code', ''],
], true);
if ($imageUrl !== '' && !preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $imageUrl)) {
return app('json')->success(['code' => false, 'image' => false]);
}
if ($codeUrl !== '' && !(preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $codeUrl) || strpos($codeUrl, 'https://mp.weixin.qq.com/cgi-bin/showqrcode') !== false)) {
return app('json')->success(['code' => false, 'image' => false]);
}
try {
$code = CacheService::get($codeUrl, function () use ($codeUrl) {
$codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
if (!$codeTmp) {
$codeUrl = explode('?', $codeUrl)[0] ?? $codeUrl;
$putCodeUrl = put_image($codeUrl);
$code = $putCodeUrl ? image_to_base64(public_path() . $putCodeUrl) : false;
$code ?? unlink(public_path() . $putCodeUrl);
}
return $code;
});
$image = CacheService::get($imageUrl, function () use ($imageUrl) {
$imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
if (!$imageTmp) {
$imageUrl = explode('?', $imageUrl)[0] ?? $imageUrl;
$putImageUrl = put_image($imageUrl);
$image = $putImageUrl ? image_to_base64(public_path() . $putImageUrl) : false;
$image ?? unlink(public_path() . $putImageUrl);
}
return $image;
});
return app('json')->successful(compact('code', 'image'));
} catch (\Exception $e) {
return app('json')->fail($e->getMessage());
}
}
/**
* 门店列表
* @param Request $request
* @param SystemStoreServices $services
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function store_list(Request $request, SystemStoreServices $services)
{
[$latitude, $longitude, $product_id, $type, $is_store, $store_id] = $request->getMore([
['latitude', ''],
['longitude', ''],
['product_id', 0],
['type', 0],//商品类型 0:普通 1:秒杀
['is_store', 1], //前端传值为 1|商城配送 2|门店自提 3|门店配送
['store_id', 0], //前端传值为 1|商城配送 2|门店自提 3|门店配送
], true);
//判断是否门店自提
$is_store == 2 ? $is_store = 1 : $is_store = '';
$where = ['type' => 0, 'is_store' => $is_store];
$field = ['id', 'name', 'phone', 'image', 'latitude', 'longitude', 'address', 'detailed_address', 'is_show', 'is_store', 'day_time', 'day_start', 'day_end', 'valid_range'];
$data['list'] = $services->getStoreList($where, $field, $latitude, $longitude, (int)$product_id, [], (int)$type, $store_id);
$data['tengxun_map_key'] = sys_config('tengxun_map_key');
return app('json')->successful($data);
}
/**
* 查找城市数据
* @param Request $request
* @return mixed
*/
public function city_list(Request $request)
{
/** @var SystemCityServices $systemCity */
$systemCity = app()->make(SystemCityServices::class);
return app('json')->successful($systemCity->cityList());
}
/**
* 获取拼团数据
* @return mixed
*/
public function pink(Request $request, StorePinkServices $pink, UserServices $user)
{
[$type] = $request->getMore([
['type', 1],
], true);
$where = ['is_refund' => 0];
if ($type == 1) {
$where['status'] = 2;
}
$data['pink_count'] = $pink->getCount($where);
$uids = array_flip($pink->getColumn($where, 'uid'));
if (count($uids)) {
mt_srand();
$uids = array_rand($uids, count($uids) < 3 ? count($uids) : 3);
}
$data['avatars'] = $uids ? $user->getColumn(is_array($uids) ? [['uid', 'in', $uids]] : ['uid' => $uids], 'avatar') : [];
return app('json')->successful($data);
}
/**
* 复制口令接口
* @return mixed
*/
public function copy_words()
{
$data['words'] = sys_config('copy_words');
return app('json')->successful($data);
}
/**
* 生成口令关键字
* @param Request $request
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function copy_share_words(Request $request)
{
[$productId] = $request->getMore([
['product_id', ''],
], true);
/** @var StoreProductServices $productService */
$productService = app()->make(StoreProductServices::class);
$keyWords['key_words'] = $productService->getProductWords($productId);
return app('json')->successful($keyWords);
}
/**
* 获取页面数据
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getDiy(DiyServices $services, $id = 0)
{
return app('json')->successful($services->getDiyInfo((int)$id));
}
/**
* @param DiyServices $services
* @param int $id
* @return mixed
* @author 等风来
* @email 136327134@qq.com
* @date 2022/11/9
*/
public function getDiyVersion(DiyServices $services, $id = 0)
{
return app('json')->successful(['version' => $services->getDiyVersion((int)$id)]);
}
/**
* 获取底部导航
* @param DiyServices $services
* @param string $template_name
* @return mixed
*/
public function getNavigation(DiyServices $services, string $template_name = '')
{
return app('json')->success($services->getNavigation($template_name));
}
/**
* 获取用户协议内容
* @return mixed
*/
public function getUserAgreement(Request $request, $type = 1)
{
/** @var CacheServices $cache */
$cache = app()->make(CacheServices::class);
/** @var UserServices $userService */
$userService = app()->make(UserServices::class);
$content = $cache->getDbCache($type, '');
$uid = $request->uid() ?? 0;
$userInfo = $userService->get($uid);
$name = $userInfo['nickname'] ?? '';
$avatar = $userInfo['avatar'] ?? '';
return app('json')->success(compact('content', 'uid', 'name', 'avatar'));
}
/**
* 统计代码
* @return array|string
*/
public function getScript()
{
return sys_config('system_statistics', '');
}
/**
* 首页开屏广告
* @return mixed
*/
public function getOpenAdv()
{
/** @var CacheServices $cache */
$cache = app()->make(CacheServices::class);
$data = $cache->getDbCache('open_adv', '');
$data['time'] = (float)($data['time'] ?? 3);
$data['interval_time'] = (float)($data['interval_time'] ?? 24);
return app('json')->success($data);
}
/**
* 用户注销
* @param Request $request
* @return mixed
*/
public function cancelUser(Request $request)
{
$uid = $request->uid();
if (!$uid) return app('json')->fail('用户不存在');
event('user.cancelUser', [$uid]);
return app('json')->success('注销成功');
}
/**
* 获取版权
* @return mixed
*/
public function getCopyright()
{
try {
$copyright = $this->__z6uxyJQ4xYa5ee1mx5();
} catch (\Throwable $e) {
$copyright = [
'copyrightContext' => '',
'copyrightImage' => '',
];
}
$copyright['record_No'] = sys_config('record_No');
$copyright['version'] = get_crmeb_version();
$copyright['routine_contact_type'] = sys_config('routine_contact_type');
$copyright['store_user_agreement'] = (int)sys_config('store_user_agreement');
$copyright['routine_auth_type'] = sys_config('routine_auth_type', []);
$copyright['wechat_auth_switch'] = (int)in_array(1, $copyright['routine_auth_type']);//微信登录开关
$copyright['phone_auth_switch'] = (int)in_array(2, $copyright['routine_auth_type']);//手机号登录开关
$copyright['site_name'] = sys_config('site_name', '');
$copyright['site_logo'] = sys_config('wap_login_logo', '');
$copyright['wechat_status'] = sys_config('wechat_appid') && sys_config('wechat_appsecret');
return $this->success($copyright);
}
/**
* 登录页面获取logo以及版本全新
* @return mixed
*/
public function getLogo()
{
try {
$copyright = $this->__z6uxyJQ4xYa5ee1mx5();
} catch (\Throwable $e) {
$copyright = [
'copyrightContext' => '',
'copyrightImage' => '',
];
}
$copyright['record_No'] = sys_config('record_No');
$copyright['version'] = get_crmeb_version();
$logo = sys_config('wap_login_logo');
if (strstr($logo, 'http') === false && $logo) $logo = sys_config('site_url') . $logo;
$copyright['site_name'] = sys_config('site_name');
$copyright['logo_url'] = str_replace('\\', '/', $logo);
$copyright['store_user_agreement'] = (int)sys_config('store_user_agreement');
$copyright['routine_auth_type'] = sys_config('routine_auth_type', []);
$copyright['wechat_auth_switch'] = (int)in_array(1, $copyright['routine_auth_type']);//微信登录开关
$copyright['phone_auth_switch'] = (int)in_array(2, $copyright['routine_auth_type']);//手机号登录开关
$copyright['wechat_status'] = sys_config('wechat_appid') && sys_config('wechat_appsecret');
return app('json')->successful($copyright);
}
public function authNotify(Request $request)
{
$data = $request->param();
$token = $data['callbackToken'];
$certifyId = $data['certifyId'];
$check_token = Cache::get($certifyId, '');
if ($token != $check_token) {
return app('json')->fail('已过期');
}
$uid = Cache::get($token, 0);
$user = User::where(['uid' => $uid])->find();
if (!$user || $user['is_auth'] == 2 || $user['is_auth'] == 3) {
return app('json')->fail('信息已审核或不存在');
}
$info = AliAuthService::result($certifyId);
if (!$info) {
return app('json')->fail(AliAuthService::getError());
}
if ($info['passed'] == 'T') {
User::where(['uid' => $uid])->update(['is_auth' => 2, 'off' => ""]);
} else {
User::where(['uid' => $uid])->update(['off' => AliAuthService::getCodeError($info['subCode']), 'is_auth' => "3"]);
}
return app('json')->success('OK');
}
}