优化了定时任务、快递公司、采购订单和收银台相关的逻辑和列表

This commit is contained in:
mkm 2024-05-28 17:37:52 +08:00
parent e9df9d9041
commit 83c0e0b04a
36 changed files with 1132 additions and 700 deletions

View File

@ -1,128 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\admin\controller\crontab;
use app\admin\controller\BaseAdminController;
use app\admin\lists\crontab\CrontabLists;
use app\admin\logic\crontab\CrontabLogic;
use app\admin\validate\crontab\CrontabValidate;
/**
* 定时任务控制器
* Class CrontabController
* @package app\admin\controller\crontab
*/
class CrontabController extends BaseAdminController
{
/**
* @notes 定时任务列表
* @author 乔峰
* @date 2022/3/29 14:27
*/
public function lists()
{
return $this->dataLists(new CrontabLists());
}
/**
* @notes 添加定时任务
* @author 乔峰
* @date 2022/3/29 14:27
*/
public function add()
{
$params = (new CrontabValidate())->post()->goCheck('add');
$result = CrontabLogic::add($params);
if($result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(CrontabLogic::getError());
}
/**
* @notes 查看定时任务详情
* @author 乔峰
* @date 2022/3/29 14:27
*/
public function detail()
{
$params = (new CrontabValidate())->goCheck('detail');
$result = CrontabLogic::detail($params);
return $this->data($result);
}
/**
* @notes 编辑定时任务
* @author 乔峰
* @date 2022/3/29 14:27
*/
public function edit()
{
$params = (new CrontabValidate())->post()->goCheck('edit');
$result = CrontabLogic::edit($params);
if($result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(CrontabLogic::getError());
}
/**
* @notes 删除定时任务
* @author 乔峰
* @date 2022/3/29 14:27
*/
public function delete()
{
$params = (new CrontabValidate())->post()->goCheck('delete');
$result = CrontabLogic::delete($params);
if($result) {
return $this->success('删除成功', [], 1, 1);
}
return $this->fail('删除失败');
}
/**
* @notes 操作定时任务
* @author 乔峰
* @date 2022/3/29 14:28
*/
public function operate()
{
$params = (new CrontabValidate())->post()->goCheck('operate');
$result = CrontabLogic::operate($params);
if($result) {
return $this->success('操作成功', [], 1, 1);
}
return $this->fail(CrontabLogic::getError());
}
/**
* @notes 获取规则执行时间
* @author 乔峰
* @date 2022/3/29 14:28
*/
public function expression()
{
$params = (new CrontabValidate())->goCheck('expression');
$result = CrontabLogic::expression($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\express;
use app\admin\controller\BaseAdminController;
use app\admin\lists\express\ExpressLists;
use app\admin\logic\express\ExpressLogic;
use app\admin\validate\express\ExpressValidate;
/**
* 快递公司控制器
* Class ExpressController
* @package app\admin\controller\express
*/
class ExpressController extends BaseAdminController
{
/**
* @notes 获取快递公司列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function lists()
{
return $this->dataLists(new ExpressLists());
}
/**
* @notes 添加快递公司
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function add()
{
$params = (new ExpressValidate())->post()->goCheck('add');
$result = ExpressLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ExpressLogic::getError());
}
/**
* @notes 编辑快递公司
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function edit()
{
$params = (new ExpressValidate())->post()->goCheck('edit');
$result = ExpressLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ExpressLogic::getError());
}
/**
* @notes 删除快递公司
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function delete()
{
$params = (new ExpressValidate())->post()->goCheck('delete');
ExpressLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取快递公司详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function detail()
{
$params = (new ExpressValidate())->goCheck('detail');
$result = ExpressLogic::detail($params);
return $this->data($result);
}
}

View File

@ -24,16 +24,21 @@ class OpurchaseGoodsOfferController extends BaseAdminController
*/
public function date_lists()
{
$supplier=$this->request->supplierId;
if(!$supplier) return $this->success('供应商不存在', []);
$supplierId=$this->request->supplierId;
if(!$supplierId) return $this->success('供应商不存在', []);
$page_no = $this->request->get('page_no', 1);
$page_size = $this->request->get('page_size', 15);
$data = Db::name('opurchase_goods_offer_date')->where('supplier_id', $supplier)->page($page_no, $page_size)->select()->each(function ($item) {
$date = $this->request->get('date');
$where=['supplier_id' =>$supplierId];
if($date){
$date=strtotime($date);
$where[]=['create_time','between',[$date, $date+24*3600-1]];
}
$data = Db::name('opurchase_goods_offer_date')->where($where)->page($page_no, $page_size)->order('create_time desc')->select()->each(function ($item) {
$item['name']=date('Y-m-d', $item['create_time']).' 报价清单';
return $item;
})->toArray();
$count = Db::name('opurchase_goods_offer_date')->where('supplier_id', $supplier)->count();
$count = Db::name('opurchase_goods_offer_date')->where($where)->count();
return $this->success('请求成功', ['lists' => $data, 'count' => $count, 'page_no' => $page_no, 'page_size' => $page_size]);
}
/**
@ -50,4 +55,19 @@ class OpurchaseGoodsOfferController extends BaseAdminController
}
return $this->fail(OpurchaseGoodsOfferLogic::getError());
}
/**
* 提交配送
*/
public function express(){
$params = (new OpurchaseGoodsOfferValidate())->post()->goCheck('express');
$supplier=$this->request->supplierId;
if(!$supplier) return $this->fail('非供应商用户不能填写');
$params['supplier_id']=$supplier;
$result = OpurchaseGoodsOfferLogic::express($params);
if (true === $result) {
return $this->success('提交成功', [], 1, 1);
}
return $this->fail(OpurchaseGoodsOfferLogic::getError());
}
}

View File

@ -103,7 +103,7 @@ class CashierclassController extends BaseAdminController
*/
public function detail()
{
$params = (new CashierclassValidate())->goCheck('detail');
$params =$this->request->get();
$result = CashierclassLogic::detail($params);
return $this->data($result);
}

View File

@ -1,61 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\admin\lists\crontab;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\Crontab;
/**
* 定时任务列表
* Class CrontabLists
* @package app\admin\lists\crontab
*/
class CrontabLists extends BaseAdminDataLists
{
/**
* @notes 定时任务列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 乔峰
* @date 2022/3/29 14:30
*/
public function lists(): array
{
$field = 'id,name,type,type as type_desc,command,params,expression,
status,status as status_desc,error,last_time,time,max_time';
$lists = Crontab::field($field)
->limit($this->limitOffset, $this->limitLength)
->order('id', 'desc')
->select()
->toArray();
return $lists;
}
/**
* @notes 定时任务数量
* @return int
* @author 乔峰
* @date 2022/3/29 14:38
*/
public function count(): int
{
return Crontab::count();
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\express;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\express\Express;
use app\common\lists\ListsSearchInterface;
/**
* 快递公司列表
* Class ExpressLists
* @package app\admin\listsexpress
*/
class ExpressLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function setSearch(): array
{
return [
'=' => ['code', 'name', 'mark'],
];
}
/**
* @notes 获取快递公司列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function lists(): array
{
return Express::where($this->searchWhere)
->field(['id', 'code', 'name', 'mark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取快递公司数量
* @return int
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function count(): int
{
return Express::where($this->searchWhere)->count();
}
}

View File

@ -55,7 +55,7 @@ class OpurchaseclassLists extends BaseAdminDataLists implements ListsSearchInter
$this->where=$where;
return Opurchaseclass::where($this->searchWhere)
->where($where)
->field(['id', 'merchant', 'order_arr', 'cart_id', 'number', 'total', 'deduction_price', 'actual', 'money', 'paid','is_opurchase'])
->field(['id', 'merchant', 'order_arr', 'cart_id', 'number', 'total', 'deduction_price', 'actual', 'money', 'paid','is_opurchase','create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){

View File

@ -32,6 +32,7 @@ class OpurchaseclassofferLists extends BaseAdminDataLists implements ListsSearch
{
return [
'=' => ['is_adopt', 'is_storage', 'order_id'],
'between_time'=>'create_time'
];
}

View File

@ -46,7 +46,7 @@ class CashierclassStreamLists extends BaseAdminDataLists implements ListsSearchI
public function lists(): array
{
return Cashierclass::where($this->searchWhere)
->field(['id', 'merchant', 'store_id', 'uid', 'number', 'total', 'deduction_price', 'actual', 'money', 'pay_type', 'type', 'auditinguser', 'auditingtime','create_time','is_stream','stream_admin_id','stream_time'])
->field(['id', 'merchant', 'store_id', 'uid', 'number', 'total', 'deduction_price', 'actual', 'money', 'pay_type', 'type', 'auditinguser', 'auditingtime','create_time','is_stream','stream_admin_id','stream_time','user_address'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){

View File

@ -1,169 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\admin\logic\crontab;
use app\common\enum\CrontabEnum;
use app\common\logic\BaseLogic;
use app\common\model\Crontab;
use Cron\CronExpression;
/**
* 定时任务逻辑层
* Class CrontabLogic
* @package app\admin\logic\crontab
*/
class CrontabLogic extends BaseLogic
{
/**
* @notes 添加定时任务
* @param $params
* @return bool
* @author 乔峰
* @date 2022/3/29 14:41
*/
public static function add($params)
{
try {
$params['remark'] = $params['remark'] ?? '';
$params['params'] = $params['params'] ?? '';
$params['last_time'] = time();
Crontab::create($params);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 查看定时任务详情
* @param $params
* @return array
* @author 乔峰
* @date 2022/3/29 14:41
*/
public static function detail($params)
{
$field = 'id,name,type,type as type_desc,command,params,status,status as status_desc,expression,remark';
$crontab = Crontab::field($field)->findOrEmpty($params['id']);
if ($crontab->isEmpty()) {
return [];
}
return $crontab->toArray();
}
/**
* @notes 编辑定时任务
* @param $params
* @return bool
* @author 乔峰
* @date 2022/3/29 14:42
*/
public static function edit($params)
{
try {
$params['remark'] = $params['remark'] ?? '';
$params['params'] = $params['params'] ?? '';
Crontab::update($params);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除定时任务
* @param $params
* @return bool
* @author 乔峰
* @date 2022/3/29 14:42
*/
public static function delete($params)
{
try {
Crontab::destroy($params['id']);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 操作定时任务
* @param $params
* @return bool
* @author 乔峰
* @date 2022/3/29 14:42
*/
public static function operate($params)
{
try {
$crontab = Crontab::findOrEmpty($params['id']);
if ($crontab->isEmpty()) {
throw new \Exception('定时任务不存在');
}
switch ($params['operate']) {
case 'start';
$crontab->status = CrontabEnum::START;
break;
case 'stop':
$crontab->status = CrontabEnum::STOP;
break;
}
$crontab->save();
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 获取规则执行时间
* @param $params
* @return array|string
* @author 乔峰
* @date 2022/3/29 14:42
*/
public static function expression($params)
{
try {
$cron = new CronExpression($params['expression']);
$result = $cron->getMultipleRunDates(5);
$result = json_decode(json_encode($result), true);
$lists = [];
foreach ($result as $k => $v) {
$lists[$k]['time'] = $k + 1;
$lists[$k]['date'] = str_replace('.000000', '', $v['date']);
}
$lists[] = ['time' => 'x', 'date' => '……'];
return $lists;
} catch (\Exception $e) {
return $e->getMessage();
}
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace app\admin\logic\express;
use app\common\model\express\Express;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 快递公司逻辑
* Class ExpressLogic
* @package app\admin\logic\express
*/
class ExpressLogic extends BaseLogic
{
/**
* @notes 添加快递公司
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/28 09:58
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Express::create([
'code' => $params['code'],
'name' => $params['name'],
'mark' => $params['mark']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑快递公司
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/28 09:58
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Express::where('id', $params['id'])->update([
'code' => $params['code'],
'name' => $params['name'],
'mark' => $params['mark']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除快递公司
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/28 09:58
*/
public static function delete(array $params): bool
{
return Express::destroy($params['id']);
}
/**
* @notes 获取快递公司详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/05/28 09:58
*/
public static function detail($params): array
{
return Express::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -16,7 +16,7 @@ use app\common\model\supplier\Supplier;
use app\common\model\supplier\SupplierBindGoods;
use support\Log;
use think\facade\Db;
use app\common\service\JgPushService;
/**
* 采购订单逻辑
@ -277,6 +277,16 @@ class OpurchaseclassLogic extends BaseLogic
FinancialRecord::create($record);
}
$res = $find->save();
$jg_register_id = Db::name('user_auth_shop')->where('pid', $find['supplier_id'])->where('type',2)->value('jg_register_id');
if($jg_register_id){
$jg=(new JgPushService())->sendMsg($jg_register_id, '平台提醒:您的商品已被采纳,请尽快发货' , '/pages/quote/list');
if($jg!==true){
Db::rollback();
self::setError('设置成功。但极光推送失败:'.$jg);
return false;
}
}
if ($res) {
return true;
}

View File

@ -149,9 +149,9 @@ class CashierclassLogic extends BaseLogic
*/
public static function detail($params): array
{
$find=Cashierclass::where($params)->find();
$find=Cashierclass::where($params)->findOrEmpty()->toArray();
if($find){
$find['goods_list']= Cashierinfo::where('pid',$params['id'])
$find['goods_list']= Cashierinfo::where('pid',$find['id'])
->with('goodsName')
->field('goods,price sell,nums')->select()->each(function($item){
$item['msg']='预计48小时发货';
@ -162,6 +162,6 @@ class CashierclassLogic extends BaseLogic
$find['merchant_info']=$merchant;
}
return $find->toArray();
return $find;
}
}

View File

@ -1,138 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\admin\validate\crontab;
use app\common\validate\BaseValidate;
use Cron\CronExpression;
/**
* 定时任务验证器
* Class CrontabValidate
* @package app\admin\validate\crontab
*/
class CrontabValidate extends BaseValidate
{
protected $rule = [
'name' => 'require',
'type' => 'require|in:1',
'command' => 'require',
'status' => 'require|in:1,2,3',
'expression' => 'require|checkExpression',
'id' => 'require',
'operate' => 'require'
];
protected $message = [
'name.require' => '请输入定时任务名称',
'type.require' => '请选择类型',
'type.in' => '类型值错误',
'command.require' => '请输入命令',
'status.require' => '请选择状态',
'status.in' => '状态值错误',
'expression.require' => '请输入运行规则',
'id.require' => '参数缺失',
'operate.require' => '请选择操作',
];
/**
* @notes 添加定时任务场景
* @return CrontabValidate
* @author 乔峰
* @date 2022/3/29 14:39
*/
public function sceneAdd()
{
return $this->remove('id', 'require')->remove('operate', 'require');
}
/**
* @notes 查看定时任务详情场景
* @return CrontabValidate
* @author 乔峰
* @date 2022/3/29 14:39
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 编辑定时任务
* @return CrontabValidate
* @author 乔峰
* @date 2022/3/29 14:39
*/
public function sceneEdit()
{
return $this->remove('operate', 'require');
}
/**
* @notes 删除定时任务场景
* @return CrontabValidate
* @author 乔峰
* @date 2022/3/29 14:40
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes CrontabValidate
* @return CrontabValidate
* @author 乔峰
* @date 2022/3/29 14:40
*/
public function sceneOperate()
{
return $this->only(['id', 'operate']);
}
/**
* @notes 获取规则执行时间场景
* @return CrontabValidate
* @author 乔峰
* @date 2022/3/29 14:40
*/
public function sceneExpression()
{
return $this->only(['expression']);
}
/**
* @notes 校验运行规则
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 乔峰
* @date 2022/3/29 14:40
*/
public function checkExpression($value, $rule, $data)
{
if (CronExpression::isValidExpression($value) === false) {
return '定时任务运行规则错误';
}
return true;
}
}

View File

@ -0,0 +1,84 @@
<?php
namespace app\admin\validate\express;
use app\common\validate\BaseValidate;
/**
* 快递公司验证器
* Class ExpressValidate
* @package app\admin\validate\express
*/
class ExpressValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'name' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'name' => '快递公司',
];
/**
* @notes 添加场景
* @return ExpressValidate
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function sceneAdd()
{
return $this->only(['name']);
}
/**
* @notes 编辑场景
* @return ExpressValidate
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function sceneEdit()
{
return $this->only(['id','name']);
}
/**
* @notes 删除场景
* @return ExpressValidate
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ExpressValidate
* @author likeadmin
* @date 2024/05/28 09:58
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -2,6 +2,7 @@
namespace app\api\controller;
use app\admin\lists\express\ExpressLists;
use app\admin\logic\operation\OpurchaseclassLogic;
use app\admin\validate\tools\GenerateTableValidate;
use app\admin\logic\tools\GeneratorLogic;
@ -27,59 +28,11 @@ use support\Redis as SupportRedis;
class IndexController extends BaseApiController
{
public $notNeedLogin = ['index','app_update'];
public $notNeedLogin = ['index','app_update','express_list'];
public function index()
{
Redis::send('push-platform-print', ['order_id' => 39]);
// $auth_code=$this->request->get('auth_code');
// $config = Config::get('payment');
// Pay::config($config);
// $result = Pay::alipay()->pos([
// 'out_trade_no' => time(),
// 'auth_code' => $auth_code,
// 'total_amount' => '0.01',
// 'subject' => 'yansongda 测试 - 01',
// 'extend_params'=>['attach'=>'cashierclass']
// ]);
// $arr = [];
// foreach ($a as $k => $v) {
// $pid = Goodsclass::where('id', $v)->value('pid');
// $arr[$pid][] = $v;
// }
// foreach ($arr as $k => $v) {
// Goodsclass::where('id', $k)->update(['children' => json_encode($v, true)]);
// }
d(1);
// $a=array_values($a);
// $client = new JPush($app_key, $master_secret);
// $client->push()
// ->setPlatform('all')
// ->addAllAudience()
// ->setNotificationAlert('Hello, JPush')
// ->send();
// var_dump(2323);
return json(['msg' =>create_password(123456, '11d3')]);
// PushService::push('store_merchant_502', 502, '支付超时,订单已被取消,请重新提交订单');
// d(1);
// $extra=$this->request->post();
// Redis::send('push-supplier-products', ['order_id'=>11]);
// createSupplierGoods
// d(OpurchaseclassLogic::createSupplierGoods(['goods'=>99]));
$queue = 'send-mail';
// 数据,可以直接传数组,无需序列化
$data = ['to' => 'tom@gmail.com', 'content' => 'hello'];
// 投递消息
Redis::send($queue, $data);
// 投递延迟消息消息会在60秒后处理
// Redis::send($queue, $data, 5);
return json(['msg' =>create_password(123456, '11d3')]);
return json(['msg' =>create_password(123456, '11d3')]);
}
/**
@ -102,4 +55,11 @@ class IndexController extends BaseApiController
$find= Db::name('app_update')->where('type',2)->order('id','desc')->findOrEmpty();
return $this->success('ok',$find);
}
/**
* @notes 获取快递列表
*/
public function express_list(){
return $this->dataLists(new ExpressLists());
}
}

View File

@ -30,8 +30,15 @@ class OpurchaseGoodsOfferController extends BaseApiController
$supplier=$this->request->userInfo['supplier'];
$page_no = $this->request->get('page_no', 1);
$page_size = $this->request->get('page_size', 15);
$data = Db::name('opurchase_goods_offer_date')->where('supplier_id', $supplier['id'])->page($page_no, $page_size)->select()
$date = $this->request->get('date');
$where=['supplier_id' =>$supplier['id']];
if($date){
$date=strtotime($date);
$where[]=['create_time','between',[$date, $date+24*3600-1]];
}
$data = Db::name('opurchase_goods_offer_date')->where($where)->page($page_no, $page_size)
->order('create_time desc')
->select()
->each(function ($item) {
$item['name']=date('Y-m-d', $item['create_time']).' 报价清单';
$item['class_arr']=[];
@ -45,7 +52,7 @@ class OpurchaseGoodsOfferController extends BaseApiController
}
return $item;
})->toArray();
$count = Db::name('opurchase_goods_offer_date')->where('supplier_id', $supplier['id'])->count();
$count = Db::name('opurchase_goods_offer_date')->where($where)->count();
return $this->success('请求成功', ['lists' => $data, 'count' => $count, 'page_no' => $page_no, 'page_size' => $page_size]);
}
/**

View File

@ -1,16 +1,20 @@
<?php
namespace app\api\controller\operation;
use app\api\controller\BaseApiController;
use app\api\lists\operation\OpurchaseGoodsOfferList;
use app\api\logic\operation\OpurchaseGoodsOfferLogic;
use app\common\model\opurchase\OpurchaseGoodsOffer;
class OpurchaseclassController extends BaseApiController{
class OpurchaseclassController extends BaseApiController
{
/**
* 报价列表
*/
public function goods_offer_list(){
public function goods_offer_list()
{
return $this->dataLists(new OpurchaseGoodsOfferList());
}
@ -18,15 +22,36 @@ class OpurchaseclassController extends BaseApiController{
/**
* 创建报价
*/
public function create_price(){
$id=$this->request->post('id');
$price=$this->request->post('price');
$nums=$this->request->post('nums');
$supplier_id=$this->request->userInfo['supplier']['id'];
if(!$supplier_id) return $this->fail('请先绑定供应商');
$res=OpurchaseGoodsOffer::where('supplier_id',$supplier_id)->where('id',$id)->update(['price'=>$price,'nums'=>$nums]);
if($res) return $this->success('报价成功');
public function create_price()
{
$id = $this->request->post('id');
$price = $this->request->post('price');
$nums = $this->request->post('nums');
$supplier_id = $this->request->userInfo['supplier']['id'];
if (!$supplier_id) return $this->fail('请先绑定供应商');
$res = OpurchaseGoodsOffer::where('supplier_id', $supplier_id)->where('id', $id)->update(['price' => $price, 'nums' => $nums]);
if ($res) return $this->success('报价成功');
return $this->fail('报价失败');
}
}
/**
* 提交物流
*/
public function express()
{
$delivery_name = $this->request->post('delivery_name');
$delivery_id = $this->request->post('delivery_id');
$supplier_id = $this->request->userInfo['supplier']['id'];
if (!$supplier_id) return $this->fail('请先绑定供应商');
$data = [
'delivery_name' => $delivery_name,
'delivery_id' => $delivery_id,
'supplier_id'=>$delivery_id,
];
$res = OpurchaseGoodsOfferLogic::express($data);
if (true === $res) {
return $this->success('提交成功', [], 1, 1);
}
return $this->fail(OpurchaseGoodsOfferLogic::getError());
}
}

View File

@ -25,8 +25,7 @@ class OpurchaseGoodsOfferList extends BaseAdminDataLists implements ListsSearchI
*/
public function setSearch(): array
{
return [
];
return [];
}
@ -40,38 +39,37 @@ class OpurchaseGoodsOfferList extends BaseAdminDataLists implements ListsSearchI
*/
public function lists(): array
{
$supplier_id=$this->request->userInfo['supplier']['id'] ?? 0;
if(!$supplier_id) return [];
$params = $this->request->get();
if(isset($params['type']) && $params['type'] == 2){
$where[] = ['price','<>',0];
$where[] = ['is_adopt','<>',0];
$where[] = ['supplier_id','=',$supplier_id];
}else{
$where[] = ['price','=',0];
$where[] = ['is_adopt','=',0];
$where[] = ['supplier_id','=',$supplier_id];
}
if($params['date']){
$where[] = ['create_time','between',[strtotime($params['date']),strtotime($params['date'])+86400]];
}else{
$supplier_id = $this->request->userInfo['supplier']['id'] ?? 0;
if (!$supplier_id) return [];
$params = $this->request->get();
if (isset($params['type']) && $params['type'] == 2) {
$where[] = ['price', '<>', 0];
$where[] = ['is_adopt', '<>', 0];
$where[] = ['supplier_id', '=', $supplier_id];
} else {
$where[] = ['price', '=', 0];
$where[] = ['is_adopt', '=', 0];
$where[] = ['supplier_id', '=', $supplier_id];
}
if ($params['date']) {
$where[] = ['create_time', 'between', [strtotime($params['date']), strtotime($params['date']) + 86400]];
} else {
return [];
}
return OpurchaseGoodsOffer::where($this->searchWhere)->where($where)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$data['is_adopt_text'] = $data->is_adopt_text;
->order(['is_adopt' => 'desc','id' => 'desc'])
->select()->each(function ($data) {
$data['is_adopt_text'] = $data->is_adopt_text;
$find = Goods::where('id', $data['goods_id'])->with('unitName')->find();
if($find){
if ($find) {
$goods['goods_name'] = $find['name'];
$goods['unit_name'] = $find['unit_name'];
$goods['imgs'] = $find['imgs'];
$data['goods']=$goods;
$data['goods'] = $goods;
}
return $data;
})
})
->toArray();
}
@ -83,14 +81,13 @@ class OpurchaseGoodsOfferList extends BaseAdminDataLists implements ListsSearchI
*/
public function count(): int
{
$supplier_id=$this->request->userInfo['supplier']['id'] ?? 0;
$params = $this->request->get();
if(isset($params['type']) && $params['type'] == 2){
$where[] = ['price','<>',0];
}else{
$where[] = ['price','=',0];
}
return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id',$supplier_id)->where($where)->count();
$supplier_id = $this->request->userInfo['supplier']['id'] ?? 0;
$params = $this->request->get();
if (isset($params['type']) && $params['type'] == 2) {
$where[] = ['price', '<>', 0];
} else {
$where[] = ['price', '=', 0];
}
return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id', $supplier_id)->where($where)->count();
}
}
}

View File

@ -1,30 +1,33 @@
<?php
namespace app\api\logic\operation;
use app\common\logic\BaseLogic;
use app\common\model\opurchase\OpurchaseGoodsOffer;
use think\facade\Db;
class OpurchaseGoodsOfferLogic extends BaseLogic{
class OpurchaseGoodsOfferLogic extends BaseLogic
{
public static function offer($params): bool
{
Db::startTrans();
try {
foreach ($params['data'] as $v){
OpurchaseGoodsOffer::where('id',$v['id'])->update([
foreach ($params['data'] as $v) {
OpurchaseGoodsOffer::where('id', $v['id'])->update([
'price' => $v['price'],
'nums' => $v['nums'],
'is_adopt' => 1,
'update_time' => time()
]);
}
$id=$params['data'][0]['id']??0;
if($id){
$find=OpurchaseGoodsOffer::where('id',$params['data'][0]['id'])->field('supplier_id','create_time')->find();
if($find){
$time=date('Y-m-d',$find['create_time']);
Db::name('opurchase_goods_offer_date')->where('supplier_id', $find['supplier_id'])->whereDay('create_time',$time)->update(['status'=>1]);
$id = $params['data'][0]['id'] ?? 0;
if ($id) {
$find = OpurchaseGoodsOffer::where('id', $params['data'][0]['id'])->field('supplier_id', 'create_time')->find();
if ($find) {
$time = date('Y-m-d', $find['create_time']);
Db::name('opurchase_goods_offer_date')->where('supplier_id', $find['supplier_id'])->whereDay('create_time', $time)->update(['status' => 1]);
}
}
@ -36,4 +39,33 @@ class OpurchaseGoodsOfferLogic extends BaseLogic{
return false;
}
}
/**
* 更新配送
*/
public static function express($params): bool
{
Db::startTrans();
try {
$where=['supplier_id'=>$params['supplier_id']];
if(isset($params['id']) &&$params['id']!=[]){
$where[]=['id','in',$params['id']];
}
if(isset($params['date']) &&$params['date']!=''){
$time=strtotime($params['date']);
$where[]=['create_time','between',[$time,$time+24*60*60-1]];//当天时间范围
}
OpurchaseGoodsOffer::where($where)->update([
'delivery_name' => $params['delivery_name'],
'delivery_id' => $params['delivery_id'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -9,17 +9,24 @@
{
protected $rule = [
'data' => 'require|checkData',
'delivery_name' => 'require',
'delivery_id' => 'require',
];
protected $message = [
'data.require' => '参数缺失',
'delivery_name.require' => '快递名称/送货人姓名',
'delivery_id.require' => '快递单号/手机号',
];
public function sceneOffer(): OpurchaseGoodsOfferValidate
{
return $this->only(['data']);
}
public function sceneExpress()
{
return $this->only(['delivery_name','delivery_id']);
}
public function checkData($value){
if(!is_array($value)) return '参数数据格式错误';
foreach($value as $k => $v){

View File

@ -1,80 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model;
use app\common\enum\CrontabEnum;
use think\model\concern\SoftDelete;
/**
* 定时任务模型
* Class Crontab
* @package app\common\model
*/
class Crontab extends BaseModel
{
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $name = 'dev_crontab';
/**
* @notes 类型获取器
* @param $value
* @return string
* @author 乔峰
* @date 2022/3/29 12:05
*/
public function getTypeDescAttr($value)
{
$desc = [
CrontabEnum::CRONTAB => '定时任务',
CrontabEnum::DAEMON => '守护进程',
];
return $desc[$value] ?? '';
}
/**
* @notes 状态获取器
* @param $value
* @return string
* @author 乔峰
* @date 2022/3/29 12:06
*/
public function getStatusDescAttr($value)
{
$desc = [
CrontabEnum::START => '运行',
CrontabEnum::STOP => '停止',
CrontabEnum::ERROR => '错误',
];
return $desc[$value] ?? '';
}
/**
* @notes 最后执行时间获取器
* @param $value
* @return string
* @author 乔峰
* @date 2022/3/29 12:06
*/
public function getLastTimeAttr($value)
{
return empty($value) ? '' : date('Y-m-d H:i:s', $value);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\express;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 快递公司模型
* Class Express
* @package app\common\model\express
*/
class Express extends BaseModel
{
use SoftDelete;
protected $name = 'express';
protected $deleteTime = 'delete_time';
}

View File

@ -52,7 +52,8 @@
"webman/redis-queue": "^1.3",
"webman/push": "^1.0",
"ext-bcmath": "*",
"jpush/jpush": "^3.6"
"jpush/jpush": "^3.6",
"workerman/crontab": "^1.0"
},
"suggest": {
"ext-event": "For better performance. "

58
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4fa679ea4f76781008e086046ab4efbe",
"content-hash": "cefecbcff919f3c1c8084830bbb72adc",
"packages": [
{
"name": "aliyuncs/oss-sdk-php",
@ -6525,6 +6525,62 @@
},
"time": "2022-06-03T18:03:27+00:00"
},
{
"name": "workerman/crontab",
"version": "v1.0.6",
"source": {
"type": "git",
"url": "https://github.com/walkor/crontab.git",
"reference": "b78f1556f2977715b9cb5653129e6d9cf160d966"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/walkor/crontab/zipball/b78f1556f2977715b9cb5653129e6d9cf160d966",
"reference": "b78f1556f2977715b9cb5653129e6d9cf160d966",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7.0",
"workerman/workerman": ">=4.0.20"
},
"type": "library",
"autoload": {
"psr-4": {
"Workerman\\Crontab\\": "./src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://www.workerman.net",
"role": "Developer"
}
],
"description": "A crontab written in PHP based on workerman",
"homepage": "http://www.workerman.net",
"keywords": [
"crontab"
],
"support": {
"email": "walkor@workerman.net",
"forum": "http://wenda.workerman.net/",
"issues": "https://github.com/walkor/workerman/issues",
"source": "https://github.com/walkor/crontab",
"wiki": "http://doc.workerman.net/"
},
"time": "2022-10-17T01:59:19+00:00"
},
{
"name": "workerman/redis",
"version": "v2.0.2",

View File

@ -1,4 +1,5 @@
<?php
/**
* This file is part of webman.
*
@ -38,5 +39,8 @@ return [
'enable_memory_monitor' => DIRECTORY_SEPARATOR === '/',
]
]
]
],
'task' => [
'handler' => process\Task::class
],
];

29
process/Task.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace process;
use app\common\model\retail\Cashierclass;
use Workerman\Crontab\Crontab;
class Task
{
public function onWorkerStart()
{
// 每分钟执行一次
new Crontab('0 */1 * * * *', function(){
$where=['paid'=>0];
$where[]=['create_time','<',time() - 600];
// 删除10分钟未支付的订单
Cashierclass::where($where)->update(['delete_time'=>time()]); // 删除时间设置为当前时间,即删除
//自动收货
$this->Cashierclass();
});
}
function Cashierclass(){
$where=['paid'=>1];
$where[]=['create_time','<',time()- 7 * 86400];
// 删除10分钟未支付的订单
Cashierclass::where($where)->update(['status'=>2]); // 删除时间设置为当前时间,即删除
}
}

View File

@ -18,6 +18,7 @@ return array(
'Yansongda\\Artful\\' => array($vendorDir . '/yansongda/artful/src'),
'Workerman\\Redis\\' => array($vendorDir . '/workerman/redis/src'),
'Workerman\\RedisQueue\\' => array($vendorDir . '/workerman/redis-queue/src'),
'Workerman\\Crontab\\' => array($vendorDir . '/workerman/crontab/src'),
'Workerman\\' => array($vendorDir . '/workerman/workerman'),
'Webmozart\\Assert\\' => array($vendorDir . '/webmozart/assert/src'),
'Webman\\ThinkOrm\\' => array($vendorDir . '/webman/think-orm/src'),

View File

@ -76,6 +76,7 @@ class ComposerStaticInitb985d5bd8942750003fe2a54df074341
array (
'Workerman\\Redis\\' => 16,
'Workerman\\RedisQueue\\' => 21,
'Workerman\\Crontab\\' => 18,
'Workerman\\' => 10,
'Webmozart\\Assert\\' => 17,
'Webman\\ThinkOrm\\' => 16,
@ -271,6 +272,10 @@ class ComposerStaticInitb985d5bd8942750003fe2a54df074341
array (
0 => __DIR__ . '/..' . '/workerman/redis-queue/src',
),
'Workerman\\Crontab\\' =>
array (
0 => __DIR__ . '/..' . '/workerman/crontab/src',
),
'Workerman\\' =>
array (
0 => __DIR__ . '/..' . '/workerman/workerman',

View File

@ -6810,6 +6810,59 @@
},
"install-path": "../webmozart/assert"
},
{
"name": "workerman/crontab",
"version": "v1.0.6",
"version_normalized": "1.0.6.0",
"source": {
"type": "git",
"url": "https://github.com/walkor/crontab.git",
"reference": "b78f1556f2977715b9cb5653129e6d9cf160d966"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/walkor/crontab/zipball/b78f1556f2977715b9cb5653129e6d9cf160d966",
"reference": "b78f1556f2977715b9cb5653129e6d9cf160d966",
"shasum": ""
},
"require": {
"php": ">=7.0",
"workerman/workerman": ">=4.0.20"
},
"time": "2022-10-17T01:59:19+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Workerman\\Crontab\\": "./src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://www.workerman.net",
"role": "Developer"
}
],
"description": "A crontab written in PHP based on workerman",
"homepage": "http://www.workerman.net",
"keywords": [
"crontab"
],
"support": {
"email": "walkor@workerman.net",
"forum": "http://wenda.workerman.net/",
"issues": "https://github.com/walkor/workerman/issues",
"source": "https://github.com/walkor/crontab",
"wiki": "http://doc.workerman.net/"
},
"install-path": "../workerman/crontab"
},
{
"name": "workerman/redis",
"version": "v2.0.2",

View File

@ -974,6 +974,15 @@
'aliases' => array(),
'dev_requirement' => false,
),
'workerman/crontab' => array(
'pretty_version' => 'v1.0.6',
'version' => '1.0.6.0',
'reference' => 'b78f1556f2977715b9cb5653129e6d9cf160d966',
'type' => 'library',
'install_path' => __DIR__ . '/../workerman/crontab',
'aliases' => array(),
'dev_requirement' => false,
),
'workerman/redis' => array(
'pretty_version' => 'v2.0.2',
'version' => '2.0.2.0',

29
vendor/workerman/crontab/README.md vendored Normal file
View File

@ -0,0 +1,29 @@
# Crontab
A crontab with precision in seconds written in PHP based on [workerman](https://github.com/walkor/workerman).
# Install
```
composer require workerman/crontab
```
# Usage
start.php
```php
<?php
use Workerman\Worker;
require __DIR__ . '/../vendor/autoload.php';
use Workerman\Crontab\Crontab;
$worker = new Worker();
$worker->onWorkerStart = function () {
// Execute the function in the first second of every minute.
new Crontab('1 * * * * *', function(){
echo date('Y-m-d H:i:s')."\n";
});
};
Worker::runAll();
```
Run with commands `php start.php start` or php `start.php start -d`

34
vendor/workerman/crontab/composer.json vendored Normal file
View File

@ -0,0 +1,34 @@
{
"name": "workerman/crontab",
"type": "library",
"keywords": [
"crontab"
],
"homepage": "http://www.workerman.net",
"license": "MIT",
"description": "A crontab written in PHP based on workerman",
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://www.workerman.net",
"role": "Developer"
}
],
"support": {
"email": "walkor@workerman.net",
"issues": "https://github.com/walkor/workerman/issues",
"forum": "http://wenda.workerman.net/",
"wiki": "http://doc.workerman.net/",
"source": "https://github.com/walkor/crontab"
},
"require": {
"php": ">=7.0",
"workerman/workerman": ">=4.0.20"
},
"autoload": {
"psr-4": {
"Workerman\\Crontab\\": "./src"
}
}
}

View File

@ -0,0 +1,16 @@
<?php
use Workerman\Worker;
require __DIR__ . '/../vendor/autoload.php';
use Workerman\Crontab\Crontab;
$worker = new Worker();
$worker->onWorkerStart = function () {
// Execute the function in the first second of every minute.
new Crontab('1 * * * * *', function(){
echo date('Y-m-d H:i:s')."\n";
});
};
Worker::runAll();

177
vendor/workerman/crontab/src/Crontab.php vendored Normal file
View File

@ -0,0 +1,177 @@
<?php
/**
* This file is part of workerman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Workerman\Crontab;
use Workerman\Timer;
/**
* Class Crontab
* @package Workerman\Crontab
*/
class Crontab
{
/**
* @var string
*/
protected $_rule;
/**
* @var callable
*/
protected $_callback;
/**
* @var string
*/
protected $_name;
/**
* @var int
*/
protected $_id;
/**
* @var array
*/
protected static $_instances = [];
/**
* Crontab constructor.
* @param string $rule
* @param callable $callback
* @param string $name
*/
public function __construct($rule, $callback, $name = '')
{
$this->_rule = $rule;
$this->_callback = $callback;
$this->_name = $name;
$this->_id = static::createId();
static::$_instances[$this->_id] = $this;
static::tryInit();
}
/**
* @return string
*/
public function getRule()
{
return $this->_rule;
}
/**
* @return callable
*/
public function getCallback()
{
return $this->_callback;
}
/**
* @return string
*/
public function getName()
{
return $this->_name;
}
/**
* @return int
*/
public function getId()
{
return $this->_id;
}
/**
* @return bool
*/
public function destroy()
{
return static::remove($this->_id);
}
/**
* @return array
*/
public static function getAll()
{
return static::$_instances;
}
/**
* @param $id
* @return bool
*/
public static function remove($id)
{
if ($id instanceof Crontab) {
$id = $id->getId();
}
if (!isset(static::$_instances[$id])) {
return false;
}
unset(static::$_instances[$id]);
return true;
}
/**
* @return int
*/
protected static function createId()
{
static $id = 0;
return ++$id;
}
/**
* tryInit
*/
protected static function tryInit()
{
static $inited = false;
if ($inited) {
return;
}
$inited = true;
$parser = new Parser();
$callback = function () use ($parser, &$callback) {
foreach (static::$_instances as $crontab) {
$rule = $crontab->getRule();
$cb = $crontab->getCallback();
if (!$cb || !$rule) {
continue;
}
$times = $parser->parse($rule);
$now = time();
foreach ($times as $time) {
$t = $time-$now;
if ($t <= 0) {
$t = 0.000001;
}
Timer::add($t, $cb, null, false);
}
}
Timer::add(60 - time()%60, $callback, null, false);
};
$next_time = time()%60;
if ($next_time == 0) {
$next_time = 0.00001;
} else {
$next_time = 60 - $next_time;
}
Timer::add($next_time, $callback, null, false);
}
}

171
vendor/workerman/crontab/src/Parser.php vendored Normal file
View File

@ -0,0 +1,171 @@
<?php
/**
* @author: Jan Konieczny <jkonieczny@gmail.com>, group@hyperf.io
* @license: http://www.gnu.org/licenses/
* @license: https://github.com/hyperf/hyperf/blob/master/LICENSE
*
* This is a simple script to parse crontab syntax to get the execution time
*
* Eg.: $timestamp = Crontab::parse('12 * * * 1-5');
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Provides basic cron syntax parsing functionality
*
* @author: Jan Konieczny <jkonieczny@gmail.com>, group@hyperf.io
* @license: http://www.gnu.org/licenses/
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Workerman\Crontab;
/**
* Class Parser
* @package Workerman\Crontab
*/
class Parser
{
/**
* Finds next execution time(stamp) parsin crontab syntax.
*
* @param string $crontab_string :
* 0 1 2 3 4 5
* * * * * * *
* - - - - - -
* | | | | | |
* | | | | | +----- day of week (0 - 6) (Sunday=0)
* | | | | +----- month (1 - 12)
* | | | +------- day of month (1 - 31)
* | | +--------- hour (0 - 23)
* | +----------- min (0 - 59)
* +------------- sec (0-59)
*
* @param null|int $start_time
* @throws \InvalidArgumentException
* @return int[]
*/
public function parse($crontab_string, $start_time = null)
{
if (! $this->isValid($crontab_string)) {
throw new \InvalidArgumentException('Invalid cron string: ' . $crontab_string);
}
$start_time = $start_time ? $start_time : time();
$date = $this->parseDate($crontab_string);
if (in_array((int) date('i', $start_time), $date['minutes'])
&& in_array((int) date('G', $start_time), $date['hours'])
&& in_array((int) date('j', $start_time), $date['day'])
&& in_array((int) date('w', $start_time), $date['week'])
&& in_array((int) date('n', $start_time), $date['month'])
) {
$result = [];
foreach ($date['second'] as $second) {
$result[] = $start_time + $second;
}
return $result;
}
return [];
}
public function isValid(string $crontab_string): bool
{
if (! preg_match('/^((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)$/i', trim($crontab_string))) {
if (! preg_match('/^((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)$/i', trim($crontab_string))) {
return false;
}
}
return true;
}
/**
* Parse each segment of crontab string.
*/
protected function parseSegment(string $string, int $min, int $max, int $start = null)
{
if ($start === null || $start < $min) {
$start = $min;
}
$result = [];
if ($string === '*') {
for ($i = $start; $i <= $max; ++$i) {
$result[] = $i;
}
} elseif (strpos($string, ',') !== false) {
$exploded = explode(',', $string);
foreach ($exploded as $value) {
if (strpos($value, '/') !== false || strpos($string, '-') !== false) {
$result = array_merge($result, $this->parseSegment($value, $min, $max, $start));
continue;
}
if (trim($value) === '' || ! $this->between((int) $value, (int) ($min > $start ? $min : $start), (int) $max)) {
continue;
}
$result[] = (int) $value;
}
} elseif (strpos($string, '/') !== false) {
$exploded = explode('/', $string);
if (strpos($exploded[0], '-') !== false) {
[$nMin, $nMax] = explode('-', $exploded[0]);
$nMin > $min && $min = (int) $nMin;
$nMax < $max && $max = (int) $nMax;
}
$start < $min && $start = $min;
for ($i = $start; $i <= $max;) {
$result[] = $i;
$i += $exploded[1];
}
} elseif (strpos($string, '-') !== false) {
$result = array_merge($result, $this->parseSegment($string . '/1', $min, $max, $start));
} elseif ($this->between((int) $string, $min > $start ? $min : $start, $max)) {
$result[] = (int) $string;
}
return $result;
}
/**
* Determire if the $value is between in $min and $max ?
*/
private function between(int $value, int $min, int $max): bool
{
return $value >= $min && $value <= $max;
}
private function parseDate(string $crontab_string): array
{
$cron = preg_split('/[\\s]+/i', trim($crontab_string));
if (count($cron) == 6) {
$date = [
'second' => $this->parseSegment($cron[0], 0, 59),
'minutes' => $this->parseSegment($cron[1], 0, 59),
'hours' => $this->parseSegment($cron[2], 0, 23),
'day' => $this->parseSegment($cron[3], 1, 31),
'month' => $this->parseSegment($cron[4], 1, 12),
'week' => $this->parseSegment($cron[5], 0, 6),
];
} else {
$date = [
'second' => [1 => 0],
'minutes' => $this->parseSegment($cron[0], 0, 59),
'hours' => $this->parseSegment($cron[1], 0, 23),
'day' => $this->parseSegment($cron[2], 1, 31),
'month' => $this->parseSegment($cron[3], 1, 12),
'week' => $this->parseSegment($cron[4], 0, 6),
];
}
return $date;
}
}