|
@@ -2,9 +2,12 @@
|
|
|
|
|
|
namespace App\Modules\Trade\Pay;
|
|
|
|
|
|
-use App\Jobs\QappTikTokUserCharge;
|
|
|
+use App\Jobs\QappTikTok\QappTikTokUserChargeRequest;
|
|
|
+use App\Jobs\QappTikTok\QappTikTokUserCharge;
|
|
|
use App\Modules\Book\Models\BookConfig;
|
|
|
+use App\Modules\SendOrder\Models\QappSendOrder;
|
|
|
use App\Modules\Subscribe\Models\Order;
|
|
|
+use App\Modules\User\Models\User;
|
|
|
use App\Modules\User\Services\ReadRecordService;
|
|
|
use App\Modules\UserTask\Services\BaseTask;
|
|
|
use App\Modules\UserTask\Services\UserTaskService;
|
|
@@ -14,77 +17,98 @@ use Illuminate\Support\Facades\Log;
|
|
|
use Redis;
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ *
|
|
|
* @property \App\Modules\Subscribe\Models\Order $order
|
|
|
*/
|
|
|
abstract class PaySuccessAbstract
|
|
|
{
|
|
|
- protected $order;
|
|
|
+ protected $order;
|
|
|
|
|
|
- /**
|
|
|
- * 处理支付成功的逻辑
|
|
|
- */
|
|
|
- abstract protected function handlePayProcess();
|
|
|
+ /**
|
|
|
+ * 处理支付成功的逻辑
|
|
|
+ */
|
|
|
+ abstract protected function handlePayProcess();
|
|
|
|
|
|
- public function __construct(Order $order)
|
|
|
- {
|
|
|
- $this->order = $order;
|
|
|
- }
|
|
|
+ public function __construct(Order $order)
|
|
|
+ {
|
|
|
+ $this->order = $order;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 支付成功入口
|
|
|
- */
|
|
|
- public function success()
|
|
|
- {
|
|
|
- try {
|
|
|
- DB::beginTransaction();
|
|
|
- $this->setOrderSuccess();
|
|
|
- $this->handlePayProcess();
|
|
|
- DB::commit();
|
|
|
- $this->addQueue();
|
|
|
- return true;
|
|
|
- } catch (Exception $e) {
|
|
|
- DB::rollback();
|
|
|
- Log::error('pay.success: ' . $e->getMessage() . ' ' . $e->getTraceAsString());
|
|
|
- }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 支付成功入口
|
|
|
+ */
|
|
|
+ public function success()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+ $this->setOrderSuccess();
|
|
|
+ $this->handlePayProcess();
|
|
|
+ DB::commit();
|
|
|
+ $this->addQueue();
|
|
|
+ return true;
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DB::rollback();
|
|
|
+ Log::error('pay.success: ' . $e->getMessage() . ' ' . $e->getTraceAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 设置order成功
|
|
|
- */
|
|
|
- protected function setOrderSuccess()
|
|
|
- {
|
|
|
- $this->order->pay_type = $this->getChargeTimes();
|
|
|
- $this->order->status = 'PAID';
|
|
|
- $this->order->pay_end_at = date('Y-m-d H:i:s');
|
|
|
- $this->order->save();
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 设置order成功
|
|
|
+ */
|
|
|
+ protected function setOrderSuccess()
|
|
|
+ {
|
|
|
+ $this->order->pay_type = $this->getChargeTimes();
|
|
|
+ $this->order->status = 'PAID';
|
|
|
+ $this->order->pay_end_at = date('Y-m-d H:i:s');
|
|
|
+ $this->order->save();
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 获取用户第几次充值
|
|
|
- * @param $uid
|
|
|
- * @return int
|
|
|
- */
|
|
|
- private function getChargeTimes()
|
|
|
- {
|
|
|
- $count = Order::where('uid', $this->order->uid)->where('status', 'PAID')->count('id');
|
|
|
- return $count + 1;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取用户第几次充值
|
|
|
+ * @param $uid
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ private function getChargeTimes()
|
|
|
+ {
|
|
|
+ $count = Order::where('uid', $this->order->uid)->where('status', 'PAID')->count('id');
|
|
|
+ return $count + 1;
|
|
|
+ }
|
|
|
|
|
|
- private function getReportType(int $channel_id)
|
|
|
- {
|
|
|
- return Redis::hGet('channel:setting:' . $channel_id, 'tiktok_report_type') ?? QappTikTokUserCharge::CURRENT_DAY_REGISTER;
|
|
|
- }
|
|
|
+ private function getReportType(int $channel_id)
|
|
|
+ {
|
|
|
+ return Redis::hGet('channel:setting:' . $channel_id, 'tiktok_report_type') ?? QappTikTokUserCharge::CURRENT_DAY_REGISTER;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- protected function addQueue()
|
|
|
- {
|
|
|
- UserTaskService::addUserTaskQueue($this->order->uid, BaseTask::charge, UserTaskService::judge_trigger);
|
|
|
- $bid = ReadRecordService::getSimpleFirstReadRecord($this->order->uid);
|
|
|
- $book_id = book_hash_encode($bid);
|
|
|
- $book = BookConfig::where('bid', $bid)->select('book_name')->first();
|
|
|
- $book_name = $book ? $book->book_name : '';
|
|
|
- $job = new QappTikTokUserCharge($this->order->uid, $this->order->price, $this->order->created_at, $this->getReportType($this->order->distribution_channel_id), $book_id, $book_name);
|
|
|
- dispatch($job->onConnection('rabbitmq')->onQueue('qapp_tiktok_user_charge_queue'));
|
|
|
- }
|
|
|
+ protected function addQueue()
|
|
|
+ {
|
|
|
+ UserTaskService::addUserTaskQueue($this->order->uid, BaseTask::charge, UserTaskService::judge_trigger);
|
|
|
+ $bid = ReadRecordService::getSimpleFirstReadRecord($this->order->uid);
|
|
|
+ $book_id = book_hash_encode($bid);
|
|
|
+ $book = BookConfig::where('bid', $bid)->select('book_name')->first();
|
|
|
+ $book_name = $book ? $book->book_name : '';
|
|
|
+
|
|
|
+ // 取用户注册的派单id,派单信息
|
|
|
+ $user = User::getUser($this->order->uid);
|
|
|
+ $sendOrderId = getProp($user, 'send_order_id');
|
|
|
+ $quickSendOrder = QappSendOrder::getSendOrderById($sendOrderId);
|
|
|
+ if ($quickSendOrder) {
|
|
|
+ // 队列处理回传业务
|
|
|
+ $tikTokChargeRequest = new QappTikTokUserChargeRequest();
|
|
|
+ $tikTokChargeRequest->uid = $this->order->uid;
|
|
|
+ $tikTokChargeRequest->amount = $this->order->price;
|
|
|
+ $tikTokChargeRequest->pay_time = $this->order->created_at;
|
|
|
+ $tikTokChargeRequest->type = $this->getReportType($this->order->distribution_channel_id);
|
|
|
+ $tikTokChargeRequest->book_id = $book_id;
|
|
|
+ $tikTokChargeRequest->book_name = $book_name;
|
|
|
+ $tikTokChargeRequest->send_order_id = $sendOrderId;
|
|
|
+ $tikTokChargeRequest->report_type = getProp($quickSendOrder, 'report_type');
|
|
|
+ $tikTokChargeRequest->report_rate = (int)getProp($quickSendOrder, 'report_rate');
|
|
|
+ $tikTokChargeRequest->molecule = (int)getProp($quickSendOrder, 'report_rate');
|
|
|
+
|
|
|
+ // 回传队列
|
|
|
+ $job = new QappTikTokUserCharge($tikTokChargeRequest);
|
|
|
+ dispatch($job->onConnection('rabbitmq')->onQueue('qapp_tiktok_user_charge_queue'));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|