132 lines
4.8 KiB
PHP
132 lines
4.8 KiB
PHP
<?php
|
||
|
||
namespace App\Jobs;
|
||
|
||
use Illuminate\Bus\Queueable;
|
||
use Illuminate\Queue\SerializesModels;
|
||
use Illuminate\Queue\InteractsWithQueue;
|
||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
use Illuminate\Foundation\Bus\Dispatchable;
|
||
use App\Services\WechatService;
|
||
use App\Services\CommonUtilsService;
|
||
use App\Services\UserService;
|
||
use App\Repositories\Eloquent\SmsRepository;
|
||
use App\Models\User;
|
||
use App\Utils\Messenger;
|
||
use App\Models\RedPacketOrder;
|
||
use App\Utils\Str;
|
||
use App\Models\RedPacketActivity;
|
||
class CommunityShare implements ShouldQueue
|
||
{
|
||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
||
protected $data;
|
||
public $tries = 1;
|
||
/**
|
||
* Create a new job instance.
|
||
*
|
||
* @return void
|
||
*/
|
||
public function __construct($data)
|
||
{
|
||
$this->data = $data;
|
||
}
|
||
|
||
/**
|
||
* Execute the job.
|
||
*
|
||
* @return void
|
||
*/
|
||
public function handle()
|
||
{
|
||
//分享人
|
||
// $from_user = User::findOrFail($this->data['from_user_id']);
|
||
$openid = $this->data['from_official_openid'];
|
||
//发红包
|
||
$common = new CommonUtilsService;
|
||
$trade_no = $common->getTradeNO();
|
||
$data = $this->data['red_packet'];
|
||
$price = $data['amount'];
|
||
$total_num = $data['num'];
|
||
$type = $data['type'];
|
||
$total_amount = $price * 100;
|
||
$wishing = '福恋一家,有你,有我、有祂!';
|
||
$act_name = '福恋社群';//act_name字段必填,并且少于32个字符.
|
||
// $openid = $from_user->wechat->official_openid;
|
||
if (empty($openid)) {
|
||
return;
|
||
}
|
||
$activity = RedPacketActivity::orderBy('id', 'desc')->first();
|
||
if ($activity) {
|
||
$activity->increment('used_amount', $price);
|
||
}
|
||
//生成红包订单
|
||
// $order = RedPacketOrder::create([
|
||
// 'user_id'=>$this->data['from_user_id'],
|
||
// 'type'=>$this->data['type'],
|
||
// 'official_openid'=>$this->data['from_official_openid'],
|
||
// 'trade_no'=>$trade_no,
|
||
// 'amount'=>$price,
|
||
// 'is_hooked'=>0,
|
||
// ]);
|
||
// if ($type == 'normal') {
|
||
// //普通红包
|
||
// $send_name = '来自福恋社群分享';
|
||
// // $result = \WechatService::sendNormalRedPack($trade_no, $send_name, $total_amount, $openid, $wishing, $act_name, $remark='');
|
||
// $result = \WechatService::officialUserTransfer($trade_no, $openid, $total_amount, $send_name);
|
||
// if (is_array($result)) {
|
||
// $order->err_code = $result['err_code'];//错误代码
|
||
// $order->return_msg = $result['return_msg'];//错误信息
|
||
// }elseif ($result == true) {
|
||
// $order->err_code = 'SUCCESS';
|
||
// }else{
|
||
// $order->err_code = 'FALSE';
|
||
// }
|
||
// $order->save();
|
||
// }else{
|
||
// //裂变红包
|
||
// if (empty($this->data['from_user_name'])) {
|
||
// $send_name = '来自福恋社群';
|
||
// }else{
|
||
// if (Str::isMobile($this->data['from_user_name'])) {
|
||
// $send_name = '来自福恋分享';
|
||
// }else{
|
||
// $send_name = '来自福恋('.$this->data['from_user_name'].')';
|
||
// if (strlen($send_name) >= 32) {
|
||
// $send_name = '来自福恋分享';
|
||
// }
|
||
// }
|
||
// }
|
||
// $result = \WechatService::sendGroupRedPack($trade_no, $send_name, $total_num, $total_amount, $openid, $wishing, $act_name, $remark='');
|
||
// if (is_array($result)) {//红包发送失败
|
||
// $order->err_code = $result['err_code'];//错误代码
|
||
// $order->return_msg = $result['return_msg'];//错误信息
|
||
// }elseif ($result == true) {
|
||
// $order->err_code = 'SUCCESS';
|
||
// }else{
|
||
// $order->err_code = 'FALSE';
|
||
// }
|
||
// $order->save();
|
||
// }
|
||
// if ($result) {
|
||
// $message = '感谢你参与福恋社群分享,已成功邀请了微信好友'.$this->data['user_name'].', 请前往微信领取随机红包(1-10元)';
|
||
// //短信通知
|
||
// $from_user_mobile = $this->data['from_user_mobile'];
|
||
// if ($from_user_mobile) {
|
||
// // Messenger::sendSMS($from_user_mobile, $message);
|
||
// }
|
||
|
||
//小程序通知
|
||
// $form_id_obj = $from_user->getValidFormId();
|
||
// if ($form_id_obj) {
|
||
|
||
// }
|
||
//福恋助手通知
|
||
// $userService = new UserService();
|
||
// $user_ids = $this->data['from_user_id'];
|
||
// $userService->sendAssistantMessage(compact('user_ids'), $message);
|
||
// }
|
||
|
||
}
|
||
}
|