| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- <?php
- namespace app\api\controller\v1;
- use app\common\model\NumRecordModel;
- use app\common\model\SystemBannerModel;
- use app\common\model\UserModel;
- use app\common\service\ArticleService;
- use app\common\service\LevelSettingService;
- use app\common\service\SystemConfigService;
- use app\Request;
- use app\api\services\RequestUtilService;
- use Minho\Captcha\CaptchaBuilder;
- use services\CacheServices;
- use think\Exception;
- use think\facade\Db;
- use think\facade\Filesystem;
- use utils\RedisCache;
- /**
- * 公共接口 by wes
- * Class Fragment
- * @package app\api\controller\v1
- */
- class Fragment
- {
- /**
- * 格式化
- * @param Request $request
- * @return \think\Response
- */
- public function balanceInArr(Request $request){
- $data = explode('|', env('APP.BALANCE_IN_SETTING'));
- return api_succ_return(['msg'=>'成功', 'data'=>$data]);
- }
- /**
- * 获取app配置
- * @param Request $request
- * @return \think\Response
- */
- public function appConfig(Request $request){
- $cacheKey = "caches:config:app";
- $data = RedisCache::get($cacheKey);
- if($data){
- return api_succ_return(['msg'=>'成功', 'data'=>$data]);
- }
- $time = time();
- $webUrl = getWebUrl();
- $withdrawFee = (int)SystemConfigService::make()->getConfigByName('withdraw_service_rate',1,'withdraw');
- $withdrawMax = (int)SystemConfigService::make()->getConfigByName('withdraw_max_money',1,'withdraw');
- $data = [
- // 地址
- 'privateInfo'=> $webUrl.'/api/privateInfo',
- 'userAgreementInfo'=> $webUrl.'/api/userAgreementInfo',
- 'helpCenter'=> $webUrl.'/api/helpCenter',
- 'aboutUs'=> $webUrl.'/api/aboutUs',
- 'chat_url'=> env('APP.CHAT_URL_CONFIG'),
- 'about_us'=> env('APP.ABOUT_US'),
- //福袋参数
- 'box'=> [
- 'is_apply'=> (int)SystemConfigService::make()->getConfigByName('fudai_is_apply',1,'fudai'),
- 'is_retrieve'=> (int)SystemConfigService::make()->getConfigByName('is_retrieve',1,'fudai')
- ],
- 'newhand_url'=> $webUrl.'/api/newhandurl',
- 'newguide_url'=> $webUrl.'/api/newguideurl',
- 'aboutbox_url'=> $webUrl.'/api/aboutboxurl',
- 'one_box_price'=> env('boxsetting.ONE_BOX_PRICE'),
- 'box_musicurl'=> $webUrl.'/static/resources/'.'box_open.mp3',
- 'box_desc' => [
- ['title'=>'普通','pic'=>$webUrl.'/'.'static/img/box/box_pic10.png', 's_pic'=>$webUrl.'/'.'static/img/box/box_pic10_small.png', 'prob'=>'3.8%', 'box_type'=>10],
- ['title'=>'稀有','pic'=>$webUrl.'/'.'static/img/box/box_pic20.png', 's_pic'=>$webUrl.'/'.'static/img/box/box_pic20_small.png','prob'=>'30%', 'box_type'=>20],
- ['title'=>'史诗','pic'=>$webUrl.'/'.'static/img/box/box_pic30.png', 's_pic'=>$webUrl.'/'.'static/img/box/box_pic30_small.png','prob'=>'0.15%', 'box_type'=>30],
- ['title'=>'传说','pic'=>$webUrl.'/'.'static/img/box/box_pic40.png', 's_pic'=>$webUrl.'/'.'static/img/box/box_pic40_small.png','prob'=>'0.05%', 'box_type'=>40],
- ],
- 'services_desc'=> [
- '购买一次服务商有效期30天,到期后需再次手动续费。'
- ],
- 'bbox_desc'=> [
- [
- 'title'=>'一袋豪物',
- 'count'=>1
- ],
- [
- 'title'=>'幸运5连',
- 'count'=>5
- ],
- [
- 'title'=>'豪气10连',
- 'count'=>10
- ],
- [
- 'title'=>'超凡二十联',
- 'count'=>20
- ]
- ],
- // 广告参数
- 'adsetting'=> [
- 'android'=>[
- 'appkey'=>env('LINGYE.ANDROID_APPKEY'),
- 'jiliid'=>env('LINGYE.ANDROID_JILIID'),
- 'kaipinid'=>env('LINGYE.ANDROID_KAIPINGID'),
- 'chapinid'=>env('LINGYE.ANDROID_CHAPINID'),
- ],
- 'ios'=>[
- 'appkey'=>env('LINGYE.IOS_APPKEY'),
- 'jiliid'=>env('LINGYE.IOS_JILIID'),
- 'kaipinid'=>env('LINGYE.IOS_KAIPINGID'),
- 'chapinid'=>env('LINGYE.IOS_CHAPINID')
- ]
- ],
- // 其他配置参数
- 'widthdraw'=> [
- 'scale'=>env('WITHDRAW.APP_WITHDRAW_SCALE'),
- 'begin'=>env('WITHDRAW.APP_WITHDRAW_BEGIN'),
- 'withdraw_is_open'=> (int)SystemConfigService::make()->getConfigByName('withdraw_is_open',1,'withdraw'),
- 'service_rate'=> $withdrawFee,
- 'desc'=>[
- '本次提现将收取'.$withdrawFee.'%手续费',
- '提现到账时间16:00前提现24:00前到账,16:00后提现次日到账',
- '提现申请金额必须是10的整数倍',
- "提现金额单笔不能超过{$withdrawMax},提现大于5千只能使用银行卡"
- ]
- ],
- 'jh_excharge'=> [
- 'desc'=>[
- '转赠不收取任何手续费',
- '请确定对方信息后在输入安全密码,由于用户自己原因导致错误转赠,平台概不负责'
- ]
- ],
- 'agent'=> [
- 'privince_agent'=>[
- 'http://downyjh.meikangjw.com/mlh/agent/p_agent1.png?time='.$time,
- 'http://downyjh.meikangjw.com/mlh/agent/p_agent2.png?time='.$time,
- 'http://downyjh.meikangjw.com/mlh/agent/p_agent3.png?time='.$time
- ],
- 'city_agent'=>[
- 'http://downyjh.meikangjw.com/mlh/agent/c_agent1.png?time='.$time,
- 'http://downyjh.meikangjw.com/mlh/agent/c_agent2.png?time='.$time,
- 'http://downyjh.meikangjw.com/mlh/agent/c_agent3.png?time='.$time
- ],
- 'p_agent_price'=>'175000|25000',
- 'c_agent_price'=>'56000|8000',
- ],
- 'version'=> env('APP.VERSION')
- ];
- RedisCache::set($cacheKey, $data, rand(300, 600));
- return api_succ_return(['msg'=>'成功', 'data'=>$data]);
- }
- /**
- * 获取图形验证码
- * @return \think\Response
- */
- public function getVerifyCode()
- {
- $captch = new CaptchaBuilder();
- $captch->initialize([
- 'width' => 100, // 宽度
- 'height' => 40, // 高度
- 'line' => true, // 直线
- 'curve' => false, // 曲线
- 'fontSize'=>25, // 验证码字体
- 'noise' => 0, // 噪点背景
- 'fonts' => [] // 字体
- ]);
- $captch->create();
- $uuid = uniqid();
- //生成并返回图片流base64编码
- ob_start ();
- $captch->output(1);
- $captchaCode = $captch->getText();
- $image_data = ob_get_contents ();
- ob_end_clean ();
- $captchaDataUrl = AESjiami(base64_encode ($image_data));
- $array = ['captchaDataUrl' => $captchaDataUrl,'captcha_uuid' => $uuid];
- CacheServices::set('catch'.$uuid, $captchaCode, 900);
- return api_succ_return(['msg'=>'成功', 'data'=>$array]);
- }
- /**
- * 发送短信验证码
- * @param Request $request
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function sendSmsCode(Request $request)
- {
- $type = $request->param('type');
- $mobile = $request->param('mobile');
- $app_sources = $request->param('app_sources');
- if (!is_numeric($mobile) || strlen($mobile)!=11){
- return api_error_return('手机号码错误');
- }
- if (!$type || !in_array($type, ['register', 'editpass', 'securitypass', 'loingcheck'])){
- return api_error_return('类型错误');
- }
- $send_user = UserModel::where(['mobile'=>$mobile])->find();
- if (in_array($type, ['editpass', 'securitypass', 'loingcheck']) && !$send_user){
- return api_error_return('该手机号码未注册');
- }
- if ($type == 'register' && $send_user){
- return api_error_return('该手机号码已注册,请直接登录');
- }
- $m = new NumRecordModel();
- if ($send_user){
- $user_count = $m->whereDay('create_time', 'today')->where('uid', $send_user['id'])->count();
- if ($user_count > 5){
- return api_error_return('发送失败,超过单日用户单日最大发送短信');
- }
- }
- Db::startTrans();
- try {
- $code = rand(100000,999999);
- $ser_request = new RequestUtilService();
- $result = $ser_request->reqeustSmsCode($mobile, $code);
- if ($result == 0){
- $data = [
- 'type'=>$type,
- 'content'=>$code,
- 'isfrom'=>$app_sources,
- 'phone'=>$mobile,
- 'uid'=>$send_user?$send_user['id']:0,
- 'create_time'=>sr_getcurtime(time()),
- 'ip'=> get_client_ip()
- ];
- $m->insert($data);
- }else{
- throw new Exception('');
- }
- Db::commit();
- return api_succ_return('发送成功');
- }catch (\Exception $e){
- Db::rollback();
- return api_error_return('发送失败'.$e->getMessage());
- }
- }
- /**
- * 获取轮播图广告
- * @param Request $request
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getAppBanner(Request $request){
- $post = $request->post();
- if (!in_array($post['type'], [1,2,3,4,5,6])){
- return api_succ_return('成功');
- }
- $cacheKey = "caches:banners:app";
- $data = RedisCache::get($cacheKey);
- if($data){
- return api_succ_return(['msg'=>'缓存数据', 'data'=>$data]);
- }
- $modelbanner = new SystemBannerModel();
- $list = $modelbanner->where('type', intval($post['type']))
- ->where('id', 'not in', [55])
- ->withAttr('img_pic', function ($val, $data){
- return __HTTPIMG($val);
- })->select()->toArray();
- if ($post['type'] == 4){
- $list = [
- ['id'=>1234,'create_time'=>sr_getcurtime(time()),'type'=>4, 'img_pic'=>getWebUrl().'/static/img/inviteuser/invite18.jpg'.'?time='.time(),'banner_desc'=>'', 'title'=>'邀请好友1','delete_time'=>''],
- ];
- }
- RedisCache::set($cacheKey, $list, rand(5, 10));
- return api_succ_return(['msg'=>'成功', 'data'=>$list]);
- }
- /**
- * 获取文章列表
- * @param Request $request
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function articleList(Request $request){
- $post = $request->post();
- return api_succ_return(['msg'=>'成功', 'data'=> ArticleService::make()->getListByType(intval($post['type']))]);
- }
- /**
- * 上传文件
- * @param Request $request
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function uploadImg(Request $request)
- {
- $file = request() -> file('file');
- $type = $request->post('type');
- if ($file == null) {
- return api_error_return('未上传图片');
- }
- $temp = explode(".", $_FILES["file"]["name"]);
- $extension = end($temp);
- if(!in_array($extension, array("jpeg","jpg","png"))){
- return api_error_return('图片格式错误');
- }
- if (!in_array($type, ['avatar', 'message'])){
- return api_error_return('参数错误');
- }
- // 发布消息时
- if ($type == 'message'){
- $user_info = Db::name('user')->where('id', $request->uid)->find();
- if ($user_info['user_type'] != 99){
- return api_error_return('没有权限');
- }
- }
- // 保存处理图片
- $saveName = Filesystem::disk('avatar') -> putFile($type, $file, 'md5');
- $baseUrl = str_replace('\\', '', 'uploadimg/' . $saveName);
- return api_succ_return(['msg'=>'成功', 'data'=>['url'=>__HTTPIMG($baseUrl),'base_url'=> $baseUrl]]);
- }
- /**
- * 版本更新
- * @param Request $request
- * @return \think\Response
- */
- public function appVersionCheck(Request $request)
- {
- $curandroid = env('app.CUR_ANDROID_VERSION', '');
- $curios = env('app.CUR_IOS_VERSION', '');
- $curAndroidVersion = str_replace('.', '', $curandroid);
- $curAndroidVersion = dispRepair($curAndroidVersion, 4, '0', '0');
- $curIosVersion = str_replace('.', '', $curios);
- $curIosVersion = dispRepair($curIosVersion, 4, '0', '0');
- $app_sources = $request->param('app_sources');
- $app_version = $request->param('app_version');
- $app_version = str_replace('.', '', $app_version);
- $app_version = dispRepair($app_version, 4, '0', '0');
- $new_udpate = explode('|', env('app.CUR_ANDROID_VERSION_INFO'));
- $new_udpate_ios = explode('|', env('app.CUR_IOS_VERSION_INFO'));
- $androidupdateurl = env('app.API_WEB_URL').'/api/downapp';
- $iosupdateurl = env('app.API_WEB_URL').'/api/downapp';
- $isandroid_force = 1;
- $isios_force = 1;
- if ($app_sources == 'ios'){
- if ($curIosVersion > $app_version){
- return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>1, 'cur_version'=>$curios, 'update_msg'=>$new_udpate_ios, 'update_url'=>$iosupdateurl, 'is_force'=>$isios_force, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
- }else{
- return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>0, 'cur_version'=>$curios, 'update_msg'=>[], 'update_url'=>'', 'is_force'=>1, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
- }
- }
- if ($app_sources == 'android'){
- if ($curAndroidVersion > $app_version){
- return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>1, 'cur_version'=>$curandroid, 'update_msg'=>$new_udpate, 'update_url'=>$androidupdateurl, 'is_force'=>$isandroid_force, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
- }else{
- return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>0, 'cur_version'=>$curandroid, 'update_msg'=>[], 'update_url'=>'', 'is_force'=>1, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
- }
- }
- return api_error_return('错误');
- }
- /**
- * 用户等级信息
- * @param Request $request
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function userLevelDesc(Request $request){
- return api_succ_return(['msg'=>"成功", 'data'=> LevelSettingService::make()->getListData()]);
- }
- }
|