Authored by cailing

Merge branch 'feature/rebuy' into release/4.6

再次购买解决冲突
# Conflicts:
#	library/LibModels/Wap/Home/OrderData.php
#	static/js/me/order-detail.js
#	static/sass/me/_order.css
@@ -199,4 +199,19 @@ class OrderData @@ -199,4 +199,19 @@ class OrderData
199 return Yohobuy::get(Yohobuy::API_URL, $param); 199 return Yohobuy::get(Yohobuy::API_URL, $param);
200 } 200 }
201 201
  202 + /** 再次购买
  203 + * @param type $uid
  204 + * @param type $orderCode
  205 + * @return type
  206 + */
  207 + public static function reAddData($uid, $orderCode)
  208 + {
  209 + $param = Yohobuy::param();
  210 + $param['method'] = 'app.Shopping.readd';
  211 + $param['uid'] = $uid;
  212 + $param['order_code'] = $orderCode;
  213 + $param['client_secret'] = Sign::getSign($param);
  214 +
  215 + return Yohobuy::get(Yohobuy::API_URL, $param);
  216 + }
202 } 217 }
@@ -8,70 +8,16 @@ var $ = require('jquery'), @@ -8,70 +8,16 @@ var $ = require('jquery'),
8 lazyLoad = require('yoho.lazyload'), 8 lazyLoad = require('yoho.lazyload'),
9 Hammer = require('yoho.hammer'), 9 Hammer = require('yoho.hammer'),
10 dialog = require('./dialog'), 10 dialog = require('./dialog'),
11 - tip = require('../plugin/tip'),  
12 - orderId = $('#order-detail').data('id'),  
13 - $countDownHours = $('.hours'),  
14 - $countdownContainer = $('.count-down'),  
15 - Swiper = require('yoho.iswiper'),  
16 - $ownerInfo = $('.owner-info'),  
17 - $reaMask = $('.reason-mask'),  
18 - reasonSwiper,  
19 - optHammer; 11 + tip = require('../plugin/tip');
  12 +
  13 +var orderId = $('#order-detail').data('id');
  14 +
  15 +var optHammer;
