Fragment.php 15 KB

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