Fragment.php 15 KB

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