|
@@ -17,7 +17,11 @@ use App\Http\Utils\Jutuike\JutuikeUtil;
|
|
|
use App\Http\Utils\LoggerFactoryUtil;
|
|
|
use App\Http\Utils\Meituan\MeituanLianmengUtil;
|
|
|
use App\Http\Utils\Pdd\DuoDuoKeUtil;
|
|
|
+use App\Http\Utils\WechatAccountUtil;
|
|
|
use App\Models\CategoryModel;
|
|
|
+use App\Models\UserModel;
|
|
|
+use App\Models\UserOrderCommissionModel;
|
|
|
+use App\Models\UserOrderModel;
|
|
|
|
|
|
class CronLogic extends BaseLogic
|
|
|
{
|
|
@@ -280,4 +284,156 @@ class CronLogic extends BaseLogic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送用户下单模版
|
|
|
+ */
|
|
|
+ public static function sendOrderTemplateLogic()
|
|
|
+ {
|
|
|
+ $instance = new LoggerFactoryUtil(CronLogic::class);
|
|
|
+ //1.新增粉丝通知
|
|
|
+ $userFans = UserModel::query()
|
|
|
+ ->where("invite_user_id","<>",0)
|
|
|
+ ->where("user_notify_status",0)
|
|
|
+ ->get();
|
|
|
+ foreach ($userFans as $userFan){
|
|
|
+ //获取推荐人
|
|
|
+ $inviteUser = UserModel::findById($userFan->invite_user_id);
|
|
|
+ if($inviteUser){
|
|
|
+ try{
|
|
|
+ //获取公众号实例
|
|
|
+ $app = WechatAccountUtil::getAppByID($userFan->wechat_account_id);
|
|
|
+ $data = [
|
|
|
+ 'touser' => $userFan->user_open_id,
|
|
|
+ 'template_id' => env("WECHAT_FANS_TEMPLATE_URL"),
|
|
|
+ 'url' => env("WECHAT_FANS_URL"),
|
|
|
+ 'data' => [
|
|
|
+ 'first' => "亲,您有新的粉丝",
|
|
|
+ 'keyword1' => $userFan->user_nickname,
|
|
|
+ 'keyword2' => $userFan->id+100000,
|
|
|
+ "remark"=>"粉丝将提供分享佣金,粉丝越多比例越高哦^v^,点击查看详情"
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $res = $app->template_message->send($data);
|
|
|
+ $instance->info("微信返回结果:".json_encode($res));
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ $instance->info("粉丝通知结果异常:".$exception->getMessage());
|
|
|
+ }
|
|
|
+ UserModel::query()->where("id",$userFan->id)->update(
|
|
|
+ [
|
|
|
+ "user_notify_status"=>1
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //2.获取自购已支付且未通知进行模版推送
|
|
|
+ $orders = UserOrderCommissionModel::query()
|
|
|
+ ->where("commission_status",0)
|
|
|
+ ->where("user_id","<>",0)
|
|
|
+ ->where("order_notify_status",0)
|
|
|
+ ->limit(10)
|
|
|
+ ->get();
|
|
|
+ foreach ($orders as $order){
|
|
|
+ //判断是否自购订单
|
|
|
+ if($order->user_provider_id){
|
|
|
+ //反佣订单
|
|
|
+ $user = UserModel::findById($order->user_id);
|
|
|
+ if($user){
|
|
|
+ try{
|
|
|
+ //获取公众号实例
|
|
|
+ $app = WechatAccountUtil::getAppByID($user->wechat_account_id);
|
|
|
+ $tmpOrder = UserOrderModel::query()->where("order_number",$order->order_number)->first();
|
|
|
+ $privideUser = UserModel::findById($order->user_provider_id);
|
|
|
+ $data = [
|
|
|
+ 'touser' => $user->user_open_id,
|
|
|
+ 'template_id' => env("WECHAT_FANS_ORDER_TEMPLATE_URL"),
|
|
|
+ 'url' => env("WECHAT_FANS_ORDER_URL"),
|
|
|
+ 'data' => [
|
|
|
+ 'first' => "粉丝下单成功通知",
|
|
|
+ 'keyword1' => $order->order_number,
|
|
|
+ 'keyword2' => $tmpOrder->product_name,
|
|
|
+ 'keyword3' => $order->created_at,
|
|
|
+ 'keyword4' => round($tmpOrder->order_price/100,2)."元",
|
|
|
+ 'keyword5' => $privideUser->user_nickname,
|
|
|
+ "remark"=>"您的粉丝有新的订单,分享佣金已产生,3天后结算到您账户中,点击详情跳转粉丝订单"
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $res = $app->template_message->send($data);
|
|
|
+ $instance->info("微信返回结果:".json_encode($res));
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ $instance->info("粉丝下单通知结果异常:".$exception->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $user = UserModel::findById($order->user_id);
|
|
|
+ if($user){
|
|
|
+ try{
|
|
|
+ //获取公众号实例
|
|
|
+ $app = WechatAccountUtil::getAppByID($user->wechat_account_id);
|
|
|
+ $tmpOrder = UserOrderModel::query()->where("order_number",$order->order_number)->first();
|
|
|
+ $data = [
|
|
|
+ 'touser' => $user->user_open_id,
|
|
|
+ 'template_id' => env("WECHAT_ORDER_TEMPLATE_URL"),
|
|
|
+ 'url' => env("WECHAT_ORDER_URL"),
|
|
|
+ 'data' => [
|
|
|
+ 'first' => "下单成功通知",
|
|
|
+ 'keyword1' => $order->created_at,
|
|
|
+ 'keyword2' => $tmpOrder->product_name,
|
|
|
+ 'keyword3' => $order->order_number,
|
|
|
+ "remark"=>"您的订单已完成,感谢您的使用,3天后佣金将会结算到您的账户中点击详情跳转我的订单"
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $res = $app->template_message->send($data);
|
|
|
+ $instance->info("微信返回结果:".json_encode($res));
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ $instance->info("自购下单通知结果异常:".$exception->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UserOrderCommissionModel::query()->where("id",$order->id)->update(
|
|
|
+ [
|
|
|
+ "order_notify_status"=>1
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ //3.获取已结算订单,并通知
|
|
|
+ $completeOrders = UserOrderCommissionModel::query()
|
|
|
+ ->where("commission_status",2)
|
|
|
+ ->where("user_id","<>",0)
|
|
|
+ ->where("order_complete_notify_status",0)
|
|
|
+ ->limit(10)
|
|
|
+ ->get();
|
|
|
+ foreach ($completeOrders as $order){
|
|
|
+ $user = UserModel::findById($order->user_id);
|
|
|
+ if($user){
|
|
|
+ try{
|
|
|
+ //获取公众号实例
|
|
|
+ $app = WechatAccountUtil::getAppByID($user->wechat_account_id);
|
|
|
+ $tmpOrder = UserOrderModel::query()->where("order_number",$order->order_number)->first();
|
|
|
+ $data = [
|
|
|
+ 'touser' => $user->user_open_id,
|
|
|
+ 'template_id' => env("WECHAT_COMPLETE_ORDER_TEMPLATE_URL"),
|
|
|
+ 'url' => env("WECHAT_BALANCE_URL"),
|
|
|
+ 'data' => [
|
|
|
+ 'first' => "您的佣金已结算完成",
|
|
|
+ 'keyword1' => round($order->order_commission/100,2)."元",
|
|
|
+ 'keyword2' => round($tmpOrder->order_price/100,2)."元",
|
|
|
+ 'keyword3' => $order->updated_at,
|
|
|
+ "remark"=>"三日前订单佣金已结算完成,感谢您的使用,点击详情跳转我的账户"
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $res = $app->template_message->send($data);
|
|
|
+ $instance->info("微信返回结果:".json_encode($res));
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ $instance->info("自购下单通知结果异常:".$exception->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UserOrderCommissionModel::query()->where("id",$order->id)->update(
|
|
|
+ [
|
|
|
+ "order_complete_notify_status"=>1
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|