<?php
|
|
namespace app\job\event;
|
|
use app\job\model\branch\Branch as BranchModel;
|
use think\facade\Cache;
|
use app\common\library\helper;
|
|
/**
|
* 分会事件管理
|
*/
|
class Branch
|
{
|
// 模型
|
private $model;
|
|
// 应用id
|
private $appId;
|
|
/**
|
* 执行函数
|
*/
|
public function handle($app_id)
|
{
|
try {
|
$this->appId = $app_id;
|
$this->model = new BranchModel();
|
// 执行已完成活动的结算
|
$this->settled();
|
// 未支付报名自动删除
|
$this->deleteActivityUser();
|
} catch (\Throwable $e) {
|
echo 'ERROR ORDER: ' . $e->getMessage() . PHP_EOL;
|
log_write('ORDER TASK : ' . $app_id . '__ ' . $e->getMessage(), 'task');
|
}
|
return true;
|
}
|
|
|
/**
|
* 未支付报名自动删除
|
*/
|
private function deleteActivityUser()
|
{
|
$key = "task_space__branch__activityUser__{$this->appId}";
|
if (Cache::has($key)) return true;
|
$orderIds = $this->model->getActivityUserIds($this->appId);
|
$this->model->deleteActivityUser($orderIds);
|
// 记录日志
|
$this->dologs('close', [
|
'orderIds' => json_encode($orderIds),
|
]);
|
Cache::set($key, time(), 8 * 3600);
|
return true;
|
}
|
|
/**
|
* 已完成活动结算
|
*/
|
private function settled()
|
{
|
$key = "task_space__branch__activity__{$this->appId}";
|
if (Cache::has($key)) return true;
|
// 查询活动列表
|
$activityList = $this->model->getActivitySettledList($this->appId);
|
// 活动id集
|
$activityIds = helper::getArrayColumn($activityList, 'activity_id');
|
$this->model->settledActivity($activityList);
|
// 记录日志
|
$this->dologs('settled', [
|
'activityIds' => json_encode($activityIds),
|
]);
|
Cache::set($key, time(), 1800);
|
return true;
|
}
|
|
/**
|
* 记录日志
|
*/
|
private function dologs($method, $params = [])
|
{
|
$value = 'behavior Branch-Activity --' . $method;
|
foreach ($params as $key => $val)
|
$value .= ' --' . $key . ' ' . $val;
|
return log_write($value, 'task');
|
}
|
|
}
|