Fragment.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\common\model\NumRecordModel;
  4. use app\common\model\SystemBannerModel;
  5. use app\common\model\UserModel;
  6. use app\common\service\ArticleService;
  7. use app\common\service\LevelSettingService;
  8. use app\common\service\SystemConfigService;
  9. use app\Request;
  10. use app\api\services\RequestUtilService;
  11. use Minho\Captcha\CaptchaBuilder;
  12. use services\CacheServices;
  13. use think\Exception;
  14. use think\facade\Db;
  15. use think\facade\Filesystem;
  16. use utils\RedisCache;
  17. /**
  18. * 公共接口 by wes
  19. * Class Fragment
  20. * @package app\api\controller\v1
  21. */
  22. class Fragment
  23. {
  24. /**
  25. * 格式化
  26. * @param Request $request
  27. * @return \think\Response
  28. */
  29. public function balanceInArr(Request $request){
  30. $data = explode('|', env('APP.BALANCE_IN_SETTING'));
  31. return api_succ_return(['msg'=>'成功', 'data'=>$data]);
  32. }
  33. /**
  34. * 获取app配置
  35. * @param Request $request
  36. * @return \think\Response
  37. */
  38. public function appConfig(Request $request){
  39. $cacheKey = "caches:config:app";
  40. $data = RedisCache::get($cacheKey);
  41. if($data){
  42. return api_succ_return(['msg'=>'成功', 'data'=>$data]);
  43. }
  44. $time = time();
  45. $webUrl = getWebUrl();
  46. $withdrawFee = (int)SystemConfigService::make()->getConfigByName('withdraw_service_rate',1,'withdraw');
  47. $withdrawMax = (int)SystemConfigService::make()->getConfigByName('withdraw_max_money',1,'withdraw');
  48. $data = [
  49. // 地址
  50. 'privateInfo'=> $webUrl.'/api/privateInfo',
  51. 'userAgreementInfo'=> $webUrl.'/api/userAgreementInfo',
  52. 'helpCenter'=> $webUrl.'/api/helpCenter',
  53. 'aboutUs'=> $webUrl.'/api/aboutUs',
  54. 'chat_url'=> env('APP.CHAT_URL_CONFIG'),
  55. 'about_us'=> env('APP.ABOUT_US'),
  56. //福袋参数
  57. 'box'=> [
  58. 'is_apply'=> (int)SystemConfigService::make()->getConfigByName('fudai_is_apply',1,'fudai'),
  59. 'is_retrieve'=> (int)SystemConfigService::make()->getConfigByName('is_retrieve',1,'fudai')
  60. ],
  61. 'newhand_url'=> $webUrl.'/api/newhandurl',
  62. 'newguide_url'=> $webUrl.'/api/newguideurl',
  63. 'aboutbox_url'=> $webUrl.'/api/aboutboxurl',
  64. 'one_box_price'=> env('boxsetting.ONE_BOX_PRICE'),
  65. 'box_musicurl'=> $webUrl.'/static/resources/'.'box_open.mp3',
  66. 'box_desc' => [
  67. ['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],
  68. ['title'=>'稀有','pic'=>$webUrl.'/'.'static/img/box/box_pic20.png', 's_pic'=>$webUrl.'/'.'static/img/box/box_pic20_small.png','prob'=>'30%', 'box_type'=>20],
  69. ['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],
  70. ['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],
  71. ],
  72. 'services_desc'=> [
  73. '购买一次服务商有效期30天,到期后需再次手动续费。'
  74. ],
  75. 'bbox_desc'=> [
  76. [
  77. 'title'=>'一袋豪物',
  78. 'count'=>1
  79. ],
  80. [
  81. 'title'=>'幸运5连',
  82. 'count'=>5
  83. ],
  84. [
  85. 'title'=>'豪气10连',
  86. 'count'=>10
  87. ],
  88. [
  89. 'title'=>'超凡二十联',
  90. 'count'=>20
  91. ]
  92. ],
  93. // 广告参数
  94. 'adsetting'=> [
  95. 'android'=>[
  96. 'appkey'=>env('LINGYE.ANDROID_APPKEY'),
  97. 'jiliid'=>env('LINGYE.ANDROID_JILIID'),
  98. 'kaipinid'=>env('LINGYE.ANDROID_KAIPINGID'),
  99. 'chapinid'=>env('LINGYE.ANDROID_CHAPINID'),
  100. ],
  101. 'ios'=>[
  102. 'appkey'=>env('LINGYE.IOS_APPKEY'),
  103. 'jiliid'=>env('LINGYE.IOS_JILIID'),
  104. 'kaipinid'=>env('LINGYE.IOS_KAIPINGID'),
  105. 'chapinid'=>env('LINGYE.IOS_CHAPINID')
  106. ]
  107. ],
  108. // 其他配置参数
  109. 'widthdraw'=> [
  110. 'scale'=>env('WITHDRAW.APP_WITHDRAW_SCALE'),
  111. 'begin'=>env('WITHDRAW.APP_WITHDRAW_BEGIN'),
  112. 'withdraw_is_open'=> (int)SystemConfigService::make()->getConfigByName('withdraw_is_open',1,'withdraw'),
  113. 'service_rate'=> $withdrawFee,
  114. 'desc'=>[
  115. '本次提现将收取'.$withdrawFee.'%手续费',
  116. '提现到账时间16:00前提现24:00前到账,16:00后提现次日到账',
  117. '提现申请金额必须是10的整数倍',
  118. "提现金额单笔不能超过{$withdrawMax},提现大于5千只能使用银行卡"
  119. ]
  120. ],
  121. 'jh_excharge'=> [
  122. 'desc'=>[
  123. '转赠不收取任何手续费',
  124. '请确定对方信息后在输入安全密码,由于用户自己原因导致错误转赠,平台概不负责'
  125. ]
  126. ],
  127. 'agent'=> [
  128. 'privince_agent'=>[
  129. 'http://downyjh.meikangjw.com/mlh/agent/p_agent1.png?time='.$time,
  130. 'http://downyjh.meikangjw.com/mlh/agent/p_agent2.png?time='.$time,
  131. 'http://downyjh.meikangjw.com/mlh/agent/p_agent3.png?time='.$time
  132. ],
  133. 'city_agent'=>[
  134. 'http://downyjh.meikangjw.com/mlh/agent/c_agent1.png?time='.$time,
  135. 'http://downyjh.meikangjw.com/mlh/agent/c_agent2.png?time='.$time,
  136. 'http://downyjh.meikangjw.com/mlh/agent/c_agent3.png?time='.$time
  137. ],
  138. 'p_agent_price'=>'175000|25000',
  139. 'c_agent_price'=>'56000|8000',
  140. ],
  141. 'version'=> env('APP.VERSION')
  142. ];
  143. RedisCache::set($cacheKey, $data, rand(300, 600));
  144. return api_succ_return(['msg'=>'成功', 'data'=>$data]);
  145. }
  146. /**
  147. * 获取图形验证码
  148. * @return \think\Response
  149. */
  150. public function getVerifyCode()
  151. {
  152. $captch = new CaptchaBuilder();
  153. $captch->initialize([
  154. 'width' => 100, // 宽度
  155. 'height' => 40, // 高度
  156. 'line' => true, // 直线
  157. 'curve' => false, // 曲线
  158. 'fontSize'=>25, // 验证码字体
  159. 'noise' => 0, // 噪点背景
  160. 'fonts' => [] // 字体
  161. ]);
  162. $captch->create();
  163. $uuid = uniqid();
  164. //生成并返回图片流base64编码
  165. ob_start ();
  166. $captch->output(1);
  167. $captchaCode = $captch->getText();
  168. $image_data = ob_get_contents ();
  169. ob_end_clean ();
  170. $captchaDataUrl = AESjiami(base64_encode ($image_data));
  171. $array = ['captchaDataUrl' => $captchaDataUrl,'captcha_uuid' => $uuid];
  172. CacheServices::set('catch'.$uuid, $captchaCode, 900);
  173. return api_succ_return(['msg'=>'成功', 'data'=>$array]);
  174. }
  175. /**
  176. * 发送短信验证码
  177. * @param Request $request
  178. * @return \think\Response
  179. * @throws \think\db\exception\DataNotFoundException
  180. * @throws \think\db\exception\DbException
  181. * @throws \think\db\exception\ModelNotFoundException
  182. */
  183. public function sendSmsCode(Request $request)
  184. {
  185. $type = $request->param('type');
  186. $mobile = $request->param('mobile');
  187. $app_sources = $request->param('app_sources');
  188. if (!is_numeric($mobile) || strlen($mobile)!=11){
  189. return api_error_return('手机号码错误');
  190. }
  191. if (!$type || !in_array($type, ['register', 'editpass', 'securitypass', 'loingcheck'])){
  192. return api_error_return('类型错误');
  193. }
  194. $send_user = UserModel::where(['mobile'=>$mobile])->find();
  195. if (in_array($type, ['editpass', 'securitypass', 'loingcheck']) && !$send_user){
  196. return api_error_return('该手机号码未注册');
  197. }
  198. if ($type == 'register' && $send_user){
  199. return api_error_return('该手机号码已注册,请直接登录');
  200. }
  201. $m = new NumRecordModel();
  202. if ($send_user){
  203. $user_count = $m->whereDay('create_time', 'today')->where('uid', $send_user['id'])->count();
  204. if ($user_count > 5){
  205. return api_error_return('发送失败,超过单日用户单日最大发送短信');
  206. }
  207. }
  208. Db::startTrans();
  209. try {
  210. $code = rand(100000,999999);
  211. $ser_request = new RequestUtilService();
  212. $result = $ser_request->reqeustSmsCode($mobile, $code);
  213. if ($result == 0){
  214. $data = [
  215. 'type'=>$type,
  216. 'content'=>$code,
  217. 'isfrom'=>$app_sources,
  218. 'phone'=>$mobile,
  219. 'uid'=>$send_user?$send_user['id']:0,
  220. 'create_time'=>sr_getcurtime(time()),
  221. 'ip'=> get_client_ip()
  222. ];
  223. $m->insert($data);
  224. }else{
  225. throw new Exception('');
  226. }
  227. Db::commit();
  228. return api_succ_return('发送成功');
  229. }catch (\Exception $e){
  230. Db::rollback();
  231. return api_error_return('发送失败'.$e->getMessage());
  232. }
  233. }
  234. /**
  235. * 获取轮播图广告
  236. * @param Request $request
  237. * @return \think\Response
  238. * @throws \think\db\exception\DataNotFoundException
  239. * @throws \think\db\exception\DbException
  240. * @throws \think\db\exception\ModelNotFoundException
  241. */
  242. public function getAppBanner(Request $request){
  243. $post = $request->post();
  244. if (!in_array($post['type'], [1,2,3,4,5,6])){
  245. return api_succ_return('成功');
  246. }
  247. $cacheKey = "caches:banners:app";
  248. $data = RedisCache::get($cacheKey);
  249. if($data){
  250. return api_succ_return(['msg'=>'缓存数据', 'data'=>$data]);
  251. }
  252. $modelbanner = new SystemBannerModel();
  253. $list = $modelbanner->where('type', intval($post['type']))
  254. ->where('id', 'not in', [55])
  255. ->withAttr('img_pic', function ($val, $data){
  256. return __HTTPIMG($val);
  257. })->select()->toArray();
  258. if ($post['type'] == 4){
  259. $list = [
  260. ['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'=>''],
  261. ];
  262. }
  263. RedisCache::set($cacheKey, $list, rand(5, 10));
  264. return api_succ_return(['msg'=>'成功', 'data'=>$list]);
  265. }
  266. /**
  267. * 获取文章列表
  268. * @param Request $request
  269. * @return \think\Response
  270. * @throws \think\db\exception\DataNotFoundException
  271. * @throws \think\db\exception\DbException
  272. * @throws \think\db\exception\ModelNotFoundException
  273. */
  274. public function articleList(Request $request){
  275. $post = $request->post();
  276. return api_succ_return(['msg'=>'成功', 'data'=> ArticleService::make()->getListByType(intval($post['type']))]);
  277. }
  278. /**
  279. * 上传文件
  280. * @param Request $request
  281. * @return \think\Response
  282. * @throws \think\db\exception\DataNotFoundException
  283. * @throws \think\db\exception\DbException
  284. * @throws \think\db\exception\ModelNotFoundException
  285. */
  286. public function uploadImg(Request $request)
  287. {
  288. $file = request() -> file('file');
  289. $type = $request->post('type');
  290. if ($file == null) {
  291. return api_error_return('未上传图片');
  292. }
  293. $temp = explode(".", $_FILES["file"]["name"]);
  294. $extension = end($temp);
  295. if(!in_array($extension, array("jpeg","jpg","png"))){
  296. return api_error_return('图片格式错误');
  297. }
  298. if (!in_array($type, ['avatar', 'message'])){
  299. return api_error_return('参数错误');
  300. }
  301. // 发布消息时
  302. if ($type == 'message'){
  303. $user_info = Db::name('user')->where('id', $request->uid)->find();
  304. if ($user_info['user_type'] != 99){
  305. return api_error_return('没有权限');
  306. }
  307. }
  308. // 保存处理图片
  309. $saveName = Filesystem::disk('avatar') -> putFile($type, $file, 'md5');
  310. $baseUrl = str_replace('\\', '', 'uploadimg/' . $saveName);
  311. return api_succ_return(['msg'=>'成功', 'data'=>['url'=>__HTTPIMG($baseUrl),'base_url'=> $baseUrl]]);
  312. }
  313. /**
  314. * 版本更新
  315. * @param Request $request
  316. * @return \think\Response
  317. */
  318. public function appVersionCheck(Request $request)
  319. {
  320. $curandroid = env('app.CUR_ANDROID_VERSION', '');
  321. $curios = env('app.CUR_IOS_VERSION', '');
  322. $curAndroidVersion = str_replace('.', '', $curandroid);
  323. $curAndroidVersion = dispRepair($curAndroidVersion, 4, '0', '0');
  324. $curIosVersion = str_replace('.', '', $curios);
  325. $curIosVersion = dispRepair($curIosVersion, 4, '0', '0');
  326. $app_sources = $request->param('app_sources');
  327. $app_version = $request->param('app_version');
  328. $app_version = str_replace('.', '', $app_version);
  329. $app_version = dispRepair($app_version, 4, '0', '0');
  330. $new_udpate = explode('|', env('app.CUR_ANDROID_VERSION_INFO'));
  331. $new_udpate_ios = explode('|', env('app.CUR_IOS_VERSION_INFO'));
  332. $androidupdateurl = env('app.API_WEB_URL').'/api/downapp';
  333. $iosupdateurl = env('app.API_WEB_URL').'/api/downapp';
  334. $isandroid_force = 1;
  335. $isios_force = 1;
  336. if ($app_sources == 'ios' || $app_sources == 'macos'){
  337. if ($curIosVersion > $app_version){
  338. 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')]]);
  339. }else{
  340. 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')]]);
  341. }
  342. }
  343. if ($app_sources == 'android'){
  344. if ($curAndroidVersion > $app_version){
  345. 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')]]);
  346. }else{
  347. 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')]]);
  348. }
  349. }
  350. return api_error_return('错误');
  351. }
  352. /**
  353. * 用户等级信息
  354. * @param Request $request
  355. * @return \think\Response
  356. * @throws \think\db\exception\DataNotFoundException
  357. * @throws \think\db\exception\DbException
  358. * @throws \think\db\exception\ModelNotFoundException
  359. */
  360. public function userLevelDesc(Request $request){
  361. return api_succ_return(['msg'=>"成功", 'data'=> LevelSettingService::make()->getListData()]);
  362. }
  363. }