diff --git a/extend/Api/Express.php b/extend/Api/Express.php index 334fd070..fe87bea3 100644 --- a/extend/Api/Express.php +++ b/extend/Api/Express.php @@ -9,7 +9,7 @@ namespace Api; use service\HttpService; -use service\SystemConfigService; +use app\core\util\SystemConfigService; class Express { diff --git a/extend/behavior/admin/CronBehavior.php b/extend/behavior/admin/CronBehavior.php new file mode 100644 index 00000000..71cc486f --- /dev/null +++ b/extend/behavior/admin/CronBehavior.php @@ -0,0 +1,177 @@ + + * @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){ + + } + + + + +} \ No newline at end of file diff --git a/extend/behavior/admin/OrderBehavior.php b/extend/behavior/admin/OrderBehavior.php new file mode 100644 index 00000000..39b6e867 --- /dev/null +++ b/extend/behavior/admin/OrderBehavior.php @@ -0,0 +1,166 @@ + + * @day: 2017/12/18 + */ + +namespace behavior\admin; + +use app\admin\model\user\User; +use app\admin\model\order\StoreOrder as AdminStoreOrder; +use app\core\util\WechatTemplateService; + +class OrderBehavior +{ + + + + /** + * 修改发货状态 为送货 + * @param $data + * $data array 送货方式 送货人姓名 送货人电话 + * @param $oid + * $oid string store_order表中的id + */ + public static function storeProductOrderDeliveryAfter($data,$oid){ + AdminStoreOrder::orderPostageAfter($oid,$data); +// AdminStoreOrder::sendOrderGoods($oid,$data); + } + + /** + * 修改发货状态 为发货 + * @param $data + * $data array 发货方式 送货人姓名 送货人电话 + * @param $oid + * $oid string store_order表中的id + */ + public static function storeProductOrderDeliveryGoodsAfter($data,$oid){ + AdminStoreOrder::orderPostageAfter($oid,$data); + } + + /** + * 后台修改状态 为已收货 + * @param $data + * $data array status 状态为 已收货 + * @param $oid + * $oid string store_order表中的id + */ + public static function storeProductOrderTakeDelivery($order) + { + + $res1 = AdminStoreOrder::gainUserIntegral($order); + $res2 = User::backOrderBrokerage($order); + AdminStoreOrder::orderTakeAfter($order); + if(!($res1 && $res2)) exception('收货失败!'); + } + + + /** + * 修改状态为 已退款 + * @param $data + * $data array type 1 直接退款 2 退款后返回原状态 refund_price 退款金额 + * @param $oid + * $oid string store_order表中的id + */ + public static function storeProductOrderRefundYAfter($data,$oid){ + if($data['is_channel']) AdminStoreOrder::refundRoutineTemplate($oid); //TODO 小程序余额退款模板消息 + else AdminStoreOrder::refundTemplate($data,$oid);//TODO 公众号余额退款模板消息 + } + + /** + * 修改状态为 不退款 + * @param $data + * $data string 退款原因 + * @param $oid + * $oid string store_order表中的id + */ + public static function storeProductOrderRefundNAfter($data,$oid){ + AdminStoreOrder::refundNoPrieTemplate($oid,$data); + } + /** + * 线下付款 + * @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 = AdminStoreOrder::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){ + + } + + /** + * TODO 后台余额退款 + * @param $product + * @param $refund_data + */ + public static function storeOrderYueRefund($product,$refund_data) + { + $res = AdminStoreOrder::integralBack($product['id']); + if(!$res) exception('退积分失败!'); + + } + + + + +} \ No newline at end of file diff --git a/extend/behavior/order/OrderBehavior.php b/extend/behavior/order/OrderBehavior.php new file mode 100644 index 00000000..0229cf50 --- /dev/null +++ b/extend/behavior/order/OrderBehavior.php @@ -0,0 +1,193 @@ + + * @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) + { + + } +} \ No newline at end of file diff --git a/extend/behavior/product/ProductBehavior.php b/extend/behavior/product/ProductBehavior.php new file mode 100644 index 00000000..50603487 --- /dev/null +++ b/extend/behavior/product/ProductBehavior.php @@ -0,0 +1,159 @@ + + * @day: 2017/12/18 + */ + +namespace behavior\product; + + +class ProductBehavior +{ + + /** + * 取消点赞产品后 + * @param $productId + * @param $uid + */ + public static function storeProductUnLikeAfter($productId, $uid) + { + + } + + /** + * 收藏产品后 + * @param $product + * @param $uid + */ + public static function storeProductCollecAfter($product, $uid) + { + + } + + /** + * 取消收藏产品后 + * @param $productId + * @param $uid + */ + public static function storeProductUnCollecAfter($productId, $uid) + { + + } + + /** + * 点赞产品后 + * @param $product + * @param $uid + */ + public static function storeProductLikeAfter($product, $uid) + { + + } + + /** + * 订单创建成功后 + * @param $oid + */ + public static function storeProductOrderCreate($order,$group) + { + + } + + + /** + * 修改状态 为已收货 + * @param $data + * $data array status 状态为 已收货 + * @param $oid + * $oid string store_order表中的id + */ + public static function storeProductOrderTakeDeliveryAfter($order,$oid) + { + + } + + /** + * 用户确认收货 + * @param $order + * @param $uid + */ + public static function storeProductOrderUserTakeDelivery($order, $uid) + { + + } + + /** + * 线下付款 + * @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){ + + } + + + /** + * 修改送货信息 + * @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) + { + + } + + + /** + * 评价产品 + * @param $replyInfo + * @param $cartInfo + */ + public static function storeProductOrderReply($replyInfo, $cartInfo) + { + + } + + /** + * 订单全部产品评价完 + * @param $oid + */ + public static function storeProductOrderOver($oid) + { + + } + + /** + * 加入购物车成功之后 + * @param array $cartInfo 购物车信息 + * @param array $userInfo 用户信息 + */ + public static function storeProductSetCartAfterAfter($cartInfo, $userInfo) + { + + } + + +} \ No newline at end of file diff --git a/extend/behavior/routine/StoreProductBehavior.php b/extend/behavior/routine/StoreProductBehavior.php index db008142..27f59400 100644 --- a/extend/behavior/routine/StoreProductBehavior.php +++ b/extend/behavior/routine/StoreProductBehavior.php @@ -8,17 +8,36 @@ namespace behavior\routine; -use app\routine\model\store\StoreOrder; -use app\routine\model\routine\RoutineTemplate; -use app\routine\model\user\User; -use app\routine\model\user\WechatUser; -use app\routine\model\user\UserAddress; +use app\ebapi\model\store\StoreOrder; +use app\core\model\routine\RoutineTemplate; +use app\core\model\user\User; +use app\ebapi\model\user\WechatUser; +use app\ebapi\model\user\UserAddress; use app\admin\model\order\StoreOrder as StoreOrderAdminModel; -use service\SystemConfigService; -use service\WechatTemplateService; +use app\core\util\SystemConfigService; +use app\core\util\WechatTemplateService; class StoreProductBehavior { + /** + * 取消点赞产品后 + * @param $productId + * @param $uid + */ + public static function storeProductUnLikeAfter($productId, $uid) + { + + } + + /** + * 点赞产品后 + * @param $product + * @param $uid + */ + public static function storeProductLikeAfter($product, $uid) + { + + } /** * 用户确认收货 * @param $order diff --git a/extend/behavior/user/UserBehavior.php b/extend/behavior/user/UserBehavior.php new file mode 100644 index 00000000..7034d689 --- /dev/null +++ b/extend/behavior/user/UserBehavior.php @@ -0,0 +1,57 @@ + + * @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){ + + } + +} \ No newline at end of file diff --git a/extend/behavior/wap/StoreProductBehavior.php b/extend/behavior/wap/StoreProductBehavior.php index c92f2697..9b3aca18 100644 --- a/extend/behavior/wap/StoreProductBehavior.php +++ b/extend/behavior/wap/StoreProductBehavior.php @@ -17,8 +17,8 @@ use app\wap\model\user\UserBill; use app\wap\model\user\WechatUser; use basic\ModelBasic; use app\admin\model\order\StoreOrder as StoreOrderAdminModel; -use service\SystemConfigService; -use service\WechatTemplateService; +use app\core\util\SystemConfigService; +use app\core\util\WechatTemplateService; class StoreProductBehavior { diff --git a/extend/behavior/wechat/MessageBehavior.php b/extend/behavior/wechat/MessageBehavior.php index 9c002bc9..2b736918 100644 --- a/extend/behavior/wechat/MessageBehavior.php +++ b/extend/behavior/wechat/MessageBehavior.php @@ -12,7 +12,7 @@ use app\admin\model\wechat\WechatMessage; use app\admin\model\wechat\WechatReply; use app\wap\model\user\WechatUser; use service\HookService; -use service\QrcodeService; +use app\core\util\QrcodeService; /** * 用户消息行为 diff --git a/extend/behavior/wechat/PaymentBehavior.php b/extend/behavior/wechat/PaymentBehavior.php index 127d89ef..b08dc26a 100644 --- a/extend/behavior/wechat/PaymentBehavior.php +++ b/extend/behavior/wechat/PaymentBehavior.php @@ -9,24 +9,33 @@ namespace behavior\wechat; use app\admin\model\wechat\WechatMessage; -use app\routine\model\store\StoreOrder as StoreOrderRoutineModel; +use app\ebapi\model\store\StoreOrder as StoreOrderRoutineModel; use app\wap\model\store\StoreOrder as StoreOrderWapModel; use app\wap\model\user\UserRecharge; use service\HookService; -use service\RoutineRefund; -use service\WechatService; +use app\core\util\WechatService; +use app\core\util\MiniProgramService; class PaymentBehavior { /** - * 下单成功之后 + * 公众号下单成功之后 * @param $order * @param $prepay_id */ public static function wechatPaymentPrepare($order, $prepay_id) { + } + /** + * 小程序下单成功之后 + * @param $order + * @param $prepay_id + */ + public static function wechatPaymentPrepareProgram($order, $prepay_id) + { + } /** @@ -61,6 +70,7 @@ class PaymentBehavior /** * 商品订单支付成功后 小程序 + * * @param $orderId * @param $notify * @return bool @@ -120,8 +130,7 @@ class PaymentBehavior */ public static function routinePayOrderRefund($orderNo, array $opt) { - $refundDesc = isset($opt['desc']) ? $opt['desc'] : ''; - $res = RoutineRefund::doRefund($opt['pay_price'],$opt['refund_price'],$orderNo,'',$orderNo,$refundDesc); + return MiniProgramService::payOrderRefund($orderNo,$opt);//2.5.36 } /** diff --git a/extend/behavior/wechat/UserBehavior.php b/extend/behavior/wechat/UserBehavior.php index 5f7481d1..7fd09c49 100644 --- a/extend/behavior/wechat/UserBehavior.php +++ b/extend/behavior/wechat/UserBehavior.php @@ -20,6 +20,9 @@ class UserBehavior */ public static function wechatOauthAfter($openid,$wechatInfo) { +// echo "调试中"; +// var_dump($wechatInfo); + $wechatInfo['nickname'] = filterEmoji($wechatInfo['nickname']); Cookie::set('is_login',1); if(isset($wechatInfo['unionid']) && $wechatInfo['unionid'] != '' && WechatUser::be(['unionid'=>$wechatInfo['unionid']])){ WechatUser::edit($wechatInfo,$wechatInfo['unionid'],'unionid'); @@ -34,6 +37,9 @@ class UserBehavior WechatUser::edit($wechatInfo,$wechatInfo['openid'],'openid'); User::updateWechatUser($wechatInfo,WechatUser::openidToUid($wechatInfo['openid'])); }else{ + if(isset($wechatInfo['subscribe_scene'])) unset($wechatInfo['subscribe_scene']); + if(isset($wechatInfo['qr_scene'])) unset($wechatInfo['qr_scene']); + if(isset($wechatInfo['qr_scene_str'])) unset($wechatInfo['qr_scene_str']); $wechatInfo = WechatUser::set($wechatInfo); User::setWechatUser($wechatInfo); } diff --git a/extend/service/JsonService.php b/extend/service/JsonService.php index 2ebdb2e8..47408b72 100644 --- a/extend/service/JsonService.php +++ b/extend/service/JsonService.php @@ -49,13 +49,34 @@ class JsonService return self::result(200,$msg,compact('status','result')); } - public static function fail($msg,$data=[]) + public static function fail($msg,$data=[],$code=400) { if(true == is_array($msg)){ $data = $msg; $msg = self::$FAIL_DEFAULT_MSG; } - return self::result(400,$msg,$data); + return self::result($code,$msg,$data); + } + + public static function success($msg,$data=[]) + { + if(true == is_array($msg)){ + $data = $msg; + $msg = self::$SUCCESSFUL_DEFAULT_MSG; + } + return self::result(200,$msg,$data); + } + + /* + * 设置返回数据 + * @param int $code 响应code + * @param string $msg 提示语 + * @param array $data 返回数据 + * @return array + * */ + public static function returnData($code,$msg='',$data=[]) + { + return compact('code','msg','data'); } } \ No newline at end of file diff --git a/extend/service/UtilService.php b/extend/service/UtilService.php index 18b5b865..9a233885 100644 --- a/extend/service/UtilService.php +++ b/extend/service/UtilService.php @@ -310,4 +310,182 @@ class UtilService return true;/* 身份证格式正确*/ } + /** + * TODO 砍价 拼团 分享海报生成 + * @param array $data + * @param string $fileName + */ + public static function setShareMarketingPoster($data = array(), $fileName = ''){ + $config = array( + 'text'=>array( + array( + 'text'=>$data['price'],//TODO 价格 + 'left'=>116, + 'top'=>200, + 'fontPath'=>ROOT_PATH.'public/static/font/SourceHanSansCN-Medium.otf', //字体文件 + 'fontSize'=>50, //字号 + 'fontColor'=>'255,0,0', //字体颜色 + 'angle'=>0, + ), + array( + 'text'=>$data['label'],//TODO 标签 + 'left'=>394, + 'top'=>190, + 'fontPath'=>ROOT_PATH.'public/static/font/SourceHanSansCN-Normal.otf', //字体文件 + 'fontSize'=>24, //字号 + 'fontColor'=>'255,255,255', //字体颜色 + 'angle'=>0, + ), + array( + 'text'=>$data['msg'],//TODO 简述 + 'left'=>80, + 'top'=>270, + 'fontPath'=>ROOT_PATH.'public/static/font/SourceHanSansCN-Normal.otf', //字体文件 + 'fontSize'=>22, //字号 + 'fontColor'=>'40,40,40', //字体颜色 + 'angle'=>0, + ) + ), + 'image'=>array( + array( + 'url'=>ROOT_PATH.$data['image'], //图片 + 'stream'=>0, + 'left'=>120, + 'top'=>340, + 'right'=>0, + 'bottom'=>0, + 'width'=>450, + 'height'=>450, + 'opacity'=>100 + ), + array( + 'url'=>ROOT_PATH.$data['url'], //二维码资源 + 'stream'=>0, + 'left'=>260, + 'top'=>890, + 'right'=>0, + 'bottom'=>0, + 'width'=>160, + 'height'=>160, + 'opacity'=>100 + ) + ), + 'background'=>ROOT_PATH.'/public/static/poster/poster.jpg' + ); + if(!file_exists($config['background'])) exception('缺少系统预设背景图片'); + if(strlen($data['title']) < 36){ + $text = array( + 'text'=>$data['title'],//TODO 标题 + 'left'=>76, + 'top'=>100, + 'fontPath'=>ROOT_PATH.'public/static/font/SourceHanSansCN-Bold.otf', //字体文件 + 'fontSize'=>32, //字号 + 'fontColor'=>'0,0,0', //字体颜色 + 'angle'=>0, + ); + array_push($config['text'],$text); + }else{ + $titleOne = array( + 'text'=>mb_substr($data['title'], 0, 12),//TODO 标题 + 'left'=>76, + 'top'=>70, + 'fontPath'=>ROOT_PATH.'public/static/font/SourceHanSansCN-Bold.otf', //字体文件 + 'fontSize'=>32, //字号 + 'fontColor'=>'0,0,0', //字体颜色 + 'angle'=>0, + ); + $titleTwo = array( + 'text'=> mb_substr($data['title'], 12, 12),//TODO 标题 + 'left'=>76, + 'top'=>120, + 'fontPath'=>ROOT_PATH.'public/static/font/SourceHanSansCN-Bold.otf', //字体文件 + 'fontSize'=>32, //字号 + 'fontColor'=>'0,0,0', //字体颜色 + 'angle'=>0, + ); + array_push($config['text'],$titleOne); + array_push($config['text'],$titleTwo); + } + self::setSharePoster($config,$fileName); + } + + /** + * TODO 生成分享二维码图片 + * @param array $config + * @param string $fileName + * @return bool|string + */ + public static function setSharePoster($config = array(),$fileName = ''){ + $imageDefault = array( + 'left'=>0, + 'top'=>0, + 'right'=>0, + 'bottom'=>0, + 'width'=>100, + 'height'=>100, + 'opacity'=>100 + ); + $textDefault = array( + 'text'=>'', + 'left'=>0, + 'top'=>0, + 'fontSize'=>32, //字号 + 'fontColor'=>'255,255,255', //字体颜色 + 'angle'=>0, + ); + $background = $config['background'];//海报最底层得背景 + $backgroundInfo = getimagesize($background); + $background = imagecreatefromstring(file_get_contents($background)); + $backgroundWidth = $backgroundInfo[0]; //背景宽度 + $backgroundHeight = $backgroundInfo[1]; //背景高度 + $imageRes = imageCreatetruecolor($backgroundWidth,$backgroundHeight); + $color = imagecolorallocate($imageRes, 0, 0, 0); + imagefill($imageRes, 0, 0, $color); + imagecopyresampled($imageRes,$background,0,0,0,0,imagesx($background),imagesy($background),imagesx($background),imagesy($background)); + if(!empty($config['image'])){ + foreach ($config['image'] as $key => $val) { + $val = array_merge($imageDefault,$val); + $info = getimagesize($val['url']); + $function = 'imagecreatefrom'.image_type_to_extension($info[2], false); + if($val['stream']){ + $info = getimagesizefromstring($val['url']); + $function = 'imagecreatefromstring'; + } + $res = $function($val['url']); + $resWidth = $info[0]; + $resHeight = $info[1]; + $canvas=imagecreatetruecolor($val['width'], $val['height']); + imagefill($canvas, 0, 0, $color); + imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'],$resWidth,$resHeight); + $val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']) - $val['width']:$val['left']; + $val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']) - $val['height']:$val['top']; + imagecopymerge($imageRes,$canvas, $val['left'],$val['top'],$val['right'],$val['bottom'],$val['width'],$val['height'],$val['opacity']);//左,上,右,下,宽度,高度,透明度 + } + } + if(isset($config['text']) && !empty($config['text'])){ + foreach ($config['text'] as $key => $val) { + $val = array_merge($textDefault,$val); + list($R,$G,$B) = explode(',', $val['fontColor']); + $fontColor = imagecolorallocate($imageRes, $R, $G, $B); + $val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']):$val['left']; + $val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']):$val['top']; + imagettftext($imageRes,$val['fontSize'],$val['angle'],$val['left'],$val['top'],$fontColor,realpath($val['fontPath']),$val['text']); + } + } + $res = imagejpeg ($imageRes,$fileName,90); + imagedestroy($imageRes); + if(!$res) return false; + return $fileName; + } + + /* + * 获取当前控制器模型方法组合成的字符串 + * @paran object $request Request 实例化后的对象 + * @retun string + * */ + public static function getCurrentController(Request $request) + { + return strtolower($request->module().'/'.$request->controller().'/'.$request->action()); + } + } \ No newline at end of file diff --git a/extend/service/cron/ManagesFrequencies.php b/extend/service/cron/ManagesFrequencies.php new file mode 100644 index 00000000..9f82f4a8 --- /dev/null +++ b/extend/service/cron/ManagesFrequencies.php @@ -0,0 +1,388 @@ +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)); + } +}