1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Client\Pay;
- use App\Modules\Subscribe\Models\Order;
- use DB;
- use Exception;
- use Log;
- /**
- *
- * @property \App\Modules\Subscribe\Models\Order $order
- */
- abstract class PaySuccessAbstract
- {
- private $order;
- /**
- * 处理支付成功的逻辑
- */
- abstract protected function handlePayProcess();
- public function __construct(Order $order)
- {
- $this->order = $order;
- }
- /**
- * 支付成功入口
- */
- public function success()
- {
- try {
- DB::beginTransaction();
- $this->setOrderSuccess();
- $this->handlePayProcess();
- DB::commit();
- } catch (Exception $e) {
- DB::rollback();
- Log::error('pay.success: ' . $e->getMessage());
- }
- }
- /**
- * 设置order成功
- */
- protected function setOrderSuccess()
- {
- $this->order->pay_type = $this->getChargeTimes($this->order->uid);
- $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($uid)
- {
- $count = Order::getUserChargeTimes($uid);
- return $count + 1;
- }
- }
|