Goods_set.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. # 批量设置商品
  5. class Goods_set
  6. {
  7. public function __construct()
  8. {
  9. Dever::load('manage/auth.init');
  10. }
  11. # 获取商品列表
  12. public function goods_api()
  13. {
  14. $result = array();
  15. $id = Dever::input('discount_id', 1);
  16. $discount = Dever::db('act/discount')->find($id);
  17. if (!$discount) {
  18. return Dever::outDiy($result);
  19. }
  20. $where['project_id'] = 1;
  21. if ($discount['category']) {
  22. $where['ids'] = $discount['category'];
  23. }
  24. $data = Dever::db('category/info')->getTop($where);
  25. if ($data) {
  26. $i = 0;
  27. foreach ($data as $k => $v) {
  28. $result[$i]['id'] = $v['id'];
  29. $result[$i]['name'] = $v['name'];
  30. $result[$i]['select'] = 2;
  31. $result[$i]['del'] = 1;
  32. $result[$i]['children'] = array();
  33. $w['top_category_id'] = $v['id'];
  34. $goods = Dever::db('goods/info')->select($w);
  35. if ($goods) {
  36. foreach ($goods as $v1) {
  37. $children = array
  38. (
  39. 'id' => $v['id'] . '-' . $v1['id'],
  40. 'name' => $v1['name'],
  41. 'class_name' => $v['name'],
  42. 'del' => 1,
  43. 'select' => 2,
  44. 'end' => true,
  45. );
  46. $bind = Dever::db('act/discount_goods')->find(array('discount_id' => $id, 'goods_id' => $v1['id']));
  47. if ($bind) {
  48. $children['select'] = 1;
  49. }
  50. $result[$i]['children'][] = $children;
  51. }
  52. $i++;
  53. } else {
  54. unset($result[$i]);
  55. }
  56. }
  57. }
  58. return Dever::outDiy($result);
  59. }
  60. # 设置商品
  61. public function home_api()
  62. {
  63. $data = array();
  64. $data['link'] = Dever::decode(Dever::input('refer'));
  65. $data['discount_id'] = Dever::input('id', 1);
  66. Dever::setInput('discount_id', $data['discount_id']);
  67. $data['host'] = Dever::url('lib/goods_set.home?id=' . $data['discount_id'], 'act');
  68. $data['url'] = Dever::url('lib/goods_set.goods?json=1&discount_id=' . $data['discount_id'], 'act');
  69. $data['submit'] = Dever::url('lib/goods_set.action_commit?json=1', 'act');
  70. return Dever::render('setGoods', $data);
  71. }
  72. # 设置
  73. public function action_commit_api()
  74. {
  75. $goods = Dever::input('goods');
  76. if (!$goods) {
  77. Dever::alert('请传入商品');
  78. }
  79. $goods = Dever::json_decode($goods);
  80. $discount_id = Dever::input('discount_id');
  81. $where['option_discount_id'] = $discount_id;
  82. $where['set_state'] = 2;
  83. Dever::db('act/discount_goods')->updates($where);
  84. foreach ($goods as $k => $v) {
  85. $temp = explode('-', $k);
  86. $cate_id = $temp[0];
  87. $goods_id = $temp[1];
  88. $w = array();
  89. $w['cate_id'] = $cate_id;
  90. $w['goods_id'] = $goods_id;
  91. $w['discount_id'] = $discount_id;
  92. $info = Dever::db('act/discount_goods')->one($w);
  93. if ($v['del'] == 2) {
  94. if ($info) {
  95. Dever::db('act/discount_goods')->update(array('where_id' => $info['id'], 'state' => 2));
  96. }
  97. } else {
  98. if (!$info) {
  99. Dever::db('act/discount_goods')->insert($w);
  100. } else {
  101. $w['where_id'] = $info['id'];
  102. $w['state'] = 1;
  103. Dever::db('act/discount_goods')->update($w);
  104. }
  105. }
  106. }
  107. $link = Dever::input('link');
  108. if ($link) {
  109. return $link;
  110. } else {
  111. return 'reload';
  112. }
  113. }
  114. }