12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace app\controller\admin;
- use laytp\controller\Backend;
- use think\facade\Config;
- use laytp\library\CommonFun;
- use laytp\library\UploadDomain;
- /**
- * 幻灯轮播
- */
- class Banner extends Backend
- {
- /**
- * slider模型对象
- * @var \app\model\Banner
- */
- protected $model;
- protected $hasSoftDel=1;//是否拥有软删除功能
- protected $noNeedLogin = []; // 无需登录即可请求的方法
- protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
- public function _initialize()
- {
- $this->model = new \app\model\Banner();
- }
- //查看和搜索列表
- public function index(){
- global $_W;
- $where = $this->buildSearchParams();
- $where[] = ['uniacid','=',$_W['uniacid']];
- $order = $this->buildOrder();
- $order = ['sort'=>'desc','id' => 'desc'];
- $data = $this->model->where($where)->order($order)->with(['img_file']);
- $paging = $this->request->param('paging', false);
- if ($paging) {
- $limit = $this->request->param('limit', Config::get('paginate.limit'));
- $data = $data->paginate($limit)->toArray();
- $data['data'] = $this->getSelectedData($data['data']);
- } else {
- $data = $data->select()->toArray();
- }
- return $this->success('数据获取成功', $data);
- }
- //查看详情
- public function info()
- {
- $id = $this->request->param('id');
- $info = $this->model->with(['img_file'])->find($id);
- return $this->success('获取成功', $info);
- }
- //设置排序
- public function setSort()
- {
- $id = $this->request->post('id');
- $fieldVal = $this->request->post('field_val');
- $isRecycle = $this->request->post('is_recycle');
- $update['sort'] = $fieldVal;
- try {
- if($isRecycle) {
- $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
- } else {
- $updateRes = $this->model->where('id', '=', $id)->update($update);
- }
- if ($updateRes) {
- return $this->success('操作成功');
- } else if ($updateRes === 0) {
- return $this->success('未作修改');
- } else {
- return $this->error('操作失败');
- }
- } catch (\Exception $e) {
- return $this->error('数据库异常,操作失败');
- }
- }
- }
|