Commit 6ed355a5 by 杨树贤

Merge branch 'ysx-ic助手服务开发-20190824'

parents cf84c92e 558cef37
<?php
namespace App\Http\Controllers;
use App\Http\Filters\CheckInFilter;
use App\Models\CheckIn;
use App\Models\ExchangeSetting;
use App\Models\Integral;
use App\Models\UserIntegral;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CheckInController extends Controller
{
public function index(Request $request, CheckIn $checkIn, CheckInFilter $filter)
{
$page = $request->get('page') ? $request->page : self::DEFAULT_PAGE;
$pageSize = $request->get('page_size') ? $request->page_size : self::DEFAULT_PAGE_SIZE;
$checkIns = $checkIn->getCheckInList($page, $pageSize, $filter);
return $this->Export(0, 'ok', $checkIns);
}
public function store(Request $request, CheckIn $checkIn, Integral $integral)
{
$data = [
'user_id' => $request->user_id,
'add_time' => time(),
];
$canCheckIn = $integral->checkIntegralLimit($data['user_id'], Integral::INTEGRAL_TYPE_CHECK_IN);
if ($canCheckIn) {
$res = $checkIn->addCheckIn($data);
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(18, 5), '新增签到记录失败');
}
}
return $this->Export(0, 'ok');
}
}
\ No newline at end of file
......@@ -3,9 +3,7 @@
namespace App\Http\Controllers;
use App\Http\Filters\CheckInFilter;
use App\Http\Filters\CodeFilter;
use App\Models\CheckIn;
use App\Models\Code;
use App\Models\Integral;
use App\Tasks\SendNoticeTask;
......
......@@ -45,7 +45,7 @@ class Controller extends BaseController
const AUDIT_USER_EXCHANGE_FAIL = 16;
//审核批量拒绝兑换失败
const BATCH_AUDIT_REJECT_USER_EXCHANGE = 17;
//新增签到记录失败
//新增签到记录失败(废弃字段)
const ADD_CHECK_IN_FAIL = 18;
//新增邀请好友记录失败
const ADD_INVITE_FAIL = 19;
......
<?php
namespace App\Http\Filters;
class CheckInFilter extends QueryFilter
{
public function user_id($userId = 0)
{
return $this->builder->where('user_id', $userId);
}
public function add_time($addTime = '')
{
$addTime = explode('~', urldecode($addTime));
foreach ($addTime as $key=>$value) {
$addTime[$key] = strtotime($value);
}
return $this->builder->whereBetween('add_time',$addTime);
}
}
\ No newline at end of file
<?php
namespace App\Models;
use App\Http\Filters\QueryFilter;
use App\Tasks\IntegralBillTask;
use Common\Model\RedisModel;
use Carbon\Carbon;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class CheckIn extends Model
{
protected $table = 'check_in';
public $timestamps = false;
public function scopePage($query, $page = 1, $pageSize = 10)
{
$pageSize = $pageSize < 50 ? $pageSize : 50;
return $query->offset(($page - 1) * $pageSize)->limit($pageSize);
}
public function scopeFilter($query, QueryFilter $filters)
{
return $filters->apply($query);
}
//获取签到记录
public function getCheckInList($page, $pageSize, $filter)
{
$checkIns = CheckIn::filter($filter)->page($page, $pageSize)
->orderBy('id', 'desc')->get()->toArray();
$count = CheckIn::filter($filter)->count();
return ['data' => $checkIns, 'count' => $count];
}
//添加签到记录
public function addCheckIn($data)
{
$result = DB::transaction(function () use ($data) {
$result = DB::table('check_in')->insert($data);
if (!$result) {
return false;
}
//使用异步任务去添加流水
$integralBill = new IntegralBill();
$data['integral_id'] = Integral::INTEGRAL_TYPE_CHECK_IN;
$result = $integralBill->createIntegralBill($data);
if (!$result) {
return false;
}
return true;
});
return $result;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment