123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- <?php
- namespace Goods\Lib;
- use Dever;
- class Manage
- {
- public function search_api()
- {
- $table = 'goods/info';
- $keyword = Dever::input('keyword');
- $yes = Dever::input('yes');
- $where = array();
- $cate = Dever::input('cate');
- if ($cate) {
- $where['cate_id'] = $cate;
- }
- if ($yes) {
- $yes = Dever::db($table)->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_cover']) {
- $table['封面图'] = '<img src="'.$info['pic_cover'].'" width="150" />';
- }
- if ($info['shop_id'] > 0) {
- $shop = Dever::load('goods/shop-one', $info['shop_id']);
- $table['所属店铺'] = $shop['name'];
- }
- if ($info['brand_id'] > 0) {
- $brand = Dever::load('goods/brand-one', $info['brand_id']);
- $table['所属品牌'] = $brand['name'];
- }
- //$table['属性'] = $this->attrInfo($info);
- if ($info['cdate']) {
- $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
- }
- }
- return Dever::table($table);
- }
- /**
- * 显示订单信息
- *
- * @return mixed
- */
- public function order($id)
- {
- $info = Dever::db('goods/order')->one($id);
- if ($info) {
- $table['编号'] = '<font style="color:red">' . $info['id'] . '</font>';
- $table['订单号'] = '<font style="color:blue">' . $info['order_id'] . '</font>';
- $config = Dever::db('goods/info')->config;
- $table['平台'] = $config['config_platform'][$info['platform']];
- $table['形态'] = $config['config_shape'][$info['shape']];
- if ($info['type'] == 'collection') {
- $user = Dever::load('user/lib/info')->get($info['uid'], $info['type_id']);
- } else {
- $user = Dever::load('passport/api')->info($info['uid']);
- }
-
- $table['购买人'] = $user['username'] . '('.$user['mobile'].')';
- if ($info['parent_uid']) {
- if ($info['type'] == 'collection') {
- $user = Dever::load('user/lib/info')->get($info['parent_uid'], $info['type_id']);
- } else {
- $user = Dever::load('passport/api')->info($info['parent_uid']);
- }
-
- $table['邀请人'] = $user['username'] . '('.$user['mobile'].')';
- //$table['邀请人佣金'] = $info['parent_reward'] . '元';
- }
- $table['商品名'] = $info['name'];
- if ($info['sku_id']) {
- $sku = Dever::db('goods/info_sku')->one($info['sku_id']);
- }
- if ($info['mode'] > 0) {
- $mode = $config['config_mode'];
- $mode = $mode[$info['mode']];
- $table['配送方式'] = $mode;
- if ($info['area_id']) {
- $info['address'] = Dever::load('area/api')->string($info['area_id'], '') . $info['address'];
- }
- if ($info['address'] && $info['mode'] == 1) {
- $table['配送地址'] = $info['address'];
- $table['联系人'] = $info['username'];
- $table['联系电话'] = $info['mobile'];
- $table['运费'] = $info['freight_price'];
- }
- if ($info['store_id'] && $info['mode'] == 2) {
- $store = Dever::db('goods/store')->one($info['store_id']);
- $table['自提点'] = $store['name'];
- $table['自提码'] = $info['id'];
- }
- }
- $table['单价'] = $info['cash'] . '元';
- $table['数量'] = $info['num'];
- $table['总价'] = $info['price'] . '元';
- }
- 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');
- $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['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 = '<thead><tr>';
- $body = '<tbody>';
- $option = array();
- foreach ($info['sell_attr'] as $k => $v) {
- $head .= '<th>'.$v['name'].'</th>';
- if (isset($v['option_sku'])) {
- $option[$k] = $v['option_sku'];
- }
- }
- $head .= '<th>原价</th>';
- $head .= '<th>现价</th>';
- $head .= '<th>库存</th>';
- $head .= '</tr></thead>';
- if ($option) {
- $option = Dever::cartesian($option);
- foreach ($option as $k => $v) {
- $body .= '<tr data-row="' .($k+1). '">';
- $key = $id = array();
- foreach ($v['name'] as $k1 => $v1) {
- $rows = 1;
- $body .= '<td width="50" rowspan="'.$rows.'">'.$v1.'</td>';
- $id[] = array
- (
- 'id' => $v['id'][$k1],
- 'attr_id' => $v['info_id'][$k1],
- );
- $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
- }
- $key = implode('_', $key);
- $s_price = $price = $num = '';
- if (isset($sku[$key])) {
- $s_price = $sku[$key]['s_price'];
- $price = $sku[$key]['price'];
- $num = $sku[$key]['num'];
- }
- $body .= '<td width="30"><input type="text" class="layui-input" name="s_price['.$k.']" value="'.$s_price.'"/></td>';
- $body .= '<td width="30"><input type="text" class="layui-input" name="price['.$k.']" value="'.$price.'"/></td>';
- $body .= '<td width="30"><input type="text" class="layui-input" name="num['.$k.']" value="'.$num.'"/><input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']">'.json_encode($id).'</textarea></td>';
- $body .= '</tr>';
- }
- }
- $body .= '</tbody>';
-
- $html = $head . $body;
- }
- return $html;
- }
- }
|