Compare commits

..

2 Commits

Author SHA1 Message Date
hantao
f0708b12aa get 2025-08-22 18:04:48 +08:00
hantao
2e77a2bcc0 get 2025-08-15 17:55:20 +08:00
16 changed files with 891 additions and 74 deletions

View File

@ -236,6 +236,7 @@ class Cars extends Backend
'title' => $params['title'],
'price' => $params['price'],
'desc' => $params['desc'],
'count' => $params['count'],
're_price' => $params['re_price'],
'cover_image' => $params['cover_image'],
'contact_id' => $params['contact_id'] ?? $this->auth->id,

View File

@ -3,11 +3,13 @@
namespace app\admin\controller;
use app\admin\model\Admin;
use app\admin\model\car\Sales;
use app\admin\model\User;
use app\common\controller\Backend;
use app\common\model\Attachment;
use fast\Date;
use think\Db;
use function Symfony\Component\Clock\now;
/**
* 控制台
@ -24,18 +26,58 @@ class Dashboard extends Backend
public function index()
{
$start = now()->modify('-30 days')->format('Y-m-d');
$end_at = now()->format('Y-m-d');
$default_daterange = $start . ' - ' . $end_at;
$this->view->assign('default_daterange',$default_daterange);
return $this->view->fetch();
}
public function getData()
{
$car_num = Db::query('SELECT
COUNT(IF(car_type = 1,1,null)) new_car,
COUNT(IF(car_type = 3,1,null)) rent_car,
COUNT(IF(car_type = 2,1,null)) old_car
FROM cars;')[0];
$this->view->assign([
...$car_num
$start = now()->modify('-30 days')->format('Y-m-d');
$end_at = now()->format('Y-m-d 23:29:59');
$filter = request()->get('range','');
if (!empty($filter)){
$arr = explode(' - ', $filter);
if (trim($arr[0])) {
$start = trim($arr[0]). ' 00:00:00';
}
if (trim($arr[1])) {
$end_at = trim($arr[1]) . ' 23:29:59';
}
}
$build = new Sales();
$build->whereBetween('finish_at', [$start, $end_at]);
$group = \model('auth_group_access')->where('uid', $this->auth->id)->find()->group_id ?? 0;
if (!in_array($group,[1,2])){
$build->where('saler_id',$this->auth->id);
}
$sale = $build->field([
"count(if(type=1,1,null)) new_count",
"count(if(type=2,1,null)) old_count",
"count(if(type=3,1,null)) rent_count",
"sum(if(type=1,total_price,0)) new_sum",
"sum(if(type=2,total_price,0)) old_sum",
"sum(if(type=3,total_price,0)) rent_sum",
"sum(total_price) total_price",
])->select()[0]->toArray();
$this->success(data:[
...$car_num,...$sale
]);
return $this->view->fetch();
}
}

View File

@ -0,0 +1,249 @@
<?php
namespace app\admin\controller\car;
use app\admin\model\Cars;
use app\common\controller\Backend;
use Carbon\Carbon;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 车辆销售/租赁记录管理
*
* @icon fa fa-circle-o
*/
class Sales extends Backend
{
/**
* Sales模型对象
* @var \app\admin\model\car\Sales
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\car\Sales;
$users = Db::name('admin')
->field(['id', 'nickname'])
->select();
$this->view->assign('users',$users);
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add($ids = null)
{
if (false === $this->request->isPost()) {
$car = Cars::where('id',$ids)->with([
'brand' =>function ($q) {
$q->field('id,name');
},
'series' =>function ($q) {
$q->field('id,name');
},
]
)->select()[0] ?? null;
$this->view->assign('car',$car);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$params['saler_id'] = ($params['saler_id'] ?? -1) == -1 ? $this->auth->id : $params['saler_id'];
if (empty($params['saler_id'])) {
$params['saler_id'] = $this->auth->id;
}
if ($params['type'] != 3){
$params['finish_at'] = (new Carbon())->format('Y-m-d H:i:s');
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$car = Cars::where('id',$row->cart_id)->with([
'brand' =>function ($q) {
$q->field('id,name');
},
'series' =>function ($q) {
$q->field('id,name');
},
]
)->select()[0] ?? null;
$this->view->assign('car',$car);
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$params['saler_id'] = ($params['saler_id'] ?? -1) == -1 ? $this->auth->id : $params['saler_id'];
if (empty($params['saler_id'])) {
$params['saler_id'] = $this->auth->id;
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
return $this->view->fetch();
}
//如果发送的来源是 Selectpage则转发到 Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->where($where)
->with('saler')
->order($sort, $order)
->paginate($limit);
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
public function end($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$car = Cars::where('id',$row->cart_id)->with([
'brand' =>function ($q) {
$q->field('id,name');
},
'series' =>function ($q) {
$q->field('id,name');
},
]
)->select()[0] ?? null;
$this->view->assign('car',$car);
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$params['finish_at'] = (new Carbon())->format('Y-m-d H:i:s');
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
}

View File

@ -0,0 +1,15 @@
<?php
return [
'Cart_id' => '车 id',
'Saler_id' => '销售 id',
'Brand' => '品牌',
'Model' => '型号',
'Start_date' => '销售日期/租赁开始日期',
'End_date' => '租赁结束日期(销售则等于开始日期)',
'Daily_price' => '日租金(销售则为单价)',
'Total_price' => '总金额',
'Customer_name' => '客户姓名',
'Customer_phone' => '客户电话',
'Remark' => '备注信息'
];

View File

@ -0,0 +1,52 @@
<?php
namespace app\admin\model\car;
use app\admin\model\Admin;
use app\admin\model\Cars;
use think\Model;
class Sales extends Model
{
// 表名
protected $table = 'car_sales';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
public function saler()
{
return $this->belongsTo(Admin::class,'saler_id');
}
public function car()
{
return $this->belongsTo(Cars::class,'cart_id');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace app\admin\validate\car;
use think\Validate;
class Sales extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}

View File

@ -0,0 +1,96 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">名称:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-cart_id" data-rule="required" disabled class="form-control" value="{$car.title}">
</div>
</div>
<input style="display: none" hidden data-rule="required" class="form-control" name="row[cart_id]" type="text" value="{$car.id}">
<input style="display: none" hidden data-rule="required" class="form-control" name="row[type]" type="text" value="{$car.car_type}">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">销售人员:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-users" data-live-search="true" title="默认当前登录账号" name="row[saler_id]" class="form-control selectpicker show-tick">
<option selected value="-1">默认当前登录账号</option>
{foreach $users as $item}
<option value="{$item['id']}">{$item['nickname']}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">品牌:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-brand" data-rule="required" readonly
class="form-control" name="row[brand]" value="{$car.brand.name}" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">型号:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-model" data-rule="required" readonly class="form-control" value="{$car.series.name}" name="row[model]" type="text">
</div>
</div>
{if condition="$car.car_type != 3"}
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Total_price')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-total_price" data-rule="required" class="form-control" step="0.01" name="row[total_price]" type="number">
</div>
</div>
{else /}
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">租赁开始时间:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-start_date" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[start_date]" type="text" value="{:date('Y-m-d')}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">租赁结束时间:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_date" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[end_date]" type="text" value="{:date('Y-m-d')}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">日租金:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-daily_price" data-rule="required" class="form-control" step="0.01" name="row[daily_price]" type="number" value="{$car.price}">
</div>
</div>
{/if}
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-customer_name" class="form-control" name="row[customer_name]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_phone')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-customer_phone" class="form-control" name="row[customer_phone]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Remark')}:</label>
<div class="col-xs-12 col-sm-8">
<textarea id="c-remark" class="form-control " rows="5" name="row[remark]" cols="50"></textarea>
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
</div>
</div>
</form>

View File

@ -0,0 +1,92 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">名称:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-cart_id" data-rule="required" disabled class="form-control" value="{$car.title}">
</div>
</div>
<input style="display: none" hidden data-rule="required" class="form-control" name="row[cart_id]" type="text" value="{$car.id}">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">销售人员:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-users" data-live-search="true" title="默认当前登录账号" name="row[saler_id]" class="form-control selectpicker show-tick">
<option value="-1">默认当前登录账号</option>
{foreach $users as $item}
<option {if $item['id'] == $row.saler_id} selected {/if} value="{$item['id']}">{$item['nickname']}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">品牌:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-brand" data-rule="required" readonly
class="form-control" name="row[brand]" value="{$car.brand.name}" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">型号:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-model" data-rule="required" readonly class="form-control" value="{$car.series.name}" name="row[model]" type="text">
</div>
</div>
{if condition="$car.car_type != 3"}
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Total_price')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-total_price" data-rule="required" class="form-control" value="{$row.total_price|htmlentities}" step="0.01" name="row[total_price]" type="number">
</div>
</div>
{else /}
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">租赁开始时间:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-start_date" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[start_date]" type="text" value="{$row.start_date|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">租赁结束时间:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_date" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[end_date]" type="text" value="{$row.end_date|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">日租金:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-daily_price" data-rule="required" class="form-control" step="0.01" name="row[daily_price]" type="number" value="{$row.daily_price}">
</div>
</div>
{/if}
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-customer_name" class="form-control" value="{$row.customer_name|htmlentities}" name="row[customer_name]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_phone')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-customer_phone" class="form-control" value="{$row.customer_phone|htmlentities}" name="row[customer_phone]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Remark')}:</label>
<div class="col-xs-12 col-sm-8">
<textarea id="c-remark" class="form-control " rows="5" name="row[remark]" cols="50">{$row.remark|htmlentities}</textarea>
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
</div>
</div>
</form>

View File

@ -0,0 +1,39 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">名称:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-cart_id" data-rule="required" disabled class="form-control" value="{$car.title}">
</div>
</div>
<input style="display: none" hidden data-rule="required" class="form-control" name="row[cart_id]" type="text" value="{$car.id}">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">品牌:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-brand" data-rule="required" readonly
class="form-control" name="row[brand]" value="{$car.brand.name}" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">型号:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-model" data-rule="required" readonly class="form-control" value="{$car.series.name}" name="row[model]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Total_price')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-total_price" data-rule="required" class="form-control" value="{$row.total_price|htmlentities}" step="0.01" name="row[total_price]" type="number">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
</div>
</div>
</form>

View File

@ -0,0 +1,24 @@
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('car/sales/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('car/sales/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('car/sales/edit')}"
data-operate-del="{:$auth->check('car/sales/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>

View File

@ -23,6 +23,12 @@
<input id="c-series_id_value" data-rule="required" class="form-control" name="row[series_id]" type="hidden" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">库存:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-count" data-rule="required" class="form-control" name="row[count]" type="number">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">售价/日租价格:</label>
<div class="col-xs-12 col-sm-8">

View File

@ -25,6 +25,12 @@
<input id="c-series_id_value" data-rule="required" class="form-control" name="row[series_id]" type="hidden" value="{$row.series_id}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">库存:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-count" data-rule="required" class="form-control" name="row[count]" value="{$row.count}" type="number">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Price')}:</label>
<div class="col-xs-12 col-sm-8">

View File

@ -1,25 +1,39 @@
<div class="panel panel-default panel-intro">
{:build_heading()}
<!-- Stats Cards -->
<div>
<div class="form-inline" id="chart-filter" style="margin-top:20px;margin-bottom: 30px;">
<!-- 时间范围 -->
<div class="form-group" style="margin-left: 15px;">
<input type="text" class="form-control datetimerange" value = "{$default_daterange|htmlentities}" data-locale='{"format":"YYYY-MM-DD"}'
placeholder="指定日期" name="filter[daterange]" id="daterange" autocomplete="off" style="width: 200px;">
</div>
<!-- 查询按钮 -->
<button class="btn btn-default" id="filter-btn" style="margin-left: 15px;">查询</button>
</div>
</div>
<div class="stats-grid">
<div class="stat-card" onclick="showTab('new-cars')">
<div class="stat-card" >
<span class="stat-icon new-car">🚙</span>
<div class="stat-number">{$new_car}</div>
<div class="stat-number">loading</div>
<div class="stat-label">新车库存</div>
</div>
<div class="stat-card" onclick="showTab('used-cars')">
<div class="stat-card">
<span class="stat-icon used-car">🚗</span>
<div class="stat-number">{$old_car}</div>
<div class="stat-number">loading</div>
<div class="stat-label">二手车库存</div>
</div>
<div class="stat-card" onclick="showTab('rentals')">
<div class="stat-card" >
<span class="stat-icon rental-car">🚐</span>
<div class="stat-number">{$rent_car}</div>
<div class="stat-number">loading</div>
<div class="stat-label">租车车辆</div>
</div>
<div class="stat-card">
<span class="stat-icon total-sales">💰</span>
<div class="stat-number">¥xxxx</div>
<div class="stat-number">loading</div>
<div class="stat-label">本月销售额</div>
</div>
</div>

View File

@ -0,0 +1,106 @@
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'car/sales/index' + location.search,
add_url: 'car/sales/add',
edit_url: 'car/sales/edit',
del_url: 'car/sales/del',
multi_url: 'car/sales/multi',
import_url: 'car/sales/import',
table: 'car_sales',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
fixedColumns: true,
fixedRightNumber: 1,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'saler.nickname', title: '销售员'},
{field: 'brand', title: __('Brand'), operate: 'LIKE'},
{field: 'model', title: __('Model'), operate: 'LIKE'},
{field: 'start_date', title: __('Start_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'end_date', title: __('End_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'daily_price', title: __('Daily_price'), operate:'BETWEEN'},
{field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
{field: 'customer_name', title: __('Customer_name'), operate: 'LIKE'},
{field: 'customer_phone', title: __('Customer_phone'), operate: 'LIKE'},
{field: 'created_at', title: __('Created_at')},
{field: 'finish_at', title: '结算时间'},
{field: 'operate', title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate,
buttons: [
{
name: 'edit',
text: "修改",
icon: 'fa fa-pencil',
title: __('Edit'),
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-info btn-editone',
},
{
name: 'del',
text: "删除",
icon: 'fa fa-trash',
title: __('Delete'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-danger btn-delone',
},
{
name: 'end',
text: "结算",
icon: 'fa',
title: '结算',
url: function (row) {
return 'car/sales/end/ids/' + row.id;
},
visible: function (row) {
if (row.type == 3 && !row.finish_at) {
return true;
}
return false;
},
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-info btn-dialog',
},
],
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
end: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});

View File

@ -45,6 +45,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
formatter: Table.api.formatter.status},
{field: 'brand.name', title: __('Brand_id'), operate: false},
{field: 'series.name', title: __('Series_id'), operate: false},
{field: 'count', title: '库存', operate: false},
{field: 'price', title: __('Price'), operate: 'BETWEEN'},
{field: 're_price', title: '现价(万元)', operate: 'BETWEEN'},
{
@ -84,7 +85,37 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate
formatter: Table.api.formatter.operate,
buttons: [
{
name: 'edit',
text: "修改",
icon: 'fa fa-pencil',
title: __('Edit'),
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-info btn-editone',
},
{
name: 'sale',
icon: 'fa fa-sale',
text: function (row) {
return row.car_type == 3?'出租':'售出'
},
url: function (row) {
return 'car/sales/add/ids/' + row.id;
},
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-info btn-dialog',
},
{
name: 'del',
text: "删除",
icon: 'fa fa-trash',
title: __('Delete'),
extend: 'data-toggle="tooltip"',
classname: 'btn btn-xs btn-danger btn-delone',
},
],
}
]
]

View File

@ -1,69 +1,86 @@
define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts','echarts-theme', 'template', 'addtabs', 'moment','citypicker'], function ($, undefined, Backend, Table, Form, echarts, undefined, Template, Datatable, Moment) {
var Controller = {
index: function () {
function showTab(tabName) {
// Hide all tab contents
const tabContents = document.querySelectorAll('.tab-content');
tabContents.forEach(content => {
content.classList.remove('active');
});
// Remove active class from all tabs
const navTabs = document.querySelectorAll('.nav-tab');
navTabs.forEach(tab => {
tab.classList.remove('active');
});
// Show selected tab content
document.getElementById(tabName).classList.add('active');
// Add active class to corresponding nav tab
const activeTab = document.querySelector(`.nav-tab[onclick="showTab('${tabName}')"]`);
if (activeTab) {
activeTab.classList.add('active');
}
}
// Add click animations to cards
document.querySelectorAll('.car-card').forEach(card => {
card.addEventListener('click', function() {
this.style.transform = 'scale(0.95)';
setTimeout(() => {
this.style.transform = '';
}, 150);
});
Controller.api.bindevent()
Controller.api.datepicker()
Controller.api.getChartData()
$('#filter-btn').on('click', function () {
Controller.api.getChartData();
});
},
api: {
getChartData:function (){
// 获取日期范围值
var daterange = $('#daterange').val();
/* var source = $('#source').val();
var city_id = $('#area_id').val();
var item_id = $('#item_id').val();
*/
// 构建查询参数
var params = {
'daterange': daterange,
/* 'source': source,
'area_id': city_id,
'item_id': item_id,*/
};
// Add hover effect to action buttons
document.querySelectorAll('.action-btn').forEach(btn => {
btn.addEventListener('click', function() {
const originalText = this.textContent;
this.textContent = '✓ 已点击';
this.style.background = 'linear-gradient(135deg, #48bb78 0%, #38a169 100%)';
setTimeout(() => {
this.textContent = originalText;
this.style.background = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)';
}, 1000);
});
});
// Simulate real-time updates
setInterval(() => {
const statNumbers = document.querySelectorAll('.stat-number');
statNumbers.forEach(num => {
if (num.textContent.includes('¥')) return;
const currentValue = parseInt(num.textContent);
if (Math.random() > 0.7) {
num.textContent = currentValue + Math.floor(Math.random() * 3);
num.style.color = '#48bb78';
setTimeout(() => {
num.style.color = '#2d3748';
}, 1000);
$.ajax({
url: "dashboard/getData", //
type: "POST",
dataType: "json",
data: params,
success: function (response) {
Controller.api.chart(response);
},
error: function () {
console.error("图表数据加载失败");
}
});
}, 5000);
},
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
datepicker: function () {
var ranges = {};
ranges[__('Today')] = [Moment().startOf('day'), Moment().endOf('day')];
ranges[__('Yesterday')] = [Moment().subtract(1, 'days').startOf('day'), Moment().subtract(1, 'days').endOf('day')];
ranges[__('Last 7 Days')] = [Moment().subtract(6, 'days').startOf('day'), Moment().endOf('day')];
ranges[__('Last 30 Days')] = [Moment().subtract(29, 'days').startOf('day'), Moment().endOf('day')];
ranges[__('This Month')] = [Moment().startOf('month'), Moment().endOf('month')];
ranges[__('Last Month')] = [Moment().subtract(1, 'month').startOf('month'), Moment().subtract(1, 'month').endOf('month')];
ranges[__('今年')] = [Moment().startOf('year'), Moment().endOf('year')];
var options = {
timePicker: false,
autoUpdateInput: false,
timePickerSeconds: true,
timePicker24Hour: true,
autoApply: true,
locale: {
format: 'YYYY-MM-DD',
customRangeLabel: __("Custom Range"),
applyLabel: __("Apply"),
cancelLabel: __("Clear"),
},
ranges: ranges,
};
var callback = function (start, end) {
$(this.element).val(start.format(options.locale.format) + " - " + end.format(options.locale.format));
};
require(['bootstrap-daterangepicker'], function () {
$(".datetimerange").each(function () {
$(this).on('apply.daterangepicker', function (ev, picker) {
callback.call(picker, picker.startDate, picker.endDate);
var label = picker.chosenLabel;
$(picker.element).data('label', label).trigger("change");
});
$(this).on('cancel.daterangepicker', function (ev, picker) {
$(this).val('');
});
$(this).daterangepicker($.extend({}, options), callback);
});
});
},
}
};