feat(zy): 添加俱乐部功能和用户消息功能
- 新增俱乐部相关接口和功能,包括创建俱乐部、申请加入俱乐部、邀请加入俱乐部等 - 添加用户消息功能,包括发送消息、查看消息等 - 优化了部分代码结构,提高了可维护性 - 更新了文档,添加了新的接口说明
This commit is contained in:
@@ -16,7 +16,7 @@ class Command extends BaseCommand
|
||||
/**
|
||||
* 执行帮助命令
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
protected function execute(?Input $input, ?Output $output)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->output = $output;
|
||||
|
||||
@@ -42,7 +42,7 @@ class ShoproChat extends Command
|
||||
/**
|
||||
* 执行帮助命令
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
protected function execute(?Input $input, ?Output $output)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->output = $output;
|
||||
|
||||
@@ -9,6 +9,7 @@ use app\admin\model\shopro\user\User as UserModel;
|
||||
use app\admin\model\shopro\user\Coupon as UserCouponModel;
|
||||
use app\admin\model\shopro\order\Order as OrderModel;
|
||||
use app\admin\model\shopro\order\Aftersale as AftersaleModel;
|
||||
use app\admin\model\zy\link\Message;
|
||||
use app\admin\model\shopro\ThirdOauth;
|
||||
|
||||
class User extends Common
|
||||
@@ -92,7 +93,7 @@ class User extends Common
|
||||
{
|
||||
$user = auth_user();
|
||||
|
||||
$params = $this->request->only(['avatar', 'nickname', 'gender']);
|
||||
$params = $this->request->only(['avatar', 'nickname', 'mobile', 'gender', 'qq', 'wechat', 'years', 'bio']);
|
||||
$this->svalidate($params);
|
||||
|
||||
$user->save($params);
|
||||
@@ -147,7 +148,7 @@ class User extends Common
|
||||
}
|
||||
//如果已经有账号则直接登录
|
||||
$ret = $this->auth->direct($user->id);
|
||||
}else {
|
||||
} else {
|
||||
$this->error('该手机号暂未注册');
|
||||
}
|
||||
if (isset($ret) && $ret) {
|
||||
@@ -302,4 +303,32 @@ class User extends Common
|
||||
|
||||
$this->success('注销成功');
|
||||
}
|
||||
|
||||
|
||||
// 用户消息
|
||||
public function msg()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
|
||||
$model = Message::where('user_id', $this->auth->id);
|
||||
if (isset($params['type'])) {
|
||||
$model->where('type', $params['type']);
|
||||
}
|
||||
$res = $model->select();
|
||||
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
|
||||
// 消息读取
|
||||
public function msgRead()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$model = Message::get($params['msg_id'] ?? NULL);
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
$model->save(['status' => 1]); //已读
|
||||
|
||||
$this->success('Success', $model);
|
||||
}
|
||||
}
|
||||
|
||||
118
addons/shopro/controller/zy/Activity.php
Normal file
118
addons/shopro/controller/zy/Activity.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
use addons\shopro\library\RedisCache;
|
||||
use think\exception\ValidateException;
|
||||
use addons\shopro\service\order\OrderCreate;
|
||||
|
||||
|
||||
class Activity extends Base
|
||||
{
|
||||
|
||||
protected $noNeedLogin = ['test'];
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new \app\admin\model\zy\game\Activity;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$model = $this->model;
|
||||
if (isset($params['name'])) {
|
||||
$model->where('name', 'like', '%' . $params['name'] . '%');
|
||||
}
|
||||
if (isset($params['club_id'])) {
|
||||
$model->where('club_id', $params['club_id']);
|
||||
}
|
||||
if (isset($params['week'])) {
|
||||
$model->where('week', $params['week']);
|
||||
}
|
||||
if (isset($params['pid'])) {
|
||||
$model->where('pid', $params['pid']);
|
||||
} else {
|
||||
$model->where('pid', 0);
|
||||
}
|
||||
|
||||
$res = $model->select();
|
||||
foreach ($res as &$v) {
|
||||
$v['public_time'] = json_decode($v['public_time'] ?? '[]', true);
|
||||
$v['join_start_time'] = json_decode($v['join_start_time'] ?? '[]', true);
|
||||
$v['join_end_time'] = json_decode($v['join_end_time'] ?? '[]', true);
|
||||
$v['quit_time'] = json_decode($v['quit_time'] ?? '[]', true);
|
||||
$v['cost'] = json_decode($v['cost'] ?? '[]', true);
|
||||
$v['referee'] = explode(',', $v['referee']);
|
||||
}
|
||||
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
$model = $this->model->get($this->request->param('id'));
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
|
||||
$model['public_time'] = json_decode($model['public_time'] ?? '[]', true);
|
||||
$model['join_start_time'] = json_decode($model['join_start_time'] ?? '[]', true);
|
||||
$model['join_end_time'] = json_decode($model['join_end_time'] ?? '[]', true);
|
||||
$model['quit_time'] = json_decode($model['quit_time'] ?? '[]', true);
|
||||
$model['cost'] = json_decode($model['cost'] ?? '[]', true);
|
||||
$model['referee'] = explode(',', $model['referee']);
|
||||
|
||||
$this->success('Success', $model);
|
||||
}
|
||||
|
||||
// 启动周期性活动创建比赛任务
|
||||
public function test()
|
||||
{
|
||||
if (!\think\Cache::has('addons\shopro\job\Test@zy')) {
|
||||
$res = \think\Queue::push('\addons\shopro\job\Test@zy', time(), 'shopro');
|
||||
\think\Cache::set('addons\shopro\job\Test@zy', $res);
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
$this->success('Success', '任务已存在');
|
||||
}
|
||||
|
||||
// 比赛报名
|
||||
public function gameJoin()
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params = $this->request->param();
|
||||
$game = \app\admin\model\zy\game\Game::where('id', $params['act_id'] ?? NULL)
|
||||
->where('date', $params['date'] ?? NULL)->find();
|
||||
if (empty($game)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
|
||||
$this->svalidate($params, ".create");
|
||||
$orderCreate = new OrderCreate($params);
|
||||
$result = $orderCreate->calc('create');
|
||||
$order = $orderCreate->create($result);
|
||||
|
||||
$join = new \app\admin\model\zy\game\GameJoin;
|
||||
$join->allowField(true)->save([
|
||||
'act_id' => $game['act_id'],
|
||||
'game_id' => $game['id'],
|
||||
'user_id' => $this->auth->id,
|
||||
'orer_id' => $order['order_sn'],
|
||||
'status' => 1,
|
||||
'users' => json_encode($params['users'] ?? [])
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage(), $e);
|
||||
}
|
||||
$this->success('Success', $join);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,18 @@ use think\exception\ValidateException;
|
||||
|
||||
class Base extends Common
|
||||
{
|
||||
protected $noNeedLogin = [];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $model;
|
||||
protected $user;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->user = auth_user();
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
@@ -21,7 +32,7 @@ class Base extends Common
|
||||
$res = $this->model->select();
|
||||
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
|
||||
public function add()
|
||||
@@ -39,7 +50,7 @@ class Base extends Common
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success();
|
||||
$this->success('Success');
|
||||
}
|
||||
|
||||
public function update()
|
||||
@@ -61,7 +72,7 @@ class Base extends Common
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success();
|
||||
$this->success('Success');
|
||||
}
|
||||
|
||||
public function view()
|
||||
@@ -70,6 +81,6 @@ class Base extends Common
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
$this->success($model);
|
||||
$this->success('Success', $model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use app\admin\model\User;
|
||||
use app\admin\model\zy\Menber;
|
||||
use think\exception\PDOException;
|
||||
use app\admin\model\zy\link\Apply;
|
||||
use app\admin\model\zy\link\Message;
|
||||
use app\admin\model\zy\game\Activity;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class Club extends Base
|
||||
{
|
||||
|
||||
// protected $noNeedLogin = ['index'];
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new \app\admin\model\zy\Club;
|
||||
@@ -25,6 +29,223 @@ class Club extends Base
|
||||
}
|
||||
$res = $model->select();
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$result = false;
|
||||
$params = $this->request->param();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params['president'] = $this->user->id;
|
||||
$result = $this->model->allowField(true)->save($params);
|
||||
$menber = new Menber;
|
||||
$menber->allowField(true)->save([
|
||||
'club_id' => $this->model->id,
|
||||
'user_id' => $this->user->id,
|
||||
'role' => 3
|
||||
]);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success('Success', $result);
|
||||
}
|
||||
|
||||
// 获取俱乐部成员
|
||||
public function menber()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$query = Db::table(Menber::$tableName)->alias('m')
|
||||
->join([User::$tableName => 'u'], 'u.id = m.user_id')
|
||||
->field('m.*,u.avatar,u.gender,u.nickname');
|
||||
if (empty($params['id'])) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
$query->where('club_id', $params['id']);
|
||||
if (isset($params['role'])) {
|
||||
$query->where('role', 'IN', explode(',', $params['role']));
|
||||
} else {
|
||||
$query->where('role', '>', 0);
|
||||
}
|
||||
$res = $query->select();
|
||||
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
|
||||
// 获取俱乐部活动
|
||||
public function activity()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$query = Db::table(Activity::$tableName)
|
||||
->where('pid', 0) //主活动
|
||||
->field('');
|
||||
if (isset($params['club_id'])) {
|
||||
$query->where('club_id', $params['club_id']);
|
||||
}
|
||||
if (isset($params['week'])) {
|
||||
$query->where('week', $params['week']);
|
||||
}
|
||||
$res = $query->select();
|
||||
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
|
||||
// 申请加入俱乐部
|
||||
public function apply()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$club = $this->model->get($params['club_id']);
|
||||
if (empty($club)) {
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
if ($club['join_type'] > 1) {
|
||||
$this->error('该俱乐部不允许申请');
|
||||
}
|
||||
if (!empty(Menber::get(['club_id' => $params['club_id'], 'user_id' => $this->user->id]))) {
|
||||
$this->error('您已经是俱乐部成员,无需重复申请');
|
||||
}
|
||||
if ($club['join_type'] == 0) {
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $params['club_id'],
|
||||
'user_id' => $this->user->id,
|
||||
'role' => 1
|
||||
]);
|
||||
$this->success('加入成功');
|
||||
}
|
||||
(new Apply)->allowField(true)->save([ // 记录申请
|
||||
'type' => 1,
|
||||
'user_id' => $this->user->id,
|
||||
'target_id' => $params['club_id'],
|
||||
'content' => json_encode(['reason' => $params['reason'] ?? '']),
|
||||
'reason' => $params['reason'],
|
||||
'status' => 1
|
||||
]);
|
||||
(new Message())->allowField(true)->save([ // 消息通知
|
||||
'type' => 3,
|
||||
'name' => $club->name,
|
||||
'avatar' => $club->logo,
|
||||
'from_id' => $this->user->id,
|
||||
'target_id' => $params['club_id'],
|
||||
'content' => json_encode([
|
||||
'topic' => '俱乐部加入申请',
|
||||
'俱乐部名称' => $club->name,
|
||||
'申请人' => $this->user->nickname,
|
||||
'申请时间' => date('Y-m-d H:i:s'),
|
||||
'reason' => $params['reason'] ?? ''
|
||||
])
|
||||
]);
|
||||
$this->success('已申请,请等候审核');
|
||||
}
|
||||
//join_type 0:'开放加入,无需审核',1:'开放申请,审核加入',2:'会员邀请,无需审核',3:'会员邀请,审核加入',4:'仅管理员邀请,无需审核'
|
||||
|
||||
// 邀请加入俱乐部
|
||||
public function invite()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$club = $this->model->get($params['club_id']);
|
||||
if (empty($club)) {
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
$menber = Menber::where('club_id', $params['club_id'])
|
||||
->where('user_id', $this->user->id)
|
||||
->where('role', '>', 0)->find();
|
||||
if (empty($menber)) {
|
||||
$this->error('您无权邀请加入俱乐部');
|
||||
}
|
||||
$user = User::get($params['user_id']);
|
||||
if (empty($user)) {
|
||||
return $this->error('用户不存在');
|
||||
}
|
||||
if ($menber['role'] > 1 || $club['join_type'] == 0 || $club['join_type'] == 2) { // 管理员或者开放加入
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $club->id,
|
||||
'user_id' => $user->id,
|
||||
'role' => 1
|
||||
]);
|
||||
$this->success('邀请加入成功');
|
||||
}
|
||||
(new Apply)->allowField(true)->save([ // 记录申请
|
||||
'type' => 1,
|
||||
'user_id' => $user->id,
|
||||
'target_id' => $club->id,
|
||||
'content' => json_encode(['reason' => $params['reason'] ?? '']),
|
||||
'reason' => $params['reason'],
|
||||
'status' => 1
|
||||
]);
|
||||
(new Message())->allowField(true)->save([ // 消息通知
|
||||
'type' => 3,
|
||||
'name' => $club->name,
|
||||
'avatar' => $club->logo,
|
||||
'from_id' => $this->user->id,
|
||||
'target_id' => $params['club_id'],
|
||||
'content' => json_encode([
|
||||
'topic' => '俱乐部加入申请',
|
||||
'俱乐部名称' => $club->name,
|
||||
'申请人' => $this->user->nickname,
|
||||
'申请时间' => date('Y-m-d H:i:s'),
|
||||
'reason' => $params['reason'] ?? ''
|
||||
])
|
||||
]);
|
||||
$this->success('已邀请,请等候审核');
|
||||
}
|
||||
|
||||
// 获取申请列表
|
||||
public function applyList()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$club = $this->model->get($params['club_id']);
|
||||
if (empty($club)) {
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
$menber = Menber::where('club_id', $params['club_id'])
|
||||
->where('user_id', $this->user->id)
|
||||
->where('role', '>', 1)->find();
|
||||
if (empty($menber)) {
|
||||
$this->error('您无权处理申请');
|
||||
}
|
||||
$query = Apply::where('type', 1)->where('target_id', $params['club_id']);
|
||||
if (isset($params['status'])) {
|
||||
$query->where('status', $params['status']);
|
||||
}
|
||||
$applyList = $query->select();
|
||||
$this->success('Success', $applyList);
|
||||
}
|
||||
|
||||
// 处理申请
|
||||
public function handle()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$apply = Apply::get($params['apply_id']);
|
||||
$menber = Menber::where('club_id', $apply['target_id'])
|
||||
->where('user_id', $this->user->id)
|
||||
->where('role', '>', 1)->find();
|
||||
if (empty($menber)) {
|
||||
$this->error('您无权处理申请');
|
||||
}
|
||||
if (empty($apply)) {
|
||||
return $this->error('申请记录不存在');
|
||||
}
|
||||
if ($apply['status'] != 1) {
|
||||
return $this->error('该申请已处理');
|
||||
}
|
||||
if ($params['status'] == 2) {
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $apply['target_id'],
|
||||
'user_id' => $apply['user_id'],
|
||||
'role' => 1
|
||||
]);
|
||||
}
|
||||
$apply->save([
|
||||
'status' => $params['status'],
|
||||
'reply' => $params['reply'] ?? ''
|
||||
]);
|
||||
|
||||
$this->success('处理成功');
|
||||
}
|
||||
}
|
||||
|
||||
60
addons/shopro/controller/zy/Game.php
Normal file
60
addons/shopro/controller/zy/Game.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
|
||||
class Game extends Base
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new \app\admin\model\zy\game\Game;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$model = $this->model;
|
||||
if (isset($params['name'])) {
|
||||
$model->where('name', 'like', '%' . $params['name'] . '%');
|
||||
}
|
||||
if (isset($params['club_id'])) {
|
||||
$model->where('club_id', $params['club_id']);
|
||||
}
|
||||
if (isset($params['week'])) {
|
||||
$model->where('week', $params['week']);
|
||||
}
|
||||
if (isset($params['pid'])) {
|
||||
$model->where('pid', $params['pid']);
|
||||
} else {
|
||||
$model->where('pid', 0);
|
||||
}
|
||||
if (isset($params['public_time'])) {
|
||||
$model->where('public_time', $params['public_time']);
|
||||
} else {
|
||||
$model->where('public_time', '<=', date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
$res = $model->select();
|
||||
foreach ($res as &$v) {
|
||||
|
||||
$v['cost'] = json_decode($v['cost'] ?? '[]', true);
|
||||
$v['referee'] = explode(',', $v['referee']);
|
||||
}
|
||||
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
$model = $this->model->get($this->request->param('id'));
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
|
||||
$model['cost'] = json_decode($model['cost'] ?? '[]', true);
|
||||
$model['referee'] = explode(',', $model['referee']);
|
||||
|
||||
$this->success('Success', $model);
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,6 @@ namespace addons\shopro\controller\zy;
|
||||
class Gym extends Base
|
||||
{
|
||||
|
||||
// protected $noNeedLogin = ['index'];
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new \app\admin\model\zy\Stadium;
|
||||
@@ -27,6 +23,6 @@ class Gym extends Base
|
||||
$res = $model->select();
|
||||
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,7 @@ use addons\shopro\controller\Common;
|
||||
|
||||
class Tags extends Common
|
||||
{
|
||||
|
||||
// protected $noNeedLogin = ['index'];
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
@@ -24,6 +20,6 @@ class Tags extends Common
|
||||
}
|
||||
$res = $model->select();
|
||||
|
||||
$this->success('获取成功', $res);
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace addons\shopro\job;
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\queue\Job;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class Test extends BaseJob
|
||||
{
|
||||
@@ -13,7 +17,7 @@ class Test extends BaseJob
|
||||
{
|
||||
// 创建目录
|
||||
$this->mkdir();
|
||||
|
||||
|
||||
// 写入日志文件
|
||||
$filename = RUNTIME_PATH . 'storage/queue/shopro.log';
|
||||
file_put_contents($filename, date('Y-m-d H:i:s'));
|
||||
@@ -48,4 +52,69 @@ class Test extends BaseJob
|
||||
@mkdir($dir, 0755, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 周期性活动创建比赛
|
||||
*/
|
||||
public function zy(Job $job, $data)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$_actModel = new \app\admin\model\zy\game\Activity();
|
||||
$_gameModel = new \app\admin\model\zy\game\Game();
|
||||
$week = date('w'); //当前星期
|
||||
$current = time(); //当前时间
|
||||
$activity = (clone $_actModel)::where('type', 1)->where('pid', 0)->select(); //周期性主活动
|
||||
foreach ($activity as $act) {
|
||||
$act = $act->toArray();
|
||||
$publicTime = json_decode($act['public_time'] ?? '[]', true);
|
||||
$publicBefore = intval($publicTime['before'] ?? 0); //提前几天
|
||||
$PublicWeek = $act['week'] - $publicBefore; //设定应该发布的星期
|
||||
if ($PublicWeek != $week && ($PublicWeek + 7) != $week) {
|
||||
print_r('星期不对');
|
||||
continue; // 星期不对
|
||||
}
|
||||
$public_time = strtotime($publicTime['time']); //设定的时间
|
||||
if ($current < $public_time) {
|
||||
print_r('时间未到');
|
||||
continue; //时间未到
|
||||
}
|
||||
$act['public_time'] = date('Y-m-d H:i:s', $public_time - $publicBefore * 86400); //设定的时间
|
||||
$act['date'] = date('Y-m-d', $public_time - $publicBefore * 86400); //设定的日期
|
||||
$games = (clone $_gameModel)::where('act_id', $act['id'])
|
||||
->where('public_time', $act['public_time'])
|
||||
->where('date', $act['date'])->select();
|
||||
if (!empty($games)) {
|
||||
print_r('已存在');
|
||||
continue; // 已存在
|
||||
}
|
||||
$joinStartTime = json_decode($act['join_start_time'] ?? '[]', true);
|
||||
$act['join_start_time'] = date('Y-m-d H:i:s', strtotime($joinStartTime['time']) - intval($joinStartTime['before']) * 86400);
|
||||
$joinEndTime = json_decode($act['join_end_time'] ?? '[]', true);
|
||||
$act['join_end_time'] = date('Y-m-d H:i:s', strtotime($joinEndTime['time']) - intval($joinEndTime['before']) * 86400);
|
||||
$quitTime = json_decode($act['quit_time'] ?? '[]', true);
|
||||
$act['quit_time'] = date('Y-m-d H:i:s', strtotime($quitTime['time']) - intval($quitTime['before']) * 86400);
|
||||
$act['act_id'] = $act['id'];
|
||||
unset($act['id']);
|
||||
$res = (clone $_gameModel)->allowField(true)->save($act);
|
||||
$subs = (clone $_actModel)::where('pid', $act['act_id'])->select();
|
||||
foreach ($subs as $sub) { //存在子活动
|
||||
$sub = $sub->toArray();
|
||||
$sub['public_time'] = $act['public_time'];
|
||||
$sub['join_start_time'] = $act['join_start_time'];
|
||||
$sub['join_end_time'] = $act['join_end_time'];
|
||||
$sub['quit_time'] = $act['quit_time'];
|
||||
$sub['act_id'] = $act['act_id'];
|
||||
$sub['date'] = $act['date'];
|
||||
unset($sub['id']);
|
||||
$res = (clone $_gameModel)->allowField(true)->save($sub);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
format_log_error($e, 'zy.activity create game');
|
||||
}
|
||||
$job->release(600); //$delay为延迟时间
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user