作者 刘朕
1 个管道 的构建 通过 耗费 1 秒

合并分支 'Branch_liuzhen' 到 'master'

新入驻社区订单功能添加



查看合并请求 !398
<?php
namespace app\admin\controller\store;
use app\admin\model\House;
use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 开通新社区订单管理
*
* @icon fa fa-circle-o
*/
class StoreOrder extends Backend
{
/**
* StoreOrder模型对象
* @var \app\admin\model\store\StoreOrder
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\store\StoreOrder;
$this->view->assign("statusList", $this->model->getStatusList());
}
/**
* 默认生成的控制器所继承的父类中有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', '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
->with(['user','store'])
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->with(['user','store'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->getRelation('user')->visible(['nickname']);
}
$list = collection($list)->toArray();
foreach ($list as &$v) {
$v['house_names'] = House::whereIn('id',$v['house_ids'])->column('name');
}
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
/**
* 已支付
*/
public function pay($ids = null)
{
if ($ids) {
$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'));
}
}
$params = $this->request->param();
// if ($row->pay_type != 3) {
// $this->error('非线下支付无法修改支付状态');
// }
if ($row->status != 1) {
$this->error('该订单已支付');
}
$row->status = 2;
Db::startTrans();
try {
$result = $row->save();
// 修改或新增关联社区
$time = time();
$info = $row->toArray();
$store = Db::name('store')->where('id',$info['store_id'])->find();
$update = [
'house_ids' => $store['house_ids'].$info['house_ids'].','
];
$res_store = Db::name('store')->where('id',$info['store_id'])->update($update);
// 修改或新增社区有效期
foreach (explode(',',$info['house_ids']) as $v) {
if($v) {
$store_house = Db::name('store_house')->where(['user_id' => $info['user_id'], 'store_id' => $info['store_id'], 'house_id' => $v])->find();
if ($store_house) {
$house_update = [
'id' => $store_house['id']
];
if ($store_house['end_time'] > $time) {
$house_update['end_time'] = $store_house['end_time'] + config('site.house_valid') * 86400;
} else {
$house_update['end_time'] = $time + config('site.house_valid') * 86400;
}
$result_store_house = Db::name('store_house')->update(['id' => $store_house['id'], '']);
} else {
$insert = [
'user_id' => $info['user_id'],
'store_id' => $info['store_id'],
'house_id' => $v,
'start_time' => $time,
'end_time' => $time + config('site.house_valid') * 86400,
'createtime' => $time,
'updatetime' => $time
];
$result_store_house = Db::name('store_house')->insertGetId($insert);
}
if (!$result_store_house) {
Db::rollback();
}
}
}
if(!$result || !$res_store) {
Db::rollback();
} else {
Db::commit();
}
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (\think\Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (!$result) {
$this->error('修改失败');
}
$this->success('修改成功');
}
}
}
... ...
<?php
return [
'Order_sn' => '订单编号',
'User_id' => '用户id',
'Store_id' => '店铺id',
'House_ids' => '社区id',
'House_names' => '所选社区',
'Status' => '状态',
'Status 1' => '待支付',
'Status 2' => '已支付',
'Status 3' => '审核驳回',
'Money' => '支付金额',
'Pay_time' => '支付时间',
'Transaction_id' => '微信支付ID',
'End_time' => '过期时间',
'Createtime' => '生成时间',
'Updatetime' => '更新时间',
'User.nickname' => '昵称',
'Store.store_name' => '店铺名称'
];
... ...
<?php
namespace app\admin\model\store;
use think\Model;
class StoreOrder extends Model
{
// 表名
protected $name = 'store_order';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text',
'pay_time_text',
'end_time_text'
];
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getPayTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getEndTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
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);
}
protected function setEndTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
public function user()
{
return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function store()
{
return $this->belongsTo('app\admin\model\store\Store', 'store_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
<?php
namespace app\admin\validate\store;
use think\Validate;
class StoreOrder 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">{:__('Order_sn')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-order_sn" data-rule="required" class="form-control" name="row[order_sn]" type="text" value="''">
</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">{:__('Store_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-store_id" data-rule="required" data-source="store/index" class="form-control selectpage" name="row[store_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('House_ids')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-house_ids" data-rule="required" data-source="house/index" data-multiple="true" class="form-control selectpage" name="row[house_ids]" type="text" value="">
</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">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="1"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Money')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-money" data-rule="required" class="form-control" name="row[money]" type="number" value="0">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-pay_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[pay_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Transaction_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-transaction_id" data-rule="required" data-source="transaction/index" class="form-control selectpage" name="row[transaction_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</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">{:__('Order_sn')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-order_sn" data-rule="required" class="form-control" name="row[order_sn]" type="text" value="{$row.order_sn|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">{:__('Store_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-store_id" data-rule="required" data-source="store/index" class="form-control selectpage" name="row[store_id]" type="text" value="{$row.store_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('House_ids')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-house_ids" data-rule="required" data-source="house/index" data-multiple="true" class="form-control selectpage" name="row[house_ids]" type="text" value="{$row.house_ids|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">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Money')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-money" data-rule="required" class="form-control" name="row[money]" type="number" value="{$row.money|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pay_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-pay_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[pay_time]" type="text" value="{:$row.pay_time?datetime($row.pay_time):''}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Transaction_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-transaction_id" data-rule="required" data-source="transaction/index" class="form-control selectpage" name="row[transaction_id]" type="text" value="{$row.transaction_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="{:$row.end_time?datetime($row.end_time):''}">
</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">
<div class="panel-heading">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs" data-field="status">
<li class="active"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
{foreach name="statusList" item="vo"}
<li><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div>
<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('store/store_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('store/store_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('store/store_order/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
<!-- <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('store/store_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('store/store_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('store/store_order/edit')}"
data-operate-del="{:$auth->check('store/store_order/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'store/store_order/index' + location.search,
// add_url: 'store/store_order/add',
// edit_url: 'store/store_order/edit',
// del_url: 'store/store_order/del',
// multi_url: 'store/store_order/multi',
pay_url: 'store/store_order/pay',
table: 'store_order',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'order_sn', title: __('Order_sn')},
{field: 'user.nickname', title: __('User.nickname')},
{field: 'store.store_name', title: __('Store.store_name')},
{field: 'house_names', title: __('House_names'),operate:false, formatter: Table.api.formatter.label},
{field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
{field: 'money', title: __('Money'), operate:'BETWEEN'},
{field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'transaction_id', title: __('Transaction_id')},
// {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {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,
buttons: [
{
name: 'pay',
text: __('设为已支付'),
title: __('设为已支付'),
classname: 'btn btn-xs btn-info btn-magic btn-ajax',
icon: '',
url: $.fn.bootstrapTable.defaults.extend.pay_url,
confirm: '是否确认该订单已线下支付?',
hidden: function (row) {
if (row.status != 1) {
return true;
}
},
success: function (data) {
table.bootstrapTable('refresh');
}
}
], 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
... ...