Manage.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace Product\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function check($id,$name,$data)
  7. {
  8. //Dever::alert('reload');
  9. }
  10. /**
  11. * 更新信息
  12. *
  13. * @return mixed
  14. */
  15. public function infoUpdate($id, $name, $data)
  16. {
  17. # 更新分类id
  18. $category = Dever::param('category', $data);
  19. if ($category) {
  20. if (is_array($category)) {
  21. $category_id = end($category);
  22. $top_category_id = $category[0];
  23. if (isset($category[1])) {
  24. $second_category_id = $category[1];
  25. } else {
  26. $second_category_id = $category[0];
  27. }
  28. } else {
  29. $category_id = $category;
  30. $top_category_id = $category;
  31. $second_category_id = $category;
  32. }
  33. $update['top_category_id'] = $top_category_id;
  34. $update['second_category_id'] = $second_category_id;
  35. $update['category_id'] = $category_id;
  36. }
  37. if (isset($update)) {
  38. $update['where_id'] = $id;
  39. Dever::db('product/info')->update($update);
  40. }
  41. }
  42. public function updateCategory($id, $name, $data)
  43. {
  44. $info = Dever::param('category', $data);
  45. if ($info && $info != -1) {
  46. $update['top_category_id'] = $info[0];
  47. $num = count($info)+1;
  48. $update['level'] = $num;
  49. $parent = Dever::param('category_id', $data);
  50. $child = Dever::db('product/category')->one(array('category_id' => $id));
  51. if (!$child) {
  52. $update['level'] = -1;
  53. }
  54. Dever::db('product/category')->update(array('where_id' => $parent, 'level' => $num - 1));
  55. } else {
  56. $update['level'] = 1;
  57. $update['top_category_id'] = -1;
  58. }
  59. if (isset($update)) {
  60. $update['where_id'] = $id;
  61. Dever::db('product/category')->update($update);
  62. }
  63. }
  64. /**
  65. * 更新属性信息
  66. *
  67. * @return mixed
  68. */
  69. public function updateAttr($id, $name, $data)
  70. {
  71. return;
  72. $is_sell = Dever::param('is_sell', $data);
  73. if ($is_sell > 1) {
  74. $update['type'] = 11;
  75. }
  76. if (isset($update)) {
  77. $update['where_id'] = $id;
  78. Dever::db('product/category_attr')->update($update);
  79. }
  80. }
  81. public function searchProduct_api()
  82. {
  83. $where = array();
  84. $cate = Dever::input('cate');
  85. if ($cate) {
  86. $where['cate_id'] = $cate;
  87. }
  88. $id = Dever::input('where_id');
  89. if ($id) {
  90. $where['id_no'] = $id;
  91. }
  92. $data = Dever::search('product/info', $where);
  93. if ($data) {
  94. $old = $data;
  95. $data = array();
  96. foreach ($old as $k => $v) {
  97. Dever::load('product/lib/sku')->getList($v, $data);
  98. }
  99. }
  100. return $data;
  101. }
  102. }