作者 杨育虎

2

... ... @@ -3,16 +3,15 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
*
*
*
* @icon fa fa-circle-o
*/
class Order extends Backend
{
/**
* Order模型对象
* @var \app\admin\model\Order
... ... @@ -25,14 +24,15 @@ class Order extends Backend
$this->model = new \app\admin\model\Order;
$this->view->assign("orderStatusList", $this->model->getOrderStatusList());
$this->view->assign("invoiceStatusList", $this->model->getInvoiceStatusList());
$this->view->assign("isPayList", $this->model->getIsPayList());
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
... ... @@ -43,27 +43,29 @@ class Order extends Backend
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['user'])
->where($where)
->order($sort, $order)
->count();
->with(['user'])
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->with(['user'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
->with(['user'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->getRelation('user')->visible(['username']);
}
$list = collection($list)->toArray();
... ... @@ -73,63 +75,4 @@ class Order extends Backend
}
return $this->view->fetch();
}
/**
* 编辑
*/
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)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$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(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
//处理订单完成后逻辑
if ($params['order_status'] == 2) {
//如果订单状态更改为已完成
//订单发票状态改为待开票
Db::name('order')->where(['order_sn' => $params['order_sn']])->update(['invoice_status' => 1]);
}
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
<?php
return [
'Id' => 'ID',
'Total' => '总价',
'Order_sn' => '订单编号',
'User_id' => '用户ID',
'Shopping' => '快递公司',
'Shop_order' => '快递单号',
'Order_status' => '订单状态',
'Order_status 0' => '待审核',
'Order_status 1' => '待收货',
'Order_status 2' => '已完成',
'Order_status 3' => '已取消 ',
'Createtime' => '创建时间',
'Updatetime' => '更改时间',
'Address' => '地址',
'Address_con' => '详细地址',
'Mobile' => '手机号',
'Name' => '收货人',
'Invoice_status' => '发票状态',
'Id' => 'ID',
'Total' => '总价',
'Order_sn' => '订单编号',
'User_id' => '用户ID',
'Shopping' => '快递公司',
'Shop_order' => '快递单号',
'Order_status' => '订单状态',
'Order_status 0' => '待审核',
'Order_status 1' => '待收货',
'Order_status 2' => '已完成',
'Order_status 3' => '已取消 ',
'Createtime' => '创建时间',
'Updatetime' => '更改时间',
'Address' => '地址',
'Address_con' => '详细地址',
'Mobile' => '手机号',
'Name' => '姓名',
'Invoice_status' => '发票状态',
'Invoice_status 0' => '没有开票资格',
'Invoice_status 1' => '待开票',
'Invoice_status 2' => '开票中',
'Invoice_status 3' => '已开票',
'Is_pay 0' => '未支付',
'Is_pay 1' => '已支付',
'User.username' => '下单用户'
'Is_pay' => '支付状态',
'Is_pay 0' => '未支付',
'Is_pay 1' => '已支付',
'User.username' => '用户名'
];
... ...
... ... @@ -8,13 +8,13 @@ use think\Model;
class Order extends Model
{
// 表名
protected $name = 'order';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
... ... @@ -26,11 +26,12 @@ class Order extends Model
// 追加属性
protected $append = [
'order_status_text',
'invoice_status_text'
'invoice_status_text',
'is_pay_text'
];
public function getOrderStatusList()
{
return ['0' => __('Order_status 0'), '1' => __('Order_status 1'), '2' => __('Order_status 2'), '3' => __('Order_status 3')];
... ... @@ -41,11 +42,12 @@ class Order extends Model
return ['0' => __('Invoice_status 0'), '1' => __('Invoice_status 1'), '2' => __('Invoice_status 2'), '3' => __('Invoice_status 3')];
}
public function getIspay()
public function getIsPayList()
{
return ['0' => __('Ispay 0'), '1' => __('Ispay 1')];
return ['0' => __('Is_pay 0'), '1' => __('Is_pay 1')];
}
public function getOrderStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
... ... @@ -62,6 +64,14 @@ class Order extends Model
}
public function getIsPayTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['is_pay']) ? $data['is_pay'] : '');
$list = $this->getIsPayList();
return isset($list[$value]) ? $list[$value] : '';
}
public function user()
... ...
... ... @@ -15,7 +15,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/index" data-field="username" class="form-control selectpage" name="row[user_id]" type="text" value="">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
</div>
</div>
<div class="form-group">
... ... @@ -33,10 +33,10 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="orderStatusList" item="vo"}
<label for="row[order_status]-{$key}"><input id="row[order_status]-{$key}" name="row[order_status]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
<label for="row[order_status]-{$key}"><input id="row[order_status]-{$key}" name="row[order_status]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
... ... @@ -69,26 +69,24 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Invoice_status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="invoiceStatusList" item="vo"}
<label for="row[invoice_status]-{$key}"><input id="row[invoice_status]-{$key}" name="row[invoice_status]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
<label for="row[invoice_status]-{$key}"><input id="row[invoice_status]-{$key}" name="row[invoice_status]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_pay')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="is_pay" item="vo"}
<label for="row[is_pay]-{$key}"><input id="row[is_pay]-{$key}" name="row[is_pay]" type="radio" value="{$key}" {in name="key" value="0"}checked{/in} /> {$vo}</label>
<select id="c-is_pay" data-rule="required" class="form-control selectpicker" name="row[is_pay]">
{foreach name="isPayList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</div>
</select>
</div>
</div>
... ...
... ... @@ -15,7 +15,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/index" data-field="username" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
</div>
</div>
<div class="form-group">
... ... @@ -78,17 +78,15 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_pay')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="is_pay" item="vo"}
<label for="row[is_pay]-{$key}"><input id="row[is_pay]-{$key}" name="row[is_pay]" type="radio" value="{$key}" {in name="key" value="$row.is_pay"}checked{/in} /> {$vo}</label>
<select id="c-is_pay" data-rule="required" class="form-control selectpicker" name="row[is_pay]">
{foreach name="isPayList" item="vo"}
<option value="{$key}" {in name="key" value="$row.is_pay"}selected{/in}>{$vo}</option>
{/foreach}
</div>
</select>
</div>
</div>
... ...
... ... @@ -7,18 +7,18 @@
<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-add {:$auth->check('order/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('order/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('order/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('order/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('order/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
<!--<div class="dropdown btn-group {:$auth->check('order/multi')?'':'hide'}">-->
<!--<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->
<!--<ul class="dropdown-menu text-left" role="menu">-->
<!--<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>-->
<!--<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>-->
<!--</ul>-->
<!--</div>-->
<div class="dropdown btn-group {:$auth->check('order/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
</div>
... ...
... ... @@ -25,21 +25,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'order_sn', title: __('Order_sn')},
{field: 'user.username', title: __('User.username')},
{field: 'total', title: __('Total'), operate:'BETWEEN'},
// {field: 'user_id', title: __('User_id')},
{field: 'order_sn', title: __('Order_sn')},
{field: 'user_id', title: __('User_id')},
{field: 'shopping', title: __('Shopping')},
{field: 'shop_order', title: __('Shop_order')},
{field: 'order_status', title: __('Order_status'), searchList: {"0":__('Order_status 0'),"1":__('Order_status 1'),"2":__('Order_status 2'),"3":__('Order_status 3')}, formatter: Table.api.formatter.status},
{field: 'name', title: __('Name')},
{field: 'mobile', title: __('Mobile')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'address', title: __('Address')},
{field: 'address_con', title: __('Address_con')},
{field: 'mobile', title: __('Mobile')},
{field: 'name', title: __('Name')},
{field: 'invoice_status', title: __('Invoice_status'), searchList: {"0":__('Invoice_status 0'),"1":__('Invoice_status 1'),"2":__('Invoice_status 2'),"3":__('Invoice_status 3')}, formatter: Table.api.formatter.status},
{field: 'is_pay', title: __('Is_pay'), searchList: {"0":__('Is_pay 0'),"1":__('Is_pay 1'),}, formatter: Table.api.formatter.status},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'is_pay', title: __('Is_pay'), searchList: {"0":__('Is_pay 0'),"1":__('Is_pay 1')}, formatter: Table.api.formatter.normal},
{field: 'user.username', title: __('User.username')},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
... ...