123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
- namespace Goods\Lib;
- use Dever;
- class Manage
- {
- /**
- * 更新信息
- *
- * @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);
- }
- 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 skuInput()
- {
- $id = Dever::input('search_option_info_id');
- $info = Dever::db('goods/info')->one($id);
- $info = Info::init(-1)->info($info, 'list_reorder');
- if ($info['attr']) {
- $head = '<thead><tr>';
- $body = '<tbody>';
- foreach ($info['attr'] as $k => $v) {
- $head .= '<th>'.$v['name'].'</th>';
- }
- $head .= '<th>原价</th>';
- $head .= '<th>现价</th>';
- $head .= '<th>库存</th>';
- $head .= '</tr></thead>';
- }
- $data = array(
- array('白色','银色','玫瑰金'),
- array('64G','128G'),
- array('移动','电信','联通'),
- array('国行','港版')
- );
- //打印结果
- $result = $this->Cartesian($info['attr']);
- print_r($result);die;
- // print_r($option);die;
- $html = $head . $body;
- return $html;
- }
- function Cartesian($data){
- $len = count($data);
- // 取第一个集合数组值
- $result = $data[0]['option'];
- for ($i = 0; $i< $len-1; $i++) {
- $arr1 = $result;
- $result = [];
- // 数组第一个值和第二个值组合
- foreach ($arr1 as $res) {
- //数组第二个值...$i+1
- foreach($data[$i+1] as $k => $v){
- if(!is_array($res)) {
- $res = array($res);
- }
- if(!is_array($v)){
- $sec = array($v['option']);
- }
- $result[] = array_merge_recursive($res,$sec);
- }
- }
- }
- return $result;
- }
- }
|