mirror of
https://github.com/crmeb/CRMEB.git
synced 2025-12-12 19:12:49 +00:00
上传钩子函数
This commit is contained in:
parent
561a5eddec
commit
c2986bc9d3
177
extend/behavior/admin/CronBehavior.php
Normal file
177
extend/behavior/admin/CronBehavior.php
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author: xaboy<365615158@qq.com>
|
||||||
|
* @day: 2017/12/18
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace behavior\admin;
|
||||||
|
|
||||||
|
use app\admin\model\user\User;
|
||||||
|
use app\admin\model\user\UserAddress;
|
||||||
|
use app\admin\model\user\UserBill;
|
||||||
|
use app\admin\model\wechat\WechatUser;
|
||||||
|
use basic\ModelBasic;
|
||||||
|
use app\admin\model\order\StoreOrder;
|
||||||
|
use app\core\util\WechatTemplateService;
|
||||||
|
use service\UtilService as Utils;
|
||||||
|
|
||||||
|
class CronBehavior
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消订单
|
||||||
|
*/
|
||||||
|
public static function cancle()
|
||||||
|
{
|
||||||
|
Utils::log('自动取消订单任务开始时间:' . date('Y-m-d H:i:s') . PHP_EOL);
|
||||||
|
// $setting = getSetting('order_cancel_time');
|
||||||
|
// $order = model('common/Order');
|
||||||
|
// $order->autoCancel($setting);
|
||||||
|
Utils::log('自动取消订单任务结束时间:' . date('Y-m-d H:i:s') . PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单自动完成
|
||||||
|
*/
|
||||||
|
public static function complete()
|
||||||
|
{
|
||||||
|
Utils::log('自动完成订单任务开始时间:'.date('Y-m-d H:i:s').PHP_EOL);
|
||||||
|
// $setting = getSetting('order_complete_time');
|
||||||
|
// model('common/Order')->autoComplete($setting);
|
||||||
|
Utils::log('自动完成订单任务结束时间:'.date('Y-m-d H:i:s').PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动评价订单
|
||||||
|
*/
|
||||||
|
public static function evaluate()
|
||||||
|
{
|
||||||
|
Utils::log('自动评价订单任务开始时间:'.date('Y-m-d H:i:s').PHP_EOL);
|
||||||
|
|
||||||
|
// $setting = getSetting('order_autoEval_time');
|
||||||
|
// model('common/Order')->autoEvaluate($setting);
|
||||||
|
Utils::log('自动评价订单任务结束时间:'.date('Y-m-d H:i:s').PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单自动签收
|
||||||
|
*/
|
||||||
|
public static function sign()
|
||||||
|
{
|
||||||
|
Utils::log('自动签收订单任务开始时间:'.date('Y-m-d H:i:s').PHP_EOL);
|
||||||
|
// $setting = getSetting('order_autoSign_time');
|
||||||
|
// model('common/Order')->autoSign($setting);
|
||||||
|
|
||||||
|
Utils::log('自动签收订单任务结束时间:'.date('Y-m-d H:i:s').PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 催付款
|
||||||
|
*/
|
||||||
|
public static function remind(){
|
||||||
|
Utils::log('催付款开始时间:'.date('Y-m-d H:i:s').PHP_EOL);
|
||||||
|
// $setting = getSetting('order_cancel_time');
|
||||||
|
// $order = new \app\common\model\Order();
|
||||||
|
// $order->remind_order_pay($setting);
|
||||||
|
Utils::log('催付款任务结束时间:'.date('Y-m-d H:i:s').PHP_EOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态为 已退款
|
||||||
|
* @param $data
|
||||||
|
* $data array type 1 直接退款 2 退款后返回原状态 refund_price 退款金额
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderRefundYAfter($data,$oid){
|
||||||
|
StoreOrder::refundTemplate($data,$oid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态为 不退款
|
||||||
|
* @param $data
|
||||||
|
* $data string 退款原因
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderRefundNAfter($data,$oid){
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 线下付款
|
||||||
|
* @param $id
|
||||||
|
* $id 订单id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderOffline($id){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改订单状态
|
||||||
|
* @param $data
|
||||||
|
* data total_price 商品总价 pay_price 实际支付
|
||||||
|
* @param $oid
|
||||||
|
* oid 订单id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderEditAfter($data,$oid){
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 修改送货信息
|
||||||
|
* @param $data
|
||||||
|
* $data array 送货人姓名/快递公司 送货人电话/快递单号
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderDistributionAfter($data,$oid){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户申请退款
|
||||||
|
* @param $oid
|
||||||
|
* @param $uid
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderApplyRefundAfter($oid, $uid)
|
||||||
|
{
|
||||||
|
$order = StoreOrder::where('id',$oid)->find();
|
||||||
|
WechatTemplateService::sendAdminNoticeTemplate([
|
||||||
|
'first'=>"亲,您有一个订单申请退款 \n订单号:{$order['order_id']}",
|
||||||
|
'keyword1'=>'申请退款',
|
||||||
|
'keyword2'=>'待处理',
|
||||||
|
'keyword3'=>date('Y/m/d H:i',time()),
|
||||||
|
'remark'=>'请及时处理'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评价产品
|
||||||
|
* @param $replyInfo
|
||||||
|
* @param $cartInfo
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderReply($replyInfo, $cartInfo)
|
||||||
|
{
|
||||||
|
//StoreOrder::checkOrderOver($cartInfo['oid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退积分
|
||||||
|
* @param $product
|
||||||
|
* $product 商品信息
|
||||||
|
* @param $back_integral
|
||||||
|
* $back_integral 退多少积分
|
||||||
|
*/
|
||||||
|
public static function storeOrderIntegralBack($product,$back_integral){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
193
extend/behavior/order/OrderBehavior.php
Normal file
193
extend/behavior/order/OrderBehavior.php
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author: xaboy<365615158@qq.com>
|
||||||
|
* @day: 2017/12/18
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace behavior\order;
|
||||||
|
|
||||||
|
|
||||||
|
use app\ebapi\model\store\StoreOrder;
|
||||||
|
use app\ebapi\model\routine\RoutineTemplate;
|
||||||
|
use app\ebapi\model\user\User;
|
||||||
|
use app\ebapi\model\user\WechatUser;
|
||||||
|
use app\ebapi\model\user\UserAddress;
|
||||||
|
use app\admin\model\order\StoreOrder as StoreOrderAdminModel;
|
||||||
|
use app\core\util\SystemConfigService;
|
||||||
|
use app\core\util\WechatTemplateService;
|
||||||
|
|
||||||
|
class OrderBehavior
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用户确认收货
|
||||||
|
* @param $order
|
||||||
|
* @param $uid
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderUserTakeDelivery($order, $uid)
|
||||||
|
{
|
||||||
|
$res1 = StoreOrder::gainUserIntegral($order);
|
||||||
|
$res2 = User::backOrderBrokerage($order);
|
||||||
|
StoreOrder::orderTakeAfter($order);
|
||||||
|
$giveCouponMinPrice = SystemConfigService::get('store_give_con_min_price');
|
||||||
|
if($order['total_price'] >= $giveCouponMinPrice) WechatUser::userTakeOrderGiveCoupon($uid);
|
||||||
|
if(!($res1 && $res2)) exception('收货失败!');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 订单创建成功后
|
||||||
|
* @param $oid
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderCreate($order,$group)
|
||||||
|
{
|
||||||
|
UserAddress::be(['is_default'=>1,'uid'=>$order['uid']]) || UserAddress::setDefaultAddress($group['addressId'],$order['uid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改发货状态 为送货
|
||||||
|
* @param $data
|
||||||
|
* $data array 送货方式 送货人姓名 送货人电话
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
// public static function storeProductOrderDeliveryAfter($data,$oid){
|
||||||
|
// StoreOrder::orderPostageAfter($data,$oid);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改发货状态 为发货
|
||||||
|
* @param $data
|
||||||
|
* $data array 发货方式 送货人姓名 送货人电话
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
// public static function storeProductOrderDeliveryGoodsAfter($data,$oid){
|
||||||
|
// StoreOrder::orderPostageAfter($data,$oid);
|
||||||
|
// RoutineTemplate::sendOrderGoods($oid,$data);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态 为已收货
|
||||||
|
* @param $data
|
||||||
|
* $data array status 状态为 已收货
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderTakeDeliveryAfter($order,$oid)
|
||||||
|
{
|
||||||
|
$res1 = StoreOrder::gainUserIntegral($order);
|
||||||
|
$res2 = User::backOrderBrokerage($order);
|
||||||
|
StoreOrder::orderTakeAfter($order);
|
||||||
|
if(!($res1 && $res2)) exception('收货失败!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线下付款
|
||||||
|
* @param $id
|
||||||
|
* $id 订单id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderOffline($id){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态为 已退款
|
||||||
|
* @param $data
|
||||||
|
* $data array type 1 直接退款 2 退款后返回原状态 refund_price 退款金额
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderRefundYAfter($data,$oid){
|
||||||
|
StoreOrderAdminModel::refundTemplate($data,$oid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态为 不退款
|
||||||
|
* @param $data
|
||||||
|
* $data string 退款原因
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderRefundNAfter($data,$oid){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改订单状态
|
||||||
|
* @param $data
|
||||||
|
* data total_price 商品总价 pay_price 实际支付
|
||||||
|
* @param $oid
|
||||||
|
* oid 订单id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderEditAfter($data,$oid){
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 修改送货信息
|
||||||
|
* @param $data
|
||||||
|
* $data array 送货人姓名/快递公司 送货人电话/快递单号
|
||||||
|
* @param $oid
|
||||||
|
* $oid string store_order表中的id
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderDistributionAfter($data,$oid){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户申请退款
|
||||||
|
* @param $oid
|
||||||
|
* @param $uid
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderApplyRefundAfter($oid, $uid)
|
||||||
|
{
|
||||||
|
$order = StoreOrder::where('id',$oid)->find();
|
||||||
|
WechatTemplateService::sendAdminNoticeTemplate([
|
||||||
|
'first'=>"亲,您有一个订单申请退款 \n订单号:{$order['order_id']}",
|
||||||
|
'keyword1'=>'申请退款',
|
||||||
|
'keyword2'=>'待处理',
|
||||||
|
'keyword3'=>date('Y/m/d H:i',time()),
|
||||||
|
'remark'=>'请及时处理'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评价产品
|
||||||
|
* @param $replyInfo
|
||||||
|
* @param $cartInfo
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderReply($replyInfo, $cartInfo)
|
||||||
|
{
|
||||||
|
StoreOrder::checkOrderOver($cartInfo['oid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单全部产品评价完
|
||||||
|
* @param $oid
|
||||||
|
*/
|
||||||
|
public static function storeProductOrderOver($oid)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退积分
|
||||||
|
* @param $product
|
||||||
|
* $product 商品信息
|
||||||
|
* @param $back_integral
|
||||||
|
* $back_integral 退多少积分
|
||||||
|
*/
|
||||||
|
public static function storeOrderIntegralBack($product,$back_integral){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入购物车成功之后
|
||||||
|
* @param array $cartInfo 购物车信息
|
||||||
|
* @param array $userInfo 用户信息
|
||||||
|
*/
|
||||||
|
public static function storeProductSetCartAfterAfter($cartInfo, $userInfo)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
57
extend/behavior/user/UserBehavior.php
Normal file
57
extend/behavior/user/UserBehavior.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author: xaboy<365615158@qq.com>
|
||||||
|
* @day: 2018/01/06
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace behavior\user;
|
||||||
|
|
||||||
|
|
||||||
|
class UserBehavior
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 管理员后台给用户添加金额
|
||||||
|
* @param $user
|
||||||
|
* $user 用户信息
|
||||||
|
* @param $money
|
||||||
|
* $money 添加的金额
|
||||||
|
*/
|
||||||
|
public static function adminAddMoney($user,$money){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员后台给用户减少金额
|
||||||
|
* @param $user
|
||||||
|
* $user 用户信息
|
||||||
|
* @param $money
|
||||||
|
* $money 减少的金额
|
||||||
|
*/
|
||||||
|
public static function adminSubMoney($user,$money){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员后台给用户增加的积分
|
||||||
|
* @param $user
|
||||||
|
* $user 用户信息
|
||||||
|
* @param $integral
|
||||||
|
* $integral 增加的积分
|
||||||
|
*/
|
||||||
|
public static function adminAddIntegral($user,$integral){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员后台给用户减少的积分
|
||||||
|
* @param $user
|
||||||
|
* $user 用户信息
|
||||||
|
* @param $integral
|
||||||
|
* $integral 减少的积分
|
||||||
|
*/
|
||||||
|
public static function adminSubIntegral($user,$integral){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
388
extend/service/cron/ManagesFrequencies.php
Normal file
388
extend/service/cron/ManagesFrequencies.php
Normal file
@ -0,0 +1,388 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace service\cron;
|
||||||
|
|
||||||
|
use Jenssegers\Date\Date;
|
||||||
|
|
||||||
|
//共用的一些属性和方法提取出来做来公共trait类
|
||||||
|
trait ManagesFrequencies
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 设置任务执行周期
|
||||||
|
*
|
||||||
|
* @param string $expression
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function expression($expression)
|
||||||
|
{
|
||||||
|
$this->expression = $expression;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置区间时间
|
||||||
|
*
|
||||||
|
* @param string $startTime
|
||||||
|
* @param string $endTime
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function between($startTime, $endTime)
|
||||||
|
{
|
||||||
|
return $this->when($this->inTimeInterval($startTime, $endTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排除区间时间
|
||||||
|
*
|
||||||
|
* @param string $startTime
|
||||||
|
* @param string $endTime
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function unlessBetween($startTime, $endTime)
|
||||||
|
{
|
||||||
|
return $this->skip($this->inTimeInterval($startTime, $endTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function inTimeInterval($startTime, $endTime)
|
||||||
|
{
|
||||||
|
return function () use ($startTime, $endTime) {
|
||||||
|
return Date::now($this->timezone)->between(
|
||||||
|
Date::parse($startTime, $this->timezone),
|
||||||
|
Date::parse($endTime, $this->timezone),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按小时执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function hourly()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按小时延期执行
|
||||||
|
*
|
||||||
|
* @param int $offset
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function hourlyAt($offset)
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按天执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function daily()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, 0)
|
||||||
|
->spliceIntoPosition(2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定时间执行
|
||||||
|
*
|
||||||
|
* @param string $time
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function at($time)
|
||||||
|
{
|
||||||
|
return $this->dailyAt($time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定时间执行
|
||||||
|
*
|
||||||
|
* @param string $time
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function dailyAt($time)
|
||||||
|
{
|
||||||
|
$segments = explode(':', $time);
|
||||||
|
|
||||||
|
return $this->spliceIntoPosition(2, (int) $segments[0])
|
||||||
|
->spliceIntoPosition(1, count($segments) == 2 ? (int) $segments[1] : '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每天执行两次
|
||||||
|
*
|
||||||
|
* @param int $first
|
||||||
|
* @param int $second
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function twiceDaily($first = 1, $second = 13)
|
||||||
|
{
|
||||||
|
$hours = $first . ',' . $second;
|
||||||
|
|
||||||
|
return $this->spliceIntoPosition(1, 0)
|
||||||
|
->spliceIntoPosition(2, $hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作日执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function weekdays()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(5, '1-5');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 周末执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function weekends()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(5, '0,6');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 星期一执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function mondays()
|
||||||
|
{
|
||||||
|
return $this->days(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 星期二执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function tuesdays()
|
||||||
|
{
|
||||||
|
return $this->days(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 星期三执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function wednesdays()
|
||||||
|
{
|
||||||
|
return $this->days(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 星期四执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function thursdays()
|
||||||
|
{
|
||||||
|
return $this->days(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 星期五执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function fridays()
|
||||||
|
{
|
||||||
|
return $this->days(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 星期六执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function saturdays()
|
||||||
|
{
|
||||||
|
return $this->days(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 星期天执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function sundays()
|
||||||
|
{
|
||||||
|
return $this->days(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按周执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function weekly()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, 0)
|
||||||
|
->spliceIntoPosition(2, 0)
|
||||||
|
->spliceIntoPosition(5, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定每周的时间执行
|
||||||
|
*
|
||||||
|
* @param int $day
|
||||||
|
* @param string $time
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function weeklyOn($day, $time = '0:0')
|
||||||
|
{
|
||||||
|
$this->dailyAt($time);
|
||||||
|
|
||||||
|
return $this->spliceIntoPosition(5, $day);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按月执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function monthly()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, 0)
|
||||||
|
->spliceIntoPosition(2, 0)
|
||||||
|
->spliceIntoPosition(3, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定每月的执行时间
|
||||||
|
*
|
||||||
|
* @param int $day
|
||||||
|
* @param string $time
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function monthlyOn($day = 1, $time = '0:0')
|
||||||
|
{
|
||||||
|
$this->dailyAt($time);
|
||||||
|
|
||||||
|
return $this->spliceIntoPosition(3, $day);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每月执行两次
|
||||||
|
*
|
||||||
|
* @param int $first
|
||||||
|
* @param int $second
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function twiceMonthly($first = 1, $second = 16)
|
||||||
|
{
|
||||||
|
$days = $first . ',' . $second;
|
||||||
|
|
||||||
|
return $this->spliceIntoPosition(1, 0)
|
||||||
|
->spliceIntoPosition(2, 0)
|
||||||
|
->spliceIntoPosition(3, $days);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按季度执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function quarterly()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, 0)
|
||||||
|
->spliceIntoPosition(2, 0)
|
||||||
|
->spliceIntoPosition(3, 1)
|
||||||
|
->spliceIntoPosition(4, '*/3');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按年执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function yearly()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, 0)
|
||||||
|
->spliceIntoPosition(2, 0)
|
||||||
|
->spliceIntoPosition(3, 1)
|
||||||
|
->spliceIntoPosition(4, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每分钟执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function everyMinute()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, '*');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每5分钟执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function everyFiveMinutes()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, '*/5');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每10分钟执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function everyTenMinutes()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, '*/10');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每30分钟执行
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function everyThirtyMinutes()
|
||||||
|
{
|
||||||
|
return $this->spliceIntoPosition(1, '0,30');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按周设置天执行
|
||||||
|
*
|
||||||
|
* @param array|mixed $days
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function days($days)
|
||||||
|
{
|
||||||
|
$days = is_array($days) ? $days : func_get_args();
|
||||||
|
|
||||||
|
return $this->spliceIntoPosition(5, implode(',', $days));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置时区
|
||||||
|
*
|
||||||
|
* @param \DateTimeZone|string $timezone
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function timezone($timezone)
|
||||||
|
{
|
||||||
|
$this->timezone = $timezone;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function spliceIntoPosition($position, $value)
|
||||||
|
{
|
||||||
|
$segments = explode(' ', $this->expression);
|
||||||
|
|
||||||
|
$segments[$position - 1] = $value;
|
||||||
|
|
||||||
|
return $this->expression(implode(' ', $segments));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user