Skip to content

Commit 417c51f

Browse files
订单备注完善
1 parent eea16dd commit 417c51f

File tree

7 files changed

+74
-18
lines changed

7 files changed

+74
-18
lines changed

app/appfront/modules/Payment/block/paypal/express/Placeorder.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class Placeorder
3131
* 用户的支付方式.
3232
*/
3333
public $_payment_method;
34-
34+
/**
35+
* 订单备注信息.
36+
*/
37+
public $_order_remark;
3538
public function getLastData()
3639
{
3740
$post = Yii::$app->request->post();
@@ -59,7 +62,7 @@ public function getLastData()
5962
// 将购物车数据,生成订单,生成订单后,不清空购物车,不扣除库存,在支付成功后在清空购物车。
6063
$innerTransaction = Yii::$app->db->beginTransaction();
6164
try {
62-
$genarateStatus = Yii::$service->order->generateOrderByCart($this->_billing, $this->_shipping_method, $this->_payment_method, false,$token);
65+
$genarateStatus = Yii::$service->order->generateOrderByCart($this->_billing, $this->_shipping_method, $this->_payment_method, false, $token, $this->_order_remark);
6366
if ($genarateStatus) {
6467
$innerTransaction->commit();
6568
} else {
@@ -223,7 +226,20 @@ public function checkOrderInfoAndInit($post)
223226
return false;
224227
}
225228
}
226-
229+
// 订单备注信息不能超过1500字符
230+
$orderRemarkStrMaxLen = Yii::$service->order->orderRemarkStrMaxLen;
231+
$order_remark = isset($post['order_remark']) ? $post['order_remark'] : '';
232+
if ($order_remark && $orderRemarkStrMaxLen) {
233+
$order_remark_strlen = strlen($order_remark);
234+
if ($order_remark_strlen > $orderRemarkStrMaxLen) {
235+
Yii::$service->helper->errors->add('order remark string length can not gt '.$orderRemarkStrMaxLen);
236+
237+
return false;
238+
} else {
239+
// 去掉xss攻击字符,关于防止xss攻击的yii文档参看:http://www.yiichina.com/doc/guide/2.0/security-best-practices#fang-zhi-xss-gong-ji
240+
$this->_order_remark = $order_remark;
241+
}
242+
}
227243
$this->_shipping_method = $shipping_method;
228244
$this->_payment_method = $payment_method;
229245
Yii::$service->payment->setPaymentMethod($this->_payment_method);

app/appfront/theme/base/front/payment/paypal/express/review.php

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
<div class="coupon_add_log"></div>
6767
</div>
6868

69+
<div class="onestepcheckout-coupons">
70+
<div class="op_block_title"><?= Yii::$service->page->translate->__('Order Remark (optional)');?></div>
71+
<label for="id_couponcode"><?= Yii::$service->page->translate->__('You can fill in the order remark information below');?></label>
72+
<textarea class="order_remark" name="order_remark" style="width:94%;height:100px;padding:10px;"></textarea>
73+
</div>
6974

7075
</div>
7176

app/apphtml5/modules/Payment/block/paypal/express/Placeorder.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class Placeorder
3131
* 用户的支付方式.
3232
*/
3333
public $_payment_method;
34-
34+
/**
35+
* 订单备注信息.
36+
*/
37+
public $_order_remark;
3538
public function getLastData()
3639
{
3740
$post = Yii::$app->request->post();
@@ -59,7 +62,7 @@ public function getLastData()
5962
// 将购物车数据,生成订单,生成订单后,不清空购物车,不扣除库存,在支付成功后在清空购物车。
6063
$innerTransaction = Yii::$app->db->beginTransaction();
6164
try {
62-
$genarateStatus = Yii::$service->order->generateOrderByCart($this->_billing, $this->_shipping_method, $this->_payment_method, false,$token);
65+
$genarateStatus = Yii::$service->order->generateOrderByCart($this->_billing, $this->_shipping_method, $this->_payment_method, false, $token, $this->_order_remark);
6366
if ($genarateStatus) {
6467
$innerTransaction->commit();
6568
} else {
@@ -223,7 +226,20 @@ public function checkOrderInfoAndInit($post)
223226
return false;
224227
}
225228
}
226-
229+
// 订单备注信息不能超过1500字符
230+
$orderRemarkStrMaxLen = Yii::$service->order->orderRemarkStrMaxLen;
231+
$order_remark = isset($post['order_remark']) ? $post['order_remark'] : '';
232+
if ($order_remark && $orderRemarkStrMaxLen) {
233+
$order_remark_strlen = strlen($order_remark);
234+
if ($order_remark_strlen > $orderRemarkStrMaxLen) {
235+
Yii::$service->helper->errors->add('order remark string length can not gt '.$orderRemarkStrMaxLen);
236+
237+
return false;
238+
} else {
239+
// 去掉xss攻击字符,关于防止xss攻击的yii文档参看:http://www.yiichina.com/doc/guide/2.0/security-best-practices#fang-zhi-xss-gong-ji
240+
$this->_order_remark = $order_remark;
241+
}
242+
}
227243
$this->_shipping_method = $shipping_method;
228244
$this->_payment_method = $payment_method;
229245
Yii::$service->payment->setPaymentMethod($this->_payment_method);

app/apphtml5/theme/base/html5/checkout/onepage/index/review_order.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@
6060
<table class="onestepcheckout-totals">
6161
<tbody>
6262
<tr>
63-
<td ><?= Yii::$service->page->translate->__('Subtotal') ?></td>
63+
<td class="totals"><?= Yii::$service->page->translate->__('Subtotal') ?></td>
6464
<td class="value">
6565
<span class="price"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['product_total']); ?></span>
6666
</td>
6767
</tr>
6868
<tr>
69-
<td ><?= Yii::$service->page->translate->__('Shipping Cost') ?></td>
69+
<td class="totals"><?= Yii::$service->page->translate->__('Shipping Cost') ?></td>
7070
<td class="value">
7171
<span class="price"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['shipping_cost']); ?></span>
7272
</td>
7373
</tr>
7474
<tr>
75-
<td ><?= Yii::$service->page->translate->__('Discount') ?></td>
75+
<td class="totals"><?= Yii::$service->page->translate->__('Discount') ?></td>
7676
<td class="value">
7777
<span class="price">-<?= $currency_info['symbol']; ?><?= Format::price($cart_info['coupon_cost']); ?></span>
7878
</td>
7979
</tr>
8080
<tr class="grand-total">
81-
<td ><?= Yii::$service->page->translate->__('Grand Total') ?></td>
81+
<td class="totals"><?= Yii::$service->page->translate->__('Grand Total') ?></td>
8282
<td class="value">
8383
<span class="price"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['grand_total']) ?></span>
8484
</td>

