mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-05 17:42:49 +08:00
重新修改主业务逻辑的命名规则
This commit is contained in:
122
extend/base/admin/controller/mall/GoodsBase.php
Normal file
122
extend/base/admin/controller/mall/GoodsBase.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace base\admin\controller\mall;
|
||||
|
||||
use app\admin\model\MallCate;
|
||||
use app\admin\model\MallGoods;
|
||||
use app\admin\service\annotation\ControllerAnnotation;
|
||||
use app\admin\service\annotation\NodeAnotation;
|
||||
use app\admin\traits\Curd;
|
||||
use app\common\controller\AdminController;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* Class Goods.
|
||||
* @ControllerAnnotation(title="商城商品管理")
|
||||
*/
|
||||
class GoodsBase extends AdminController
|
||||
{
|
||||
use Curd;
|
||||
|
||||
protected $relationSearch = true;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new MallGoods();
|
||||
|
||||
$this->assign('select_list_cate', MallCate::select(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="列表")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
if (input('selectFields')) {
|
||||
return $this->selectList();
|
||||
}
|
||||
list($page, $limit, $where) = $this->buildTableParames();
|
||||
$count = $this->model
|
||||
->withJoin('cate', 'LEFT')
|
||||
->where($where)
|
||||
->count();
|
||||
$list = $this->model
|
||||
->withJoin('cate', 'LEFT')
|
||||
->where($where)
|
||||
->page($page, $limit)
|
||||
->order($this->sort)
|
||||
->select();
|
||||
$data = [
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $list,
|
||||
];
|
||||
|
||||
return json($data);
|
||||
}
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="入库")
|
||||
*/
|
||||
public function stock($id)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
empty($row) && $this->error('数据不存在');
|
||||
if ($this->request->isPost()) {
|
||||
$post = $this->request->post();
|
||||
$rule = [];
|
||||
$this->validate($post, $rule);
|
||||
try {
|
||||
$post['total_stock'] = $row->total_stock + $post['stock'];
|
||||
$post['stock'] = $row->stock + $post['stock'];
|
||||
$save = $row->save($post);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('保存失败');
|
||||
}
|
||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||
}
|
||||
$this->assign('row', $row);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
$row = $this->model->find($id);
|
||||
|
||||
$this->assign('row', $row);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NodeAnotation(title="导出")
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
list($page, $limit, $where) = $this->buildTableParames();
|
||||
|
||||
$this->model = $this->model
|
||||
->withJoin('cate', 'LEFT');
|
||||
|
||||
$fields = $this->request->param('fields', '{}', null);
|
||||
$image_fields = $this->request->param('image_fields', '{}', null);
|
||||
$select_fields = $this->request->param('select_fields', '{}', null);
|
||||
$date_fields = $this->request->param('date_fields', '{}', null);
|
||||
|
||||
$fields = json_decode($fields, true);
|
||||
$image_fields = json_decode($image_fields, true);
|
||||
$select_fields = json_decode($select_fields, true);
|
||||
$date_fields = json_decode($date_fields, true);
|
||||
|
||||
$content = \app\common\tools\ExportTools::excel($this->model, $where, $fields, $image_fields, $select_fields, $date_fields);
|
||||
|
||||
return download($content, $this->model->getName() . date('YmdHis') . '.xlsx', true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user