123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- namespace App\Http\Controllers\Share;
- use App\Exceptions\ApiException;
- use App\Models\Share\RedpackListModel;
- use App\Services\Share\RedpackService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Core\Auth;
- use App\Http\Controllers\Controller;
- class RedpackController extends Controller
- {
- /**
- * 最近10个成功的气泡
- */
- public function bannerlist()
- {
- $rs = new RedpackService();
- $data = $rs->bannerlist();
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 某人正在进行的现金红包
- */
- public function ingredpack()
- {
- $uid = Auth::auth();
- $redpackService = new RedpackService();
- $data = $redpackService->ingredpack($uid);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 获取红包信息
- * @param int $list_id
- * @return array
- */
- public function get(int $list_id)
- {
- $rs = new RedpackService();
- $data = $rs->get($list_id);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 检验助力现金红包
- * @param int $list_id
- * @return array
- * @throws \Throwable
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function check(int $list_id)
- {
- $uid = Auth::auth();
- $rs = new RedpackService();
- $data = $rs->pcheck($uid, $list_id);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- public function succlist(Request $request)
- {
- $uid = Auth::auth();
- $page = $request->get('page') ?? 1;
- $pages = array(
- 'limit' => 20,
- 'page' => $page
- );
- $rs = new RedpackService();
- $data = $rs->susslist($uid, $pages);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- public function faillist(Request $request)
- {
- $uid = Auth::auth();
- $page = $request->get('page') ?? 1;
- $pages = array(
- 'limit' => 20,
- 'page' => $page
- );
- $rs = new RedpackService();
- $data = $rs->faillist($uid, $pages);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 创建现金红包
- */
- public function store()
- {
- $uid = Auth::auth();
- $listModel = new RedpackListModel();
- $data = $listModel->where([
- ['uid', $uid],
- ['expired_at', '>', time()],
- ['is_withdraw', 0]
- ])->OrWhere([
- ['uid', $uid],
- ['completeness', '>=', 100],
- ['is_withdraw', 0]
- ])->first();
- if (collect($data)->isEmpty()) {
- $rs = new RedpackService();
- $data = $rs->store($uid);
- $data['get_fee'] = (string)sprintf('%.2f', $data['fee'] * $data['completeness'] / 100);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- } else {
- $data['get_fee'] = (string)sprintf('%.2f', $data['fee'] * $data['completeness'] / 100);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- }
- /**
- * 切换通知
- * @param int $list_id
- * @return array
- * @throws ApiException
- * @throws \App\Exceptions\AlertException
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function notice(int $list_id)
- {
- $uid = Auth::auth();
- $rs = new RedpackService();
- if ($rs->notice($uid, $list_id)) {
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- } else {
- throw new ApiException("系统异常", 500);
- }
- }
- /**
- * 现金红包提现
- * @param int $list_id
- * @return array
- * @throws \App\Exceptions\AlertException
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function withdraw(int $list_id)
- {
- $uid = Auth::auth();
- $rs = new RedpackService();
- $rs->withdraw($uid, $list_id);
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- }
- }
|