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

11

1 -<?php  
2 -  
3 -namespace app\admin\controller;  
4 -  
5 -use app\common\controller\Backend;  
6 -  
7 -/**  
8 - * 商品评价管理  
9 - *  
10 - * @icon fa fa-circle-o  
11 - */  
12 -class Appraise extends Backend  
13 -{  
14 -  
15 - /**  
16 - * Appraise模型对象  
17 - * @var \app\admin\model\Appraise  
18 - */  
19 - protected $model = null;  
20 -  
21 - public function _initialize()  
22 - {  
23 - parent::_initialize();  
24 - $this->model = new \app\admin\model\Appraise;  
25 -  
26 - }  
27 -  
28 - public function import()  
29 - {  
30 - parent::import();  
31 - }  
32 -  
33 - /**  
34 - * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法  
35 - * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑  
36 - * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改  
37 - */  
38 -  
39 -  
40 - /**  
41 - * 查看  
42 - */  
43 - public function index()  
44 - {  
45 - //当前是否为关联查询  
46 - $this->relationSearch = false;  
47 - //设置过滤方法  
48 - $this->request->filter(['strip_tags', 'trim']);  
49 - if ($this->request->isAjax())  
50 - {  
51 - //如果发送的来源是Selectpage,则转发到Selectpage  
52 - if ($this->request->request('keyField'))  
53 - {  
54 - return $this->selectpage();  
55 - }  
56 - list($where, $sort, $order, $offset, $limit) = $this->buildparams();  
57 - $total = $this->model  
58 -  
59 - ->where($where)  
60 - ->order($sort, $order)  
61 - ->count();  
62 -  
63 - $list = $this->model  
64 -  
65 - ->where($where)  
66 - ->order($sort, $order)  
67 - ->limit($offset, $limit)  
68 - ->select();  
69 -  
70 - foreach ($list as $row) {  
71 - $row->visible(['id','appraise_content','appraise_images','appraise_star','user_id','createtime']);  
72 -  
73 - }  
74 - $list = collection($list)->toArray();  
75 - $result = array("total" => $total, "rows" => $list);  
76 -  
77 - return json($result);  
78 - }  
79 - return $this->view->fetch();  
80 - }  
81 -}  
1 -<?php  
2 -  
3 -return [  
4 - 'Appraise_content' => '评价内容',  
5 - 'Appraise_images' => '评价图片',  
6 - 'Appraise_star' => '评价星级',  
7 - 'User_id' => '用户id',  
8 - 'Goods_id' => '商品id',  
9 - 'Order_id' => '订单id',  
10 - 'Createtime' => '创建时间'  
11 -];  
1 -<?php  
2 -  
3 -namespace app\admin\model;  
4 -  
5 -use think\Model;  
6 -  
7 -  
8 -class Appraise extends Model  
9 -{  
10 -  
11 -  
12 -  
13 -  
14 -  
15 - // 表名  
16 - protected $name = 'appraise';  
17 -  
18 - // 自动写入时间戳字段  
19 - protected $autoWriteTimestamp = 'int';  
20 -  
21 - // 定义时间戳字段名  
22 - protected $createTime = 'createtime';  
23 - protected $updateTime = false;  
24 - protected $deleteTime = false;  
25 -  
26 - // 追加属性  
27 - protected $append = [  
28 -  
29 - ];  
30 -  
31 -  
32 -  
33 -  
34 -  
35 -  
36 -  
37 -  
38 -  
39 -  
40 -}  
1 -<?php  
2 -  
3 -namespace app\admin\validate;  
4 -  
5 -use think\Validate;  
6 -  
7 -class Appraise extends Validate  
8 -{  
9 - /**  
10 - * 验证规则  
11 - */  
12 - protected $rule = [  
13 - ];  
14 - /**  
15 - * 提示消息  
16 - */  
17 - protected $message = [  
18 - ];  
19 - /**  
20 - * 验证场景  
21 - */  
22 - protected $scene = [  
23 - 'add' => [],  
24 - 'edit' => [],  
25 - ];  
26 -  
27 -}  
1 -<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">  
2 -  
3 - <div class="form-group">  
4 - <label class="control-label col-xs-12 col-sm-2">{:__('Appraise_content')}:</label>  
5 - <div class="col-xs-12 col-sm-8">  
6 - <input id="c-appraise_content" data-rule="required" class="form-control" name="row[appraise_content]" type="text" value="">  
7 - </div>  
8 - </div>  
9 - <div class="form-group">  
10 - <label class="control-label col-xs-12 col-sm-2">{:__('Appraise_images')}:</label>  
11 - <div class="col-xs-12 col-sm-8">  
12 - <div class="input-group">  
13 - <input id="c-appraise_images" data-rule="required" class="form-control" size="50" name="row[appraise_images]" type="text" value="">  
14 - <div class="input-group-addon no-border no-padding">  
15 - <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>  
16 - <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>  
17 - </div>  
18 - <span class="msg-box n-right" for="c-appraise_images"></span>  
19 - </div>  
20 - <ul class="row list-inline plupload-preview" id="p-appraise_images"></ul>  
21 - </div>  
22 - </div>  
23 - <div class="form-group">  
24 - <label class="control-label col-xs-12 col-sm-2">{:__('Appraise_star')}:</label>  
25 - <div class="col-xs-12 col-sm-8">  
26 - <input id="c-appraise_star" data-rule="required" class="form-control" name="row[appraise_star]" type="number" value="0">  
27 - </div>  
28 - </div>  
29 - <div class="form-group">  
30 - <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>  
31 - <div class="col-xs-12 col-sm-8">  
32 - <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="">  
33 - </div>  
34 - </div>  
35 - <div class="form-group">  
36 - <label class="control-label col-xs-12 col-sm-2">{:__('Goods_id')}:</label>  
37 - <div class="col-xs-12 col-sm-8">  
38 - <input id="c-goods_id" data-rule="required" data-source="goods/index" class="form-control selectpage" name="row[goods_id]" type="text" value="">  
39 - </div>  
40 - </div>  
41 - <div class="form-group">  
42 - <label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>  
43 - <div class="col-xs-12 col-sm-8">  
44 - <input id="c-order_id" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value="">  
45 - </div>  
46 - </div>  
47 - <div class="form-group layer-footer">  
48 - <label class="control-label col-xs-12 col-sm-2"></label>  
49 - <div class="col-xs-12 col-sm-8">  
50 - <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>  
51 - <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>  
52 - </div>  
53 - </div>  
54 -</form>  
1 -<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">  
2 -  
3 - <div class="form-group">  
4 - <label class="control-label col-xs-12 col-sm-2">{:__('Appraise_content')}:</label>  
5 - <div class="col-xs-12 col-sm-8">  
6 - <input id="c-appraise_content" data-rule="required" class="form-control" name="row[appraise_content]" type="text" value="{$row.appraise_content|htmlentities}">  
7 - </div>  
8 - </div>  
9 - <div class="form-group">  
10 - <label class="control-label col-xs-12 col-sm-2">{:__('Appraise_images')}:</label>  
11 - <div class="col-xs-12 col-sm-8">  
12 - <div class="input-group">  
13 - <input id="c-appraise_images" data-rule="required" class="form-control" size="50" name="row[appraise_images]" type="text" value="{$row.appraise_images|htmlentities}">  
14 - <div class="input-group-addon no-border no-padding">  
15 - <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>  
16 - <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>  
17 - </div>  
18 - <span class="msg-box n-right" for="c-appraise_images"></span>  
19 - </div>  
20 - <ul class="row list-inline plupload-preview" id="p-appraise_images"></ul>  
21 - </div>  
22 - </div>  
23 - <div class="form-group">  
24 - <label class="control-label col-xs-12 col-sm-2">{:__('Appraise_star')}:</label>  
25 - <div class="col-xs-12 col-sm-8">  
26 - <input id="c-appraise_star" data-rule="required" class="form-control" name="row[appraise_star]" type="number" value="{$row.appraise_star|htmlentities}">  
27 - </div>  
28 - </div>  
29 - <div class="form-group">  
30 - <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>  
31 - <div class="col-xs-12 col-sm-8">  
32 - <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}">  
33 - </div>  
34 - </div>  
35 - <div class="form-group">  
36 - <label class="control-label col-xs-12 col-sm-2">{:__('Goods_id')}:</label>  
37 - <div class="col-xs-12 col-sm-8">  
38 - <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}">  
39 - </div>  
40 - </div>  
41 - <div class="form-group">  
42 - <label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>  
43 - <div class="col-xs-12 col-sm-8">  
44 - <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}">  
45 - </div>  
46 - </div>  
47 - <div class="form-group layer-footer">  
48 - <label class="control-label col-xs-12 col-sm-2"></label>  
49 - <div class="col-xs-12 col-sm-8">  
50 - <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>  
51 - <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>  
52 - </div>  
53 - </div>  
54 -</form>  
1 -<div class="panel panel-default panel-intro">  
2 - {:build_heading()}  
3 -  
4 - <div class="panel-body">  
5 - <div id="myTabContent" class="tab-content">  
6 - <div class="tab-pane fade active in" id="one">  
7 - <div class="widget-body no-padding">  
8 - <div id="toolbar" class="toolbar">  
9 - <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>  
10 - <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('appraise/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>  
11 - <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>  
12 - <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>  
13 - <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>  
14 -  
15 - <div class="dropdown btn-group {:$auth->check('appraise/multi')?'':'hide'}">  
16 - <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>  
17 - <ul class="dropdown-menu text-left" role="menu">  
18 - <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>  
19 - <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>  
20 - </ul>  
21 - </div>  
22 -  
23 -  
24 - </div>  
25 - <table id="table" class="table table-striped table-bordered table-hover table-nowrap"  
26 - data-operate-edit="{:$auth->check('appraise/edit')}"  
27 - data-operate-del="{:$auth->check('appraise/del')}"  
28 - width="100%">  
29 - </table>  
30 - </div>  
31 - </div>  
32 -  
33 - </div>  
34 - </div>  
35 -</div>  
@@ -248,12 +248,10 @@ class Order extends Api @@ -248,12 +248,10 @@ class Order extends Api
248 if(!$order = $this->model->getUserOrderDetail($post['order_id'], $this->user['id'])){ 248 if(!$order = $this->model->getUserOrderDetail($post['order_id'], $this->user['id'])){
249 $this->error($this->model->getError()); 249 $this->error($this->model->getError());
250 } 250 }
251 - empty($post['refund_reason']) && $this->error(__('请选择退款原因!'));  
252 - $order['refund_status'] == '2' && $this->error(__('订单已退款!'));  
253 - $order['refund_status'] == '1' && $this->error(__('正在申请退款中!'));  
254 - $order['delivery_status'] == '1' && $this->error(__('订单当前无法退款!'));  
255 - $this->model->allowField(true)->save($post);  
256 - $this->success(__('申请退款成功')); 251 + if ($order->refund($post)) {
  252 + $this->success(__('成功'));
  253 + }
  254 + $this->error($order->getError());
257 } 255 }
258 256
259 /** 257 /**
@@ -275,6 +273,25 @@ class Order extends Api @@ -275,6 +273,25 @@ class Order extends Api
275 if(!$order = $this->model->getUserOrderDetail($post['order_id'], $this->user['id'])){ 273 if(!$order = $this->model->getUserOrderDetail($post['order_id'], $this->user['id'])){
276 $this->error($this->model->getError()); 274 $this->error($this->model->getError());
277 } 275 }
278 - 276 + empty($post['goods_appraise']) && $this->error(__('请填写评价'));
  277 + $goods_appraise = json_decode($post['goods_appraise'],true);
  278 + foreach($goods_appraise as $v){
  279 + $v['goods_id']
  280 + }
  281 + $appraiseList = [];
  282 + foreach ($goods_appraise as $appraise) {
  283 + $appraiseList[] = [
  284 + 'user_id' => $this->user['id'],
  285 + 'order_id' => $post['order_id'],
  286 + 'goods_id' => $appraise['goods_id'],
  287 + 'star' => $appraise['star'],
  288 + 'content' => $appraise['content'],
  289 + 'images' => $appraise['images']
  290 + ];
  291 + }
  292 + // 保存订单商品信息
  293 + (new \app\common\model\GoodsAppraise)->saveAll($appraiseList);
  294 + $order->
  295 + $this->success(__('评价成功'));
279 } 296 }
280 } 297 }
@@ -66,6 +66,8 @@ class Order extends Model @@ -66,6 +66,8 @@ class Order extends Model
66 'goods_num' => $goods['goods_num'], 66 'goods_num' => $goods['goods_num'],
67 'user_size_id' => !empty($goods['user_size']) ? $goods['user_size']['id'] : 0, 67 'user_size_id' => !empty($goods['user_size']) ? $goods['user_size']['id'] : 0,
68 'goods_style' => $goods['goods_style'], 68 'goods_style' => $goods['goods_style'],
  69 + 'spec_sku_id' => $goods['goods_sku']['spec_sku_id'],
  70 + 'goods_attr' => $goods['goods_sku']['goods_attr'],
69 'goods_total_price' => $goods['goods_total_price'] 71 'goods_total_price' => $goods['goods_total_price']
70 ]; 72 ];
71 } 73 }
@@ -139,7 +141,7 @@ class Order extends Model @@ -139,7 +141,7 @@ class Order extends Model
139 'id' => $order_id, 141 'id' => $order_id,
140 'user_id' => $user_id, 142 'user_id' => $user_id,
141 'order_status' => ['<>', '2'] 143 'order_status' => ['<>', '2']
142 - ], ['goods', 'address'])) { 144 + ], ['goods' => ['goods','spec'], 'address'])) {
143 $this->setError('订单不存在'); 145 $this->setError('订单不存在');
144 return false; 146 return false;
145 } 147 }
@@ -186,10 +188,25 @@ class Order extends Model @@ -186,10 +188,25 @@ class Order extends Model
186 /** 188 /**
187 * 退款 189 * 退款
188 */ 190 */
189 - public function refund() 191 + public function refund($post)
190 { 192 {
191 -  
192 - return true; 193 + if(empty($post['refund_reason'])){
  194 + $this->setError('请选择退款原因!');
  195 + return false;
  196 + }
  197 + if($this['refund_status'] == '2'){
  198 + $this->setError('订单已退款!');
  199 + return false;
  200 + }
  201 + if($this['refund_status'] == '1'){
  202 + $this->setError('正在申请退款中!');
  203 + return false;
  204 + }
  205 + if($this['delivery_status'] == '1'){
  206 + $this->setError('订单当前无法退款!');
  207 + return false;
  208 + }
  209 + return $this->allowField(true)->save($post);
193 } 210 }
194 211
195 /** 212 /**
@@ -220,10 +237,10 @@ class Order extends Model @@ -220,10 +237,10 @@ class Order extends Model
220 return false; 237 return false;
221 } 238 }
222 // 付款减库存 239 // 付款减库存
223 - // if ($goods['spec']['stock_num'] < 1) {  
224 - // $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');  
225 - // return false;  
226 - // } 240 + if ($goods['spec']['stock_num'] < 1) {
  241 + $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');
  242 + return false;
  243 + }
227 } 244 }
228 return true; 245 return true;
229 } 246 }
@@ -24,6 +24,14 @@ class OrderGoods extends Model @@ -24,6 +24,14 @@ class OrderGoods extends Model
24 { 24 {
25 return $this->belongsTo('Goods'); 25 return $this->belongsTo('Goods');
26 } 26 }
  27 +
  28 + /**
  29 + * 关联商品规格表
  30 + */
  31 + public function spec()
  32 + {
  33 + return $this->belongsTo('GoodsSpec', 'spec_sku_id', 'spec_sku_id');
  34 + }
