<?php
/**
* +----------------------------------------------------------------------
* | TickyPHP [ This is a freeware ]
* +----------------------------------------------------------------------
* | Copyright (c) 2019 All rights reserved.
* +----------------------------------------------------------------------
* | Author: 罗敏贵 <e-mail:minguiluo@163.com> <QQ:271391233>
* +----------------------------------------------------------------------
* | SVN: $Id: Payspend.php 16557 2019-01-30 15:05:43 luomingui $
* +----------------------------------------------------------------------
* | 文件功能:消费记录
* 对应的表名:tky_pay_spend
* +----------------------------------------------------------------------
*/
namespace application\member\controller;
use application\admin\controller\auth as auth;
use ticky\request;
use ticky\response;
class payspend extends auth {
public function index() {
$search = $this->search_frm();
$ret = $this->db->page('pay_spend', $search['sql'], 'id', $this->p);
$this->assign('page', $ret['page']);
$this->assign('items', $ret['items']);
$this->assign('search', $search['arr']);
$this->display('payspend/index');
}
public function add() {
if (request::isPost()) {
$data = $this->post_frm();
$this->db->table('pay_spend')->add($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '添加成功']);
} else {
showmsg('添加成功', '/member/payspend');
}
} else {
$id = request::get('id', 0);
$item = db('pay_spend')->where(['id' => $id])->find();
$this->assign('postUrl', '/member/payspend/update');
$this->assign('action', '修改');
$this->assign('item', $item);
$this->display('payspend/manage');
}
}
public function update() {
$data = $this->post_frm();
$id = request::post('id', 0);
$this->db->table('pay_spend')->where(['id' => $id])->update($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('修改成功', '/member/payspend');
}
}
public function delete() {
$id = request::post('id', 0);
$result = $this->db->table('pay_spend')->where(['id' => $id])->delete();
if (request::isAjax()) {
if ($result) {
response::ajax(['code' => 200, 'msg' => '删除成功!']);
} else {
response::ajax(['code' => 403, 'msg' => '删除失败! id=' . $id]);
}
} else {
showmsg('删除成功', '/member/payspend');
}
}
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('pay_spend')->where(['id' => $id])->delete();
}
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('删除成功', '/member/payspend');
}
}
}
private function search_frm() {
$search = request::get('search', []);
$where = '1=1 ';
$type = request::get('type', '');
$keyword = request::get('keyword', '');
$search['type'] = $type;
if ($keyword != '') {
$search['keyword'] = $keyword;
switch ($type) {
case "id":
$where .= "and id = '" . $keyword . "' ";
break;
case "trade_sn":
$where .= "and trade_sn = '" . $keyword . "' ";
break;
case "userid":
$where .= "and userid = '" . $keyword . "' ";
break;
case "username":
$where .= "and username = '" . $keyword . "' ";
break;
case "money":
$where .= "and money = '" . $keyword . "' ";
break;
case "creat_time":
$where .= "and creat_time = '" . $keyword . "' ";
break;
case "msg":
$where .= "and msg = '" . $keyword . "' ";
break;
case "type":
$where .= "and type = '" . $keyword . "' ";
break;
case "ip":
$where .= "and ip = '" . $keyword . "' ";
break;
case "remarks":
$where .= "and remarks = '" . $keyword . "' ";
break;
}
}
return [
'arr' => $search,
'sql' => $where
];
}
private function post_frm() {
$arr = array();
$arr['trade_sn'] = request::post('trade_sn', '');
$arr['userid'] = request::post('userid', '');
$arr['username'] = request::post('username', '');
$arr['money'] = request::post('money', '');
$arr['creat_time'] = request::post('creat_time', '');
$arr['msg'] = request::post('msg', '');
$arr['type'] = request::post('type', '');
$arr['ip'] = request::post('ip', '');
$arr['remarks'] = request::post('remarks', '');
return $arr;
}
}