Manage.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace Ku\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. /**
  7. * 完成反馈,发送短信
  8. *
  9. * @return mixed
  10. */
  11. public function spider($id, $name, $data)
  12. {
  13. $link = Dever::param('link', $data);
  14. if (strpos($link, 'taobao.com')) {
  15. $type = 2;
  16. } elseif (strpos($link, 'tmall.com')) {
  17. $type = 3;
  18. } else {
  19. $type = 1;
  20. }
  21. $update['where_id'] = $id;
  22. $update['type'] = $type;
  23. Dever::db('ku/product')->update($update);
  24. # 生成产品的链接
  25. Dever::daemon('spider/handle.createProduct?id=' . $id, 'ku');
  26. //Dever::load('ku/spider/handle.createProduct?id=' . $id);
  27. }
  28. public function showType($type, $set)
  29. {
  30. if ($set == 2) {
  31. return '自有商品';
  32. } else {
  33. if ($type == 1) {
  34. return '有赞';
  35. } elseif ($type == 2) {
  36. return '淘宝';
  37. } elseif ($type == 3) {
  38. return '天猫';
  39. }
  40. }
  41. return '';
  42. }
  43. /**
  44. * 获取所有产品
  45. *
  46. * @return mixed
  47. */
  48. public function products($state = true)
  49. {
  50. $result = Dever::db('ku/cate')->state();
  51. foreach ($result as $k => $v) {
  52. $result[$k]['child'] = Dever::db('ku/product')->state(array('cate' => $v['id']));
  53. }
  54. $result['state'] = 1;
  55. return $result;
  56. }
  57. /**
  58. * 获取产品列表,用于后台联动搜索
  59. *
  60. * @return mixed
  61. */
  62. public function search_product_api()
  63. {
  64. $name = Dever::input('term');
  65. $data = array();
  66. if ($name) {
  67. $name = explode('|', $name);
  68. $search = array();
  69. foreach ($name as $k => $v) {
  70. if ($v) {
  71. $search[] = 'name like("%'.$v.'%")';
  72. }
  73. }
  74. $search = implode(' and ', $search);
  75. $sql = 'select *,name as value,name as label,cate,pic from jiazhi_ku_product where state = 1 and ' . $search;
  76. $data = Dever::db('ku/product')->fetchAll($sql);
  77. //print_r($data);die;
  78. //$data += Dever::db('ku/product')->search(array('name' => $name));
  79. }
  80. /*
  81. if ($name) {
  82. $name = explode('|', $name);
  83. foreach ($name as $k => $v) {
  84. $data += Dever::db('ku/product')->search(array('name' => $v));
  85. }
  86. }
  87. */
  88. //Dever::debug($data);
  89. if ($data) {
  90. foreach ($data as $k => $v) {
  91. if (isset($v['cate']) && $v['cate'] > 0) {
  92. $cate = Dever::db('ku/cate')->one($v['cate']);
  93. $data[$k]['category'] = $cate['name'];
  94. }
  95. if(isset($v['pic']) && $v['pic']) {
  96. //$data[$k]['label'] = $data[$k]['value'] = '<img src="'.$v['pic'].'" />' . $data[$k]['value'];
  97. }
  98. }
  99. return $data;
  100. }
  101. return array
  102. (
  103. 0 => array('id' => -1, 'value' => '没有找到您搜索的数据', 'label' => '没有找到您搜索的数据'),
  104. );
  105. }
  106. /**
  107. * 获取产品列表,用于后台联动搜索
  108. *
  109. * @return mixed
  110. */
  111. public function search_product_by_ids($id)
  112. {
  113. $data = Dever::db('ku/product')->search($id);
  114. return $data;
  115. }
  116. /**
  117. * 获取产品列表,用于后台联动搜索
  118. *
  119. * @return mixed
  120. */
  121. public function search_product_list_api()
  122. {
  123. $name = trim(Dever::input('term'));
  124. $search_cate = Dever::input('cate');
  125. $search_brand = Dever::input('brand');
  126. $data = $cate = array();
  127. $search = '';
  128. if ($name) {
  129. $name = explode('|', $name);
  130. $search = array();
  131. foreach ($name as $k => $v) {
  132. if ($v) {
  133. $search[] = 'name like("%'.$v.'%")';
  134. }
  135. }
  136. $search = ' and ' . implode(' and ', $search);
  137. }
  138. if ($search_cate && $search_cate > 0) {
  139. $search .= ' and cate =' . $search_cate;
  140. }
  141. if ($search_brand && $search_brand > 0) {
  142. $search .= ' and brand =' . $search_brand;
  143. }
  144. $sql = 'select *,name as value,name as label,cate,pic from jiazhi_ku_product where state = 1 ' . $search;
  145. $data = Dever::db('ku/product')->fetchAll($sql);
  146. if ($data) {
  147. foreach ($data as $k => $v) {
  148. if (isset($v['cate']) && $v['cate'] > 0) {
  149. if (!isset($cate[$v['cate']])) {
  150. $info = Dever::db('ku/cate')->one($v['cate']);
  151. $cate[$v['cate']] = $info;
  152. }
  153. $cate[$v['cate']]['child'][] = $v;
  154. }
  155. }
  156. return $cate;
  157. }
  158. return array();
  159. }
  160. public function search_cate_api()
  161. {
  162. $array = array
  163. (
  164. -1 => '请选择分类'
  165. );
  166. $info = Dever::db('ku/cate')->state();
  167. if($info)
  168. {
  169. $array += $info;
  170. }
  171. return $array;
  172. }
  173. public function search_brand_api()
  174. {
  175. $array = array
  176. (
  177. -1 => '请选择品牌'
  178. );
  179. $info = Dever::db('ku/brand')->state();
  180. if($info)
  181. {
  182. $array += $info;
  183. }
  184. return $array;
  185. }
  186. }