123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace Ku\Lib;
- use Dever;
- class Manage
- {
- /**
- * 完成反馈,发送短信
- *
- * @return mixed
- */
- public function spider($id, $name, $data)
- {
- $link = Dever::param('link', $data);
- if (strpos($link, 'taobao.com')) {
- $type = 2;
- } elseif (strpos($link, 'tmall.com')) {
- $type = 3;
- } else {
- $type = 1;
- }
- $update['where_id'] = $id;
- $update['type'] = $type;
- Dever::db('ku/product')->update($update);
- # 生成产品的链接
- Dever::daemon('spider/handle.createProduct?id=' . $id, 'ku');
- //Dever::load('ku/spider/handle.createProduct?id=' . $id);
- }
- public function showType($type, $set)
- {
- if ($set == 2) {
- return '自有商品';
- } else {
- if ($type == 1) {
- return '有赞';
- } elseif ($type == 2) {
- return '淘宝';
- } elseif ($type == 3) {
- return '天猫';
- }
- }
- return '';
- }
- /**
- * 获取所有产品
- *
- * @return mixed
- */
- public function products($state = true)
- {
- $result = Dever::db('ku/cate')->state();
- foreach ($result as $k => $v) {
- $result[$k]['child'] = Dever::db('ku/product')->state(array('cate' => $v['id']));
- }
- $result['state'] = 1;
- return $result;
- }
- /**
- * 获取产品列表,用于后台联动搜索
- *
- * @return mixed
- */
- public function search_product_api()
- {
- $name = Dever::input('term');
-
- $data = array();
- if ($name) {
- $name = explode('|', $name);
- $search = array();
- foreach ($name as $k => $v) {
- if ($v) {
- $search[] = 'name like("%'.$v.'%")';
- }
-
- }
- $search = implode(' and ', $search);
- $sql = 'select *,name as value,name as label,cate,pic from jiazhi_ku_product where state = 1 and ' . $search;
- $data = Dever::db('ku/product')->fetchAll($sql);
- //print_r($data);die;
- //$data += Dever::db('ku/product')->search(array('name' => $name));
- }
- /*
- if ($name) {
- $name = explode('|', $name);
-
- foreach ($name as $k => $v) {
- $data += Dever::db('ku/product')->search(array('name' => $v));
- }
- }
- */
- //Dever::debug($data);
- if ($data) {
- foreach ($data as $k => $v) {
- if (isset($v['cate']) && $v['cate'] > 0) {
- $cate = Dever::db('ku/cate')->one($v['cate']);
- $data[$k]['category'] = $cate['name'];
- }
- if(isset($v['pic']) && $v['pic']) {
- //$data[$k]['label'] = $data[$k]['value'] = '<img src="'.$v['pic'].'" />' . $data[$k]['value'];
- }
- }
- return $data;
- }
- return array
- (
- 0 => array('id' => -1, 'value' => '没有找到您搜索的数据', 'label' => '没有找到您搜索的数据'),
- );
- }
- /**
- * 获取产品列表,用于后台联动搜索
- *
- * @return mixed
- */
- public function search_product_by_ids($id)
- {
- $data = Dever::db('ku/product')->search($id);
- return $data;
- }
- /**
- * 获取产品列表,用于后台联动搜索
- *
- * @return mixed
- */
- public function search_product_list_api()
- {
- $name = trim(Dever::input('term'));
- $search_cate = Dever::input('cate');
- $search_brand = Dever::input('brand');
-
- $data = $cate = array();
- $search = '';
- if ($name) {
- $name = explode('|', $name);
- $search = array();
- foreach ($name as $k => $v) {
- if ($v) {
- $search[] = 'name like("%'.$v.'%")';
- }
-
- }
- $search = ' and ' . implode(' and ', $search);
- }
- if ($search_cate && $search_cate > 0) {
- $search .= ' and cate =' . $search_cate;
- }
- if ($search_brand && $search_brand > 0) {
- $search .= ' and brand =' . $search_brand;
- }
- $sql = 'select *,name as value,name as label,cate,pic from jiazhi_ku_product where state = 1 ' . $search;
- $data = Dever::db('ku/product')->fetchAll($sql);
- if ($data) {
- foreach ($data as $k => $v) {
- if (isset($v['cate']) && $v['cate'] > 0) {
- if (!isset($cate[$v['cate']])) {
- $info = Dever::db('ku/cate')->one($v['cate']);
- $cate[$v['cate']] = $info;
- }
- $cate[$v['cate']]['child'][] = $v;
- }
- }
- return $cate;
- }
- return array();
- }
- public function search_cate_api()
- {
- $array = array
- (
- -1 => '请选择分类'
- );
- $info = Dever::db('ku/cate')->state();
- if($info)
- {
- $array += $info;
- }
- return $array;
- }
- public function search_brand_api()
- {
- $array = array
- (
- -1 => '请选择品牌'
- );
- $info = Dever::db('ku/brand')->state();
- if($info)
- {
- $array += $info;
- }
- return $array;
- }
- }
|