作者 郭盛
1 个管道 的构建 失败 耗费 9 秒

添加苹果订单

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
* 苹果用户购买素材订单
*
* @icon fa fa-circle-o
*/
class Iphone extends Backend
{
/**
* Iphone模型对象
* @var \app\admin\model\Iphone
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Iphone;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$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
->with(['pic','video'])
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->with(['pic','video'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->getRelation('pic')->visible(['title']);
$row->getRelation('video')->visible(['title']);
}
$list = collection($list)->toArray();
foreach ($list as $k=>$v){
$list[$k]['user_id'] = Db::name('user')->where('id',$v['user_id'])->value('nickname');
}
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
... ...
<?php
return [
'Id' => 'id',
'User_id' => '用户id',
'Pic_id' => '图片id',
'Video_id' => '视频id',
'Total' => '价格',
'Status' => '状态(1待支付2已完成)',
'Num' => '订单号',
'Createtime' => '创建时间',
'Updatetime' => '修改时间',
'Pic.title' => '图片标题',
'Video.title' => '视频标题'
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class Iphone extends Model
{
// 表名
protected $name = 'iphone';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
public function pic()
{
return $this->belongsTo('Pic', 'pic_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function video()
{
return $this->belongsTo('Video', 'video_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
... ... @@ -27,9 +27,9 @@ class Order extends Model
protected $append = [
'paytime_text'
];
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Iphone 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">{:__('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">{:__('Pic_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-pic_id" data-rule="required" data-source="pic/index" class="form-control selectpage" name="row[pic_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Video_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-video_id" data-rule="required" data-source="video/index" class="form-control selectpage" name="row[video_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Total')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-total" class="form-control" step="0.01" name="row[total]" type="number">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-status" class="form-control" name="row[status]" type="number">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Num')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-num" class="form-control" name="row[num]" type="text">
</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">{:__('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">{:__('Pic_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-pic_id" data-rule="required" data-source="pic/index" class="form-control selectpage" name="row[pic_id]" type="text" value="{$row.pic_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Video_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-video_id" data-rule="required" data-source="video/index" class="form-control selectpage" name="row[video_id]" type="text" value="{$row.video_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Total')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-total" class="form-control" step="0.01" name="row[total]" type="number" value="{$row.total|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-status" class="form-control" name="row[status]" type="number" value="{$row.status|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Num')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-num" class="form-control" name="row[num]" type="text" value="{$row.num|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('iphone/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('iphone/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('iphone/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('iphone/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('iphone/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('iphone/edit')}"
data-operate-del="{:$auth->check('iphone/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -1681,6 +1681,97 @@ class User extends Api
}
}
/**
* @ApiTitle (创建苹果订单)
* @ApiSummary (创建苹果订单)
* @ApiMethod (POST)
* @ApiRoute (/api/user/iphone_order)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="video_id", type="string", required=true, description="视频ID")
* @ApiParams (name="video_attr", type="string", required=true, description="视频品质属性")
* @ApiParams (name="pic_id", type="string", required=true, description="图片ID")
* @ApiParams (name="total", type="float", required=true, description="总价格")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"order_id"://订单ID
}
})
*/
public function iphone_order()
{
$param['user_id'] = $this->uid;
//接收视频ID加视频属性
$video['id'] = $this->request->post('video_id');
$video['attr'] = $this->request->post('video_attr');
//接收图片的ID
$pic_id = $this->request->param('pic_id');
//价格
$param['total'] = $this->request->post('total');
if(empty( $param['total'])){
$this->error(['code'=>2,'msg'=>'缺少必要参数']);
}elseif ( $param['total']<=0){
$this->error(['code'=>3,'msg'=>'非法操作']);
}
$where['user_id'] = ['eq',$param['user_id']];
$where['status'] = ['eq',2];
if(!empty($video['id']) && !empty($video['attr'])){
//查看该图片或者该视频属性是否已经购买过
$res = Db::name('iphone')
->where($where)
->field('video_id')
->select();
foreach ($res as &$v){
$v['video_id'] = unserialize($v['video_id']);
if(!empty($v['video_id']) && !empty($video)){
foreach ($v['video_id'] as $v1){
foreach ($video as &$v2){
if($v1['id'] == $v2['id'] && $v1['attr'] == $v2['attr']){
$this->error(['code'=>2,'msg'=>'该属性的视频已经购买过了','video_id'=>$v2['id']]);
}
}
}
}
}
$param['video_id'] = serialize($video);
}else{
//查询图片ID
$arr = Db::name('iphone')
->field('pic_id')
->where($where)
->select();
foreach ($arr as &$v){
if(!empty($v['pic_id'])){
if($v['pic_id'] == $pic_id){
$this->error(['code'=>2,'msg'=>'该图片已经购买过了','pic_id'=>$pic_id]);
}
}
}
$param['pic_id'] = $pic_id;
}
$param['createtime'] = time();
$param['num'] = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
$data = Db::name('order')
->insertGetId($param);
if(empty($data)){
$this->error(['code'=>2,'msg'=>'sql执行失败']);
}
$this->success('SUCCESS',['order_id'=>$data]);
}
//将多个一维数组转为二维数组
public function array_merge_more($keys, ...$arrs){
// 检查参数是否正确
... ...
此 diff 太大无法显示。
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'iphone/index' + location.search,
add_url: 'iphone/add',
edit_url: 'iphone/edit',
del_url: 'iphone/del',
multi_url: 'iphone/multi',
table: 'iphone',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'user_id', title: __('用户昵称')},
{field: 'pic.title', title: __('Pic.title'), operate:'like'},
{field: 'video.title', title: __('Video.title'), operate:'like'},
{field: 'total', title: __('Total'), operate:'BETWEEN'},
{field: 'status', title: __('Status')},
{field: 'num', title: __('Num')},
{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: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
var that = $.extend({}, this);
var table = $(that.table).clone(true);
$(table).data("operate-del", null);
that.table = table;
return Table.api.formatter.operate.call(that, value, row, index);
}}
]
]
});
// 为表格绑定事件
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
... ...
... ... @@ -56,7 +56,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'num', title: __('Num'), operate:false},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'user.is_vip', title: __('User.is_vip'),formatter: Table.api.formatter.label,searchList:{'0': '否', '1': '是'}}
{field: 'user.is_vip', title: __('User.is_vip'),formatter: Table.api.formatter.label,searchList:{'0': '否', '1': '是'}},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
var that = $.extend({}, this);
var table = $(that.table).clone(true);
$(table).data("operate-del", null);
that.table = table;
return Table.api.formatter.operate.call(that, value, row, index);
}}
]
]
});
... ...