20 16
21 lazyLoad({ 17 lazyLoad({
22 try_again_css: 'order-failure' 18 try_again_css: 'order-failure'
23 }); 19 });
24 20
25 -function downCount(options) {  
26 -  
27 - var difference = options,// difference of dates  
28 - interval;  
29 - /**  
30 - * Main downCount function that calculates everything  
31 - */  
32 - function countdown() {  
33 -  
34 - // basic math variables  
35 - var _second = 1000,  
36 - _minute = _second * 60,  
37 - _hour = _minute * 60,  
38 - _day = _hour * 24,  
39 - hours,  
40 - minutes,  
41 - seconds;  
42 -  
43 - // calculate dates  
44 - hours = Math.floor((difference % _day) / _hour),  
45 - minutes = Math.floor((difference % _hour) / _minute),  
46 - seconds = Math.floor((difference % _minute) / _second);  
47 -  
48 - // fix dates so that it will show two digets  
49 - hours = (String(hours).length >= 2) ? hours : '0' + hours;  
50 - minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes;  
51 - seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds;  
52 -  
53 - // set to DOM  
54 - $countdownContainer.removeClass('hide');  
55 - if (hours === '00') {  
56 - $countDownHours.text('剩余' + minutes + ':' + seconds);  
57 - } else {  
58 - $countDownHours.text('剩余' + hours + ':' + minutes + ':' + seconds);  
59 - }  
60 -  
61 - difference -= 1000;  
62 -  
63 - if (difference < 0) {  
64 - clearInterval(interval);// stop timer  
65 - return;  
66 - }  
67 - }  
68 - if (difference !== '' && difference > 0) {  
69 - interval = setInterval(countdown, 1000);// start  
70 - }  
71 -}  
72 -  
73 -downCount($countDownHours.text());  
74 -  
75 //订单删除 21 //订单删除
76 optHammer = new Hammer(document.getElementsByClassName('opt')[0]); 22 optHammer = new Hammer(document.getElementsByClassName('opt')[0]);
77 optHammer.on('tap', function(e) { 23 optHammer.on('tap', function(e) {
@@ -109,66 +55,23 @@ optHammer.on('tap', function(e) { @@ -109,66 +55,23 @@ optHammer.on('tap', function(e) {
109 }); 55 });
110 }); 56 });
111 } else if ($cur.hasClass('btn-cancel')) { 57 } else if ($cur.hasClass('btn-cancel')) {
112 - $reaMask.css('visibility', 'visible');  
113 - }  
114 -});  
115 58
116 -if ($ownerInfo.data('changeable') === true) {  
117 - $ownerInfo.find('.rest').show();  
118 - $ownerInfo.on('touchend', function() {  
119 - location.href = $ownerInfo.data('url');  
120 - });  
121 -}  
122 -  
123 -$(function() {  
124 - reasonSwiper = new Swiper('.box-main', {  
125 - initialSlide: 0,  
126 - centeredSlides: true,  
127 - slidesPerView: 5,  
128 - direction: 'vertical',  
129 - onSlideChangeStart: function(reasonSwiper) {  
130 - var activeIndex = reasonSwiper.activeIndex,  
131 - slides = reasonSwiper.slides,  
132 - i = 0;  
133 -  
134 - if (slides.length !== 1) {  
135 - if (activeIndex === 0) {  
136 - for (i = 1; i < slides.length; i++) {  
137 - $(slides[i]).css('transform', '');  
138 - }  
139 - } else if (activeIndex === slides.length - 1) {  
140 - for (i = 0; i < activeIndex; i++) {  
141 - $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)');  
142 - }  
143 - } else {  
144 - for (i = 0; i < activeIndex; i++) {  
145 - $(slides[i]).css('transform', 'rotateX(' + (30 + (activeIndex - i) * 12) + 'deg)');  
146 - }  
147 - for (i = activeIndex + 1; i < slides.length; i++) {  
148 - $(slides[i]).css('transform', '');  
149 - }  
150 - }  
151 - }  
152 - $(slides[activeIndex]).css('transform', ''); 59 + //取消订单
  60 + dialog.showDialog({
  61 + dialogText: '确定取消订单吗?',
  62 + hasFooter: {
  63 + leftBtnText: '取消',
  64 + rightBtnText: '确定'
153 } 65 }
154 - });  
155 -});  
156 -  
157 -$reaMask.find('.box-cmp').on('touchend', function(e) {  
158 - var selSolid = reasonSwiper.slides[reasonSwiper.activeIndex],  
159 - reason = $(selSolid).text(),  
160 - reasonId = $(selSolid).data('reasonId');  
161 - 66 + }, function() {
162 $.ajax({ 67 $.ajax({
163 type: 'GET', 68 type: 'GET',
164 url: '/home/cancelOrder', 69 url: '/home/cancelOrder',
165 data: { 70 data: {
166 - id: orderId,  
167 - reason: reason,  
168 - reasonId: reasonId 71 + id: orderId
169 } 72 }
170 }).then(function(res) { 73 }).then(function(res) {
171 - $reaMask.fadeOut(); 74 + $('#dialog-wrapper').hide();
172 if ($.type(res) !== 'object') { 75 if ($.type(res) !== 'object') {
173 return; 76 return;
174 } 77 }
@@ -181,13 +84,21 @@ $reaMask.find('.box-cmp').on('touchend', function(e) { @@ -181,13 +84,21 @@ $reaMask.find('.box-cmp').on('touchend', function(e) {
181 }).fail(function() { 84 }).fail(function() {
182 tip.show('网络错误'); 85 tip.show('网络错误');
183 }); 86 });
184 -});  
185 -  
186 -$reaMask.on('touchend', function(event) {  
187 - if (event.target.className !== 'reason-mask') {  
188 - return false; 87 + });
  88 + } else if ($cur.hasClass('btn-rebuy')) {
  89 + $.ajax({
  90 + type: 'GET',
  91 + url: '/home/readd',
  92 + data: {
  93 + orderCode: orderId
  94 + },
  95 + success: function(res) {
  96 + tip.show(res.message);
  97 + location.href = '/cart/index/index';
  98 + },
  99 + error: function(res) {
  100 + tip.show(res.message);
  101 + }
  102 + });
189 } 103 }
190 -  
191 - $reaMask.css('visibility', 'hidden');  
192 - event.stopPropagation();  
193 }); 104 });
@@ -223,6 +223,21 @@ orderHammer.on('tap', function(e) { @@ -223,6 +223,21 @@ orderHammer.on('tap', function(e) {
223 //Location to order detail 223 //Location to order detail
224 url = $order.data('href'); 224 url = $order.data('href');
225 location.href = url; 225 location.href = url;
  226 + } else if ($cur.closest('.rebuy').length > 0) {
  227 + $.ajax({
  228 + type: 'GET',
  229 + url: '/home/readd',
  230 + data: {
  231 + orderCode: id
  232 + },
  233 + success: function(res) {
  234 + tip.show(res.message);
  235 + location.href = '/cart/index/index';
  236 + },
  237 + error: function(res) {
  238 + tip.show(res.message);
  239 + }
  240 + });
226 } 241 }
227 }); 242 });
228 243
@@ -267,4 +267,8 @@ @@ -267,4 +267,8 @@
267 267
268 } 268 }
269 } 269 }
  270 +
  271 + .btn-rebuy {
  272 + margin-left: 10px;
  273 + }
