Currency.php
5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace Home;
use LibModels\Web\Home\CurrencyData;
use LibModels\Web\Product\SearchData;
use WebPlugin\Helpers;
use WebPlugin\HelperSearch;
/**
* 个人中心-我的咨询相关业务逻辑处理
*/
class CurrencyModel
{
public static function currencyData($uid, $condition){
$result = array();
$yohoCoinInfo = self::currencyTotal($uid);
if (isset($yohoCoinInfo['code']) && $yohoCoinInfo['code'] == 200) {
$result['myCurrency'] = isset($yohoCoinInfo['data']['yohocoin_num']) ? $yohoCoinInfo['data']['yohocoin_num'] : 0;
if (isset($yohoCoinInfo['data']['nearExpCoinNum']) && $yohoCoinInfo['data']['nearExpCoinNum'] > 0) {
$result['tip']['count'] = $yohoCoinInfo['data']['nearExpCoinNum'];
$result['tip']['date'] = date('Y年12月31日');
}
}
$currency = self::currencyList($uid, $condition);
$result['currency'] = $currency['list'];
$result['pager'] = $currency['pager'];
$result['coinHelperUrl'] = '//www.yohobuy.com/help/?category_id=87';//yoho币帮助
$result['tabs'] = self::currencyTabs($condition['queryType']);
$result['options'] = self::currencyOptions($condition);
return $result;
}
/**
* yoho币列表
* @param $uid
* @param $condition
* @return array
*/
public static function currencyList($uid, $condition)
{
$result = array('list' => array(), 'pager' => array());
if (!isset($condition['limit'])) {
$condition['limit'] = 15;
}
$data = CurrencyData::yohoCoinList($uid, $condition);
if (isset($data['code']) && $data['code'] ==200 && isset($data['data']['coinlist']) && !empty($data['data']['coinlist'])) {
foreach ($data['data']['coinlist'] as $key => $val) {
$result['list'][$key]['date'] = $val['date'];
$result['list'][$key]['desc'] = $val['message'];
$result['list'][$key]['isIncome'] = true;
//2:订单取消退还,9:下单使用,10:退货退还
if (in_array($val['type'], array(2,9,10)) && isset($val['key'])) {
$result['list'][$key]['detailUrl'] = Helpers::url('/home/orders/detail', array('orderCode'=>$val['key']));
}
//晒单奖励
elseif ($val['type'] == 14 && isset($val['key'])) {
$product = SearchData::searchAll(array('query'=>intval($val['key']),'viewNum'=>1));
if (isset($product['code']) && $product['code'] == 200 && !empty($product['data']['product_list']) && !empty($product['data']['product_list'][0]['goods_list'])) {
$productId = $product['data']['product_list'][0]['product_id'];
$goodsId = $product['data']['product_list'][0]['goods_list'][0]['goods_id'];
$result['list'][$key]['detailUrl'] = Helpers::getUrlBySkc($productId, $goodsId, $product['data']['product_list'][0]['cn_alphabet']);
}
}
if (intval($val['num']) < 0) {
$result['list'][$key]['isIncome'] = false;
}
$result['list'][$key]['value'] = $val['num'] > 0 ? '+'.$val['num'] : $val['num'] ;
}
//分页
$result['pager']['hasCheckAll'] = false;
$result['pager']['count'] = $data['data']['total'];
$result['pager']['curPage'] = $data['data']['page'];
$result['pager']['totalPages'] = ceil($data['data']['total'] / $condition['limit']);
$result['pager']['pagerHtml'] = HelperSearch::pager($data['data']['total'], $condition['limit']);
}
return $result;
}
/**
* 可用yoho币 和 即将过期的yoho币
* @param $uid
* @return int
*/
public static function currencyTotal($uid)
{
return CurrencyData::yohoCoinTotal($uid);
}
/**
* yoho币列表类型
* @param int $type
* @return array
*/
public static function currencyTabs($type = 0)
{
$result = array();
$tabs = array('全部明细', '全部收入', '全部支出');
foreach ($tabs as $key => $val) {
$urlParam['type'] = $key;
$result[$key]['active'] = $key == $type ? true : false;
$result[$key]['url'] = Helpers::url('/home/currency', $urlParam);
$result[$key]['name'] = $val;
}
return $result;
}
/**
* yoho币时间类型
* @return array
*/
public static function currencyOptions($condition)
{
$result = array();
$tabs = array('90'=>'最近3个月明细', '180'=>'最近半年明细', '360'=>'最近一年明细');
foreach ($tabs as $key => $val) {
if (isset($condition['queryType'])) {
$paramUrl['type'] = $condition['queryType'];
}
$time = date('Y-m-d', time()-$key*24*60*60);
$paramUrl['beginTime'] = $time;
$result[$key]['url'] = Helpers::url('/home/currency',$paramUrl);
$result[$key]['name'] = $val;
$result[$key]['selected'] = isset($condition['beginTime']) && $time == $condition['beginTime'] ? true : false;
}
return array_values($result);
}
}