123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace app\admin\controller;
- use app\admin\BaseController;
- use app\common\model\Config;
- use app\common\model\Train as TrainModel;
- class Train extends BaseController
- {
- public function index()
- {
- return view('train/index');
- }
- public function form()
- {
- $id = input('id/d, 0');
- $info = TrainModel::findOrEmpty($id);
- return view('train/form', [
- 'info' => $info,
- ]);
- }
- public function list()
- {
- $limit = input('limit');
- $page = input('page');
- $where = [];
- $title = input('title', '');
- if (!empty($title)) {
- $where[] = ['title', 'like', "%{$title}%"];
- }
- $contact = input('contact', '');
- if (!empty($contact)) {
- $where[] = ['contact|mobile', 'like', "%{$contact}%"];
- }
- $status = input('status', 0);
- if (!empty($status)) {
- $where[] = ['status', '=', $status];
- }
- $list = TrainModel::order(['priority' => 'desc', 'id' => 'desc'])->where($where)->limit($limit)->page($page)->select()->append(['status_text']);
- $count = TrainModel::where($where)->count();
- if ($count == 0) {
- exit(json_encode([
- 'code' => 1,
- 'msg' => "未查询到数据",
- ]));
- }
- exit(json_encode([
- 'code' => 0,
- 'msg' => "",
- 'count' => $count,
- 'data' => $list,
- ]));
- }
- public function field()
- {
- $id = input('id/d');
- $info = TrainModel::find($id);
- if ($info == null) {
- exit(json_encode([
- 'code' => 1,
- 'msg' => "数据不存在",
- ]));
- } else {
- $info->save([
- input('field/s') => input('value/s'),
- ]);
- }
- exit(json_encode([
- 'code' => 0,
- ]));
- }
- public function edit()
- {
- $id = input('id/d');
- if (empty($id)) {
- TrainModel::create([
- 'title' => input('title/s'),
- 'contact' => input('contact/s'),
- 'mobile' => input('mobile/s'),
- 'address' => input('address/s'),
- 'status' => input('status/d') == 1 ? 1 : 2,
- 'priority' => input('priority/d'),
- 'create_time' => time(),
- ]);
- } else {
- $info = TrainModel::find($id);
- $info->save([
- 'title' => input('title/s'),
- 'contact' => input('contact/s'),
- 'mobile' => input('mobile/s'),
- 'address' => input('address/s'),
- 'status' => input('status/d') == 1 ? 1 : 2,
- 'priority' => input('priority/d'),
- ]);
- }
- exit(json_encode([
- 'code' => 0,
- ]));
- }
- public function del()
- {
- $id = input('id/d');
- $info = TrainModel::where('id', $id)->select();
- $result = $info->delete();
- if ($result) {
- exit(json_encode([
- 'code' => 0,
- 'msg' => "",
- ]));
- }
- exit(json_encode([
- 'code' => 1,
- 'msg' => "删除失败,请稍后重试",
- ]));
- }
- public function post()
- {
- $post = Config::getConfigValue('train_post');
- return view('train/post', [
- 'post' => $post,
- ]);
- }
- public function editpost()
- {
- $post = input('post', 0);
- Config::setConfigValueSingle('train_post', $post);
- exit(json_encode([
- 'code' => 0,
- ]));
- }
- }
|