Authored by Rock Zhang

优化新势力领券活动调用逻辑

Code Review By Rock Zhang
  1 +<?php
  2 +
  3 +namespace Cuxiao;
  4 +use LibModels\Wap\Cuxiao\ActivityData;
  5 +
  6 +/**
  7 + * Created by PhpStorm.
  8 + * User: DELL
  9 + * Date: 2016/2/25
  10 + * Time: 15:11
  11 + *
  12 + * @name XinshiliModel
  13 + * @package models/Cuxiao
  14 + * @author Gtskk(tttt6399998@126.com)
  15 + */
  16 +class XinshiliModel
  17 +{
  18 + /**
  19 + * 获取领券活动结果
  20 + *
  21 + * @param int $uid 用户id
  22 + * @param int $actId 活动id
  23 + * @return array
  24 + */
  25 + public static function getXinshiliCoupon($uid, $actId)
  26 + {
  27 + $result = array('code' => 201);
  28 +
  29 + do {
  30 + if (empty($uid) || empty($actId)) {
  31 + break;
  32 + }
  33 +
  34 + $result = ActivityData::getCouponAll($uid, $actId);
  35 + if (!$result) {
  36 + $result = array('code' => 201);
  37 + break;
  38 + }
  39 +
  40 + if (intval($result['code']) === 200) {
  41 + self::sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');
  42 + }
  43 + } while (false);
  44 +
  45 + return $result;
  46 + }
  47 +
  48 + /**
  49 + * 发送站内信
  50 + *
  51 + * @param int $uid 用户ID
  52 + * @param string $title 站内信标题
  53 + * @param string $content 站内信内容
  54 + */
  55 + private static function sendMessage($uid, $title, $content)
  56 + {
  57 + try {
  58 + ActivityData::message($uid, $title, $content);
  59 + } catch (Exception $e) {
  60 + // do nothing
  61 + }
  62 + }
  63 +}
1 <?php 1 <?php
2 2
3 use Action\HuodongAction; 3 use Action\HuodongAction;
4 -use LibModels\Wap\Cuxiao\ActivityData; 4 +use Cuxiao\XinshiliModel;
5 use Plugin\Helpers; 5 use Plugin\Helpers;
6 6
7 /** 7 /**
@@ -35,14 +35,13 @@ class XinshiliController extends HuodongAction @@ -35,14 +35,13 @@ class XinshiliController extends HuodongAction
35 private function checkLogin() 35 private function checkLogin()
36 { 36 {
37 $playUrl = Helpers::url('/cuxiao/xinshili/index'); 37 $playUrl = Helpers::url('/cuxiao/xinshili/index');
38 - $playUrlEncode = strtr($playUrl, array('/' => '\\/'));  
39 38
40 $uid = $this->getLoggedUid(); 39 $uid = $this->getLoggedUid();
41 if (!$uid) { 40 if (!$uid) {
42 if (!$this->_isApp) { 41 if (!$this->_isApp) {
43 - $this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/xinshili/index')), 'default')); 42 + $this->go(Helpers::url('/signin.html', array('refer' => $playUrl), 'default'));
44 } else { 43 } else {
45 - $playUrl = Helpers::url('/cuxiao/xinshili/index'); 44 + $playUrlEncode = strtr($playUrl, array('/' => '\\/'));
46 $this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'); 45 $this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
47 } 46 }
48 } 47 }
@@ -92,14 +91,7 @@ class XinshiliController extends HuodongAction @@ -92,14 +91,7 @@ class XinshiliController extends HuodongAction
92 91
93 $activityId = $this->getActivityId(); 92 $activityId = $this->getActivityId();
94 $uid = $this->getLoggedUid(); 93 $uid = $this->getLoggedUid();
95 - $result = ActivityData::getCouponAll($uid, $activityId);  
96 - if (!isset($result['code'])) {  
97 - break;  
98 - }  
99 -  
100 - if (intval($result['code']) === 200) {  
101 - $this->sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');  
102 - } 94 + $result = XinshiliModel::getXinshiliCoupon($uid, $activityId);
103 } while (false); 95 } while (false);
104 96
105 $this->echoJson($result); 97 $this->echoJson($result);
@@ -124,20 +116,4 @@ class XinshiliController extends HuodongAction @@ -124,20 +116,4 @@ class XinshiliController extends HuodongAction
124 } 116 }
125 } 117 }
126 118
127 - /**  
128 - * 发送站内信  
129 - *  
130 - * @param int $uid 用户ID  
131 - * @param string $title 站内信标题  
132 - * @param string $content 站内信内容  
133 - */  
134 - private function sendMessage($uid, $title, $content)  
135 - {  
136 - try {  
137 - ActivityData::message($uid, $title, $content);  
138 - } catch (Exception $e) {  
139 - // do nothing  
140 - }  
141 - }  
142 -  
143 } 119 }