manghe/app/admin/controller/Profit.php
2025-03-21 18:43:39 +08:00

237 lines
6.9 KiB
PHP

<?php
namespace app\admin\controller;
use app\admin\controller\Base;
use app\common\model\ProfitExpenses;
use app\common\model\ProfitRvenue;
use \think\Request;
use think\facade\View;
use app\common\model\Goods as GoodsModel;
use app\common\model\GoodsList;
use app\common\model\AdminGoodsLog;
use think\facade\Db;
use app\common\model\Shang;
/**
* Summary of Profit
*/
class Profit extends Base
{
/**
* 盒子列表
*/
public function index(Request $request)
{
$description = trim(input('get.description'));
$expense_type = trim(input('get.expense_type'));
$whe = array();
if ($description) {
$whe[] = ['description', 'like', '%' . $description . '%'];
}
if ($expense_type) {
$whe[] = ['expense_type', '=', $expense_type];
}
$field = "*";
$order = "id desc";
$data = ProfitExpenses::getList($whe, $field, $order, $this->page);
View::assign('list', $data['list']);
View::assign('count', $data['count']);
View::assign('page', $data['page']);
return View::fetch("Profit/index");
}
/**
* 添加盒子
*/
public function profit_add(Request $request)
{
if (!$request->isPost()) {
View::assign('profit_date', date('Y-m-d'));
return View::fetch("Profit/add");
} else {
$data = input('post.');
if (empty($data['profit_date'])) {
return $this->renderError("请选择时间");
}
if (RegMoney($data['amount'])) {
return $this->renderError("支出金额输出不规范");
}
$dd = ProfitExpenses::insert($data);
if ($dd) {
return $this->renderSuccess("添加成功");
} else {
return $this->renderError("网络繁忙,请稍后");
}
}
}
/**
* 编辑盒子
*/
public function profit_edit(Request $request)
{
if (!$request->isPost()) {
$id = $request->param('id/d', 0);
$info = ProfitExpenses::where(['id' => $id])->find();
if (!$info) {
return $this->renderError("请求参数错误");
}
View::assign('info', $info);
return View::fetch("Profit/edit");
} else {
$data = input('post.');
if (empty($data['profit_date'])) {
return $this->renderError("请选择时间");
}
if (RegMoney($data['amount'])) {
return $this->renderError("支出金额输出不规范");
}
ProfitExpenses::startTrans();
$id = $data['id'];
unset($data['id']);
$dd = ProfitExpenses::where(['id' => $id])->update($data);
if ($dd) {
ProfitExpenses::commit();
return $this->renderSuccess("编辑成功");
} else {
ProfitExpenses::rollback();
return $this->renderError("网络繁忙,请稍后");
}
}
}
/**
* 上、下架,删除盒子
*/
public function profit_del(Request $request)
{
$id = $request->post('id/d');
$data = ProfitExpenses::where(['id' => $id])->field('id')->find();
if (!$data) {
return $this->renderError("数据不存在");
}
$result = ProfitExpenses::where(['id' => $id])->delete();
if ($result) {
return $this->renderSuccess("操作成功");
} else {
return $this->renderError("网络繁忙,请稍后");
}
}
public function rvenue_index(Request $request)
{
$description = trim(input('get.description'));
$user_id = trim(input('get.user_id'));
$expense_type = trim(input('get.expense_type'));
$whe = array();
if ($description) {
$whe[] = ['description', 'like', '%' . $description . '%'];
}
if ($user_id) {
$whe[] = ['user_id', '=', $user_id];
}
if ($expense_type) {
$whe[] = ['expense_type', '=', $expense_type];
}
$field = "*";
$order = "id desc";
$data = ProfitRvenue::getList($whe, $field, $order, $this->page);
View::assign('list', $data['list']);
View::assign('count', $data['count']);
View::assign('page', $data['page']);
return View::fetch("Profit/rvenue_index");
}
/**
* 添加
*/
public function rvenue_add(Request $request)
{
if (!$request->isPost()) {
View::assign('profit_date', date('Y-m-d'));
return View::fetch("Profit/rvenue_add");
} else {
$data = input('post.');
if (empty($data['profit_date'])) {
return $this->renderError("请选择时间");
}
if (RegMoney($data['price'])) {
return $this->renderError("金额不规范");
}
$dd = ProfitRvenue::insert($data);
if ($dd) {
return $this->renderSuccess("添加成功");
} else {
return $this->renderError("网络繁忙,请稍后");
}
}
}
/**
* 编辑
*/
public function rvenue_edit(Request $request)
{
if (!$request->isPost()) {
$id = $request->param('id/d', 0);
$info = ProfitRvenue::where(['id' => $id])->find();
if (!$info) {
return $this->renderError("请求参数错误");
}
View::assign('info', $info);
return View::fetch("Profit/rvenue_edit");
} else {
$data = input('post.');
if (empty($data['profit_date'])) {
return $this->renderError("请选择时间");
}
if (RegMoney($data['price'])) {
return $this->renderError("金额不规范");
}
ProfitRvenue::startTrans();
$id = $data['id'];
unset($data['id']);
$dd = ProfitRvenue::where(['id' => $id])->update($data);
if ($dd) {
ProfitRvenue::commit();
return $this->renderSuccess("编辑成功");
} else {
ProfitRvenue::rollback();
return $this->renderError("网络繁忙,请稍后");
}
}
}
/**
* 上、下架,删除
*/
public function rvenue_del(Request $request)
{
$id = $request->post('id/d');
$data = ProfitRvenue::where(['id' => $id])->field('id')->find();
if (!$data) {
return $this->renderError("数据不存在");
}
$result = ProfitRvenue::where(['id' => $id])->delete();
if ($result) {
return $this->renderSuccess("操作成功");
} else {
return $this->renderError("网络繁忙,请稍后");
}
}
}