This commit is contained in:
hantao 2025-08-22 18:04:48 +08:00
parent 2e77a2bcc0
commit f0708b12aa
11 changed files with 431 additions and 141 deletions

View File

@ -3,11 +3,13 @@
namespace app\admin\controller; namespace app\admin\controller;
use app\admin\model\Admin; use app\admin\model\Admin;
use app\admin\model\car\Sales;
use app\admin\model\User; use app\admin\model\User;
use app\common\controller\Backend; use app\common\controller\Backend;
use app\common\model\Attachment; use app\common\model\Attachment;
use fast\Date; use fast\Date;
use think\Db; use think\Db;
use function Symfony\Component\Clock\now;
/** /**
* 控制台 * 控制台
@ -24,18 +26,58 @@ class Dashboard extends Backend
public function index() 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 $car_num = Db::query('SELECT
COUNT(IF(car_type = 1,1,null)) new_car, COUNT(IF(car_type = 1,1,null)) new_car,
COUNT(IF(car_type = 3,1,null)) rent_car, COUNT(IF(car_type = 3,1,null)) rent_car,
COUNT(IF(car_type = 2,1,null)) old_car COUNT(IF(car_type = 2,1,null)) old_car
FROM cars;')[0]; 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

@ -4,6 +4,7 @@ namespace app\admin\controller\car;
use app\admin\model\Cars; use app\admin\model\Cars;
use app\common\controller\Backend; use app\common\controller\Backend;
use Carbon\Carbon;
use think\Db; use think\Db;
use think\exception\DbException; use think\exception\DbException;
use think\exception\PDOException; use think\exception\PDOException;
@ -27,7 +28,11 @@ class Sales extends Backend
{ {
parent::_initialize(); parent::_initialize();
$this->model = new \app\admin\model\car\Sales; $this->model = new \app\admin\model\car\Sales;
$users = Db::name('admin')
->field(['id', 'nickname'])
->select();
$this->view->assign('users',$users);
} }
@ -77,6 +82,17 @@ class Sales extends Backend
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate); $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); $result = $this->model->allowField(true)->save($params);
Db::commit(); Db::commit();
} catch (ValidateException|PDOException|Exception $e) { } catch (ValidateException|PDOException|Exception $e) {
@ -108,6 +124,18 @@ class Sales extends Backend
$this->error(__('You have no permission')); $this->error(__('You have no permission'));
} }
if (false === $this->request->isPost()) { 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); $this->view->assign('row', $row);
return $this->view->fetch(); return $this->view->fetch();
} }
@ -125,6 +153,12 @@ class Sales extends Backend
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate); $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); $result = $row->allowField(true)->save($params);
Db::commit(); Db::commit();
} catch (ValidateException|PDOException|Exception $e) { } catch (ValidateException|PDOException|Exception $e) {
@ -137,5 +171,79 @@ class Sales extends Backend
$this->success(); $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

@ -2,6 +2,8 @@
namespace app\admin\model\car; namespace app\admin\model\car;
use app\admin\model\Admin;
use app\admin\model\Cars;
use think\Model; use think\Model;
@ -27,9 +29,19 @@ class Sales extends Model
protected $append = [ protected $append = [
]; ];
public function saler()
{
return $this->belongsTo(Admin::class,'saler_id');
}
public function car()
{
return $this->belongsTo(Cars::class,'cart_id');
}

View File

@ -8,19 +8,25 @@
</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[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"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">销售人员:</label> <label class="control-label col-xs-12 col-sm-2">销售人员:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-saler_id" data-rule="required" class="form-control" name="row[saler_id]" type="text" value=""> <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> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">品牌:</label> <label class="control-label col-xs-12 col-sm-2">品牌:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-brand" data-rule="required" disabled <input id="c-brand" data-rule="required" readonly
class="form-control" name="row[brand]" value="{$car.brand.name}" type="text"> class="form-control" name="row[brand]" value="{$car.brand.name}" type="text">
</div> </div>
</div> </div>
@ -28,33 +34,41 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">型号:</label> <label class="control-label col-xs-12 col-sm-2">型号:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-model" data-rule="required" disabled class="form-control" value="{$car.series.name}" name="row[model]" type="text"> <input id="c-model" data-rule="required" readonly class="form-control" value="{$car.series.name}" name="row[model]" type="text">
</div> </div>
</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"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Start_date')}:</label> <label class="control-label col-xs-12 col-sm-2">租赁开始时间:</label>
<div class="col-xs-12 col-sm-8"> <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')}"> <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> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_date')}:</label> <label class="control-label col-xs-12 col-sm-2">租赁结束时间:</label>
<div class="col-xs-12 col-sm-8"> <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')}"> <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> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Daily_price')}:</label> <label class="control-label col-xs-12 col-sm-2">日租金:</label>
<div class="col-xs-12 col-sm-8"> <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="0.00"> <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>
<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>
</div> </div>
{/if}
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_name')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Customer_name')}:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
@ -73,12 +87,6 @@
<textarea id="c-remark" class="form-control " rows="5" name="row[remark]" cols="50"></textarea> <textarea id="c-remark" class="form-control " rows="5" name="row[remark]" cols="50"></textarea>
</div> </div>
</div> </div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Created_at')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-created_at" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[created_at]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group layer-footer"> <div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label> <label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">

View File

@ -1,63 +1,80 @@
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Cart_id')}:</label> <label class="control-label col-xs-12 col-sm-2">名称:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-cart_id" data-rule="required" data-source="cart/index" class="form-control selectpage" name="row[cart_id]" type="text" value="{$row.cart_id|htmlentities}"> <input id="c-cart_id" data-rule="required" disabled class="form-control" value="{$car.title}">
</div> </div>
</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"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Saler_id')}:</label> <label class="control-label col-xs-12 col-sm-2">销售人员:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-saler_id" data-rule="required" data-source="saler/index" class="form-control selectpage" name="row[saler_id]" type="text" value="{$row.saler_id|htmlentities}"> <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> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Brand')}:</label> <label class="control-label col-xs-12 col-sm-2">品牌:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-brand" data-rule="required" class="form-control" name="row[brand]" type="text" value="{$row.brand|htmlentities}"> <input id="c-brand" data-rule="required" readonly
class="form-control" name="row[brand]" value="{$car.brand.name}" type="text">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Model')}:</label> <label class="control-label col-xs-12 col-sm-2">型号:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-model" data-rule="required" class="form-control" name="row[model]" type="text" value="{$row.model|htmlentities}"> <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">{:__('Start_date')}:</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}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_date')}:</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}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Daily_price')}:</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|htmlentities}">
</div> </div>
</div> </div>
{if condition="$car.car_type != 3"}
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Total_price')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Total_price')}:</label>
<div class="col-xs-12 col-sm-8"> <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" value="{$row.total_price|htmlentities}"> <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> </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"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_name')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Customer_name')}:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-customer_name" class="form-control" name="row[customer_name]" type="text" value="{$row.customer_name|htmlentities}"> <input id="c-customer_name" class="form-control" value="{$row.customer_name|htmlentities}" name="row[customer_name]" type="text">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_phone')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Customer_phone')}:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-customer_phone" class="form-control" name="row[customer_phone]" type="text" value="{$row.customer_phone|htmlentities}"> <input id="c-customer_phone" class="form-control" value="{$row.customer_phone|htmlentities}" name="row[customer_phone]" type="text">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -66,12 +83,6 @@
<textarea id="c-remark" class="form-control " rows="5" name="row[remark]" cols="50">{$row.remark|htmlentities}</textarea> <textarea id="c-remark" class="form-control " rows="5" name="row[remark]" cols="50">{$row.remark|htmlentities}</textarea>
</div> </div>
</div> </div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Created_at')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-created_at" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[created_at]" type="text" value="{:$row.created_at?datetime($row.created_at):''}">
</div>
</div>
<div class="form-group layer-footer"> <div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label> <label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">

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

@ -7,14 +7,9 @@
<div class="widget-body no-padding"> <div class="widget-body no-padding">
<div id="toolbar" class="toolbar"> <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-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('car/sales/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</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-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> <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> </div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap" <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('car/sales/edit')}" data-operate-edit="{:$auth->check('car/sales/edit')}"

View File

@ -1,25 +1,39 @@
<div class="panel panel-default panel-intro"> <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="stats-grid">
<div class="stat-card" onclick="showTab('new-cars')"> <div class="stat-card" >
<span class="stat-icon new-car">🚙</span> <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 class="stat-label">新车库存</div>
</div> </div>
<div class="stat-card" onclick="showTab('used-cars')"> <div class="stat-card">
<span class="stat-icon used-car">🚗</span> <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 class="stat-label">二手车库存</div>
</div> </div>
<div class="stat-card" onclick="showTab('rentals')"> <div class="stat-card" >
<span class="stat-icon rental-car">🚐</span> <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 class="stat-label">租车车辆</div>
</div> </div>
<div class="stat-card"> <div class="stat-card">
<span class="stat-icon total-sales">💰</span> <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 class="stat-label">本月销售额</div>
</div> </div>
</div> </div>

View File

@ -28,8 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[ [
{checkbox: true}, {checkbox: true},
{field: 'id', title: __('Id')}, {field: 'id', title: __('Id')},
{field: 'cart_id', title: __('Cart_id')}, {field: 'saler.nickname', title: '销售员'},
{field: 'saler_id', title: __('Saler_id')},
{field: 'brand', title: __('Brand'), operate: 'LIKE'}, {field: 'brand', title: __('Brand'), operate: 'LIKE'},
{field: 'model', title: __('Model'), operate: 'LIKE'}, {field: 'model', title: __('Model'), operate: 'LIKE'},
{field: 'start_date', title: __('Start_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, {field: 'start_date', title: __('Start_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
@ -39,7 +38,48 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'customer_name', title: __('Customer_name'), operate: 'LIKE'}, {field: 'customer_name', title: __('Customer_name'), operate: 'LIKE'},
{field: 'customer_phone', title: __('Customer_phone'), operate: 'LIKE'}, {field: 'customer_phone', title: __('Customer_phone'), operate: 'LIKE'},
{field: 'created_at', title: __('Created_at')}, {field: 'created_at', title: __('Created_at')},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} {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',
},
],
}
] ]
] ]
}); });
@ -53,6 +93,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit: function () { edit: function () {
Controller.api.bindevent(); Controller.api.bindevent();
}, },
end: function () {
Controller.api.bindevent();
},
api: { api: {
bindevent: function () { bindevent: function () {
Form.api.bindevent($("form[role=form]")); Form.api.bindevent($("form[role=form]"));

View File

@ -97,9 +97,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
}, },
{ {
name: 'sale', name: 'sale',
icon: 'fa fa-copy', icon: 'fa fa-sale',
title: '售出', text: function (row) {
text: "售出", return row.car_type == 3?'出租':'售出'
},
url: function (row) { url: function (row) {
return 'car/sales/add/ids/' + row.id; return 'car/sales/add/ids/' + row.id;
}, },

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 = { var Controller = {
index: function () { index: function () {
function showTab(tabName) { Controller.api.bindevent()
// Hide all tab contents Controller.api.datepicker()
const tabContents = document.querySelectorAll('.tab-content'); Controller.api.getChartData()
tabContents.forEach(content => { $('#filter-btn').on('click', function () {
content.classList.remove('active'); Controller.api.getChartData();
});
// 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);
});
}); });
},
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 $.ajax({
document.querySelectorAll('.action-btn').forEach(btn => { url: "dashboard/getData", //
btn.addEventListener('click', function() { type: "POST",
const originalText = this.textContent; dataType: "json",
this.textContent = '✓ 已点击'; data: params,
this.style.background = 'linear-gradient(135deg, #48bb78 0%, #38a169 100%)'; success: function (response) {
Controller.api.chart(response);
setTimeout(() => { },
this.textContent = originalText; error: function () {
this.style.background = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'; console.error("图表数据加载失败");
}, 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);
} }
}); });
}, 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);
});
});
},
} }
}; };