IndexController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Http\Controllers\V1;
  3. use App\Models\Config;
  4. use App\Models\Help;
  5. use App\Models\PaymentConfig;
  6. use App\Models\Region;
  7. use App\Models\TaskList;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Redis;
  10. class IndexController extends Controller
  11. {
  12. public function getServiceConfig()
  13. {
  14. $service_phone = Config::query()->where('key', 'service_phone')->first();
  15. $service_wx = Config::query()->where('key', 'service_wx')->first();
  16. $service_qrcode = Config::query()->where('key', 'service_qrcode')->first();
  17. $about = Config::query()->where('key', 'about')->first();
  18. $push_promotion = Config::query()->where('key', 'push_promotion')->first();
  19. return $this->success(['service_qrcode' => $service_qrcode,'service_phone' => $service_phone,'service_wx' => $service_wx,'about' => $about,'push' => $push_promotion]);
  20. }
  21. // 隐私政策
  22. public function privacyPolice()
  23. {
  24. $info = Config::query()->where('key', 'privacy')->first();
  25. return $this->success($info);
  26. }
  27. public function getConfigByKey(){
  28. $key = \request()->input('key','');
  29. $result = Config::query()->where('key', $key)->first();
  30. return $this->success($result);
  31. }
  32. // 用户协议
  33. public function userAgreement()
  34. {
  35. $info = Config::query()->where('key', 'agreement')->first();
  36. return $this->success($info);
  37. }
  38. // 用户协议
  39. public function payConfig()
  40. {
  41. $info = PaymentConfig::query()->where('state', 1)->orderByDesc('sort')->get();
  42. return $this->success($info);
  43. }
  44. /**
  45. * 获取精选.
  46. *
  47. * @return \Illuminate\Http\JsonResponse
  48. */
  49. public function getHandpick()
  50. {
  51. // $size = \request()->input('size',15);
  52. // var_dump($size);
  53. $result = TaskList::query()->where('is_handpick', 1)->orderByDesc('sort')->paginate();
  54. return $this->success($result);
  55. }
  56. // 帮助类型
  57. public function helpList()
  58. {
  59. $list = Help::query()->select('id', 'title')->get();
  60. if ($list->isEmpty()) {
  61. return [];
  62. }
  63. $list = $list->toArray();
  64. return $this->success($list);
  65. }
  66. // 帮助类答案
  67. public function answer(Request $request)
  68. {
  69. $info = Help::query()->where('id', $request->id)->first();
  70. $info->look_num = $info->look_num + 1;
  71. $info->save();
  72. return $this->success($info);
  73. }
  74. // 全国地区
  75. public function allRegion()
  76. {
  77. $regionList = Redis::get('all_region');
  78. if (!empty($regionList)) {
  79. return $this->success(json_decode($regionList, true));
  80. }
  81. $list = Region::query()
  82. ->where('type', 1)
  83. ->select('code', 'full_name')
  84. ->get()
  85. ->toArray();
  86. foreach ($list as $key => $val) {
  87. $cityList = Region::query()->where('parent_code', $val['code'])->select('code', 'full_name')->get()->toArray();
  88. foreach ($cityList as $k => $v) {
  89. $areaList = Region::query()->where('parent_code', $v['code'])->select('code', 'full_name')->get()->toArray();
  90. $v['area_list'] = $areaList;
  91. $cityList[$k] = $v;
  92. }
  93. $val['city_list'] = $cityList;
  94. $list[$key] = $val;
  95. }
  96. Redis::setex('all_region', 24 * 3600, json_encode($list));
  97. return $this->success($list);
  98. }
  99. }