Goods_set.php 3.9 KB

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