Example #1
0
 public function handle($data)
 {
     parent::handle($data);
     # handle the wechat message
     LogUtil::info(['channel weconnect event' => $data], 'channel-webhook');
     if (empty($data)) {
         throw new BadRequestHttpException(Yii::t('channel', 'parameter_format_error'));
     }
     $data = $data['data'];
     $requiredParameters = ['outTradeNo', 'tradeNo', 'tradeStatus'];
     ValidatorUtil::fieldsRequired($data, $requiredParameters);
     $tradePayment = TradePayment::findOne(['orderNumber' => $data['outTradeNo']]);
     LogUtil::info(['tradePayment' => $tradePayment->toArray()], 'channel-webhook');
     if (empty($tradePayment)) {
         throw new InvalidParameterException(Yii::t('common', 'data_error'));
     }
     $memberId = $tradePayment['user']['memberId'];
     $couponId = $tradePayment['couponId'];
     LogUtil::info(['memberId' => $memberId, 'couponId' => $couponId], 'channel-webhook');
     if ($data['tradeStatus'] == 'PAY_SUCCESS') {
         $tradePayment->status = TradePayment::STATUS_PAID;
         $tradePayment->realAmount = intval($data['totalFee']) / 100;
         // Make coupon used
         if (!empty($couponId)) {
             Yii::$app->service->coupon->makeUsed($memberId, $couponId);
         }
     } else {
         if ($data['tradeStatus'] == 'PAY_ERROR') {
             $tradePayment->status = TradePayment::STATUS_FAILED;
         }
     }
     $tradePayment->paymentTime = MongodbUtil::msTimetamp2MongoDate($data['paymentTime']);
     $tradePayment->transactionId = $data['tradeNo'];
     return $tradePayment->save(true, ['paymentTime', 'status', 'transactionId', 'realAmount']);
 }
Example #2
0
 public function offlinePayment($paymentInfo)
 {
     $requiredFields = ['user' => ['name', 'telephone'], 'orderNumber', 'payMode', 'expectedAmount', 'realAmount', 'payAccount', 'paymentTime', 'subject'];
     if (ValidatorUtil::fieldsRequired($paymentInfo, $requiredFields, false)) {
         return ModelPayment::offlinePayment($paymentInfo, $this->accountId);
     }
     return false;
 }
 public function actionExport()
 {
     $params = $this->getQuery();
     $accountId = $this->getAccountId();
     $condition = TradePayment::getSearchCondition($accountId, $params);
     $data = TradePayment::findOne($condition);
     if (empty($data)) {
         return ['result' => 'error', 'message' => 'no datas', 'data' => []];
     }
     $key = Yii::t('channel', 'payment_file_name') . '_' . date('Y-m-d H:i:s');
     $fields = 'transactionId,user,expectedAmount,realAmount,subject,paymentTime';
     $sort = ['paymentTime' => -1];
     $fileTitle = Yii::t('channel', 'export_payment_title');
     $header = ['transactionId', 'userName', 'realAmount', 'expectedAmount', 'subject', 'paymentTime'];
     $header = array_combine($header, explode(',', $fileTitle));
     $args = ['accountId' => (string) $accountId, 'key' => $key, 'header' => $header, 'fields' => $fields, 'sort' => $sort, 'params' => [], 'collection' => 'tradePayment', 'condition' => serialize($condition), 'classFunction' => '\\backend\\modules\\channel\\models\\TradePayment::preProcessData', 'description' => 'Direct: Export TradePayment data'];
     $jobId = Yii::$app->job->create('backend\\modules\\common\\job\\MongoExportFile', $args);
     unset($header, $args);
     return ['result' => 'success', 'message' => 'exporting file', 'data' => ['jobId' => $jobId, 'key' => $key]];
 }