123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/8/19
- * Time: 2:23 PM
- */
- namespace App\Http\Controllers\V1;
- use App\Http\Requests\ApplyAddParkingRequest;
- use App\Http\Requests\HomePageRequest;
- use App\Models\ApplyParking;
- use App\Models\Area;
- use App\Models\Bike;
- use App\Models\CardRiding;
- use App\Models\Coupon;
- use App\Models\DepositOrder;
- use App\Models\InviteNewUsersConfig;
- use App\Models\InviteNewUsersGiveGiftLog;
- use App\Models\RechargeConfiguration;
- use App\Models\RefundLog;
- use App\Repositories\AreaRepository;
- use App\Repositories\CardRidingRepository;
- use App\Repositories\CouponRepository;
- use App\Repositories\InviteNewUsersConfigRepository;
- use App\Repositories\OrderRepository;
- use App\Repositories\RechargeConfigurationRepository;
- use App\Transformers\AreaTransformer;
- use App\Transformers\OrderRideStatusTransformer;
- use App\Transformers\RechargeConfigurationTransformer;
- use Dingo\Api\Http\Request;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class PageController extends BaseController
- {
- /**
- * 首页
- * User: Mead
- */
- public function home(HomePageRequest $request, AreaRepository $areaRepository)
- {
- $lat = (string)$request->get('lat');
- $lng = (string)$request->get('lng');
- $bike_no = (string)$request->get('bike_no', false);
- try {
- $area_id = 0;
- if ($bike_no) {
- $area_id = Bike::byBikeNoGetAreaId($bike_no);
- }
- $user = $this->user;
- if (!$area_id) {
- $options = ['SORT' => 'ASC', 'COUNT' => 1];
- $redis = Redis::connection();
- $area_ids = $redis->georadius(Area::REDIS_AREAS_LOCATION_TAG, $lng, $lat, 30, 'km', $options);
- if (count($area_ids) === 1) {
- $area_id = $area_ids[0];
- }
- if (!$area_id) {
- if ($user) {
- $area_id = $user->register_area_id;
- }
- }
- }
- if (!$area_id) {
- return $this->errorNoValidation('该附近暂无运营区域');
- }
- $area = $areaRepository->byIdGetModel($area_id);
- $area->load('setting');
- if ($user) {
- if (!$user->register_area_id) {
- $user->register_area_id = $area->id;
- $user->register_area = $area->name;
- $user->save();
- }
- }
- return $this->response->item($area, AreaTransformer::class);
- // // 查找最近区域
- // $options = ['SORT' => 'ASC', 'COUNT' => 1];
- // $redis = Redis::connection();
- // $area_ids = $redis->georadius(Area::REDIS_AREAS_LOCATION_TAG, $lng, $lat, 30, 'km', $options);
- // if (count($area_ids) === 1) {
- // $area = $areaRepository->byIdGetModel($area_ids[0]);
- // if (!$area) {
- // return $this->errorNoValidation('该附近暂无运营区域');
- // }
- // $area->load('setting');
- // return $this->response->item($area, AreaTransformer::class);
- // } else {
- // return $this->errorNoValidation('该附近暂无运营区域');
- // }
- } catch (\Exception $exception) {
- return $this->errorException($exception->getMessage());
- }
- }
- /**
- * 骑行订单
- * User: Mead
- */
- public function rideOrder(Request $request, OrderRepository $orderRepository)
- {
- $no = $request->get('no');
- try {
- $order = $orderRepository->byNo($no);
- if (!$order) {
- return $this->errorNoValidation('订单找不到');
- }
- return $this->response->item($order, OrderRideStatusTransformer::class);
- } catch (\Exception $exception) {
- return $this->errorException($exception->getMessage());
- }
- }
- /**
- * 充值页面
- * @param RechargeConfigurationRepository $configurationRepository
- */
- public function rechargePage(Request $request, RechargeConfigurationRepository $configurationRepository)
- {
- try {
- $area_id = $request->get('area_id', $this->user->register_area_id);
- $setting = $configurationRepository->byAreaIdGetActiveConfig($area_id);
- if (count($setting) === 0) {
- return $this->response->array(RechargeConfiguration::DEFAULT_CONFIG);
- }
- return $this->response->collection($setting->sortBy('recharge_money'), RechargeConfigurationTransformer::class);
- } catch (\Exception $e) {
- return $this->errorNoValidation($e->getMessage());
- }
- }
- /**
- * 邀请新用户活动列表 inviteNewusersConfigs
- *
- * @param InviteNewUsersConfigRepository $inviteNewUsersConfigRepository
- * @return \Dingo\Api\Http\Response|void
- * @author Fx
- *
- */
- public function inviteNewusersConfigs(InviteNewUsersConfigRepository $inviteNewUsersConfigRepository, CouponRepository $couponRepository, CardRidingRepository $cardRidingRepository)
- {
- try {
- $area_id = $this->user->register_area_id;
- $inviteConfigs = $inviteNewUsersConfigRepository->getInviteNewUsersConfigByAreaId($area_id);
- if (empty($inviteConfigs)) return $this->response->array([]);
- $dynamic_item = $inviteConfigs->dynamic_item;
- if (count($dynamic_item) == 0) return $this->response->array([]);
- foreach ($dynamic_item as &$v) {
- if ($v['give_type'] == InviteNewUsersGiveGiftLog::GIFT_TYPE_BALANCE) {
- $v['gift_name'] = '赠送余额';
- $v['gift_id'] = $v['balance']; // id就是钱
- $v['gift_num'] = $v['balance']; // 数量就是钱
- } elseif ($v['give_type'] == InviteNewUsersGiveGiftLog::GIFT_TYPE_COUPON) {
- $coupon = $couponRepository->byIdGetModel($v['coupon_id']);
- if (empty($coupon)) {
- unset($v);
- } else {
- $v['gift_name'] = $coupon->title;
- $v['gift_id'] = $v['coupon_id'];
- $v['gift_num'] = $v['coupon_num'];
- $v['gift_detail'] = $coupon;
- }
- } elseif ($v['give_type'] == InviteNewUsersGiveGiftLog::GIFT_TYPE_CARD) {
- $card = $cardRidingRepository->byIdGetModel($v['card_id']);
- if (empty($card)) {
- unset($v);
- } else {
- $v['gift_name'] = $card->name;
- $v['gift_id'] = $v['card_id'];
- $v['gift_num'] = 1; // 骑行卡 默认一张
- $v['gift_detail'] = $card;
- }
- } else {
- unset($v);
- }
- }
- if (count($dynamic_item) == 0) return $this->response->array([]);
- $inviteConfigs->dynamic_item = $dynamic_item;
- $inviteConfigs->condition = InviteNewUsersConfig::$conditionMaps[$inviteConfigs->condition];
- return $this->response->array($inviteConfigs->toArray());
- } catch (\Exception $e) {
- return $this->errorNoValidation($e->getMessage());
- }
- }
- /**
- * 申请还车点
- * @param ApplyAddParkingRequest $request
- * @return \Dingo\Api\Http\Response|void
- * Author: Mead
- */
- public function applyAddParking(ApplyAddParkingRequest $request)
- {
- try {
- $data = [
- 'location_name' => $request->get('location_name'),
- 'longitude' => $request->get('longitude'),
- 'latitude' => $request->get('latitude'),
- 'area_id' => $request->get('area_id'),
- 'user_id' => $this->user->id,
- ];
- ApplyParking::query()->create($data);
- return $this->response->array([
- 'status' => 'OK'
- ]);
- } catch (\Exception $e) {
- return $this->errorNoValidation($e->getMessage());
- }
- }
- /**
- * 退款状态
- * @return \Dingo\Api\Http\Response|void
- * Author: Mead
- */
- public function userDepositStatus()
- {
- try {
- $order = DepositOrder::where('user_id', $this->user->id)->where('pay_status', DepositOrder::PAY_STATUS_OK)->where('is_refund', DepositOrder::REFUND_NO)->orderBy('id', 'desc')->first();
- if (!$order) {
- return $this->response()->array([
- 'type' => 1,
- 'msg' => '未缴纳',
- ]);
- }
- $refundLog = RefundLog::where('deposit_id', $order->id)->first();
- if (!$refundLog) {
- return $this->response()->array([
- 'type' => 4,
- 'msg' => '申请退押金',
- 'money' => $order->pay_money
- ]);
- }
- $pay_status = (int)$refundLog->pay_status;
- if ($pay_status === RefundLog::PAY_STATUS_WAIT) {
- return $this->response()->array([
- 'type' => 3,
- 'msg' => '退款排队中',
- ]);
- }
- if ($pay_status === RefundLog::PAY_STATUS_NO) {
- return $this->response()->array([
- 'type' => 0,
- 'msg' => '退款中',
- ]);
- }
- if ($pay_status === RefundLog::PAY_STATUS_ERROR) {
- return $this->response()->array([
- 'type' => 2,
- 'msg' => $refundLog->result,
- ]);
- }
- if ($pay_status === RefundLog::PAY_STATUS_OK) {
- return $this->response()->array([
- 'type' => 1,
- 'msg' => '已退款',
- ]);
- }
- } catch (\Exception $e) {
- return $this->errorNoValidation($e->getMessage());
- }
- }
- }
|