diff --git a/admin/controllers/Common.php b/admin/controllers/Common.php index 5e92df04..0257656d 100644 --- a/admin/controllers/Common.php +++ b/admin/controllers/Common.php @@ -178,7 +178,7 @@ class Common extends CI_Controller $this->load->model("sys/sys_tag_model"); $rows = $this->sys_tag_model->select($where); - if($rows){ + if ($rows) { foreach ($rows as $v) { $v['tag_id'] = $v['id']; $v['tag_name'] = $v['tag_name']; @@ -1177,7 +1177,8 @@ class Common extends CI_Controller * 导入excel表格生成数组 * @return bool */ - public function excel2arr(){ + public function excel2arr() + { require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php'; $key = $this->input->get('key'); @@ -1201,7 +1202,7 @@ class Common extends CI_Controller $arr = array(); for ($i = 1; $i <= $rowCnt; $i++) { //读取内容 $row = array(); - for($j='A'; $j < $col_max; $j++){ + for ($j = 'A'; $j < $col_max; $j++) { $row[] = $objWorksheet->getCell($j . $i)->getValue(); } $arr[] = $row; @@ -1271,11 +1272,11 @@ class Common extends CI_Controller $where = []; $status && $where['lc_auto_series.status'] = $status; $title && $where['lc_auto_series.name like "%' . $title . '%"'] = null; - $count = $this->auto_series_model->select_brand($where,'','','','',1); + $count = $this->auto_series_model->select_brand($where, '', '', '', '', 1); $itemsList = []; if ($count) { $lists = $this->auto_series_model->select_brand($where, 'lc_auto_series.id desc', $page, $size); - foreach($lists as $key=>$val){ + foreach ($lists as $key => $val) { $itemsList[] = [ 'id' => $val['id'], 'name' => $val['name'], @@ -1289,4 +1290,37 @@ class Common extends CI_Controller $this->data['itemsPage'] = array('page' => $page, 'pageLimit' => $size, 'pageCount' => $count, 'hasNext' => $hasNext); return $this->show_json(SYS_CODE_SUCCESS); } + + /** + * Notes:车型库 + * Created on: 2021/7/19 10:18 + * Created by: dengbw + * @return bool + */ + public function auto() + { + $type = intval($this->input->get('type'));//1品牌2车系3型号 + $pid = intval($this->input->get('pid')); + $name = $this->input->get('name'); + $tp = intval($this->input->get('tp'));//0搜索使用,1修改使用 + $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); + $this->load->model('auto/auto_series_model', 'mdAutoSeries'); + $this->load->model('auto/auto_attr_model', 'mdAutoAttr'); + $res = $lists = array(); + if ($type == 1) { + $tp == 0 && $lists[] = array('id' => 0, 'name' => $name ? $name : '选择品牌'); + $res = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); + } else if ($type == 2) { + $tp == 0 && $lists[] = array('id' => 0, 'name' => $name ? $name : '选择车系'); + $res = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $pid), 'id desc', 0, 0, 'id,name'); + } else if ($type == 3) { + $tp == 0 && $lists[] = array('id' => 0, 'name' => $name ? $name : '选择车型'); + $res = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $pid), 'id desc', 0, 0, 'id,title as name'); + } + foreach ($res as $key => $value) { + $lists[] = array('id' => $value['id'], 'name' => $value['name']); + } + $this->data = $lists; + return $this->show_json(SYS_CODE_SUCCESS); + } } diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php new file mode 100644 index 00000000..b0c72008 --- /dev/null +++ b/admin/controllers/items/goods/Goods.php @@ -0,0 +1,314 @@ + '无', 1 => '是'); + private $statusAry = array(0 => '下架', 1 => '正常', 2 => '已售'); + + public function __construct() + { + parent::__construct(); + $this->load->model('items/items_model', 'mdItems'); + $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); + $this->load->model('auto/auto_series_model', 'mdAutoSeries'); + $this->load->model('auto/auto_attr_model', 'mdAutoAttr'); + } + + public function index() + { + $this->lists(); + } + + public function lists() + { + $params = $this->input->get(); + $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; + $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; + $where = $autoList = array(); + if ($params['brand_id']) { + $where['brand_id'] = $params['brand_id']; + $autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $params['brand_id']), 'id desc', 0, 0, 'id,name'); + } + if ($params['s_id']) { + $where['s_id'] = $params['s_id']; + $autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $params['s_id']), 'id desc', 0, 0, 'id,title as name'); + } + if ($params['v_id']) { + $where['v_id'] = $params['v_id']; + } + $autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); + $count = $this->mdItems->count($where); + $lists = array(); + if ($count) { + $fileds = 'id,brand_id,s_id,ori_price,sale_price,bill_price,c_time,if_pack,discount,buy_price,address,status + ,v_id,cor_id,incor_id'; + $rows = $this->mdItems->select($where, 'id desc', $page, $size, $fileds); + $brand_id_arr = array_unique(array_column($rows, 'brand_id')); + $brands_rows = $this->mdAutoBrand->get_map_by_ids($brand_id_arr, 'id,name'); + $series_id_arr = array_unique(array_column($rows, 's_id')); + $series_rows = $this->mdAutoSeries->get_map_by_ids($series_id_arr, 'id,name'); + $attr_vid_arr = array_unique(array_column($rows, 'v_id')); + $attr_vid_rows = $this->mdAutoAttr->get_map_by_ids($attr_vid_arr, 'id,title'); + $attr_corid_arr = array_unique(array_column($rows, 'cor_id')); + $attr_corid_rows = $this->mdAutoAttr->get_map_by_ids($attr_corid_arr, 'id,title'); + $attr_incorid_arr = array_unique(array_column($rows, 'incor_id')); + $attr_incorid_rows = $this->mdAutoAttr->get_map_by_ids($attr_incorid_arr, 'id,title'); + foreach ($rows as $key => $val) { + $setVal = array(); + $setVal['id'] = $val['id']; + $setVal['brand_name'] = isset($brands_rows[$val['brand_id']]) ? $brands_rows[$val['brand_id']][0]['name'] : ''; + $setVal['s_name'] = isset($series_rows[$val['s_id']]) ? $series_rows[$val['s_id']][0]['name'] : ''; + $setVal['v_name'] = isset($attr_vid_rows[$val['v_id']]) ? $attr_vid_rows[$val['v_id']][0]['title'] : ''; + $setVal['cor_name'] = isset($attr_corid_rows[$val['cor_id']]) ? $attr_corid_rows[$val['cor_id']][0]['title'] : ''; + $setVal['incor_name'] = isset($attr_incorid_rows[$val['incor_id']]) ? $attr_incorid_rows[$val['incor_id']][0]['title'] : ''; + $setVal['if_pack_name'] = $this->packAry[$val['if_pack']]; + $setVal['ori_price'] = $val['ori_price']; + $setVal['discount'] = $val['discount'] ? $val['discount'] . '%' : '100%'; + $setVal['buy_price'] = $val['buy_price']; + $setVal['status_name'] = $this->statusAry[$val['status']]; + $setVal['address'] = $val['address'] ? '收货地址:' . $val['address'] : ''; + $lists[] = $setVal; + } + } + $this->data['lists'] = $lists; + $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); + $this->data['params'] = $params; + $this->data['autoList'] = $autoList; + $this->data['_title'] = '商品管理'; + return $this->show_view('/items/goods/lists', true); + } + + public function get() + { + $autoList = array(); + $id = intval($this->input->get('id')); + $info['brand_id'] = $info['s_id'] = $info['v_id'] = 0; + if ($id > 0) { + $re = $this->mdItems->get(array('id' => $id)); + if (!$re || empty($re)) { + return $this->show_json(SYS_CODE_FAIL, '商品不存在!'); + } + $info = $re; + if ($re['brand_id']) { + $autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $re['brand_id']), 'id desc', 0, 0, 'id,name'); + } + if ($re['s_id']) { + $autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name'); + $autoList[4] = $this->mdAutoAttr->select(array('type' => 0, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name'); + $autoList[5] = $this->mdAutoAttr->select(array('type' => 2, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name'); + } + $_title = '编辑商品'; + $edit_url = '/items/goods/goods/edit'; + } else { + $_title = '新增商品'; + $edit_url = '/items/goods/goods/add'; + } + $autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); + $showInfo['autoList'] = $autoList; + $showInfo['packAry'] = $this->packAry; + $showInfo['statusAry'] = $this->statusAry; + $this->data['info'] = $info; + $this->data['showInfo'] = $showInfo; + $this->data['edit_url'] = $edit_url; + $this->data['_title'] = $_title; + return $this->show_view('/items/goods/edit', true); + } + + public function get_info() + { + $id = intval($this->input->get('id')); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '非法参数!'); + } + $re = $this->mdItems->get(array('id' => $id)); + if (!$re || empty($re)) { + return $this->show_json(SYS_CODE_FAIL, '商品不存在!'); + } + $info = $re; + $re_b = $this->mdAutoBrand->get(array('id' => $re['brand_id']), 'name'); + $re_s = $this->mdAutoSeries->get(array('id' => $re['s_id']), 'name'); + $re_v = $this->mdAutoAttr->get(array('id' => $re['v_id']), 'title'); + $re_cor = $this->mdAutoAttr->get(array('id' => $re['cor_id']), 'title'); + $re_incor = $this->mdAutoAttr->get(array('id' => $re['incor_id']), 'title'); + $info['brand_name'] = $re_b ? $re_b['name'] : ''; + $info['s_name'] = $re_s ? $re_s['name'] : ''; + $info['v_name'] = $re_v ? $re_v['title'] : ''; + $info['cor_name'] = $re_cor ? $re_cor['title'] : ''; + $info['incor_name'] = $re_incor ? $re_incor['title'] : ''; + $info['if_pack_name'] = $this->packAry[$re['if_pack']]; + $info['status_name'] = $this->statusAry[$re['status']]; + $info['ori_price'] = $re['ori_price'] . '元'; + $info['dis_price'] = $re['dis_price'] . '元'; + $info['bill_price'] = $re['bill_price'] . '元'; + $info['buy_price'] = $re['buy_price'] . '元'; + $info['discount'] = $re['discount'] ? $re['discount'] . '%' : '100%'; + $info['pro_time'] = $re['pro_time'] != '0000-00-00 00:00:00' ? $re['pro_time'] : ''; + $info['p_time'] = $re['p_time'] != '0000-00-00 00:00:00' ? $re['p_time'] : ''; + $info['out_time'] = $re['out_time'] != '0000-00-00 00:00:00' ? $re['out_time'] : ''; + $info['bill_time'] = $re['bill_time'] != '0000-00-00 00:00:00' ? $re['bill_time'] : ''; + $this->data['info'] = $info; + return $this->show_view('/items/goods/get_info'); + } + + private function checkInfo($info) + { + $msg = ''; + $code = SYS_CODE_FAIL; + if (!$info) { + $msg = '非法参数'; + } else if (!$info['brand_id']) { + $msg = '请选择品牌'; + } else if (!$info['s_id']) { + $msg = '请选择车系'; + } else { + $code = SYS_CODE_SUCCESS; + } + return array('code' => $code, 'msg' => $msg); + } + + //添加单条数据 + public function add() + { + } + + //编辑单条数据 + public function edit() + { + $info = $this->input->post('info'); + $checkInfo = $this->checkInfo($info); + if (!$checkInfo['code']) { + return $this->show_json($checkInfo['code'], $checkInfo['msg']); + } + $editData['brand_id'] = $info['brand_id']; + $editData['s_id'] = $info['s_id']; + $editData['v_id'] = $info['v_id']; + $editData['cor_id'] = $info['cor_id']; + $editData['incor_id'] = $info['incor_id']; + $editData['if_pack'] = $info['if_pack']; + $editData['status'] = $info['status']; + + $editData['address'] = $info['address']; + $editData['vin'] = $info['vin']; + $editData['stdard_num'] = $info['stdard_num']; + $editData['engine_num'] = $info['engine_num']; + $editData['frame_num'] = $info['frame_num']; + $editData['ori_price'] = $info['ori_price']; + $editData['discount'] = $info['discount']; + $editData['dis_price'] = $info['dis_price']; + $editData['bill_num'] = $info['bill_num']; + $editData['bill_price'] = $info['bill_price']; + $editData['buy_price'] = $info['buy_price']; + + $editData['pro_time'] = $info['pro_time']; + $editData['p_time'] = $info['p_time']; + $editData['out_time'] = $info['out_time']; + $editData['bill_time'] = $info['bill_time']; + $this->mdItems->update($editData, array('id' => $info['id'])); + $this->data['status'] = 2; + return $this->show_json(SYS_CODE_SUCCESS, '修改成功!'); + } + + //删除单条数据 + public function del() + { + + } + + //批量操作(默认修改状态) + public function batch() + { + + } + + //导出数据列表 + public function export() + { + + } + + public function edit_excel() + { + require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php'; + $res = $this->upload(); + if (!$res['code']) { + return $this->show_json(0, $res['message']); + } + $file = $res['path']; + if ($res['file_ext'] == '.xls') { + $reader = \PHPExcel_IOFactory::createReader('Excel5'); // 读取 excel 文档 + } elseif ($res['file_ext'] == '.xlsx') { + $reader = \PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档 + } + $PHPExcel = $reader->load($file); // 文档名称 + $objWorksheet = $PHPExcel->getActiveSheet(); + $rowCnt = $objWorksheet->getHighestRow(); //获取总行数 + if ($rowCnt > 10000) { + @unlink($file); + return $this->show_json(0, '数据大于一万请拆分多个表格导入'); + } + $j = 0; + for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容 + $vin = $objWorksheet->getCell('F' . $_row)->getValue(); //vin码 + if ($vin) { + $re_i = $this->mdItems->get(array('vin' => $vin)); + if (!$re_i) { + $brand_id = $objWorksheet->getCell('A' . $_row)->getValue(); //品牌id + $s_id = $objWorksheet->getCell('B' . $_row)->getValue(); //车系id + $v_id = $objWorksheet->getCell('C' . $_row)->getValue(); //车型id + $cor_id = $objWorksheet->getCell('D' . $_row)->getValue(); //车身颜色id + $incor_id = $objWorksheet->getCell('E' . $_row)->getValue(); //内饰颜色id + $stdard_num = $objWorksheet->getCell('G' . $_row)->getValue(); //合格证号 + $frame_num = $objWorksheet->getCell('H' . $_row)->getValue(); //车架号 + $pro_time = $objWorksheet->getCell('I' . $_row)->getValue(); //生产时间 + $ori_price = $objWorksheet->getCell('J' . $_row)->getValue(); //指导价 + $re_b = $this->mdAutoBrand->get(array('name' => $brand_id)); + $brand_id = $re_b ? $re_b['id'] : 0; + $re_s = $this->mdAutoSeries->get(array('brand_id' => $brand_id, 'name' => $s_id)); + $s_id = $re_s ? $re_s['id'] : 0; + $re_a1 = $this->mdAutoAttr->get(array('s_id' => $s_id, 'type' => 1, 'title' => $v_id)); + $v_id = $re_a1 ? $re_a1['id'] : 0; + $re_a0 = $this->mdAutoAttr->get(array('s_id' => $s_id, 'type' => 0, 'title' => $cor_id)); + $cor_id = $re_a0 ? $re_a0['id'] : 0; + $re_a2 = $this->mdAutoAttr->get(array('s_id' => $s_id, 'type' => 2, 'title' => $incor_id)); + $incor_id = $re_a2 ? $re_a2['id'] : 0; + $addData = array('brand_id' => $brand_id, 's_id' => $s_id, 'v_id' => $v_id, 'cor_id' => $cor_id, 'incor_id' => $incor_id + , 'ori_price' => $ori_price, 'vin' => $vin, 'frame_num' => $frame_num, 'stdard_num' => $stdard_num, 'pro_time' => $pro_time, 'c_time' => time()); + $id = $this->mdItems->add($addData); + if ($id) { + $j++; + } + } + } + } + @unlink($file); + return $this->show_json(SYS_CODE_SUCCESS, '导入完成,导入总条数为:' . $j); + } + + /** + * Notes:上传excel + * Created on: 2021/7/14 15:06 + * Created by: dengbw + * @return array + */ + private function upload() + { + $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/'; + $config['allowed_types'] = '*';//xls|xlsx + $config['max_size'] = 2 * 1024; + $config['file_name'] = 'items_' . time() . rand(1, 99999); + $this->load->library('upload', $config); + if (!$this->upload->do_upload('file')) { + return array('code' => SYS_CODE_FAIL, 'message' => $this->upload->display_errors('', '')); + } else { + $data = $this->upload->data(); + return array('code' => SYS_CODE_SUCCESS, 'path' => $data['full_path'], 'file_ext' => $data['file_ext']); + } + } + +} diff --git a/admin/views/items/goods/edit.php b/admin/views/items/goods/edit.php new file mode 100644 index 00000000..b215c939 --- /dev/null +++ b/admin/views/items/goods/edit.php @@ -0,0 +1,384 @@ +
+
+
+
+ + 车辆信息 + +
+
+ + + + + + + + + + + + + + + +
+
+
品牌
+ +
+
+
+
车系
+ +
+
+
+
车型
+ +
+
+
+
选包装
+ +
+
+
+
车身色
+ +
+
+
+
内饰色
+ +
+
+
+
车辆状态
+ +
+
+
+
送货地址
+ +
+
+ + + + + + + + + +
+
+
VIN码
+ +
+
+
+
合格证号
+ +
+
+
+
发动机号
+ +
+
+
+
车架号
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
+
+
生产日期
+ +
+
+
+
分配日期
+ +
+
+
+
出库日期
+ +
+
+
+
指导价
+ +
+
+
+
折扣%
+ +
+
+
+
折扣金额
+ +
+
+
+
开票日期
+ +
+
+
+
发票号
+ +
+
+
+
发票金额
+ +
+
+
+
采购成本
+ +
+
+
+ 保存 +
+
+
+
+
+ + \ No newline at end of file diff --git a/admin/views/items/goods/get_info.php b/admin/views/items/goods/get_info.php new file mode 100644 index 00000000..e07ffaa0 --- /dev/null +++ b/admin/views/items/goods/get_info.php @@ -0,0 +1,111 @@ +
+
+
+
+ + 车辆信息 + +
+
+ + + + + + + + + + + + + + + +
+ 品牌: + + 车系: + + 车型: +
+ 选包装: + + 车身色: + + 内饰色: +
+ 车辆状态: + + 送货地址: +
+ + + + + + + + + +
+ VIN码: + + 合格证号: +
+ 发动机号: + + 车架号: +
+ + + + + + + + + + + + + + + + + + + +
+ 生产日期: + + 分配日期: + + 出库日期: +
+ 指导价: + + 折扣%: + + 折扣金额: +
+ 开票日期: + + 发票号: + + 发票金额: +
+ 采购成本: +
+
+
+
+
+ \ No newline at end of file diff --git a/admin/views/items/goods/lists.php b/admin/views/items/goods/lists.php new file mode 100644 index 00000000..0c19b995 --- /dev/null +++ b/admin/views/items/goods/lists.php @@ -0,0 +1,178 @@ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
商品ID品牌车系车型车身颜色内饰颜色选装包市场指导价折扣%采购成本采购状态
+
+
+ +
+
+ 查看 + 编辑 +
+
+
+
+
+ +
+
+
+ \ No newline at end of file diff --git a/common/models/auto/Auto_attr_model.php b/common/models/auto/Auto_attr_model.php index d614b4de..ceb9ce7a 100644 --- a/common/models/auto/Auto_attr_model.php +++ b/common/models/auto/Auto_attr_model.php @@ -13,4 +13,25 @@ class Auto_attr_model extends HD_Model{ { parent::__construct($this->table_name, 'default'); } + + /** + * Notes:根据id获取数据 + * Created on: 2021/7/15 17:27 + * Created by: dengbw + * @param $ids + * @param string $fileds + * @return array + */ + public function get_map_by_ids($ids, $fileds = '') + { + $rows = []; + if ($ids) { + $cf_ids = implode(',', $ids); + $where = [ + "id in ($cf_ids)" => null + ]; + $rows = $this->map('id', '', $where, '', '', '', $fileds); + } + return $rows; + } } diff --git a/common/models/auto/Auto_brand_model.php b/common/models/auto/Auto_brand_model.php index 281c3be2..37a2a302 100644 --- a/common/models/auto/Auto_brand_model.php +++ b/common/models/auto/Auto_brand_model.php @@ -1,16 +1,39 @@ table_name, 'default'); } + + /** + * Notes:根据id获取数据 + * Created on: 2021/7/15 17:27 + * Created by: dengbw + * @param $ids + * @param string $fileds + * @return array + */ + public function get_map_by_ids($ids, $fileds = '') + { + $rows = []; + if ($ids) { + $cf_ids = implode(',', $ids); + $where = [ + "id in ($cf_ids)" => null + ]; + $rows = $this->map('id', '', $where, '', '', '', $fileds); + } + return $rows; + } } diff --git a/common/models/auto/Auto_series_model.php b/common/models/auto/Auto_series_model.php index 0990995e..97b27cc0 100644 --- a/common/models/auto/Auto_series_model.php +++ b/common/models/auto/Auto_series_model.php @@ -14,6 +14,27 @@ class Auto_series_model extends HD_Model{ parent::__construct($this->table_name, 'default'); } + /** + * Notes:根据id获取数据 + * Created on: 2021/7/15 17:27 + * Created by: dengbw + * @param $ids + * @param string $fileds + * @return array + */ + public function get_map_by_ids($ids, $fileds = '') + { + $rows = []; + if ($ids) { + $cf_ids = implode(',', $ids); + $where = [ + "id in ($cf_ids)" => null + ]; + $rows = $this->map('id', '', $where, '', '', '', $fileds); + } + return $rows; + } + //获取车系品牌 public function select_brand($where=[],$order,$page,$size,$fileds='',$count=''){ diff --git a/common/models/items/Items_model.php b/common/models/items/Items_model.php new file mode 100644 index 00000000..154792f5 --- /dev/null +++ b/common/models/items/Items_model.php @@ -0,0 +1,17 @@ +table_name, 'default'); + } +}