Authored by Rock Zhang

添加元宵节抽签活动调用接口的逻辑

Code Review By Rock Zhang
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace LibModels\Wap\Cuxiao; 3 namespace LibModels\Wap\Cuxiao;
4 4
  5 +use Api\Sign;
5 use Api\Yohobuy; 6 use Api\Yohobuy;
6 7
7 /** 8 /**
@@ -69,9 +70,35 @@ class ActivityData @@ -69,9 +70,35 @@ class ActivityData
69 } 70 }
70 71
71 /** 72 /**
  73 + * @param int $uid 用户UID
  74 + * @param string $nickName 用户昵称
  75 + * @param string $birthday 用户生日
  76 + * @param int $gender 用户性别
  77 + * @return mixed 抽签的结果
  78 + */
  79 + public static function getYuanxiaoInfo($uid, $nickName, $birthday, $gender)
  80 + {
  81 + $param = Yohobuy::param();
  82 + $param['method'] = 'wap.activity.draw';
  83 + $param['uid'] = $uid;
  84 + $param['nick_name'] = $nickName;
  85 + $param['birthday'] = $birthday;
  86 + $param['gender'] = $gender;
  87 + $param['client_secret'] = Sign::getSign($param);
  88 +
  89 + return Yohobuy::get(Yohobuy::API_URL, $param);
  90 + }
  91 +
  92 + /**
72 * 发送站内信 93 * 发送站内信
73 - *  
74 - * @param int $activityId 活动ID 94 + *
  95 + * @param int $uid
  96 + * @param string $title
  97 + * @param int $content
  98 + * @param int $type
  99 + * @param string $verify_key
  100 + * @param int $send_uid
  101 + * @param string $call_back
75 * @return array 102 * @return array
76 */ 103 */
77 public static function message($uid, $title, $content, $type = 1, $verify_key = '', $send_uid = 0, $call_back = '') 104 public static function message($uid, $title, $content, $type = 1, $verify_key = '', $send_uid = 0, $call_back = '')
@@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
28 <span class="check {{#if gender}}checked{{/if}}" data-gender="{{#if gender}}1{{/if}}"></span> 28 <span class="check {{#if gender}}checked{{/if}}" data-gender="{{#if gender}}1{{/if}}"></span>
29 </div> 29 </div>
30 <div class="icon girl"> 30 <div class="icon girl">
31 - <span class="check {{#unless gender}}checked{{/if}}" data-gender="{{#if gender}}0{{/if}}"></span> 31 + <span class="check {{#unless gender}}checked{{/if}}" data-gender="{{#if gender}}2{{/if}}"></span>
32 </div> 32 </div>
33 <input type="hidden" name="gender" id="gender" value="{{gender}}"> 33 <input type="hidden" name="gender" id="gender" value="{{gender}}">
34 </div> 34 </div>
1 <?php 1 <?php
2 2
3 namespace Cuxiao; 3 namespace Cuxiao;
  4 +use LibModels\Wap\Cuxiao\ActivityData;
4 use LibModels\Wap\Home\UserData; 5 use LibModels\Wap\Home\UserData;
5 6
6 /** 7 /**
@@ -25,7 +26,7 @@ class YuanxiaoModel @@ -25,7 +26,7 @@ class YuanxiaoModel
25 { 26 {
26 $result = array( 27 $result = array(
27 'birthday' => '2000-01-01', 28 'birthday' => '2000-01-01',
28 - 'gender' => 0 29 + 'gender' => 2
29 ); 30 );
30 31
31 // 调用接口获取个人详情 32 // 调用接口获取个人详情
@@ -39,4 +40,44 @@ class YuanxiaoModel @@ -39,4 +40,44 @@ class YuanxiaoModel
39 40
40 return $result; 41 return $result;
41 } 42 }
  43 +
  44 + /**
  45 + * @param int $uid 用户UID
  46 + * @param sring $nickName 用户昵称
  47 + * @param string $birthday 用户生日
  48 + * @param int $gender 用户性别
  49 + * @return array 处理之后抽签的结果
  50 + */
  51 + public static function getChouqianInfo($uid, $nickName, $birthday, $gender)
  52 + {
  53 + $result = array('code' => 400, 'message' => '出错啦~');
  54 +
  55 + do {
  56 + if (empty($uid)) {
  57 + break;
  58 + }
  59 +
  60 + if (empty($nickName)) {
  61 + $result['message'] = '昵称不能为空';
  62 + break;
  63 + }
  64 +
  65 + if (empty($birthday)) {
  66 + $result['message'] = '生日不能为空';
  67 + break;
  68 + }
  69 +
  70 + if (empty($gender)) {
  71 + $result['message'] = '性别不能为空';
  72 + break;
  73 + }
  74 +
  75 + $chouqian = ActivityData::getYuanxiaoInfo($uid, $nickName, $birthday, $gender);
  76 + if ($chouqian) {
  77 + $result = $chouqian;
  78 + }
  79 + } while (false);
  80 +
  81 + return $result;
  82 + }
42 } 83 }
@@ -11,7 +11,7 @@ use LibModels\Wap\Cuxiao\ActivityData; @@ -11,7 +11,7 @@ use LibModels\Wap\Cuxiao\ActivityData;
11 class ChristmasController extends HuodongAction 11 class ChristmasController extends HuodongAction
12 { 12 {
13 13
14 - private $_isApp = false; 14 +// private $_isApp = false;
15 15
16 /** 16 /**
17 * 备注:2015年12月11号上线 17 * 备注:2015年12月11号上线
@@ -52,20 +52,15 @@ class YuanxiaoController extends HuodongAction @@ -52,20 +52,15 @@ class YuanxiaoController extends HuodongAction
52 // 审判跳转登录页 52 // 审判跳转登录页
53 $this->auditJumpLogin(); 53 $this->auditJumpLogin();
54 54
  55 + $uid = $this->getUid();
55 // POST提交请求 56 // POST提交请求
56 if (!empty($this->post())) { 57 if (!empty($this->post())) {
  58 + $nickName = $this->post('nick', '');
57 $birthday = $this->post('birthday', ''); 59 $birthday = $this->post('birthday', '');
58 $gender = $this->post('gender', 0); 60 $gender = $this->post('gender', 0);
59 61
60 // 调用接口 62 // 调用接口
61 - $result = array(  
62 - 'code' => 200,  
63 - 'data' => array(  
64 - 'name' => '李四',  
65 - 'type' => 'P1',  
66 - 'count' => 8888  
67 - )  
68 - ); 63 + $result = YuanxiaoModel::getChouqianInfo($uid, $nickName, $birthday, $gender);
69 if ($result['code'] === 200) { // 处理成功就跳转到等待页 64 if ($result['code'] === 200) { // 处理成功就跳转到等待页
70 // 将返回的结果存入cookeie中15分钟 65 // 将返回的结果存入cookeie中15分钟
71 $this->setCookie('yuanxiaochouqian', json_encode($result['data']), time() + 15*60); 66 $this->setCookie('yuanxiaochouqian', json_encode($result['data']), time() + 15*60);
@@ -83,7 +78,6 @@ class YuanxiaoController extends HuodongAction @@ -83,7 +78,6 @@ class YuanxiaoController extends HuodongAction
83 )); 78 ));
84 } 79 }
85 } else { 80 } else {
86 - $uid = $this->getUid();  
87 $userData = YuanxiaoModel::getUserProfileData($uid); 81 $userData = YuanxiaoModel::getUserProfileData($uid);
88 82
89 $this->_view->display('info', array( 83 $this->_view->display('info', array(