添加限购码商品详情的代码逻辑(模板仍需要调整)
Code Review By Rock Zhang
Showing
7 changed files
with
209 additions
and
60 deletions
@@ -133,8 +133,10 @@ class DetailData | @@ -133,8 +133,10 @@ class DetailData | ||
133 | 133 | ||
134 | /** | 134 | /** |
135 | * 为你优选的商品列表 | 135 | * 为你优选的商品列表 |
136 | - * | 136 | + * |
137 | * @param int $productSkn 商品SKN号 | 137 | * @param int $productSkn 商品SKN号 |
138 | + * @param int $channel | ||
139 | + * @param int $brandId | ||
138 | * @return array | 140 | * @return array |
139 | */ | 141 | */ |
140 | public static function preference($productSkn, $channel, $brandId) | 142 | public static function preference($productSkn, $channel, $brandId) |
@@ -220,4 +222,20 @@ class DetailData | @@ -220,4 +222,20 @@ class DetailData | ||
220 | return Yohobuy::get(Yohobuy::API_URL, $param); | 222 | return Yohobuy::get(Yohobuy::API_URL, $param); |
221 | } | 223 | } |
222 | 224 | ||
225 | + /** | ||
226 | + * 获取限购商品详情 | ||
227 | + * | ||
228 | + * @param string $productCode 限购商品商品码 | ||
229 | + * @return mixed | ||
230 | + */ | ||
231 | + public static function limitProductData($productCode) | ||
232 | + { | ||
233 | + $param = Yohobuy::param(); | ||
234 | + $param['method'] = 'app.consult.useful'; | ||
235 | + $param['limit_product_code'] = $productCode; | ||
236 | + $param['client_secret'] = Sign::getSign($param); | ||
237 | + | ||
238 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
239 | + } | ||
240 | + | ||
223 | } | 241 | } |
@@ -895,4 +895,21 @@ class Helpers | @@ -895,4 +895,21 @@ class Helpers | ||
895 | } | 895 | } |
896 | return $area.'-'.$mobile; | 896 | return $area.'-'.$mobile; |
897 | } | 897 | } |
898 | + | ||
899 | + /** | ||
900 | + * 按照数组中指定字段排序二维数组 | ||
901 | + * | ||
902 | + * @param array &$array 需要排序的数组 | ||
903 | + * @param string $field 字段名称 | ||
904 | + * @param boolean $desc 时候降序排列,默认为false | ||
905 | + */ | ||
906 | + public static function sortArrByField(&$array, $field, $desc = false) | ||
907 | + { | ||
908 | + $fieldArr = array(); | ||
909 | + foreach ($array as $k => $v) { | ||
910 | + $fieldArr[$k] = isset($v[$field]) ? $v[$field] : ''; | ||
911 | + } | ||
912 | + $sort = $desc == false ? SORT_ASC : SORT_DESC; | ||
913 | + array_multisort($fieldArr, $sort, $array); | ||
914 | + } | ||
898 | } | 915 | } |
@@ -717,6 +717,8 @@ class DetailModel | @@ -717,6 +717,8 @@ class DetailModel | ||
717 | * 获取为你优选的商品 | 717 | * 获取为你优选的商品 |
718 | * | 718 | * |
719 | * @param int $productSkn 商品SKN | 719 | * @param int $productSkn 商品SKN |
720 | + * @param int $channel | ||
721 | + * @param int $brandId | ||
720 | * @return array | 722 | * @return array |
721 | */ | 723 | */ |
722 | public static function getPreference($productSkn, $channel, $brandId) | 724 | public static function getPreference($productSkn, $channel, $brandId) |
@@ -738,6 +740,107 @@ class DetailModel | @@ -738,6 +740,107 @@ class DetailModel | ||
738 | return $result; | 740 | return $result; |
739 | } | 741 | } |
740 | 742 | ||
743 | + | ||
744 | + /** | ||
745 | + * 获取限购商品详情 | ||
746 | + * | ||
747 | + * @param string $productCode | ||
748 | + * @return array | ||
749 | + */ | ||
750 | + public static function getLimitProductData($productCode) | ||
751 | + { | ||
752 | + $result = array(); | ||
753 | + | ||
754 | + do { | ||
755 | + if (empty($productCode)) { | ||
756 | + break; | ||
757 | + } | ||
758 | + | ||
759 | + $product = DetailData::limitProductData($productCode); | ||
760 | + $product = array( | ||
761 | + "activityId" => null, | ||
762 | + "attachment" => array( | ||
763 | + array( | ||
764 | + "attachName" => "", | ||
765 | + "attachType" => 1, | ||
766 | + "attachUrl" => "http://img10.static.yhbimg.com/yhb-img01/2016/03/03/17/012ddf849c5bd975452063594f36d21c37.png", | ||
767 | + "id" => 445, | ||
768 | + "intro" => "", | ||
769 | + "isDefault" => 1, | ||
770 | + "orderBy" => 0, | ||
771 | + "productId" => 197, | ||
772 | + "status" => 0 | ||
773 | + ) | ||
774 | + ), | ||
775 | + "batchNo" => "20160303171415", | ||
776 | + "createTime" => 1456996513, | ||
777 | + "dayFlag" => 1, | ||
778 | + "description" => "", | ||
779 | + "hotFlag" => 1, | ||
780 | + "id" => 197, | ||
781 | + "lastUpdateTime" => 1456998239, | ||
782 | + "limitProductCode" => "2016030317150854", | ||
783 | + "limitProductType" => 1, | ||
784 | + "notSaleOrderBy" => 0, | ||
785 | + "orderBy" => 72, | ||
786 | + "price" => "¥65.00", | ||
787 | + "productName" => "damao-已开售-码已发完-已售罄", | ||
788 | + "productSkn" => 51147512, | ||
789 | + "saleTime" => 1454342400, | ||
790 | + "showFlag" => 1, | ||
791 | + "status" => 1 | ||
792 | + ); | ||
793 | + | ||
794 | + if (empty($product)) { | ||
795 | + break; | ||
796 | + } | ||
797 | + | ||
798 | + $result['price'] = $product['price']; | ||
799 | + $result['name'] = $product['productName']; | ||
800 | + $result['releaseDate'] = date('Y年m月', $product['saleTime']) . '发售'; | ||
801 | + $result['description'] = $product['description']; | ||
802 | + | ||
803 | + // 附件 | ||
804 | + foreach ($product['attachment'] as $item) { | ||
805 | + $result['attach'][] = self::procLimitProductAttach($item); | ||
806 | + } | ||
807 | + | ||
808 | + } while (false); | ||
809 | + | ||
810 | + return $result; | ||
811 | + } | ||
812 | + | ||
813 | + /** | ||
814 | + * 处理限购商品附件数据 | ||
815 | + * | ||
816 | + * @param array $attachment 附件数据 | ||
817 | + * @return array | ||
818 | + */ | ||
819 | + private static function procLimitProductAttach($attachment) | ||
820 | + { | ||
821 | + $result = array(); | ||
822 | + | ||
823 | + switch(intval($attachment['attachType'])) { | ||
824 | + case 1: // 大图文字 | ||
825 | + $result['mainImg'] = $attachment['attachUrl']; | ||
826 | + $result['goodDescription'] = $attachment['intro']; | ||
827 | + $result['orderBy'] = $attachment['orderBy']; | ||
828 | + break; | ||
829 | + case 2: // 图片列表 | ||
830 | + break; | ||
831 | + case 3: // 视频 | ||
832 | + break; | ||
833 | + default: | ||
834 | + break; | ||
835 | + } | ||
836 | + | ||
837 | + if(count($result) > 1) { | ||
838 | + Helpers::sortArrByField($result, 'orderBy'); | ||
839 | + } | ||
840 | + | ||
841 | + return $result; | ||
842 | + } | ||
843 | + | ||
741 | /** | 844 | /** |
742 | * 处理限购商品的有关按钮状态(或取现购买以及底部商品购买按钮) | 845 | * 处理限购商品的有关按钮状态(或取现购买以及底部商品购买按钮) |
743 | * | 846 | * |
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | use Action\AbstractAction; | 3 | use Action\AbstractAction; |
4 | use Plugin\Helpers; | 4 | use Plugin\Helpers; |
5 | use LibModels\Wap\Product\DetailData; | 5 | use LibModels\Wap\Product\DetailData; |
6 | +use Product\DetailModel; | ||
6 | 7 | ||
7 | /** | 8 | /** |
8 | * 商品详情的控制器 | 9 | * 商品详情的控制器 |
@@ -33,7 +34,7 @@ class DetailController extends AbstractAction | @@ -33,7 +34,7 @@ class DetailController extends AbstractAction | ||
33 | $vipLevel = Helpers::getVipLevel($this->_vip); | 34 | $vipLevel = Helpers::getVipLevel($this->_vip); |
34 | } | 35 | } |
35 | 36 | ||
36 | - $data = \Product\DetailModel::getBaseInfo($productId, $goodsId, $uid, $vipLevel); | 37 | + $data = DetailModel::getBaseInfo($productId, $goodsId, $uid, $vipLevel); |
37 | if (array() === $data) { | 38 | if (array() === $data) { |
38 | $this->error(); | 39 | $this->error(); |
39 | } | 40 | } |
@@ -66,7 +67,7 @@ class DetailController extends AbstractAction | @@ -66,7 +67,7 @@ class DetailController extends AbstractAction | ||
66 | $vipLevel = Helpers::getVipLevel($this->_vip); | 67 | $vipLevel = Helpers::getVipLevel($this->_vip); |
67 | } | 68 | } |
68 | 69 | ||
69 | - $data = \Product\DetailModel::getBaseInfo(null, null, $uid, $vipLevel, $productSkn); | 70 | + $data = DetailModel::getBaseInfo(null, null, $uid, $vipLevel, $productSkn); |
70 | if (array() === $data) { | 71 | if (array() === $data) { |
71 | $this->error(); | 72 | $this->error(); |
72 | } | 73 | } |
@@ -94,7 +95,7 @@ class DetailController extends AbstractAction | @@ -94,7 +95,7 @@ class DetailController extends AbstractAction | ||
94 | // 加入uid和udid参数,为了实现记录浏览记录的功能 | 95 | // 加入uid和udid参数,为了实现记录浏览记录的功能 |
95 | $uid = $this->getUid(); | 96 | $uid = $this->getUid(); |
96 | $udid = $this->getUdid(); | 97 | $udid = $this->getUdid(); |
97 | - $data = \Product\DetailModel::getSizeInfo($productSkn, $uid, $udid); | 98 | + $data = DetailModel::getSizeInfo($productSkn, $uid, $udid); |
98 | if (array() === $data) { | 99 | if (array() === $data) { |
99 | echo ' '; | 100 | echo ' '; |
100 | exit(); | 101 | exit(); |
@@ -126,7 +127,7 @@ class DetailController extends AbstractAction | @@ -126,7 +127,7 @@ class DetailController extends AbstractAction | ||
126 | 'goodsCommentsPage' => true, | 127 | 'goodsCommentsPage' => true, |
127 | 'pageFooter' => true, | 128 | 'pageFooter' => true, |
128 | 'comments' => array( | 129 | 'comments' => array( |
129 | - 'list' => \Product\DetailModel::getComments($productId), | 130 | + 'list' => DetailModel::getComments($productId), |
130 | ), | 131 | ), |
131 | ); | 132 | ); |
132 | 133 | ||
@@ -155,14 +156,14 @@ class DetailController extends AbstractAction | @@ -155,14 +156,14 @@ class DetailController extends AbstractAction | ||
155 | $this->setTitle('购买咨询'); | 156 | $this->setTitle('购买咨询'); |
156 | 157 | ||
157 | $uid = $this->getUid(); | 158 | $uid = $this->getUid(); |
158 | - $consults = \Product\DetailModel::getConsults($uid, $productId); | 159 | + $consults = DetailModel::getConsults($uid, $productId); |
159 | $data = array( | 160 | $data = array( |
160 | 'goodsConsultsPage' => true, | 161 | 'goodsConsultsPage' => true, |
161 | 'pageFooter' => true, | 162 | 'pageFooter' => true, |
162 | 'consults' => array( | 163 | 'consults' => array( |
163 | 'list' => $consults | 164 | 'list' => $consults |
164 | ), | 165 | ), |
165 | - 'faq' => \Product\DetailModel::getCommonConsults(), | 166 | + 'faq' => DetailModel::getCommonConsults(), |
166 | 'showReadMore' => count($consults) > 2, | 167 | 'showReadMore' => count($consults) > 2, |
167 | 'link' => Helpers::url('/product/detail/consultform', array('product_id' => $productId)), | 168 | 'link' => Helpers::url('/product/detail/consultform', array('product_id' => $productId)), |
168 | ); | 169 | ); |
@@ -184,7 +185,7 @@ class DetailController extends AbstractAction | @@ -184,7 +185,7 @@ class DetailController extends AbstractAction | ||
184 | $total = $this->post('total', 0); | 185 | $total = $this->post('total', 0); |
185 | $uid = $this->getUid(); | 186 | $uid = $this->getUid(); |
186 | $id = $this->post('id'); | 187 | $id = $this->post('id'); |
187 | - $result = \Product\DetailModel::upvoteConsult($uid, $id, $productId, $total); | 188 | + $result = DetailModel::upvoteConsult($uid, $id, $productId, $total); |
188 | } | 189 | } |
189 | 190 | ||
190 | $this->echoJson($result); | 191 | $this->echoJson($result); |
@@ -202,7 +203,7 @@ class DetailController extends AbstractAction | @@ -202,7 +203,7 @@ class DetailController extends AbstractAction | ||
202 | $total = $this->post('total', 0); | 203 | $total = $this->post('total', 0); |
203 | $uid = $this->getUid(); | 204 | $uid = $this->getUid(); |
204 | $id = $this->post('id'); | 205 | $id = $this->post('id'); |
205 | - $result = \Product\DetailModel::usefulConsult($uid, $id, $productId, $total); | 206 | + $result = DetailModel::usefulConsult($uid, $id, $productId, $total); |
206 | } | 207 | } |
207 | 208 | ||
208 | $this->echoJson($result); | 209 | $this->echoJson($result); |
@@ -266,7 +267,7 @@ class DetailController extends AbstractAction | @@ -266,7 +267,7 @@ class DetailController extends AbstractAction | ||
266 | $productSkn = $this->get('productSkn'); | 267 | $productSkn = $this->get('productSkn'); |
267 | $brandId = $this->get('brandId'); | 268 | $brandId = $this->get('brandId'); |
268 | $channel = Helpers::getChannelByCookie(); | 269 | $channel = Helpers::getChannelByCookie(); |
269 | - $result = \Product\DetailModel::getPreference($productSkn, $channel, $brandId); | 270 | + $result = DetailModel::getPreference($productSkn, $channel, $brandId); |
270 | } | 271 | } |
271 | 272 | ||
272 | if (empty($result)) { | 273 | if (empty($result)) { |
@@ -276,4 +277,64 @@ class DetailController extends AbstractAction | @@ -276,4 +277,64 @@ class DetailController extends AbstractAction | ||
276 | } | 277 | } |
277 | } | 278 | } |
278 | 279 | ||
280 | + /** | ||
281 | + * 限购商品说明页面 | ||
282 | + */ | ||
283 | + public function limitHelpAction() | ||
284 | + { | ||
285 | + $data = array(); | ||
286 | + $this->_view->display('limit-help', $data); | ||
287 | + } | ||
288 | + | ||
289 | + /** | ||
290 | + * 限购商品详情页 | ||
291 | + */ | ||
292 | + public function limitAction() | ||
293 | + { | ||
294 | + /*$data = array( | ||
295 | + 'profile' => 'http://cdn.yoho.cn/myohobuy/assets/img/me/index/user-avatar.png?1455719653', | ||
296 | + 'banner' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240', | ||
297 | + 'bannerSrc' => './', | ||
298 | + 'name' => '潮流尖端商品啊啊啊啊', | ||
299 | + 'price' => '1999', | ||
300 | + 'releaseDate' => '2016年12月发售', | ||
301 | + 'appSrc' => './', | ||
302 | + 'mainImg' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240', | ||
303 | + 'goodDescription' => '独独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤', | ||
304 | + 'imgList' => array( | ||
305 | + array( | ||
306 | + 'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240' | ||
307 | + ), | ||
308 | + array( | ||
309 | + 'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240' | ||
310 | + ), | ||
311 | + array( | ||
312 | + 'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240' | ||
313 | + ) | ||
314 | + ), | ||
315 | + 'vedio' => array( | ||
316 | + 'img' => './', | ||
317 | + 'list' => array( | ||
318 | + array( | ||
319 | + 'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.mp4' | ||
320 | + ), | ||
321 | + array( | ||
322 | + 'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.webm' | ||
323 | + ), | ||
324 | + array( | ||
325 | + 'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.ogv' | ||
326 | + ) | ||
327 | + ) | ||
328 | + ) | ||
329 | + );*/ | ||
330 | + | ||
331 | + $productCode = $this->get('code', '34343'); | ||
332 | + $data = DetailModel::getLimitProductData($productCode); | ||
333 | + | ||
334 | + // APP下载链接地址 | ||
335 | + $data['appSrc'] = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho'; | ||
336 | + | ||
337 | + $this->_view->display('limit', $data); | ||
338 | + } | ||
339 | + | ||
279 | } | 340 | } |
@@ -228,54 +228,4 @@ class IndexController extends AbstractAction | @@ -228,54 +228,4 @@ class IndexController extends AbstractAction | ||
228 | 228 | ||
229 | $this->_view->display('index', $data); | 229 | $this->_view->display('index', $data); |
230 | } | 230 | } |
231 | - | ||
232 | - public function limitHelpAction() | ||
233 | - { | ||
234 | - $data = array(); | ||
235 | - $this->_view->display('limit-help', $data); | ||
236 | - } | ||
237 | - | ||
238 | - public function limitAction() | ||
239 | - { | ||
240 | - $data = array( | ||
241 | - 'profile' => 'http://cdn.yoho.cn/myohobuy/assets/img/me/index/user-avatar.png?1455719653', | ||
242 | - 'banner' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240', | ||
243 | - 'bannerSrc' => './', | ||
244 | - 'name' => '潮流尖端商品啊啊啊啊', | ||
245 | - 'price' => '1999', | ||
246 | - 'releaseDate' => '2016年12月发售', | ||
247 | - 'appSrc' => './', | ||
248 | - 'mainImg' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240', | ||
249 | - 'goodDescription' => '独独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤', | ||
250 | - 'imgList' => array( | ||
251 | - array( | ||
252 | - 'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240' | ||
253 | - ), | ||
254 | - array( | ||
255 | - 'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240' | ||
256 | - ), | ||
257 | - array( | ||
258 | - 'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240' | ||
259 | - ) | ||
260 | - ), | ||
261 | - 'vedio' => array( | ||
262 | - 'img' => './', | ||
263 | - 'list' => array( | ||
264 | - array( | ||
265 | - 'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.mp4' | ||
266 | - ), | ||
267 | - array( | ||
268 | - 'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.webm' | ||
269 | - ), | ||
270 | - array( | ||
271 | - 'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.ogv' | ||
272 | - ) | ||
273 | - ) | ||
274 | - ) | ||
275 | - ); | ||
276 | - | ||
277 | - | ||
278 | - | ||
279 | - $this->_view->display('limit', $data); | ||
280 | - } | ||
281 | } | 231 | } |
-
Please register or login to post a comment