You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
<?php
|
|
|
|
namespace app\index\controller;
|
|
|
|
use think\Db;
|
|
use think\Request;
|
|
use think\response\Json;
|
|
use think\Exception;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
use think\exception\DbException;
|
|
|
|
class Product extends Base
|
|
{
|
|
public function _initialize()
|
|
{
|
|
// parent::_initialize(); // TODO: Change the autogenerated stub
|
|
if (!session('root')) {
|
|
$this->error('亲,您还没有登录呢!', '/');
|
|
}
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return $this->fetch();
|
|
}
|
|
|
|
/**
|
|
* 获取产品列表
|
|
* @return Json
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws Exception
|
|
* @throws ModelNotFoundException
|
|
*/
|
|
public function productList()
|
|
{
|
|
$request = Request::instance();
|
|
$receive = $request->get();
|
|
$page = input("get.page") ? input("get.page") : 1;
|
|
$page = intval($page);
|
|
$limit = input("get.limit") ? input("get.limit") : 1;
|
|
$limit = intval($limit);
|
|
$start = $limit * ($page - 1);
|
|
|
|
$where = [];
|
|
if (isset($receive['productId']) && !empty($receive['productId'])) {
|
|
$where['productId'] = $receive['productId'];
|
|
}
|
|
$result = Db::table("bs_product")->where($where)->order('id desc')->limit($start, $limit)->select();
|
|
$num = Db::table("bs_product")->where($where)->count();
|
|
|
|
foreach ($result as &$item) {
|
|
$item['encryptionType'] = $item['encryptionType'] == 1 ? '一型一密' : '一机一密';
|
|
}
|
|
|
|
$list["msg"] = "";
|
|
$list["code"] = 0;
|
|
$list["count"] = $num;
|
|
$list["data"] = $result;
|
|
|
|
return json($list);
|
|
}
|
|
}
|