<?php
/**
* +----------------------------------------------------------------------
* | TickyPHP [ This is a freeware ]
* +----------------------------------------------------------------------
* | Copyright (c) 2019 All rights reserved.
* +----------------------------------------------------------------------
* | Author: 罗敏贵 <e-mail:minguiluo@163.com> <QQ:271391233>
* +----------------------------------------------------------------------
* | SVN: $Id: Order.php 92886 2019-01-28 15:22:15 luomingui $
* +----------------------------------------------------------------------
* | 文件功能:对应的表名:tky_order
* +----------------------------------------------------------------------
*/
namespace application\member\controller;
use application\admin\controller\auth as auth;
use ticky\request;
use ticky\response;
class order extends auth {
public $paytype = array('1' => '支付宝', '2' => '微信'); public $order_status = array('0' => '未付款', '1' => '已付款');
public function index() {
$search = $this->search_frm();
$ret = $this->db->page('order', $search['sql'], 'id', $this->p);
foreach ($ret['items'] as $row) {
if ($row['paytime'] == 0) {
$row['paytime'] = '<span style="color: red;">未支付</span>';
} else {
$row['paytime'] = date("Y-m-d H:i:s", $row['paytime']);
}
$row['status'] = $this->order_status[$row['status']];
$row['paytype'] = $this->paytype[$row['paytype']];
$data[] = $row;
}
$this->assign('page', $ret['page']);
$this->assign('items', $data);
$this->assign('search', $search['arr']);
$this->display('order/order_list');
}
public function add() {
if (request::isPost()) {
$data = $this->post_frm();
db('order')->add($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '添加成功']);
} else {
showmsg('添加成功', '/admin/order');
}
} else {
$this->assign('postUrl', '/admin/order/add');
$this->assign('action', '添加');
$this->display('order/manage');
}
}
public function update() {
if (request::isPost()) {
$data = $this->post_frm();
$id = request::post('id', 0);
$this->db->table('order')->where(['id' => $id])->update($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('修改成功', '/admin/order');
}
} else {
$id = request::get('id', 0);
$item = db('order')->where(['id' => $id])->find();
$this->assign('postUrl', '/admin/order/update');
$this->assign('action', '修改');
$this->assign('item', $item);
$this->display('order/manage');
}
}
public function delete() {
$id = request::post('id', 0);
$result = $this->db->table('order')->where(['id' => $id])->delete();
if (request::isAjax()) {
if ($result) {
response::ajax(['code' => 200, 'msg' => '删除成功!']);
} else {
response::ajax(['code' => 403, 'msg' => '删除失败! id=' . $id]);
}
} else {
showmsg('删除成功', '/admin/order');
}
}
public function batchremove() {
$optype = request::post('optype', 'del');
$ids = request::post('ids', []);
if ($optype == "del") {
for ($i = 0; $i < count($ids); $i++) {
$id = $ids[$i];
$this->db->table('order')->where(['id' => $id])->delete();
}
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('删除成功', '/admin/order');
}
}
}
private function search_frm() {
$search = request::get('search', []);
$where = '1=1 ';
if ($id = trim($search['id'])) {
$where .= "and id = '{$id}' ";
}
if ($order_sn = trim($search['order_sn'])) {
$where .= "and order_sn = '{$order_sn}' ";
}
if ($status = trim($search['status'])) {
$where .= "and status = '{$status}' ";
}
if ($userid = trim($search['userid'])) {
$where .= "and userid = '{$userid}' ";
}
if ($username = trim($search['username'])) {
$where .= "and username = '{$username}' ";
}
if ($addtime = trim($search['addtime'])) {
$where .= "and addtime = '{$addtime}' ";
}
if ($paytime = trim($search['paytime'])) {
$where .= "and paytime = '{$paytime}' ";
}
if ($paytype = trim($search['paytype'])) {
$where .= "and paytype = '{$paytype}' ";
}
if ($transaction = trim($search['transaction'])) {
$where .= "and transaction = '{$transaction}' ";
}
if ($money = trim($search['money'])) {
$where .= "and money = '{$money}' ";
}
if ($quantity = trim($search['quantity'])) {
$where .= "and quantity = '{$quantity}' ";
}
if ($ip = trim($search['ip'])) {
$where .= "and ip = '{$ip}' ";
}
if ($desc = trim($search['desc'])) {
$where .= "and desc = '{$desc}' ";
}
return [
'arr' => $search,
'sql' => $where
];
}
private function post_frm() {
$arr = array();
$arr['order_sn'] = request::post('order_sn', '');
$arr['status'] = request::post('status', '');
$arr['userid'] = request::post('userid', '');
$arr['username'] = request::post('username', '');
$arr['addtime'] = request::post('addtime', '');
$arr['paytime'] = request::post('paytime', '');
$arr['paytype'] = request::post('paytype', '');
$arr['transaction'] = request::post('transaction', '');
$arr['money'] = request::post('money', '');
$arr['quantity'] = request::post('quantity', '');
$arr['ip'] = request::post('ip', '');
$arr['desc'] = request::post('desc', '');
return $arr;
}
public function change_price() {
if (isset($_POST['dosubmit'])) {
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
$money = isset($_POST['money']) ? floatval($_POST['money']) : 0;
if ($money < 0.01) {
showmsg('支付金额不能小于0.01元', '/admin/order');
}
db('order')->where(['id' => $id])->update(array('money' => $money));
showmsg('订单改价成功', '/admin/order');
}
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$data = db('order')->where(array('id' => $id))->find();
$this->assign('item', $data);
$this->display('order/change_price');
}
public function details() {
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$data = db('order')->where(array('id' => $id))->find();
$this->assign('item', $data);
$this->display('order/order_details');
}
}