Prod.class.php
4.24 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
133
134
135
136
137
<?php
/**
* 产品控制器
*/
class Controller_Admin_Prod extends Controller_Admin_Base
{
/**
* Prod列表Index
*/
public function indexAction()
{
$limit = 20 ;
$brand_id = intval($this->_request->query('brand_id', 0));
$status = intval($this->_request->query('status', 0));
$brand = array();
$brands = array();
if(!empty($brand_id))
{
$brand = Facade_Brand::getBrandbyID($brand_id);
$total = Facade_Prod::getProdTotalByBrandId($brand_id);
$brands[$brand_id] = $brand;
}
else
{
$total = Facade_Prod::getProdTotal($status);
}
$page = new Lib_Helper_Pagination($total, $limit);
$page->setParames(array('brand_id'=> $brand_id,'status'=> $status));
$offset = $page->getOffset();
if(!empty($brand_id))
{
$info = Facade_Prod::getProdByBrandId($offset, $limit, $brand_id);
}
else
{
$info = Facade_Prod::getProd($status, $offset, $limit);
}
foreach($info as $prod)
{
if(!isset($brands[$prod['brand_id']]))
{
$brands[$prod['brand_id']] = Facade_Brand::getBrandbyID($prod['brand_id']);
}
}
$this->_view['pagination'] = $page->getPagination();
$this->_view['data'] = $info;
$this->_view['key'] = Lib_Images::genKey('fragmentimg');
$this->_view['status'] = $status;
$this->_view['brand'] = $brand;
$this->_view['brand_id'] = $brand_id;
$this->_view['brands'] = $brands;
}
/**
* 提交prod
*/
public function submitAction()
{
$id = $this->_request->query('id',0);
$pic = $this->_request->query('pic','');
$name = $this->_request->query('name','');
$url = $this->_request->query('url','');
$text = $this->_request->query('text','');
$create_time = strtotime($this->_request->query('create_time', 0));
$brand_id = $this->_request->query('brand_id',0);
$price = $this->_request->query('price', 0);
$sort = $this->_request->query('sort', 0);
$recom_status = $this->_request->query('recom_status', 0);
$market_price = $this->_request->query('market_price', 0);
$product_skn = $this->_request->query('product_skn', 0);
$product_id = $this->_request->query('product_id', 0);
$ret = false;
if($id)
{
$ret = Facade_Prod::updateProd($name, $brand_id, $url, $pic, $text, $sort, $create_time, $price, $recom_status, $market_price, $product_skn, $product_id, $id);
}
else
{
$ret = Facade_Prod::submitProd($name, $brand_id, $url, $pic, $text, $sort, $price, $recom_status, $market_price, $product_skn, $product_id);
}
if($ret)
{
return $this->returnJson(true,200,null);
}
else
{
return $this->returnJson(false,404,null);
}
}
/**
* 删除
*/
public function delAction()
{
$id = $this->_request->query('id',0);
$ret = Facade_Prod::delProd($id);
if($ret)
{
return $this->returnJson(true,200,null);
}
else
{
return $this->returnJson(false,404,null);
}
}
public function getprodAction()
{
$url = 'http://v5.open.yohobuy.com/?open_key=c4ca4238a0b923820dcc509a6f75849b&method=yh.product.getByUrl&product_url=';
$prodUrl = $this->_request->query('url','');
if($prodUrl)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$prodUrl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$ret = json_decode($result,true);
if($ret['code'] == 200)
{
return $this->returnJson(true,200,$ret['data']);
}
else
{
return $this->returnJson(true,404,null,'链接有问题');
}
}
else
{
return $this->returnJson(false,404,null,'获链接有问题');
}
}
}