作者 何书鹏
1 个管道 的构建 通过 耗费 2 秒

11

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
* 商品评价管理
*
* @icon fa fa-circle-o
*/
class Appraise extends Backend
{
/**
* Appraise模型对象
* @var \app\admin\model\Appraise
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Appraise;
}
public function import()
{
parent::import();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = false;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->visible(['id','appraise_content','appraise_images','appraise_star','user_id','createtime']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
<?php
return [
'Appraise_content' => '评价内容',
'Appraise_images' => '评价图片',
'Appraise_star' => '评价星级',
'User_id' => '用户id',
'Goods_id' => '商品id',
'Order_id' => '订单id',
'Createtime' => '创建时间'
];
<?php
namespace app\admin\model;
use think\Model;
class Appraise extends Model
{
// 表名
protected $name = 'appraise';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
}
<?php
namespace app\admin\validate;
use think\Validate;
class Appraise extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
<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">{:__('Appraise_content')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-appraise_content" data-rule="required" class="form-control" name="row[appraise_content]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_images')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-appraise_images" data-rule="required" class="form-control" size="50" name="row[appraise_images]" type="text" value="">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-appraise_images" class="btn btn-danger plupload" data-input-id="c-appraise_images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="true" data-preview-id="p-appraise_images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-appraise_images" class="btn btn-primary fachoose" data-input-id="c-appraise_images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-appraise_images"></span>
</div>
<ul class="row list-inline plupload-preview" id="p-appraise_images"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-appraise_star" data-rule="required" class="form-control" name="row[appraise_star]" type="number" value="0">
</div>
</div>
<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/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-goods_id" data-rule="required" data-source="goods/index" class="form-control selectpage" name="row[goods_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-order_id" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value="">
</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-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<form id="edit-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">{:__('Appraise_content')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-appraise_content" data-rule="required" class="form-control" name="row[appraise_content]" type="text" value="{$row.appraise_content|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_images')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-appraise_images" data-rule="required" class="form-control" size="50" name="row[appraise_images]" type="text" value="{$row.appraise_images|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-appraise_images" class="btn btn-danger plupload" data-input-id="c-appraise_images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="true" data-preview-id="p-appraise_images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-appraise_images" class="btn btn-primary fachoose" data-input-id="c-appraise_images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-appraise_images"></span>
</div>
<ul class="row list-inline plupload-preview" id="p-appraise_images"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-appraise_star" data-rule="required" class="form-control" name="row[appraise_star]" type="number" value="{$row.appraise_star|htmlentities}">
</div>
</div>
<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/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">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-goods_id" data-rule="required" data-source="goods/index" class="form-control selectpage" name="row[goods_id]" type="text" value="{$row.goods_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-order_id" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value="{$row.order_id|htmlentities}">
</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-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<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-add {:$auth->check('appraise/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('appraise/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('appraise/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('appraise/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('appraise/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>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('appraise/edit')}"
data-operate-del="{:$auth->check('appraise/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ... @@ -248,12 +248,10 @@ class Order extends Api
if(!$order = $this->model->getUserOrderDetail($post['order_id'], $this->user['id'])){
$this->error($this->model->getError());
}
empty($post['refund_reason']) && $this->error(__('请选择退款原因!'));
$order['refund_status'] == '2' && $this->error(__('订单已退款!'));
$order['refund_status'] == '1' && $this->error(__('正在申请退款中!'));
$order['delivery_status'] == '1' && $this->error(__('订单当前无法退款!'));
$this->model->allowField(true)->save($post);
$this->success(__('申请退款成功'));
if ($order->refund($post)) {
$this->success(__('成功'));
}
$this->error($order->getError());
}
/**
... ... @@ -275,6 +273,25 @@ class Order extends Api
if(!$order = $this->model->getUserOrderDetail($post['order_id'], $this->user['id'])){
$this->error($this->model->getError());
}
empty($post['goods_appraise']) && $this->error(__('请填写评价'));
$goods_appraise = json_decode($post['goods_appraise'],true);
foreach($goods_appraise as $v){
$v['goods_id']
}
$appraiseList = [];
foreach ($goods_appraise as $appraise) {
$appraiseList[] = [
'user_id' => $this->user['id'],
'order_id' => $post['order_id'],
'goods_id' => $appraise['goods_id'],
'star' => $appraise['star'],
'content' => $appraise['content'],
'images' => $appraise['images']
];
}
// 保存订单商品信息
(new \app\common\model\GoodsAppraise)->saveAll($appraiseList);
$order->
$this->success(__('评价成功'));
}
}
... ...
... ... @@ -66,6 +66,8 @@ class Order extends Model
'goods_num' => $goods['goods_num'],
'user_size_id' => !empty($goods['user_size']) ? $goods['user_size']['id'] : 0,
'goods_style' => $goods['goods_style'],
'spec_sku_id' => $goods['goods_sku']['spec_sku_id'],
'goods_attr' => $goods['goods_sku']['goods_attr'],
'goods_total_price' => $goods['goods_total_price']
];
}
... ... @@ -139,7 +141,7 @@ class Order extends Model
'id' => $order_id,
'user_id' => $user_id,
'order_status' => ['<>', '2']
], ['goods', 'address'])) {
], ['goods' => ['goods','spec'], 'address'])) {
$this->setError('订单不存在');
return false;
}
... ... @@ -186,10 +188,25 @@ class Order extends Model
/**
* 退款
*/
public function refund()
public function refund($post)
{
return true;
if(empty($post['refund_reason'])){
$this->setError('请选择退款原因!');
return false;
}
if($this['refund_status'] == '2'){
$this->setError('订单已退款!');
return false;
}
if($this['refund_status'] == '1'){
$this->setError('正在申请退款中!');
return false;
}
if($this['delivery_status'] == '1'){
$this->setError('订单当前无法退款!');
return false;
}
return $this->allowField(true)->save($post);
}
/**
... ... @@ -220,10 +237,10 @@ class Order extends Model
return false;
}
// 付款减库存
// if ($goods['spec']['stock_num'] < 1) {
// $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');
// return false;
// }
if ($goods['spec']['stock_num'] < 1) {
$this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');
return false;
}
}
return true;
}
... ...
... ... @@ -26,6 +26,14 @@ class OrderGoods extends Model
}
/**
* 关联商品规格表
*/
public function spec()
{
return $this->belongsTo('GoodsSpec', 'spec_sku_id', 'spec_sku_id');
}
/**
* 定制项详情
*/
public function getGoodsStyleTextAttr($value,$data){
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'appraise/index' + location.search,
add_url: 'appraise/add',
edit_url: 'appraise/edit',
del_url: 'appraise/del',
multi_url: 'appraise/multi',
import_url: 'appraise/import',
table: 'appraise',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'appraise_content', title: __('Appraise_content')},
{field: 'appraise_images', title: __('Appraise_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
{field: 'appraise_star', title: __('Appraise_star')},
{field: 'user_id', title: __('User_id')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file