|
|
@@ -15,7 +15,7 @@ use think\Session;
|
|
|
*/
|
|
|
class Goods extends Backend
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Goods模型对象
|
|
|
* @var \app\cmgadm\model\Goods
|
|
|
@@ -26,18 +26,18 @@ class Goods extends Backend
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->model = new \app\cmgadm\model\Goods;
|
|
|
- $this->categoryList=Goodscats::getTreeList();
|
|
|
- array_unshift($this->categoryList, ['id' => 0, 'name' => '无','type'=>0]);
|
|
|
+ $this->categoryList = Goodscats::getTreeList();
|
|
|
+ array_unshift($this->categoryList, ['id' => 0, 'name' => '无', 'type' => 0]);
|
|
|
$this->assign('categoryList', $this->categoryList);
|
|
|
- $this->assign('shoptype',config('shopType'));
|
|
|
+ $this->assign('shoptype', config('shopType'));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查看
|
|
|
@@ -48,41 +48,35 @@ class Goods extends Backend
|
|
|
$this->relationSearch = false;
|
|
|
//设置过滤方法
|
|
|
$this->request->filter(['strip_tags']);
|
|
|
- if ($this->request->isAjax())
|
|
|
- {
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
//如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
- if ($this->request->request('keyField'))
|
|
|
- {
|
|
|
+ if ($this->request->request('keyField')) {
|
|
|
return $this->selectpage();
|
|
|
}
|
|
|
- $filter = $this->request->get("filter", '');
|
|
|
- $filter = $filter? json_decode($filter, true) : [];
|
|
|
+ $filter = $this->request->get("filter", '');
|
|
|
+ $filter = $filter ? json_decode($filter, true) : [];
|
|
|
+ if (isset($filter['stuid']) && $filter['stuid']) {
|
|
|
+ $filter['stuid'] = Studio::where(['title' => $filter['stuid']])->value('id');
|
|
|
+ }
|
|
|
|
|
|
- if(isset($filter['stuid']) && $filter['stuid']){
|
|
|
- global $_GET;
|
|
|
- $filter['stuid'] = Studio::where(['title'=>$filter['stuid']])->value('id');
|
|
|
- $_GET['filter'] = urlencode(json_encode($filter, 256));
|
|
|
- }
|
|
|
-
|
|
|
- var_dump($_GET);
|
|
|
- var_dump($this->request->get('filter'));
|
|
|
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
-
|
|
|
- $total = $this->model
|
|
|
- ->where($where)
|
|
|
- ->order($sort, $order)
|
|
|
- ->count();
|
|
|
-
|
|
|
- $list = $this->model
|
|
|
- ->where($where)
|
|
|
- ->order($sort, $order)
|
|
|
- ->limit($offset, $limit)
|
|
|
- ->select();
|
|
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparamsFilter('', '', $filter);
|
|
|
+
|
|
|
+ $total = $this->model
|
|
|
+ ->where($where)
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->count();
|
|
|
+
|
|
|
+ var_dump($this->model->getLastSql());
|
|
|
+ $list = $this->model
|
|
|
+ ->where($where)
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->limit($offset, $limit)
|
|
|
+ ->select();
|
|
|
|
|
|
foreach ($list as &$row) {
|
|
|
- $row['catid']=get_table_column('goods_cats',$row['catid'],'name');
|
|
|
- $row['stuid']=get_table_column('studio',$row['stuid'],'title');
|
|
|
- $row['userid']=get_user_info($row['userid'],'username','mobile');
|
|
|
+ $row['catid'] = get_table_column('goods_cats', $row['catid'], 'name');
|
|
|
+ $row['stuid'] = get_table_column('studio', $row['stuid'], 'title');
|
|
|
+ $row['userid'] = get_user_info($row['userid'], 'username', 'mobile');
|
|
|
}
|
|
|
$result = array("total" => $total, "rows" => $list);
|
|
|
|
|
|
@@ -90,6 +84,7 @@ class Goods extends Backend
|
|
|
}
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
+
|
|
|
function add()
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
|
|
@@ -99,7 +94,7 @@ class Goods extends Backend
|
|
|
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
|
|
$params[$this->dataLimitField] = $this->auth->id;
|
|
|
}
|
|
|
- $params['price1']=$params['price'];
|
|
|
+ $params['price1'] = $params['price'];
|
|
|
|
|
|
$result = false;
|
|
|
Db::startTrans();
|
|
|
@@ -112,7 +107,7 @@ class Goods extends Backend
|
|
|
}
|
|
|
$result = $this->model->allowField(true)->insertGetId($params);
|
|
|
Db::commit();
|
|
|
- $this->model->where(['id'=> $result])->update(['description'=> 'G'.$result]);
|
|
|
+ $this->model->where(['id' => $result])->update(['description' => 'G' . $result]);
|
|
|
} catch (ValidateException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
@@ -133,17 +128,17 @@ class Goods extends Backend
|
|
|
}
|
|
|
return parent::add();
|
|
|
}
|
|
|
+
|
|
|
public function edit($ids = NULL)
|
|
|
{
|
|
|
$row = $this->model->get($ids);
|
|
|
- if (!$row)
|
|
|
- {
|
|
|
+ if (!$row) {
|
|
|
$this->error(__('No Results were found'));
|
|
|
}
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
|
|
- $params['price1']=$params['price'];
|
|
|
+ $params['price1'] = $params['price'];
|
|
|
$params = $this->preExcludeFields($params);
|
|
|
$result = false;
|
|
|
Db::startTrans();
|
|
|
@@ -176,25 +171,25 @@ class Goods extends Backend
|
|
|
}
|
|
|
return parent::edit($ids);
|
|
|
}
|
|
|
- function multi($ids = '')
|
|
|
- {
|
|
|
- $ids = $ids ? $ids : $this->request->param("ids");
|
|
|
- if ($ids) {
|
|
|
- $params=input('params');
|
|
|
- $arrs=explode('=', $params);
|
|
|
- $data[$arrs[0]]=$arrs[1];
|
|
|
- $res=$this->model->where(['id'=>$ids])->update ($data);
|
|
|
- if($res)
|
|
|
- {
|
|
|
- $this->success('操作成功');
|
|
|
- }else{
|
|
|
- $this->error('操作失败');
|
|
|
- }
|
|
|
- }else{
|
|
|
- $this->error('请选择要操作的数据');
|
|
|
+
|
|
|
+ function multi($ids = '')
|
|
|
+ {
|
|
|
+ $ids = $ids ? $ids : $this->request->param("ids");
|
|
|
+ if ($ids) {
|
|
|
+ $params = input('params');
|
|
|
+ $arrs = explode('=', $params);
|
|
|
+ $data[$arrs[0]] = $arrs[1];
|
|
|
+ $res = $this->model->where(['id' => $ids])->update($data);
|
|
|
+ if ($res) {
|
|
|
+ $this->success('操作成功');
|
|
|
+ } else {
|
|
|
+ $this->error('操作失败');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->error('请选择要操作的数据');
|
|
|
}
|
|
|
- return parent::multi($ids);
|
|
|
- }
|
|
|
+ return parent::multi($ids);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|