作者 郭盛
1 个管道 的构建 通过 耗费 5 秒

修改后台子订单

... ... @@ -115,15 +115,9 @@ class Order extends Backend
->field('a.teacher_id,a.order_status,a.commission,b.money')
->where('a.id',$ids)
->find();
if($money['order_status'] == 1){
//查出老师现在有的余额
$teacher = Db::name('teacher')
->where('id',$money['teacher_id'])
->field('id,balance,user_id')
->find();
$gold = $teacher['balance'] + ($money['money'] - $money['money'] * ($money['commission']/100));
Db::name('teacher')->where('id',$money['teacher_id'])->update(['balance'=>$gold]);
}else{
//本身状态就为1的情况
if($money['order_status'] != 1){
//查出老师现在有的余额
$teacher = Db::name('teacher')
->where('id',$money['teacher_id'])
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/1/19
* Time: 14:44
*/
namespace app\admin\controller;
use think\Db;
use app\common\controller\Backend;
class Sonorder extends Backend
{
/**
* Order模型对象
* @var \app\admin\model\Order
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Sonorder;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index1($ids)
{
//设置过滤方法
$this->request->filter(['strip_tags']);
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('order_id',$ids)
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where('order_id',$ids)
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
$this->assignconfig("order_id",$ids);
return $this->view->fetch();
}
/**
* 批量更新
*/
public function multi($ids = "")
{
$ids = $ids ? $ids : $this->request->param("ids");
if ($ids) {
if ($this->request->has('params')) {
parse_str($this->request->post("params"), $values);
$values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
if ($values) {
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$count = 0;
//查询子订单信息
$order = Db::name('sonorder')->where('id',$ids)->find();
//如果审核通过情况
if($values['order_status'] == 1){
//查询主订单信息 老师设定的金额 以及该订单的佣金比例
$zhu_order = Db::name('order')
->alias('a')
->join('territory b','a.territory_id = b.id')
->field('a.teacher_id,a.user_id,a.order_status,a.commission,b.money')
->where('a.id',$order['order_id'])
->find();
//本身状态就为1的情况
if($order['order_status'] != 1){
//查出老师现在有的余额
$teacher = Db::name('teacher')
->where('id',$zhu_order['teacher_id'])
->field('id,balance,user_id')
->find();
//添加佣金明细表
$record['money'] = $zhu_order['money'] - $zhu_order['money'] * ($zhu_order['commission']/100);
$record['type'] = 1;
$record['createtime'] = time();
$record['teacher_id'] = $zhu_order['teacher_id'];
$record['user_id'] = $zhu_order['user_id'];
Db::name('record')->insertGetId($record);
$gold = $teacher['balance'] + ($zhu_order['money'] - $zhu_order['money'] * ($zhu_order['commission']/100));
Db::name('teacher')->where('id',$zhu_order['teacher_id'])->update(['balance'=>$gold]);
}
}
Db::startTrans();
try {
$list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
foreach ($list as $index => $item) {
$count += $item->allowField(true)->isUpdate(true)->save($values);
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
} else {
$this->error(__('You have no permission'));
}
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/1/19
* Time: 15:17
*/
namespace app\admin\model;
use think\Model;
class Sonorder extends Model
{
// 表名
protected $name = 'sonorder';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
'paytime_text',
];
public function getPaytimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setPaytimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
}
\ No newline at end of file
... ...
<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('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>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('order/edit')}"
data-operate-del="{:$auth->check('order/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -130,6 +130,10 @@ class Order extends Api
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$yong = Db::name('commission')
->where('id',1)
->find();
$param['commission'] = $yong['proportion'];
if($param['is_use'] == 1){
if(empty($param['coupon_id'])){
$this->error('优惠劵ID错误');
... ... @@ -513,7 +517,7 @@ class Order extends Api
"id": //id,
"teacher_id"://老师ID,
"user_id"://用户ID
"type"://类型(1订单结算2提现审核中3提现已结算)
"type"://类型(1订单结算2提现审核中3提现已结算
"money"://金额
"createtime"://创建时间
}
... ...
... ... @@ -230,11 +230,6 @@ class Teacher extends Api
}
}
/**
* @ApiTitle (我的擅长领域)
* @ApiSummary (我的擅长领域)
... ...
... ... @@ -4464,7 +4464,11 @@
"id": //id,
"teacher_id"://老师ID,
"user_id"://用户ID
"type"://类型(1订单结算2提现审核中3提现已结算</pre>
"type"://类型(1订单结算2提现审核中3提现已结算
"money"://金额
"createtime"://创建时间
}
}</pre>
</div>
</div>
</div><!-- #sample -->
... ... @@ -7983,7 +7987,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2020-01-19 14:38:05 </div>
Generated on 2020-01-19 16:21:51 </div>
<div class="col-md-6" align="right">
<a href="https://www.fastadmin.net" target="_blank">FastAdmin</a>
</div>
... ...
... ... @@ -57,6 +57,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
classname: 'btn btn-xs btn-primary btn-dialog',
url: 'order/summary',
extend: 'data-area=\'["80%","80%"]\'',
},
{
text: '续约订单列表',
title: '续约订单列表',
icon: 'fa fa-list',
classname: 'btn btn-xs btn-primary btn-dialog',
url: 'sonorder/index1',
extend: 'data-area=\'["80%","80%"]\'',
}
], operate:false, formatter: Table.api.formatter.buttons
},
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index1: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'sonorder/index1' + location.search,
edit_url: 'sonorder/edit',
del_url: 'sonorder/del',
multi_url: 'sonorder/multi',
table: 'sonorder',
},
queryParams: function (params) { //自定义搜索条件
params.ids = Config.order_id;//将搜索过滤器和操作方法 都转为JSON字符串
return params;
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('ID'), operate:false},
{field: 'is_use', title: __('是否使用优惠劵'), operate:false,formatter: Table.api.formatter.label,searchList:{'0': '不使用','1':'使用'}},
{field: 'money', title: __('金额'), operate:'BETWEEN'},
{field: 'status', title: __('状态'),formatter: Table.api.formatter.status,searchList:{'1': '待支付','2':'已支付','3':'已退款'}},
{field: 'order_status', title: __('订单审核状态文字描述'),formatter: Table.api.formatter.label,searchList:{'1': '通过','2':'不通过'}},
{field: 'order_status', title: __('订单审核状态'),formatter: Table.api.formatter.toggle,yes:'1',no:'2',searchList:{'1': '通过','2':'不通过'}},
{field: 'num', title: __('订单号'), operate:false},
{field: 'commission', title: __('佣金比例(单位%)'), operate:false},
{field: 'createtime', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'paytime', title: __('支付时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'operate', title: __('操作'), 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
... ...