27 35
28 /** 36 /**
29 * 定制项详情 37 * 定制项详情
1 -define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {  
2 -  
3 - var Controller = {  
4 - index: function () {  
5 - // 初始化表格参数配置  
6 - Table.api.init({  
7 - extend: {  
8 - index_url: 'appraise/index' + location.search,  
9 - add_url: 'appraise/add',  
10 - edit_url: 'appraise/edit',  
11 - del_url: 'appraise/del',  
12 - multi_url: 'appraise/multi',  
13 - import_url: 'appraise/import',  
14 - table: 'appraise',  
15 - }  
16 - });  
17 -  
18 - var table = $("#table");  
19 -  
20 - // 初始化表格  
21 - table.bootstrapTable({  
22 - url: $.fn.bootstrapTable.defaults.extend.index_url,  
23 - pk: 'id',  
24 - sortName: 'id',  
25 - columns: [  
26 - [  
27 - {checkbox: true},  
28 - {field: 'id', title: __('Id')},  
29 - {field: 'appraise_content', title: __('Appraise_content')},  
30 - {field: 'appraise_images', title: __('Appraise_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},  
31 - {field: 'appraise_star', title: __('Appraise_star')},  
32 - {field: 'user_id', title: __('User_id')},  
33 - {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},  
34 - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}  
35 - ]  
36 - ]  
37 - });  
38 -  
39 - // 为表格绑定事件  
40 - Table.api.bindevent(table);  
41 - },  
42 - add: function () {  
43 - Controller.api.bindevent();  
44 - },  
45 - edit: function () {  
46 - Controller.api.bindevent();  
47 - },  
48 - api: {  
49 - bindevent: function () {  
50 - Form.api.bindevent($("form[role=form]"));  
51 - }  
52 - }  
53 - };  
54 - return Controller;  
55 -});