Authored by Rock Zhang

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

Code Review By Rock Zhang
<?php
namespace Cuxiao;
use LibModels\Wap\Cuxiao\ActivityData;
/**
* Created by PhpStorm.
* User: DELL
* Date: 2016/2/25
* Time: 15:11
*
* @name XinshiliModel
* @package models/Cuxiao
* @author Gtskk(tttt6399998@126.com)
*/
class XinshiliModel
{
/**
* 获取领券活动结果
*
* @param int $uid 用户id
* @param int $actId 活动id
* @return array
*/
public static function getXinshiliCoupon($uid, $actId)
{
$result = array('code' => 201);
do {
if (empty($uid) || empty($actId)) {
break;
}
$result = ActivityData::getCouponAll($uid, $actId);
if (!$result) {
$result = array('code' => 201);
break;
}
if (intval($result['code']) === 200) {
self::sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');
}
} while (false);
return $result;
}
/**
* 发送站内信
*
* @param int $uid 用户ID
* @param string $title 站内信标题
* @param string $content 站内信内容
*/
private static function sendMessage($uid, $title, $content)
{
try {
ActivityData::message($uid, $title, $content);
} catch (Exception $e) {
// do nothing
}
}
}
\ No newline at end of file
... ...
<?php
use Action\HuodongAction;
use LibModels\Wap\Cuxiao\ActivityData;
use Cuxiao\XinshiliModel;
use Plugin\Helpers;
/**
... ... @@ -35,14 +35,13 @@ class XinshiliController extends HuodongAction
private function checkLogin()
{
$playUrl = Helpers::url('/cuxiao/xinshili/index');
$playUrlEncode = strtr($playUrl, array('/' => '\\/'));
$uid = $this->getLoggedUid();
if (!$uid) {
if (!$this->_isApp) {
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url('/cuxiao/xinshili/index')), 'default'));
$this->go(Helpers::url('/signin.html', array('refer' => $playUrl), 'default'));
} else {
$playUrl = Helpers::url('/cuxiao/xinshili/index');
$playUrlEncode = strtr($playUrl, array('/' => '\\/'));
$this->go($playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $playUrlEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
}
}
... ... @@ -92,14 +91,7 @@ class XinshiliController extends HuodongAction
$activityId = $this->getActivityId();
$uid = $this->getLoggedUid();
$result = ActivityData::getCouponAll($uid, $activityId);
if (!isset($result['code'])) {
break;
}
if (intval($result['code']) === 200) {
$this->sendMessage($uid, '【优惠券】您获得1000元套券', '尊敬的客户:恭喜您成功获得1000元套券!您可以在个人中心的交易管理中查看‘我的优惠券’。');
}
$result = XinshiliModel::getXinshiliCoupon($uid, $activityId);
} while (false);
$this->echoJson($result);
... ... @@ -124,20 +116,4 @@ class XinshiliController extends HuodongAction
}
}
/**
* 发送站内信
*
* @param int $uid 用户ID
* @param string $title 站内信标题
* @param string $content 站内信内容
*/
private function sendMessage($uid, $title, $content)
{
try {
ActivityData::message($uid, $title, $content);
} catch (Exception $e) {
// do nothing
}
}
}
... ...