diff --git a/app/admin/controller/crontab/CrontabController.php b/app/admin/controller/crontab/CrontabController.php deleted file mode 100755 index cf20eb4..0000000 --- a/app/admin/controller/crontab/CrontabController.php +++ /dev/null @@ -1,128 +0,0 @@ -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); - } -} \ No newline at end of file diff --git a/app/admin/controller/express/ExpressController.php b/app/admin/controller/express/ExpressController.php new file mode 100644 index 0000000..24e0e76 --- /dev/null +++ b/app/admin/controller/express/ExpressController.php @@ -0,0 +1,95 @@ +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); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/operation/OpurchaseGoodsOfferController.php b/app/admin/controller/operation/OpurchaseGoodsOfferController.php index 75c0391..e611614 100644 --- a/app/admin/controller/operation/OpurchaseGoodsOfferController.php +++ b/app/admin/controller/operation/OpurchaseGoodsOfferController.php @@ -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()); + } } diff --git a/app/admin/controller/retail/CashierclassController.php b/app/admin/controller/retail/CashierclassController.php index 97b7aad..d5ce524 100644 --- a/app/admin/controller/retail/CashierclassController.php +++ b/app/admin/controller/retail/CashierclassController.php @@ -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); } diff --git a/app/admin/lists/crontab/CrontabLists.php b/app/admin/lists/crontab/CrontabLists.php deleted file mode 100755 index 10d1eb4..0000000 --- a/app/admin/lists/crontab/CrontabLists.php +++ /dev/null @@ -1,61 +0,0 @@ -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(); - } -} \ No newline at end of file diff --git a/app/admin/lists/express/ExpressLists.php b/app/admin/lists/express/ExpressLists.php new file mode 100644 index 0000000..f028e14 --- /dev/null +++ b/app/admin/lists/express/ExpressLists.php @@ -0,0 +1,65 @@ + ['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(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/operation/OpurchaseclassLists.php b/app/admin/lists/operation/OpurchaseclassLists.php index 2cf63f2..ce31487 100644 --- a/app/admin/lists/operation/OpurchaseclassLists.php +++ b/app/admin/lists/operation/OpurchaseclassLists.php @@ -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){ diff --git a/app/admin/lists/operation/OpurchaseclassofferLists.php b/app/admin/lists/operation/OpurchaseclassofferLists.php index 9684b29..64e0d4d 100644 --- a/app/admin/lists/operation/OpurchaseclassofferLists.php +++ b/app/admin/lists/operation/OpurchaseclassofferLists.php @@ -32,6 +32,7 @@ class OpurchaseclassofferLists extends BaseAdminDataLists implements ListsSearch { return [ '=' => ['is_adopt', 'is_storage', 'order_id'], + 'between_time'=>'create_time' ]; } diff --git a/app/admin/lists/retail/CashierclassStreamLists.php b/app/admin/lists/retail/CashierclassStreamLists.php index 2afae3e..babcf77 100644 --- a/app/admin/lists/retail/CashierclassStreamLists.php +++ b/app/admin/lists/retail/CashierclassStreamLists.php @@ -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){ diff --git a/app/admin/logic/crontab/CrontabLogic.php b/app/admin/logic/crontab/CrontabLogic.php deleted file mode 100755 index 5a6518c..0000000 --- a/app/admin/logic/crontab/CrontabLogic.php +++ /dev/null @@ -1,169 +0,0 @@ -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(); - } - } -} \ No newline at end of file diff --git a/app/admin/logic/express/ExpressLogic.php b/app/admin/logic/express/ExpressLogic.php new file mode 100644 index 0000000..d44e38b --- /dev/null +++ b/app/admin/logic/express/ExpressLogic.php @@ -0,0 +1,98 @@ + $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(); + } +} \ No newline at end of file diff --git a/app/admin/logic/operation/OpurchaseclassLogic.php b/app/admin/logic/operation/OpurchaseclassLogic.php index a53d1c8..f07e94d 100644 --- a/app/admin/logic/operation/OpurchaseclassLogic.php +++ b/app/admin/logic/operation/OpurchaseclassLogic.php @@ -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; } diff --git a/app/admin/logic/retail/CashierclassLogic.php b/app/admin/logic/retail/CashierclassLogic.php index 5c5de21..26b5024 100644 --- a/app/admin/logic/retail/CashierclassLogic.php +++ b/app/admin/logic/retail/CashierclassLogic.php @@ -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; } } \ No newline at end of file diff --git a/app/admin/validate/crontab/CrontabValidate.php b/app/admin/validate/crontab/CrontabValidate.php deleted file mode 100755 index c81a172..0000000 --- a/app/admin/validate/crontab/CrontabValidate.php +++ /dev/null @@ -1,138 +0,0 @@ - '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; - } -} \ No newline at end of file diff --git a/app/admin/validate/express/ExpressValidate.php b/app/admin/validate/express/ExpressValidate.php new file mode 100644 index 0000000..a154ca8 --- /dev/null +++ b/app/admin/validate/express/ExpressValidate.php @@ -0,0 +1,84 @@ + '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']); + } + +} \ No newline at end of file diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index e51f477..7a6c843 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -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()); + } } diff --git a/app/api/controller/operation/OpurchaseGoodsOfferController.php b/app/api/controller/operation/OpurchaseGoodsOfferController.php index 84573e7..198f717 100644 --- a/app/api/controller/operation/OpurchaseGoodsOfferController.php +++ b/app/api/controller/operation/OpurchaseGoodsOfferController.php @@ -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]); } /** diff --git a/app/api/controller/operation/OpurchaseclassController.php b/app/api/controller/operation/OpurchaseclassController.php index 3944a16..ed72d18 100644 --- a/app/api/controller/operation/OpurchaseclassController.php +++ b/app/api/controller/operation/OpurchaseclassController.php @@ -1,16 +1,20 @@ 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('报价失败'); } -} \ No newline at end of file + /** + * 提交物流 + */ + 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()); + } +} diff --git a/app/api/lists/operation/OpurchaseGoodsOfferList.php b/app/api/lists/operation/OpurchaseGoodsOfferList.php index 3027c31..e44354a 100644 --- a/app/api/lists/operation/OpurchaseGoodsOfferList.php +++ b/app/api/lists/operation/OpurchaseGoodsOfferList.php @@ -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(); } - -} \ No newline at end of file +} diff --git a/app/api/logic/operation/OpurchaseGoodsOfferLogic.php b/app/api/logic/operation/OpurchaseGoodsOfferLogic.php index d53ef9c..84a15b5 100644 --- a/app/api/logic/operation/OpurchaseGoodsOfferLogic.php +++ b/app/api/logic/operation/OpurchaseGoodsOfferLogic.php @@ -1,30 +1,33 @@ 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; + } + } } diff --git a/app/api/validate/OpurchaseGoodsOfferValidate.php b/app/api/validate/OpurchaseGoodsOfferValidate.php index 44bbe6d..c3ca615 100644 --- a/app/api/validate/OpurchaseGoodsOfferValidate.php +++ b/app/api/validate/OpurchaseGoodsOfferValidate.php @@ -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){ diff --git a/app/common/model/Crontab.php b/app/common/model/Crontab.php deleted file mode 100755 index 88d4de3..0000000 --- a/app/common/model/Crontab.php +++ /dev/null @@ -1,80 +0,0 @@ - '定时任务', - 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); - } -} \ No newline at end of file diff --git a/app/common/model/express/Express.php b/app/common/model/express/Express.php new file mode 100644 index 0000000..829a426 --- /dev/null +++ b/app/common/model/express/Express.php @@ -0,0 +1,22 @@ +=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", diff --git a/config/process.php b/config/process.php index f22f488..916875c 100644 --- a/config/process.php +++ b/config/process.php @@ -1,4 +1,5 @@ DIRECTORY_SEPARATOR === '/', ] ] - ] + ], + 'task' => [ + 'handler' => process\Task::class + ], ]; diff --git a/process/Task.php b/process/Task.php new file mode 100644 index 0000000..bb46994 --- /dev/null +++ b/process/Task.php @@ -0,0 +1,29 @@ +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]); // 删除时间设置为当前时间,即删除 + } +} \ No newline at end of file diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index 784202e..4940d7c 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -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'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 03942c8..e036cd1 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 333666f..9ff3bd3 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -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", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index df28dca..912b25b 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -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', diff --git a/vendor/workerman/crontab/README.md b/vendor/workerman/crontab/README.md new file mode 100644 index 0000000..0117eb9 --- /dev/null +++ b/vendor/workerman/crontab/README.md @@ -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 +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` diff --git a/vendor/workerman/crontab/composer.json b/vendor/workerman/crontab/composer.json new file mode 100644 index 0000000..2561bdf --- /dev/null +++ b/vendor/workerman/crontab/composer.json @@ -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" + } + } +} diff --git a/vendor/workerman/crontab/example/test.php b/vendor/workerman/crontab/example/test.php new file mode 100644 index 0000000..e6a87ed --- /dev/null +++ b/vendor/workerman/crontab/example/test.php @@ -0,0 +1,16 @@ +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(); diff --git a/vendor/workerman/crontab/src/Crontab.php b/vendor/workerman/crontab/src/Crontab.php new file mode 100644 index 0000000..9bee915 --- /dev/null +++ b/vendor/workerman/crontab/src/Crontab.php @@ -0,0 +1,177 @@ + + * @copyright walkor + * @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); + } + +} diff --git a/vendor/workerman/crontab/src/Parser.php b/vendor/workerman/crontab/src/Parser.php new file mode 100644 index 0000000..e9a9a86 --- /dev/null +++ b/vendor/workerman/crontab/src/Parser.php @@ -0,0 +1,171 @@ +, 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 . + */ + +/** + * Provides basic cron syntax parsing functionality + * + * @author: Jan Konieczny , 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; + } +}