Commit 4c13de3c by 杨树贤

修改好友助力逻辑还有修复获取配置数量的bug

parent 9d5506b3
<?php
namespace App\Http\Controllers;
use App\Http\Filters\CheckInFilter;
use App\Models\Assist;
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 AssistsController extends Controller
{
public function store(Request $request, Assist $assist)
{
$exchangeId = $request->get('exchange_id');
$data = [
'user_id' => $request->user_id,
'add_time' => time(),
'exchange_id' => $exchangeId,
];
$canAdd = $assist->checkCanAddAssist($exchangeId);
if ($canAdd) {
$res = $assist->addAssist($data);
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(20, 5), '新增好友助力记录失败');
}
}
return $this->Export(0, 'ok');
}
}
\ 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 Assist extends Model
{
public $timestamps = false;
public function scopePage($query, $page = 1, $pageSize = 10)
{
return $query->offset(($page - 1) * $pageSize)->limit($pageSize);
}
public function scopeFilter($query, QueryFilter $filters)
{
return $filters->apply($query);
}
//添加助力记录
public function addAssist($data)
{
$result = DB::transaction(function () use ($data) {
$result = DB::table('assists')->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;
}
protected function checkCanAddIntegralBill()
{
//先从redis里面取出对应的好友助攻情况
}
//检查是否可以添加助力记录,目前的是最多两个好友助力
public function checkCanAddAssist($exchangeId)
{
}
}
\ No newline at end of file
......@@ -46,11 +46,8 @@ class ExchangeSetting extends Model
$result = $this->addExchangeSettingListToRedis();
if (!$result) {
ErrorLog(ErrorCode(19, 5), '写入商品配置列表到Redis失败');
$count = ExchangeSetting::where('status', 1)->count();
$settings = $this->getExchangeSettingsFromRedis();
}
} else {
$count = $redis->hlen('ic_welfare_integrals');
}
//如果需要过滤type
......@@ -59,6 +56,7 @@ class ExchangeSetting extends Model
return $value['type'] == $map['type'] ? true : false;
});
}
$count = count($settings);
if ($settings) {
$settings = arraySequence($settings, 'id', 'SORT_ASC');
}
......
<?php
namespace App\Tasks;
use App\Models\Integral;
use App\Models\IntegralBill;
use App\Models\UserIntegral;
use Common\Model\RedisModel;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class TestTask extends Task
{
private $data;
public function __construct()
{
}
public function handle()
{
Log::error('测试是否会消失');
}
public function finish()
{
}
}
\ 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