find($id); if (!$card) { return Dever::outDiy($result); } $where['project_id'] = 1; if ($card['category']) { $where['ids'] = $card['category']; } $data = Dever::db('category/info')->getTop($where); if ($data) { $i = 0; foreach ($data as $k => $v) { $result[$i]['id'] = $v['id']; $result[$i]['name'] = $v['name']; $result[$i]['select'] = 2; $result[$i]['del'] = 1; $result[$i]['children'] = array(); $w['top_category_id'] = $v['id']; $goods = Dever::db('goods/info')->select($w); if ($goods) { foreach ($goods as $v1) { $children = array ( 'id' => $v['id'] . '-' . $v1['id'], 'name' => $v1['name'], 'class_name' => $v['name'], 'del' => 1, 'select' => 2, 'end' => true, ); $bind = Dever::db('card/info_goods')->find(array('card_id' => $id, 'goods_id' => $v1['id'])); if ($bind) { $children['select'] = 1; } $result[$i]['children'][] = $children; } $i++; } else { unset($result[$i]); } } } return Dever::outDiy($result); } # 设置商品 public function home_api() { $data = array(); $data['link'] = Dever::decode(Dever::input('refer')); $data['card_id'] = Dever::input('id', 1); Dever::setInput('card_id', $data['card_id']); $data['host'] = Dever::url('lib/goods_set.home?id=' . $data['card_id'], 'card'); $data['url'] = Dever::url('lib/goods_set.goods?json=1&card_id=' . $data['card_id'], 'card'); $data['submit'] = Dever::url('lib/goods_set.action_commit?json=1', 'card'); return Dever::render('setGoods', $data); } # 设置 public function action_commit_api() { $goods = Dever::input('goods'); if (!$goods) { Dever::alert('请传入商品'); } $goods = Dever::json_decode($goods); $card_id = Dever::input('card_id'); $where['option_card_id'] = $card_id; $where['set_state'] = 2; Dever::db('card/info_goods')->updates($where); foreach ($goods as $k => $v) { $temp = explode('-', $k); $cate_id = $temp[0]; $goods_id = $temp[1]; $w = array(); $w['cate_id'] = $cate_id; $w['goods_id'] = $goods_id; $w['card_id'] = $card_id; $info = Dever::db('card/info_goods')->one($w); if ($v['del'] == 2) { if ($info) { Dever::db('card/info_goods')->update(array('where_id' => $info['id'], 'state' => 2)); } } else { if (!$info) { Dever::db('card/info_goods')->insert($w); } else { $w['where_id'] = $info['id']; $w['state'] = 1; Dever::db('card/info_goods')->update($w); } } } $link = Dever::input('link'); if ($link) { return $link; } else { return 'reload'; } } }