add-admin-auto

This commit is contained in:
lccsw
2021-08-06 10:06:53 +08:00
parent 8a3d01b873
commit bf195e45bb
9 changed files with 350 additions and 30 deletions
+140
View File
@@ -0,0 +1,140 @@
<?php
/**
* Created by Vim
* User: lcc
* Date: 2020/08/05
* Time: 10:19
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Attr extends HD_Controller{
public function __construct(){
parent::__construct();
$this->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(){
}
}
+8 -7
View File
@@ -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, '保存成功');
}
+112
View File
@@ -0,0 +1,112 @@
<form id="vue-app" class="am-form am-form-horizontal" action="" data-auto="true" method="post" style="width: 90%;padding-top: 10px">
<div class="am-form-group">
<label class="am-para-label">标题:</label>
<div class="am-para-input">
<input type="text" placeholder="输入标题" name="title" v-model="info.title">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">车系:</label>
<div class="am-para-input w200">
<select v-model="info.s_id">
<option v-for="item in series" :value="item.id">
{{item.name}}
</option>
</select>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">类型:</label>
<div class="am-para-input w200">
<select v-model="info.type">
<option v-for="(item,index) in type_arr" :value="index">
{{item}}
</option>
</select>
</div>
</div>
<!--颜色-->
<template v-if="info.type==0">
<div class="am-form-group">
<label class="am-para-label">图片:</label>
<div class="am-para-input">
<div class="am-form-group am-form-file">
<button type="button" class="am-btn am-btn-default am-btn-sm"
data-file="1" data-type="jpg,png,gif,png,jpeg"
data-uptype="qiniu" data-field="img"><i class="am-icon-cloud-upload"></i> 选择要上传的文件
</button>
<input type="hidden" name="img" class="layui-input" value="" id="value_img">
<img data-tips-image style="height:auto;max-height:32px;max-width:32px"
:src="info.jsondata.s_img"/>
</div>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">颜色代码:</label>
<div class="am-para-input w200">
<input type="text" placeholder="输入颜色代码" name="" v-model="info.jsondata.code">
<span>(例如:#fff)</span>
</div>
</div>
</template>
<!--汽车型号-->
<template v-if="info.type==1">
<div class="am-form-group">
<label class="am-para-label">指导价:</label>
<div class="am-para-input w200">
<input type="text" placeholder="输入指导价" name="" v-model="info.jsondata.price">
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">订金:</label>
<div class="am-para-input w200">
<input type="text" placeholder="请输入订金" name="" v-model="info.jsondata.deposit">
</div>
</div>
</template>
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="am-para-input">
<button class="am-btn am-btn-secondary" type="button" @click="saveEdit()">保存</button>
</div>
</div>
</form>
<script>
$(document).ready(function () {
vue_obj = new Vue({
el: '#vue-app',
data: {
info:[],
series:[],
type_arr:[]
},
mounted: function () {
this.info = <?=json_encode($info)?>;
this.series = <?=json_encode($series)?>;
this.type_arr = <?=json_encode($type_arr)?>;
},
methods: {
saveEdit: function(){
var action = '';
if(this.info.id){
action = 'auto/attr/edit'
}else{
action = 'auto/attr/add'
}
var img = $("#value_img").val();
if(img){
this.info.jsondata.img = $("#value_img").val();
}
$.post(action,this.info,function(result){
if (result.code) {
layer.msg(result.msg, {time: 2000, icon: 1}, function () {
$.form.reload();
});
} else {
layer.msg(result.msg, {icon: 2});
}
},'json')
}
}
})
});
</script>
+59
View File
@@ -0,0 +1,59 @@
<div class="coms-table-wrap mt10">
<form class="form-search" onsubmit="return false" action="/auto/attr/lists">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w100">标题:</label>
<div class="am-para-inline w200">
<input type="text" name="title" value="<?=$params['title'] ?>"/>
</div>
</div>
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success w100">搜索</button>
</div>
<div class="am-form-group fl ml10">
<button type="button" data-title="新增车系" data-open="/auto/attr/get" class="am-btn am-btn-success w100">新增</button>
</div>
<div class="am-form-group fr" style="font-size: 15px;padding-right: 20px;padding-top: 6px;">
共有<?= $pager['totle'] ?>条数据
</div>
</div>
</form>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="10%"><span>ID</span></th>
<th width="20%"><span>标题</span></th>
<th width="10%"><span>车系名称</span></th>
<th width="10%"><span>类型</span></th>
<th width="10%"><span>状态</span></th>
<th width="15%"><span>创建时间</span></th>
<th width="15%"><span>操作</span></th>
</tr>
</thead>
<tbody>
<?php foreach ($lists as $v) { ?>
<tr>
<td><?= $v['id'] ?></td>
<td><?= $v['title'] ?></td>
<td><?= $v['s_name'] ?></td>
<td><?= $v['type_cn'] ?></td>
<td><?= $v['status_name'] ?></td>
<td><?= $v['c_time'] ?></td>
<td>
<a href="javascript:void (0);" data-title="编辑车系" data-open="/auto/attr/get?id=<?= $v['id'] ?>"
class="am-text-primary"><?= '编辑' ?></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
+11 -17
View File
@@ -1,25 +1,19 @@
<form class="am-form am-form-horizontal" action="<?=$info?'/auto/brand/edit':'auto/brand/add'?>" data-auto="true" method="post" style="width: 90%;padding-top: 10px">
<form class="am-form am-form-horizontal" action="<?=$info?'/auto/series/edit':'auto/series/add'?>" data-auto="true" method="post" style="width: 90%;padding-top: 10px">
<input type="hidden" value="<?=$info['id']?>" name="id">
<div class="am-form-group">
<label class="am-para-label">品牌名称</label>
<div class="am-para-input">
<input type="text" placeholder="输入品牌名称" name="name" value="<?=$info['name']?>"/>
<label class="am-para-label">所属品牌:</label>
<div class="am-para-input w200">
<select name="brand_id">
<?foreach($brands as $key=>$val){?>
<option value="<?=$val['id']?>" <?=$val['id']==$info['brand_id']?'selected':''?>><?=$val['name']?></option>
<?}?>
</select>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 0">
<label class="am-para-label">logo</label>
<div class="am-form-group">
<label class="am-para-label">车系名称:</label>
<div class="am-para-input">
<div class="am-form-group am-form-file">
<button type="button" class="am-btn am-btn-default am-btn-sm"
data-file="1" data-type="jpg,png,gif,png,jpeg"
data-uptype="qiniu" data-field="img"><i class="am-icon-cloud-upload"></i> 选择要上传的文件
</button>
<input type="hidden" name="img" value="<?= $info['logo'] ?>" class="layui-input">
<img data-tips-image style="height:auto;max-height:32px;max-width:32px"
src="<?= $info['logo'] ? build_qiniu_image_url($info['logo']) : '' ?>"/>
尺寸100x100
</div>
<input type="text" placeholder="输入车系名称" name="name" value="<?=$info['name']?>"/>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
+5 -5
View File
@@ -1,5 +1,5 @@
<div class="coms-table-wrap mt10">
<form class="form-search" onsubmit="return false" action="/auto/brand/lists">
<form class="form-search" onsubmit="return false" action="/auto/series/lists">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w100">车系名称:</label>
@@ -11,7 +11,7 @@
<button type="submit" class="am-btn am-btn-success w100">搜索</button>
</div>
<div class="am-form-group fl ml10">
<button type="button" data-title="新增车系" data-modal="/auto/brand/get" class="am-btn am-btn-success w100">新增</button>
<button type="button" data-title="新增车系" data-modal="/auto/series/get" class="am-btn am-btn-success w100">新增</button>
</div>
<div class="am-form-group fr" style="font-size: 15px;padding-right: 20px;padding-top: 6px;">
共有<?= $pager['totle'] ?>条数据
@@ -39,14 +39,14 @@
<td><?= $v['status_name'] ?></td>
<td><?= $v['c_time'] ?></td>
<td>
<a href="javascript:void (0);" data-title="编辑车系" data-modal="/auto/brand/get?id=<?= $v['id'] ?>"
<a href="javascript:void (0);" data-title="编辑车系" data-modal="/auto/series/get?id=<?= $v['id'] ?>"
class="am-text-primary"><?= '编辑' ?></a> |
<?php if ($v['status'] == 1) { ?>
<a href="javascript:void (0);" data-ajax="post" data-action="/auto/brand/del"
<a href="javascript:void (0);" data-ajax="post" data-action="/auto/series/del"
data-params-id="<?= $v['id'] ?>" data-params-status="0">禁用</a>
<?php } else { ?>
<a style="color: red" href="javascript:void (0);" data-ajax="post"
data-action="/auto/brand/del"
data-action="/auto/series/del"
data-params-id="<?= $v['id'] ?>" data-params-status="1">恢复</a>
<?php } ?>
</td>
+4 -1
View File
@@ -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);
+10
View File
@@ -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;
}
}
+1
View File
@@ -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;