123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- <?php
- namespace Goods\Lib;
- use Dever;
- class Manage
- {
- public function getByName_api()
- {
- $data = Dever::db('goods/info')->getAllByName(array
- (
- 'name' => Dever::input('term'))
- );
- if ($data) {
- return $data;
- }
- return array
- (
- 0 => array('id' => -1, 'value' => '没有找到您搜索的数据', 'label' => '没有找到您搜索的数据'),
- );
- }
- public function getByCate()
- {
- $cate = Dever::input('cate');
- $data = Dever::db('goods/info')->getAllByCate(array('top_category_id' => $cate));
- return Dever::load('manage/database')->getAjax($data);
- }
- public function search_api()
- {
- $where = array();
- $cate = Dever::input('cate');
- if ($cate) {
- $where['cate_id'] = $cate;
- }
- $price_type = Dever::input('price_type');
- if ($price_type) {
- $where['price_type'] = $price_type;
- }
- return Dever::search('goods/info', $where);
- }
- public function search_sku_api()
- {
- $where = array();
- $info_id = Dever::input('info_id');
- if ($info_id) {
- $where['info_id'] = $info_id;
- }
- $data = Dever::search('goods/info_sku', $where);
- if ($data) {
- foreach ($data as $k => $v) {
- $v['attr'] = Dever::json_decode($v['attr']);
- if ($v['attr']) {
- $v['attr'] = Dever::load('attr/api')->getInfoByJson($v['attr']);
- $v['name'] = $v['attr']['string'];
- }
- }
- }
- return $data;
- }
- /**
- * 验证是否可以上架
- *
- * @return mixed
- */
- public function statusUpdate($id, $name, $data)
- {
- $status = Dever::param('status', $data);
- if ($status == 1) {
- $id = $id['where_id'];
- $info = Dever::db('goods/info')->find($id);
- if (!$info) {
- Dever::alert('商品不存在');
- }
- if (!$info['tax']) {
- Dever::alert('商品税点未设置');
- }
- if (!$info['cover'] || !$info['pic']) {
- Dever::alert('商品图未设置');
- }
- $sku = Dever::db('goods/info_sku')->select(array('info_id' => $info['id']));
- if (!$sku) {
- Dever::alert('商品规格未设置');
- }
- foreach ($sku as $k => $v) {
- if (!$v['s_price']) {
- Dever::alert('市场价未设置');
- }
- if (!$v['f_price']) {
- Dever::alert('门店采购价未设置');
- }
- if (!$v['c_price']) {
- Dever::alert('成本价未设置');
- }
- if (!$v['price']) {
- Dever::alert('销售价未设置');
- }
- if ($v['min'] < 1) {
- Dever::alert('采购起订数未设置');
- }
- }
- }
- }
- /**
- * 更新信息
- *
- * @return mixed
- */
- public function infoUpdate($id, $name, $data)
- {
- $status = Dever::param('status', $data);
- if ($status > 0) {
- Dever::db('shop/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
- Dever::db('store/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
- Dever::db('factory/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
- Dever::db('shop/goods_sku')->updates(array('option_goods_id' => $id, 'set_status' => $status));
- Dever::db('store/goods_sku')->updates(array('option_goods_id' => $id, 'set_status' => $status));
- }
- # 更新分类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) {
- }
- }
- public function column($cate, $im = ',')
- {
- if ($cate) {
- $cate = explode(',', $cate);
- $result = array();
- foreach ($cate as $k => $v) {
- $info = Dever::db('goods/column')->one($v);
- $result[$k] = $info['name'];
- }
- $result = implode($im, $result);
- return $result;
- }
- return '';
- }
- /**
- * 显示信息
- *
- * @return mixed
- */
- public function info($id)
- {
- $info = Dever::db('goods/info')->one($id);
- if ($info) {
- $table['名称'] = $info['name'];
- $table['编号'] = $info['id'];
- $table['税点'] = $info['tax'];
- $table['栏目'] = $this->column($info['column_id']);
- //$table['标题'] = $info['name'];
- $table['分类'] = Dever::load("category/api.string", $info['category']);
- if ($info['cover']) {
- $table['商品图'] = '<img src="'.$info['cover'].'" width="150" />';
- }
- if ($info['price_type'] == 3) {
- # 获取套餐的商品
- $goods = Dever::array_decode($info['goods']);
- foreach ($goods as $k => $v) {
- $goods_info = Dever::db('goods/info')->one($v['goods_id']);
- if ($goods_info) {
- $table['套餐商品'][] = $v['num'] . '个' . $goods_info['name'];
- }
- }
- $table['套餐商品'] = implode(',', $table['套餐商品']);
- } elseif ($info['price_type'] == 4) {
- # 获取套餐的商品
- $goods = Dever::array_decode($info['goods']);
- foreach ($goods as $k => $v) {
- $goods_info = Dever::db('goods/info')->one($v['goods_id']);
- if ($goods_info) {
- $table['组合商品'][] = $v['num'] . '个' . $goods_info['name'];
- }
- }
- $table['组合商品'] = implode(',', $table['组合商品']);
- }
- $attr = $this->attrInfo($info);
- if ($attr) {
- $table['属性'] = $attr;
- }
- $table['价格'] = Dever::load('goods/lib/sku')->table($info['id'], false, false, false, false);
-
- if ($info['udate']) {
- $table['更新时间'] = date("Y-m-d H:i:s", $info['udate']);
- }
- if ($info['cdate']) {
- $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
- }
- }
- return Dever::table($table);
- }
- private function attrInfo($info)
- {
- $table = array();
- $class = Info::init($info['top_category_id']);
- if ($info) {
- $info = $class->info($info);
- if ($info && isset($info['attr'])) {
- foreach ($info['attr'] as $k => $v) {
- if ($v['value_string']) {
- $table[$v['name']] = $v['value_string'];
- }
- }
- }
- }
-
- return $table ? Dever::table($table) : false;
- }
- 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);
- }
- }
- }
- /**
- * 显示用户信息
- *
- * @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);
- $info = Dever::db('goods/card')->find($card_id);
- if ($info && $num > 0) {
- for ($i = 0; $i< $num;$i++) {
- $this->createCode($info);
- }
- }
- }
- private function createCode($info)
- {
- # 生成卡号和密码
- $card = $info['card_prefix'] . Dever::rand($info['card_len'], $info['card_type'] - 1);
- $pwd = $info['pwd_prefix'] . Dever::rand($info['pwd_len'], $info['pwd_type'] - 1);
- $where['card'] = $card;
- $where['pwd'] = $pwd;
- $state = Dever::db('goods/card_code')->find($where);
- if (!$state) {
- $where['card_id'] = $info['id'];
- if ($info['type'] == 1) {
- $info['day'] = 3650;
- }
- $where['edate'] = time() + ($info['day']*86400);
- Dever::db('goods/card_code')->insert($where);
- } else {
- $this->createCode($info);
- }
- }
- /**
- * 作废
- *
- * @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';
- }
- public function editor_api()
- {
- $data['name'] = '商品';
- $where = array();
- $name = Dever::input('search_name');
- $cate = Dever::input('search_cate');
- if ($name) {
- $where['name'] = $name;
- }
- if ($cate > 0) {
- $where['column_id'] = $cate;
- }
- $data['file'] = Dever::db('goods/info')->getPageAll($where);
- $data['cate'] = Dever::db('goods/column')->select();
- if ($data['file']) {
- foreach ($data['file'] as $k => $v) {
- $data['file'][$k]['source_name'] = $v['name'];
- $data['file'][$k]['file'] = $v['cover'];
- $data['file'][$k]['pic'] = $v['cover'];
- }
- }
- return $data;
- }
- }
|