|
|
@@ -31,6 +31,7 @@ use common\models\ShopGoods;
|
|
|
use common\models\User;
|
|
|
use common\models\UserBonus;
|
|
|
use common\models\UserWallet;
|
|
|
+use Exception;
|
|
|
use Yii;
|
|
|
use yii\data\Pagination;
|
|
|
use yii\db\Query;
|
|
|
@@ -386,27 +387,140 @@ class ShopController extends BaseController {
|
|
|
if ($formModel->load($load, '') && $result = $formModel->verifyPayOnline()) {
|
|
|
LoggerTool::info($result);
|
|
|
|
|
|
- return http_response_code(200);
|
|
|
+ echo 'RECEIVEOK';
|
|
|
+ return http_response_code('RECEIVEOK');
|
|
|
} else {
|
|
|
+ echo 'RECEIVEOK';
|
|
|
LoggerTool::error(Form::formatErrorsForApi($formModel->getErrors()));
|
|
|
- return http_response_code(500);
|
|
|
+ return http_response_code('RECEIVEOK');
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
+ echo 'RECEIVEOK';
|
|
|
LoggerTool::error(sprintf('actionVerifyApproachOrderError: File[%s], Line:[%s], Message[%s]', $e->getFile(), $e->getLine(), $e->getMessage()));
|
|
|
- return http_response_code(500);
|
|
|
+ return http_response_code('RECEIVEOK');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function actionReQueryPayment()
|
|
|
+ {
|
|
|
+ // 每天巡查一次,查询近24小时的未支付订单. 支付参数记录在NOTE字段中,如没有此数据,则不能进行查询.(待支付、支付方式online、当天订单、未删除)
|
|
|
+ $orderList = ApproachOrder::find()
|
|
|
+ ->where('STATUS=:STATUS AND PAY_TYPE=:PAY_TYPE AND CREATED_AT>=:CREATED_AT AND DELETED_AT=0',
|
|
|
+ [':STATUS' => 0, ':PAY_TYPE' => 'online', ':CREATED_AT' => strtotime(date('Y-m-d', time()))])
|
|
|
+ ->andWhere(['not', ['NOTE' => null]])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+
|
|
|
+ if (!$orderList) {
|
|
|
+ return static::notice('no record');
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($orderList as $order) {
|
|
|
+ $message = '';
|
|
|
+ // 支付参数记录在NOTE字段中,如没有此数据,则不能进行查询
|
|
|
+ $orderPayment = json_decode($order['NOTE'], true);
|
|
|
+ $rawPostData = "MerchantCode={$orderPayment['MerchantCode']}&RefNo={$orderPayment['RefNo']}&Amount={$orderPayment['Amount']}";
|
|
|
+ try {
|
|
|
+ $ch = curl_init();
|
|
|
+ $url = 'https://payment.ipay88.com.my/epayment/enquiry.asp' . '?' . $rawPostData;
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ $result = curl_exec($ch);
|
|
|
+
|
|
|
+ switch ($result) {
|
|
|
+ case '00': // Successful payment.
|
|
|
+ $paymentParams = [
|
|
|
+ 'RefNo' => $orderPayment['RefNo'],
|
|
|
+ 'Amount' => $orderPayment['Amount'],
|
|
|
+ 'PaymentId' => '182',
|
|
|
+ 'ProdDesc' => 'Pay for sales',
|
|
|
+ 'UserName' => 'MY32',
|
|
|
+ 'SignatureType' => 'SHA256',
|
|
|
+ 'UserEmail' => 'ek_dummy25@elken.com',
|
|
|
+ 'UserContact' => '60172249692',
|
|
|
+ ];
|
|
|
+ $paymentFields = \Yii::$app->iPay88->getPaymentFields($paymentParams, self::TRANSACTION_TYPE_PAYMENT);
|
|
|
+
|
|
|
+ $formModel = new ApproachOrderForm();
|
|
|
+ $formModel->scenario = 'verifyPay';
|
|
|
+ $load = [
|
|
|
+ 'sn' => $orderPayment['RefNo'],
|
|
|
+ 'scenario' => 'verifyPay',
|
|
|
+ 'status' => \Yii::$app->params['orderStatus']['paid']['value'],
|
|
|
+ 'note' => [
|
|
|
+ 'MerchantCode' => $orderPayment['MerchantCode'],
|
|
|
+ 'PaymentId' => $paymentFields['PaymentId'],
|
|
|
+ 'status' => \Yii::$app->params['orderStatus']['paid']['value'],
|
|
|
+ 'Signature' => $paymentFields['Signature'],
|
|
|
+ 'Currency' => $paymentFields['Currency'],
|
|
|
+ 'Amount' => $paymentFields['Amount'],
|
|
|
+ 'TransId' => '',
|
|
|
+ 'TranDate' => '',
|
|
|
+ 'BankMID' => '',
|
|
|
+ 'CCNo' => '',
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if ($formModel->load($load, '') && $result = $formModel->verifyPayOnline()) {
|
|
|
+ LoggerTool::info($result);
|
|
|
+ }
|
|
|
+ $message = '(ReQueryIPay88Payment). orderSN{%s} 00: Successful payment';
|
|
|
+ break;
|
|
|
+ case 'Invalid parameters':
|
|
|
+ $message = '(ReQueryIPay88Payment). orderSN{%s} Invalid parameters: Parameters pass in incorrect';
|
|
|
+ break;
|
|
|
+ case 'Record not found':
|
|
|
+ $message = '(ReQueryIPay88Payment). orderSN{%s} Record not found: Cannot found the record';
|
|
|
+ break;
|
|
|
+ case 'Incorrect amount':
|
|
|
+ $message = '(ReQueryIPay88Payment). orderSN{%s} Incorrect amount: Amount different';
|
|
|
+ break;
|
|
|
+ case 'Payment fail':
|
|
|
+ ApproachOrder::updateAll(
|
|
|
+ ['STATUS' => \Yii::$app->params['orderStatus']['failPaid']['value'], 'REMARK' => 'Payment fail: Payment fail'],
|
|
|
+ 'SN=:SN', [':SN' => $order['SN']]
|
|
|
+ );
|
|
|
+ $message = '(ReQueryIPay88Payment). orderSN{%s} Payment fail: Payment fail';
|
|
|
+ break;
|
|
|
+ case 'M88Admin':
|
|
|
+ ApproachOrder::updateAll(
|
|
|
+ ['STATUS' => \Yii::$app->params['orderStatus']['failPaid']['value'], 'REMARK' => 'M88Admin: Payment status updated by iPay88 Admin(Fail)'],
|
|
|
+ 'SN=:SN', [':SN' => $order['SN']]
|
|
|
+ );
|
|
|
+ $message = '(ReQueryIPay88Payment). orderSN{%s} M88Admin: Payment status updated by iPay88 Admin(Fail)';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
+
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ // 推送消息到预警平台
|
|
|
+ Alarm::reportAlarm(['brand' => 'MSG', 'message' => sprintf($message, $orderPayment['RefNo'])]);
|
|
|
+ } catch (exception $e) {
|
|
|
+ curl_close($ch);
|
|
|
+ LoggerTool::error('err. ' . $e->getMessage());
|
|
|
+ Alarm::reportAlarm(['brand' => 'MSG', 'message' => sprintf('err. (ReQueryIPay88Payment). orderSN{%s}. %s', $orderPayment['RefNo'], $e->getMessage())]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return static::notice('');
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除准订单
|
|
|
*/
|
|
|
public function actionDeleteApproachOrder()
|
|
|
{
|
|
|
$orderSn = \Yii::$app->request->post('orderSn');
|
|
|
- // 删除订单中间表
|
|
|
- ApproachOrder::deleteAll('SN = :SN', [':SN' => $orderSn]);
|
|
|
- // 删除订单商品中间表
|
|
|
- ApproachOrderGoods::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $orderSn]);
|
|
|
+ // 订单中间表更新订单状态为取消
|
|
|
+ ApproachOrder::updateAll(
|
|
|
+ [
|
|
|
+ 'STATUS' => \Yii::$app->params['orderStatus']['cancel']['value'],
|
|
|
+ 'DELETED_AT' => Date::nowTime(),
|
|
|
+ 'REMARK' => 'Member cancel order',
|
|
|
+ ],
|
|
|
+ 'SN=:SN',
|
|
|
+ [':SN' => $orderSn]);
|
|
|
|
|
|
return static::notice('');
|
|
|
}
|
|
|
@@ -422,7 +536,7 @@ class ShopController extends BaseController {
|
|
|
$paymentParams['RefNo'] = \Yii::$app->request->post('RefNo');
|
|
|
// 订单
|
|
|
$order = ApproachOrder::findOne(['SN' => $paymentParams['RefNo']]);
|
|
|
- if (!$order) {
|
|
|
+ if (!$order->toArray()) {
|
|
|
return static::notice('订单编号无效');
|
|
|
}
|
|
|
// 转为分
|
|
|
@@ -461,6 +575,17 @@ class ShopController extends BaseController {
|
|
|
'transactionUrl' => $transactionUrl,
|
|
|
];
|
|
|
|
|
|
+ // 支付信息写入note
|
|
|
+ $order->NOTE = json_encode([
|
|
|
+ 'MerchantCode' => $paymentFields['MerchantCode'],
|
|
|
+ 'PaymentId' => $paymentFields['PaymentId'],
|
|
|
+ 'RefNo' => $paymentFields['RefNo'],
|
|
|
+ 'Amount' => $paymentFields['Amount'],
|
|
|
+ 'Currency' => $paymentFields['Currency'],
|
|
|
+ 'Signature' => $paymentFields['Signature'],
|
|
|
+ ]);
|
|
|
+ $order->update();
|
|
|
+
|
|
|
return static::notice($res);
|
|
|
}
|
|
|
|