search(array('ids' => $yes)); } if (!$keyword) { $where['limit'] = '0,50'; $data = Dever::db($table)->search($where); } else { $where['name'] = $keyword; $data = Dever::db($table)->search($where); } $result = array(); if ($yes) { foreach ($yes as $k => $v) { if (isset($data[$k])) { unset($data[$k]); } $yes[$k]['selected'] = 'selected'; } $data = $yes + $data; $data = array_merge($data, array()); } else { $data = array_merge($data, array()); } if (!$data) { Dever::alert('暂无数据'); } return $data; } /** * 更新信息 * * @return mixed */ public function infoUpdate($id, $name, $data) { # 更新分类id $category = Dever::param('category', $data); if ($category) { if (is_array($category)) { $category_id = end($category); $top_category_id = $category[0]; if (isset($category[1])) { $second_category_id = $category[1]; } else { $second_category_id = $category[0]; } } else { $category_id = $category; $top_category_id = $category; $second_category_id = $category; } $update['top_category_id'] = $top_category_id; $update['second_category_id'] = $second_category_id; $update['category_id'] = $category_id; } $pic = Dever::param('pic', $data); $pic_cover = Dever::param('pic_cover', $data); if ($pic && !$pic_cover) { if (is_string($pic)) { $pic = explode(',', $pic); } $update['pic_cover'] = $pic[0]; } if (isset($update)) { $update['where_id'] = $id; Dever::db('goods/info')->update($update); } } /** * 更新需求属性信息 * * @return mixed */ public function attrUpdate($id, $name, $data) { print_r($data);die; foreach ($data as $k => $v) { } } /** * 显示信息 * * @return mixed */ public function info($id) { $info = Dever::db('goods/info')->one($id); if ($info) { $table['编号'] = $info['id']; $table['标题'] = $info['name']; $table['分类'] = Dever::load("category/api.string", $info['category']); if ($info['pic']) { $table['商品图'] = ''; } //$table['属性'] = $this->attrInfo($info); if ($info['cdate']) { $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']); } if ($info['udate']) { $table['更新时间'] = date("Y-m-d H:i:s", $info['udate']); } } return Dever::table($table); } private function attrInfo($info) { $table = array(); $info = Info::init($info['top_category_id']); if ($info) { $info = $info->info($info, 'id'); if ($info && isset($info['attr'])) { foreach ($info['attr'] as $k => $v) { $table[$v['name']] = $v['value_string']; } } } return Dever::table($table); } public function area($id, $name, $data) { # 不再执行syncone等后续操作 Dever::config('base')->after = 1; $type = Dever::input('type'); $area = Dever::param('area', $data); if ($area) { if (isset($area[2])) { $update['district_id'] = $area[2]; } if (isset($area[1])) { $update['city_id'] = $area[1]; } if (isset($area[0])) { $update['province_id'] = $area[0]; } if (isset($update)) { $update['where_id'] = $id; Dever::db($type . '/info')->update($update); } } } public function skuConfig() { $data['action'] = Dever::url('goods/lib/manage.skuUp'); $data['info_id'] = Dever::input('search_option_info_id'); return $data; } public function skuUp_api() { $info_id = Dever::input('info_id'); $attr = Dever::input('attr'); $key = Dever::input('key'); $price = Dever::input('price'); $s_price = Dever::input('s_price'); $f_price = Dever::input('f_price'); $num = Dever::input('num'); if ($key) { foreach ($key as $k => $v) { if (isset($price[$k]) && $price[$k]) { $info = Dever::db('goods/info_sku')->one(array('key' => $v)); $data['info_id'] = $info_id; $data['attr'] = $attr[$k]; $data['key'] = $v; $data['price'] = $price[$k]; $data['s_price'] = $s_price[$k]; $data['f_price'] = $f_price[$k]; $data['num'] = $num[$k]; if (!$info) { Dever::db('goods/info_sku')->insert($data); } else { $data['where_id'] = $info['id']; Dever::db('goods/info_sku')->update($data); } } } } Dever::out('yes'); } public function skuInput() { $id = Dever::input('search_option_info_id'); $sku = Dever::db('goods/info_sku')->getData(array('info_id' => $id)); $info = Dever::db('goods/info')->one($id); $info = Info::init(-1)->info($info, 'list_reorder'); $html = '请先选择属性'; if ($info['sell_attr']) { $head = ''; $body = ''; $option = array(); foreach ($info['sell_attr'] as $k => $v) { $head .= ''.$v['name'].''; if (isset($v['option_sku'])) { $option[$k] = $v['option_sku']; } } $head .= '销售价'; $head .= '市场价'; $head .= '进货价'; //$head .= '库存'; $head .= ''; if ($option) { $option = Dever::cartesian($option); foreach ($option as $k => $v) { $body .= ''; $key = $id = array(); foreach ($v['name'] as $k1 => $v1) { $rows = 1; $body .= ''.$v1.''; $id[] = array ( 'id' => $v['id'][$k1], 'attr_id' => $v['info_id'][$k1], ); $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1]; } $key = implode('_', $key); $f_price = $s_price = $price = $num = ''; if (isset($sku[$key])) { $f_price = $sku[$key]['f_price']; $s_price = $sku[$key]['s_price']; $price = $sku[$key]['price']; //$num = $sku[$key]['num']; } $body .= ''; $body .= ''; $body .= ''; //$body .= ''; $body .= ''; $body .= ''; } } $body .= ''; $html = $head . $body; } return $html; } /** * 显示用户信息 * * @return mixed */ public function showUserInfo($id) { $info = Dever::db('goods/card_code')->find($id); $table = array(); if ($info && $info['status'] > 1 && $info['uid'] && $info['uid'] > 0) { $user = Dever::load('passport/user-one', $info['uid']); $shop = Dever::load('shop/info-one', $info['shop_id']); if ($user) { $table['领取门店'] = $shop['name'] . '('.$shop['mobile'].')'; $table['领取人'] = $user['username'] . '('.$info['uid'].')'; $table['手机号'] = $user['mobile']; $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']); } } return Dever::table($table); } /** * 创建兑换码 * * @return mixed */ public function createCard($id, $name, $param) { $num = Dever::param('num', $param); $card_id = Dever::param('card_id', $param); if ($num > 0) { for ($i = 0; $i< $num;$i++) { $this->createCode($card_id); } } } private function createCode($card_id) { # 生成卡号和密码 $card = 'CR' . Dever::rand(14); $pwd = Dever::rand(8); $where['card'] = $card; $where['pwd'] = $pwd; $info = Dever::db('goods/card_code')->find($where); if (!$info) { $where['card_id'] = $card_id; Dever::db('goods/card_code')->insert($where); } else { $this->createCode($card_id); } } /** * 作废 * * @return mixed */ public function drop_api($id) { $update['where_id'] = $id; $update['type'] = 4; Dever::db('goods/card_code')->update($update); return 'ok'; } public function recovery_api($id) { $update['where_id'] = $id; $update['type'] = 1; Dever::db('goods/card_code')->update($update); return 'ok'; } }