From 0e0365639763036b2d4ac12bd449ce582da3edea Mon Sep 17 00:00:00 2001 From: lccsw <1127794702@qq.com> Date: Fri, 6 Aug 2021 10:06:53 +0800 Subject: [PATCH] add-admin-auto --- admin/controllers/auto/Attr.php | 140 +++++++++++++++++++++++++ admin/controllers/auto/Series.php | 15 +-- admin/views/auto/attr/edit.php | 112 ++++++++++++++++++++ admin/views/auto/attr/lists.php | 59 +++++++++++ admin/views/auto/series/edit.php | 28 ++--- admin/views/auto/series/lists.php | 10 +- api/controllers/wxapp/app/Payment.php | 5 +- common/models/auto/Auto_attr_model.php | 10 ++ sql/auto.sql | 1 + 9 files changed, 350 insertions(+), 30 deletions(-) create mode 100644 admin/controllers/auto/Attr.php create mode 100755 admin/views/auto/attr/edit.php create mode 100755 admin/views/auto/attr/lists.php diff --git a/admin/controllers/auto/Attr.php b/admin/controllers/auto/Attr.php new file mode 100644 index 00000000..6c5da5d2 --- /dev/null +++ b/admin/controllers/auto/Attr.php @@ -0,0 +1,140 @@ +load->model('auto/auto_brand_model'); + $this->load->model('auto/auto_series_model'); + $this->load->model('auto/auto_attr_model'); + } + + public function index(){ + $this->lists(); + } + + public function lists(){ + $params = $this->input->get(); + $page = $this->input->get('page'); + !$page && $page = 1; + $size = 20; + $where["status > -1"] = null; + $params['title'] && $where["title like '%{$params['title']}%'"] = null; + $count = $this->auto_attr_model->count($where); + $rows = $this->auto_attr_model->select($where, 'id desc', $page, $size); + $type_arr = $this->auto_attr_model->get_type(); + $status_arr = $this->auto_brand_model->get_status(); + $list = []; + if($rows){ + $series_arr = array_column($rows,'s_id'); + $series_rows = $this->auto_series_model->get_map_by_ids($series_arr,'id,name'); + foreach($rows as $key=>$val){ + $list[] = [ + 'id' => $val['id'], + 'title' => $val['title'], + 's_name' => $series_rows[$val['s_id']] ? $series_rows[$val['s_id']][0]['name'] : '', + 'status_name' => $status_arr[$val['status']], + 'type_cn' => $type_arr[$val['type']], + 'c_time' => date('Y-m-d H:i:s',$val['c_time']) + ]; + } + } + $this->data['lists'] = $list; + $this->data['params'] = $params; + $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); + $this->data['_title'] = '属性管理'; + $this->show_view('auto/attr/lists', true); + } + + public function get(){ + $id = $this->input->get('id'); + + $info = [ + 'title' => '' + ]; + if ($id) { + $info = $this->auto_attr_model->get(array('id' => $id)); + if (!$info || empty($info)) { + return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); + } + $info['jsondata'] = json_decode($info['jsondata'],true); + $info['jsondata']['img'] && $info['jsondata']['s_img'] = build_qiniu_image_url($info['jsondata']['img']); + } + $series = $this->auto_series_model->select([],'','','','id,name'); + $type_arr = $this->auto_attr_model->get_type(); + !$info['type'] && $info['type'] = 0; + !$info['s_id'] && $info['s_id'] = $series[0]['id']; + !$info['jsondata']['img'] && $info['jsondata']['img'] = ''; + $this->data['series'] = $series; + $this->data['type_arr'] = $type_arr; + $this->data['info'] = $info; + $this->data['_title'] = $id ? '编辑' : '新增'; + return $this->show_view('auto/attr/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'], + 's_id' => $post['s_id'], + 'type' => $post['type'], + 'c_time' => time() + ]; + $post['jsondata'] && $add_data['jsondata'] = json_encode($post['jsondata'],JSON_UNESCAPED_UNICODE); + $result = $this->auto_attr_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_attr_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'], + 's_id' => $post['s_id'], + 'type' => $post['type'], + ]; + $post['jsondata'] && $update['jsondata'] = json_encode($post['jsondata'],JSON_UNESCAPED_UNICODE); + $result = $this->auto_attr_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(){ + } + + public function batch(){ + + } + + public function export(){ + + } + +} diff --git a/admin/controllers/auto/Series.php b/admin/controllers/auto/Series.php index b1bc86f4..3ca323cb 100644 --- a/admin/controllers/auto/Series.php +++ b/admin/controllers/auto/Series.php @@ -62,7 +62,8 @@ class Series extends HD_Controller{ return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); } } - + $brands = $this->auto_brand_model->select([],'','','','id,name'); + $this->data['brands'] = $brands; $this->data['info'] = $info; $this->data['_title'] = $id ? '编辑车系' : '新增车系'; return $this->show_view('auto/series/edit'); @@ -74,7 +75,7 @@ class Series extends HD_Controller{ } $id = $this->input->post('id'); $name = $this->input->post('name'); - $img = $this->input->post('img'); + $brand_id = $this->input->post('brand_id'); if (!$name || empty($name)) { return $this->show_json(SYS_CODE_FAIL, '车系名称不能为空'); } @@ -84,7 +85,7 @@ class Series extends HD_Controller{ } $add_data = array( 'name' => $name, - 'logo' => $img, + 'brand_id' => $brand_id, 'c_time' => time() ); $brand_id = $this->auto_series_model->add($add_data); @@ -100,8 +101,8 @@ class Series extends HD_Controller{ } $id = $this->input->post('id'); $name = $this->input->post('name'); - $img = $this->input->post('img'); - $row = $this->auto_brand_model->get(['id' => $id]); + $brand_id = $this->input->post('brand_id'); + $row = $this->auto_series_model->get(['id' => $id]); if (!$row) { return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); } @@ -116,10 +117,10 @@ class Series extends HD_Controller{ return $this->show_json(SYS_CODE_FAIL, '车系已经存在'); } $up_data = array( + 'brand_id' => $brand_id, 'name' => $name, ); - $img && $up_data['logo'] = $img; - $this->auto_brand_model->update($up_data, array('id' => $id)); + $this->auto_series_model->update($up_data, array('id' => $id)); return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); } diff --git a/admin/views/auto/attr/edit.php b/admin/views/auto/attr/edit.php new file mode 100755 index 00000000..80e42f98 --- /dev/null +++ b/admin/views/auto/attr/edit.php @@ -0,0 +1,112 @@ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + + + +
+
+ +
+
+
+ diff --git a/admin/views/auto/attr/lists.php b/admin/views/auto/attr/lists.php new file mode 100755 index 00000000..056b00f5 --- /dev/null +++ b/admin/views/auto/attr/lists.php @@ -0,0 +1,59 @@ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
ID标题车系名称类型状态创建时间操作
+ +
+
+
+
+ +
+
+
+ + diff --git a/admin/views/auto/series/edit.php b/admin/views/auto/series/edit.php index f332ead2..b527152d 100755 --- a/admin/views/auto/series/edit.php +++ b/admin/views/auto/series/edit.php @@ -1,25 +1,19 @@ -
+
- -
- + +
+
-
- +
+
-
- - - - - 尺寸100x100 -
+
diff --git a/admin/views/auto/series/lists.php b/admin/views/auto/series/lists.php index 312fe674..daf2a65f 100755 --- a/admin/views/auto/series/lists.php +++ b/admin/views/auto/series/lists.php @@ -1,5 +1,5 @@
- +
@@ -11,7 +11,7 @@
- +
共有条数据 @@ -39,14 +39,14 @@ - | - 禁用 恢复 diff --git a/api/controllers/wxapp/app/Payment.php b/api/controllers/wxapp/app/Payment.php index 5a5087d0..ad601b46 100644 --- a/api/controllers/wxapp/app/Payment.php +++ b/api/controllers/wxapp/app/Payment.php @@ -32,7 +32,10 @@ class Payment extends Wxapp{ if($row['total_price']>0){ $url = http_host_com('api'); $notify_url = $url."/wxapp/{$this->app_key}/wxnotify"; - $result = $this->pay($sid, $row['total_price']=0.01, $this->session['openid'], $row['item_title'], $notify_url); + if($this->uid<=10){ + $row['total_price'] = 0.01; + } + $result = $this->pay($sid, $row['total_price'], $this->session['openid'], $row['item_title'], $notify_url); }else{ $this->load->service('apporder/payment_service', array('app_id' => $this->app_id)); $result = $this->payment_service->after_pay($sid); diff --git a/common/models/auto/Auto_attr_model.php b/common/models/auto/Auto_attr_model.php index 02d45529..a507bd11 100644 --- a/common/models/auto/Auto_attr_model.php +++ b/common/models/auto/Auto_attr_model.php @@ -8,6 +8,8 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class Auto_attr_model extends HD_Model{ private $table_name = 'lc_auto_attr'; + private $type_arr = [ 0 => '颜色', 1 => '型号', 2 => '内饰颜色']; + private $status_arr = [ '-1' => '删除',0 => '下架',1 => '正常']; public function __construct() { @@ -35,4 +37,12 @@ class Auto_attr_model extends HD_Model{ } return $rows; } + + public function get_type(){ + return $this->type_arr; + } + + public function get_status(){ + return $this->status_arr; + } } diff --git a/sql/auto.sql b/sql/auto.sql index 51dcadff..f7d24d91 100644 --- a/sql/auto.sql +++ b/sql/auto.sql @@ -46,3 +46,4 @@ create table lc_auto_attr ( c_time int(10) not null default '0' comment '创建时间', primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型属性'; +alter table lc_auto_attr add status tinyint(1) not null default 1 comment '状态(-1删除 0禁用 1正常)' after jsondata;