270 } 274 }
@@ -161,6 +161,8 @@ @@ -161,6 +161,8 @@
161 font-size: 24px; 161 font-size: 24px;
162 line-height: 24px; 162 line-height: 24px;
163 } 163 }
  164 + .rebuy {
  165 + margin-left: 20px;
164 } 166 }
165 } 167 }
166 } 168 }
@@ -96,6 +96,7 @@ @@ -96,6 +96,7 @@
96 {{#unless unreceived}} 96 {{#unless unreceived}}
97 {{#unless unpaid}} 97 {{#unless unpaid}}
98 <span class="btn btn-del">删除订单</span> 98 <span class="btn btn-del">删除订单</span>
  99 + <span class="btn btn-rebuy">再次购买</span>
99 {{/unless}} 100 {{/unless}}
100 {{/unless}} 101 {{/unless}}
101 102
@@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
20 {{#unless unreceived}} 20 {{#unless unreceived}}
21 <div class="order-opt"> 21 <div class="order-opt">
22 <span class="btn del">删除订单</span> 22 <span class="btn del">删除订单</span>
  23 + <span class="btn rebuy">再次购买</span>
23 </div> 24 </div>
24 {{/unless}} 25 {{/unless}}
25 {{/unless}} 26 {{/unless}}
@@ -830,6 +830,40 @@ class HomeController extends AbstractAction @@ -830,6 +830,40 @@ class HomeController extends AbstractAction
830 $this->_view->display('order-content', $order); 830 $this->_view->display('order-content', $order);
831 } 831 }
832 832
  833 + /**
  834 + * 我的订单——再次购买
  835 + */
  836 + public function reAddAction()
  837 + {
  838 + $result = array('code' => 401, 'message' => '商品加入购物车失败', 'data' => '');
  839 +
  840 + do {
  841 + /* 判断是不是AJAX请求 */
  842 + if (!$this->isAjax()) {
  843 + break;
  844 + }
  845 + //获取相关参数
  846 + $uid = $this->getUid(true);
  847 + $orderCode = $this->get('orderCode', '');
  848 + if (!$uid || !$orderCode) {
  849 + $result = array('code' => 400, 'message' => '缺失参数', 'data' => '');
  850 + break;
  851 + }
  852 + $reAddData = OrderData::reAddData($uid, $orderCode);
  853 + if(!isset($reAddData['code']) || $reAddData['code'] != 200){
  854 + break;
  855 + }
  856 + $result = array('code' => 200, 'message' => '商品已重新加入购物车', 'data' => $reAddData['data']);
  857 +
  858 + if (!isset($result['code'])) {
  859 + break;
  860 + }
  861 + }
  862 + while (false);
  863 +
  864 + $this->echoJson($result);
  865 + }
  866 +
833 /* 867 /*
834 * 我的订单-取消订单 868 * 我的订单-取消订单
835 */ 869 */
@@ -1063,6 +1097,8 @@ class HomeController extends AbstractAction @@ -1063,6 +1097,8 @@ class HomeController extends AbstractAction
1063 1097
1064 /* 判断订单信息是否存在 */ 1098 /* 判断订单信息是否存在 */
1065 $orderDetail = OrderModel::orderDetail($orderCode, $this->_uid, $this->_usession); 1099 $orderDetail = OrderModel::orderDetail($orderCode, $this->_uid, $this->_usession);
  1100 +// $readd = OrderData::reAddData($this->_uid, 1611143210);
  1101 +// print_r($readd);
1066 if (empty($orderDetail)) { 1102 if (empty($orderDetail)) {
1067 $this->error(); 1103 $this->error();
1068 } 1104 }