app/apphtml5/theme/base/html5/payment/paypal/express/review.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@
6565
<div class="coupon_add_log"></div>
6666
</div>
6767

68-
68+
<div class="onestepcheckout-coupons">
69+
<div class="op_block_title"><?= Yii::$service->page->translate->__('Order Remark (optional)');?></div>
70+
<label for="id_couponcode"><?= Yii::$service->page->translate->__('You can fill in the order remark information below');?></label>
71+
<textarea class="order_remark" name="order_remark" style="width:100%;height:100px;padding:10px;"></textarea>
72+
</div>
6973
</div>
7074

7175
<div class="onestepcheckout-column-right">

app/apphtml5/theme/base/html5/payment/paypal/express/review/review_order.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@
6161
<table class="onestepcheckout-totals">
6262
<tbody>
6363
<tr>
64-
<td class="title"><?= Yii::$service->page->translate->__('Subtotal') ?></td>
64+
<td class="totals"><?= Yii::$service->page->translate->__('Subtotal') ?></td>
6565
<td class="value">
6666
<span class="price"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['product_total']); ?></span>
6767
</td>
6868
</tr>
6969
<tr>
70-
<td class="title"><?= Yii::$service->page->translate->__('Shipping Cost') ?></td>
70+
<td class="totals"><?= Yii::$service->page->translate->__('Shipping Cost') ?></td>
7171
<td class="value">
7272
<span class="price"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['shipping_cost']); ?></span>
7373
</td>
7474
</tr>
7575
<tr>
76-
<td class="title"><?= Yii::$service->page->translate->__('Discount') ?></td>
76+
<td class="totals"><?= Yii::$service->page->translate->__('Discount') ?></td>
7777
<td class="value">
7878
<span class="price">-<?= $currency_info['symbol']; ?><?= Format::price($cart_info['coupon_cost']); ?></span>
7979
</td>
8080
</tr>
8181
<tr class="grand-total">
82-
<td class="title"><?= Yii::$service->page->translate->__('Grand Total') ?></td>
82+
<td class="totals"><?= Yii::$service->page->translate->__('Grand Total') ?></td>
8383
<td class="value">
8484
<span class="price"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['grand_total']) ?></span>
8585
</td>

app/appserver/modules/Payment/block/paypal/express/Placeorder.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class Placeorder
3131
* 用户的支付方式.
3232
*/
3333
public $_payment_method;
34-
34+
35+
public $_order_remark;
36+
3537
public function getLastData()
3638
{
3739
$post = Yii::$app->request->post();
@@ -66,7 +68,7 @@ public function getLastData()
6668
// 将购物车数据,生成订单,生成订单后,不清空购物车,不扣除库存,在支付成功后在清空购物车。
6769
$innerTransaction = Yii::$app->db->beginTransaction();
6870
try {
69-
$genarateStatus = Yii::$service->order->generateOrderByCart($this->_billing, $this->_shipping_method, $this->_payment_method, false,$token);
71+
$genarateStatus = Yii::$service->order->generateOrderByCart($this->_billing, $this->_shipping_method, $this->_payment_method, false, $token, $this->_order_remark);
7072
if ($genarateStatus) {
7173
$innerTransaction->commit();
7274
} else {
@@ -266,7 +268,20 @@ public function checkOrderInfoAndInit($post)
266268
}
267269

268270
}
269-
271+
// 订单备注信息不能超过1500字符
272+
$orderRemarkStrMaxLen = Yii::$service->order->orderRemarkStrMaxLen;
273+
$order_remark = isset($post['order_remark']) ? $post['order_remark'] : '';
274+
if ($order_remark && $orderRemarkStrMaxLen) {
275+
$order_remark_strlen = strlen($order_remark);
276+
if ($order_remark_strlen > $orderRemarkStrMaxLen) {
277+
Yii::$service->helper->errors->add('order remark string length can not gt '.$orderRemarkStrMaxLen);
278+
279+
return false;
280+
} else {
281+
// 去掉xss攻击字符,关于防止xss攻击的yii文档参看:http://www.yiichina.com/doc/guide/2.0/security-best-practices#fang-zhi-xss-gong-ji
282+
$this->_order_remark = $order_remark;
283+
}
284+
}
270285
$this->_shipping_method = $shipping_method;
271286
$this->_payment_method = $payment_method;
272287
Yii::$service->payment->setPaymentMethod($this->_payment_method);

0 commit comments

Comments
 (0)