From 300a4910d0cc1d4c7953a8355459b795cf45c87c Mon Sep 17 00:00:00 2001 From: lccsw <805383944@qq.com> Date: Tue, 21 Mar 2023 16:02:33 +0800 Subject: [PATCH] add-licheb-options --- admin/controllers/auto/Attr.php | 9 +- admin/controllers/auto/Options.php | 192 ++++++++++++++++++ admin/controllers/items/goods/Goods.php | 4 + admin/views/auto/attr/edit.php | 24 ++- admin/views/auto/options/edit.php | 113 +++++++++++ admin/views/auto/options/lists.php | 158 ++++++++++++++ admin/views/items/goods/edit.php | 30 ++- api/controllers/wxapp/app/Options.php | 54 +++++ api/controllers/wxapp/licheb/CusorderV2.php | 28 +++ .../libraries/receiver/Orders_v2_entity.php | 3 + common/models/auto/Auto_option_model.php | 21 ++ sql/receiver/order.sql | 2 +- 12 files changed, 634 insertions(+), 4 deletions(-) create mode 100644 admin/controllers/auto/Options.php create mode 100755 admin/views/auto/options/edit.php create mode 100755 admin/views/auto/options/lists.php create mode 100644 api/controllers/wxapp/app/Options.php create mode 100644 common/models/auto/Auto_option_model.php diff --git a/admin/controllers/auto/Attr.php b/admin/controllers/auto/Attr.php index 6589633a..a9c0d335 100644 --- a/admin/controllers/auto/Attr.php +++ b/admin/controllers/auto/Attr.php @@ -16,6 +16,7 @@ class Attr extends HD_Controller $this->load->model('auto/auto_brand_model'); $this->load->model('auto/auto_series_model'); $this->load->model('auto/auto_attr_model'); + $this->load->model('auto/auto_option_model'); } public function index() @@ -105,7 +106,8 @@ class Attr extends HD_Controller $id = $this->input->get('id'); $info = [ - 'title' => '' + 'title' => '', + 'options' => [], ]; if ($id) { $info = $this->auto_attr_model->get(array('id' => $id)); @@ -114,17 +116,20 @@ class Attr extends HD_Controller } $info['jsondata'] = json_decode($info['jsondata'], true); $info['jsondata']['img'] && $info['jsondata']['s_img'] = build_qiniu_image_url($info['jsondata']['img']); + $info['options'] = $info['jsondata']['options'] ? $info['jsondata']['options'] : []; } $brand_id = ''; if ($info['s_id']) { $row_sery = $this->auto_series_model->get(array('id' => $info['s_id'])); $brand_id = $row_sery['brand_id']; } + $options = $this->auto_option_model->select(['status'=>1],'id desc',0,0,'id,title,price'); $type_arr = $this->auto_attr_model->get_type(); !$info['type'] && $info['type'] = 0; $info['brand_id'] = $brand_id; !$info['s_id'] && $info['s_id'] = ''; !$info['jsondata']['img'] && $info['jsondata']['img'] = ''; + $this->data['options'] = $options; $this->data['type_arr'] = $type_arr; $this->data['info'] = $info; $this->data['_title'] = $id ? '编辑' : '新增'; @@ -146,6 +151,7 @@ class Attr extends HD_Controller 'type' => $post['type'], 'c_time' => time() ]; + $post['jsondata']['options'] = $post['options'] ? $post['options'] : []; $post['jsondata'] && $add_data['jsondata'] = json_encode($post['jsondata'], JSON_UNESCAPED_UNICODE); $result = $this->auto_attr_model->add($add_data); if (!$result) { @@ -172,6 +178,7 @@ class Attr extends HD_Controller 's_id' => $post['s_id'], 'type' => $post['type'], ]; + $post['jsondata']['options'] = $post['options'] ? $post['options'] : []; $post['jsondata'] && $update['jsondata'] = json_encode($post['jsondata'], JSON_UNESCAPED_UNICODE); $result = $this->auto_attr_model->update($update, ['id' => $row['id']]); if (!$result) { diff --git a/admin/controllers/auto/Options.php b/admin/controllers/auto/Options.php new file mode 100644 index 00000000..094fff81 --- /dev/null +++ b/admin/controllers/auto/Options.php @@ -0,0 +1,192 @@ +load->model('auto/auto_option_model'); + $this->load->model('auto/auto_brand_model'); + $this->load->model('auto/auto_series_model'); + } + + public function index() + { + $this->lists(); + } + + public function lists() + { + $params = $this->input->get(); + !$params['s_id'] && $params['s_id'] = ''; + !$params['brand_id'] && $params['brand_id'] = ''; + $page = $this->input->get('page'); + !$page && $page = 1; + $size = 20; + $where["status > -1"] = null; + $params['title'] && $where["title like '%{$params['title']}%'"] = null; + + //获取品牌map + $where_brand = array('status > -1' => null); + $map_brand = $this->auto_brand_model->map_brand($where_brand); + + $params['brand_id'] && $where['brand_id'] = intval($params['brand_id']); + $params['s_id'] && $where['s_id'] = intval($params['s_id']); + $count = $this->auto_option_model->count($where); + + $list = []; + if($count){ + $status_arr = $this->auto_option_model->get_status(); + $rows = $this->auto_option_model->select($where,'id desc',$page,$size); + $b_rows = $this->auto_brand_model->get_map_by_ids(array_column($rows,'brand_id')); + $s_rows = $this->auto_series_model->get_map_by_ids(array_column($rows,'s_id')); + foreach ($rows as $item) { + $b_row = $b_rows[$item['brand_id']][0]; + $s_row = $s_rows[$item['s_id']][0]; + $list[] = [ + 'id' => $item['id'], + 'brand_cn' => $b_row['name'], + 'series_cn' => $s_row['name'], + 'title' => $item['title'], + 'price' => $item['price'], + 'status_name' => $status_arr[$item['status']], + 'status' => $item['status'], + 'c_time' => date('Y-m-d H:i:s',$item['c_time']) + ]; + } + } + $this->data['lists'] = $list; + $this->data['params'] = $params; + $this->data['brandAry'] = $this->auto_brand_model->map_brand_list($map_brand); + $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); + $this->data['_title'] = '选装管理'; + $this->show_view('auto/options/lists', true); + } + + public function get() + { + $id = $this->input->get('id'); + + $info = [ + 'title' => '', + 'options' => [], + 'brand_id' => 0, + 's_id' => 0 + ]; + if ($id) { + $info = $this->auto_option_model->get(array('id' => $id)); + if (!$info) { + return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); + } + $info['brand_id'] = " {$info['brand_id']}"; + } + //获取品牌map + $where_brand = array('status > -1' => null); + $map_brand = $this->auto_brand_model->map_brand($where_brand); + $this->data['brandAry'] = $this->auto_brand_model->map_brand_list($map_brand); + $this->data['info'] = $info; + $this->data['_title'] = $id ? '编辑' : '新增'; + return $this->show_view('auto/options/edit',true); + } + + public function add() + { + if (!$this->if_ajax) { + return $this->show_json(SYS_CODE_FAIL, '提交出错!'); + } + $post = $this->input->post(); + if (!$post['title']) { + return $this->show_json(SYS_CODE_FAIL, '标题不能为空'); + } + $add_data = [ + 'title' => $post['title'], + 'price' => floatval($post['price']), + 'brand_id' => intval($post['brand_id']), + 's_id' => intval($post['s_id']), + 'descrip' => $post['descrip'], + 'c_time' => time() + ]; + $result = $this->auto_option_model->add($add_data); + if (!$result) { + return $this->show_json(SYS_CODE_FAIL, '添加失败'); + } + return $this->show_json(SYS_CODE_SUCCESS, '添加成功'); + } + + public function edit() + { + if (!$this->if_ajax) { + return $this->show_json(SYS_CODE_FAIL, '提交出错!'); + } + $post = $this->input->post(); + $row = $this->auto_option_model->get(['id' => $post['id']]); + if (!$row) { + return $this->show_json(SYS_CODE_FAIL, '数据不存在'); + } + if (!$post['title']) { + return $this->show_json(SYS_CODE_FAIL, '标题不能为空'); + } + $update = [ + 'title' => $post['title'], + 'price' => floatval($post['price']), + 'descrip' => $post['descrip'], + 'brand_id' => intval($post['brand_id']), + 's_id' => intval($post['s_id']), + ]; + $result = $this->auto_option_model->update($update, ['id' => $row['id']]); + if (!$result) { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + public function del() + { + $id = $this->input->post('id'); + if (!$id) { + $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $stauts = $this->input->post('status'); + $where = ['id' => $id]; + $this->auto_option_model->update(['status' => $stauts], $where); + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } + + public function batch() + { + + } + + public function export() + { + + } + + function json_lists() + { + $brand_id = $this->input->get('brand_id'); + $s_id = $this->input->get('s_id'); + $where = [ + 'status'=>1, + 'brand_id' => intval($brand_id) + ]; + $s_id && $where['s_id'] = $s_id; + $lists = []; + $rows = $this->auto_option_model->select($where,'','','','id,title,price'); + if($rows){ + foreach ($rows as $items) { + $lists[] = $items; + } + } + $this->data['lists'] = $lists; + $this->show_json(SYS_CODE_SUCCESS,''); + } +} diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index 7c140097..27aadcc4 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -432,6 +432,7 @@ class Goods extends HD_Controller $info['company_id'] = $info['brand_id'] = $info['s_id'] = $info['v_id'] = $info['cor_id'] = $info['incor_id'] = 0; $info['if_pack'] = $info['city_id'] = $info['county_id'] = $info['biz_id'] = $info['addr_id'] = ''; $info['status'] = 1; + $info['option_ids'] = []; $autoList[2] = $autoList[3] = $autoList[4] = $autoList[5] = array(); $comList = $this->sys_company_model->select(['status' => 1], '', '', '', 'id,short'); if ($id > 0) { @@ -440,6 +441,7 @@ class Goods extends HD_Controller return $this->show_json(SYS_CODE_FAIL, '商品不存在!'); } $info = $re; + $info['option_ids'] = $info['option_ids'] ? json_decode($info['option_ids'],true) : []; $info['pro_time'] = $re['pro_time'] != '0000-00-00 00:00:00' ? $re['pro_time'] : ''; $info['in_time'] = $re['in_time'] != '0000-00-00 00:00:00' ? $re['in_time'] : ''; $info['out_time'] = $re['out_time'] != '0000-00-00 00:00:00' ? $re['out_time'] : ''; @@ -634,6 +636,7 @@ class Goods extends HD_Controller } $addData['biz_id'] = $biz_id; $addData['addr_id'] = $addr_id; + $addData['option_ids'] = $info['option_ids'] ? json_encode($info['option_ids']) : json_encode([]); $id = $this->mdItems->add($addData); if (!$id) { return $this->show_json(SYS_CODE_FAIL, '添加失败!'); @@ -806,6 +809,7 @@ class Goods extends HD_Controller } $editData['biz_id'] = $biz_id; $editData['addr_id'] = $addr_id; + $editData['option_ids'] = $info['option_ids'] ? json_encode($info['option_ids']) : json_encode([]); $ret = $this->mdItems->update($editData, array('id' => $info['id'])); if (!$ret) { return $this->show_json(SYS_CODE_FAIL, '修改失败!'); diff --git a/admin/views/auto/attr/edit.php b/admin/views/auto/attr/edit.php index 77b67023..75614983 100755 --- a/admin/views/auto/attr/edit.php +++ b/admin/views/auto/attr/edit.php @@ -59,6 +59,16 @@ + +