| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace addons\WangDianTong\common\service;
- use addons\WangDianTong\common\traits\CompensateTrait;
- use addons\WangDianTong\common\traits\CreateRefundSendTrait;
- use addons\WangDianTong\common\traits\RequestRetryTrait;
- use common\enums\RabbitMqEnum;
- use common\models\order\OrderRefund;
- use Yii;
- use yii\helpers\Json;
- class OrderRefundRejectService
- {
- use RequestRetryTrait, CreateRefundSendTrait, CompensateTrait;
- /**
- * @param int $mall_id
- * @param int $refund_id
- * @return void
- * @throws \Exception
- */
- public function sync(int $mall_id, int $refund_id)
- {
- \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_ORDER, RabbitMqEnum::ORDER_QUEUE, [
- 'mall_id' => $mall_id,
- 'id' => $refund_id,
- ],
- self::class, 'execute');
- }
- /**
- * @param array $data
- * @return void|null
- * @throws \Exception
- */
- public function execute(array $data)
- {
- \Yii::error(__CLASS__ . "->async_handle: " . Json::encode($data));
- if (empty($data)) {
- Yii::error('OrderRefundRejectService error:售后处理失败,内容为空');
- return null;
- }
- try {
- // 退款申请
- $refund = OrderRefund::getOne([
- ['id' => $data['id']]
- ], true, ['orderDetail', 'base_user', 'order']);
- if (empty($refund) || $refund['order']['store_id'] > 0 || $refund['order']['mch_id'] > 0) return;
- $data['mall_id'] = $refund['mall_id'];
- $config = (new SettingService())->get($refund['mall_id']);
- if (empty($config['is_enable'])) {
- \Yii::error("{$refund['mall_id']} 未开启旺店通插件");
- return;
- }
- $trade_list[] = (new CreateRefundService())->assembleData($refund, $config);
- $flag = $this->retry(function () use ($config, $trade_list) {
- return $this->send($config, $trade_list);
- });
- if (is_string($flag)) throw new \Exception($flag);
- $this->compensateFinish($data['compensate_id']??0);
- } catch (\Exception $e) {
- $this->compensate($data, __CLASS__, __FUNCTION__, $e);
- }
- }
- }
|