作者 王智

daima

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace app\admin\controller; 3 namespace app\admin\controller;
4 4
  5 +use think\Db;
5 use app\common\controller\Backend; 6 use app\common\controller\Backend;
6 7
7 /** 8 /**
@@ -11,7 +12,7 @@ use app\common\controller\Backend; @@ -11,7 +12,7 @@ use app\common\controller\Backend;
11 */ 12 */
12 class Seller extends Backend 13 class Seller extends Backend
13 { 14 {
14 - 15 +
15 /** 16 /**
16 * Seller模型对象 17 * Seller模型对象
17 * @var \app\admin\model\Seller 18 * @var \app\admin\model\Seller
@@ -24,12 +25,64 @@ class Seller extends Backend @@ -24,12 +25,64 @@ class Seller extends Backend
24 $this->model = new \app\admin\model\Seller; 25 $this->model = new \app\admin\model\Seller;
25 $this->view->assign("isShowList", $this->model->getIsShowList()); 26 $this->view->assign("isShowList", $this->model->getIsShowList());
26 } 27 }
27 - 28 +
28 /** 29 /**
29 * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 30 * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
30 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 31 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
31 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 32 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
32 */ 33 */
33 -  
34 34
35 -} 35 +
  36 + /**
  37 + * 编辑
  38 + */
  39 + public function edit($ids = null)
  40 + {
  41 + $row = $this->model->get($ids);
  42 + if (!$row) {
  43 + $this->error(__('No Results were found'));
  44 + }
  45 + $adminIds = $this->getDataLimitAdminIds();
  46 + if (is_array($adminIds)) {
  47 + if (!in_array($row[$this->dataLimitField], $adminIds)) {
  48 + $this->error(__('You have no permission'));
  49 + }
  50 + }
  51 + if ($this->request->isPost()) {
  52 + $params = $this->request->post("row/a");
  53 + if ($params) {
  54 + $params = $this->preExcludeFields($params);
  55 + $result = false;
  56 + Db::startTrans();
  57 + try {
  58 + //是否采用模型验证
  59 + if ($this->modelValidate) {
  60 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  61 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  62 + $row->validateFailException(true)->validate($validate);
  63 + }
  64 + $params['talk_num'] = 0;
  65 + $result = $row->allowField(true)->save($params);
  66 + Db::commit();
  67 + } catch (ValidateException $e) {
  68 + Db::rollback();
  69 + $this->error($e->getMessage());
  70 + } catch (PDOException $e) {
  71 + Db::rollback();
  72 + $this->error($e->getMessage());
  73 + } catch (Exception $e) {
  74 + Db::rollback();
  75 + $this->error($e->getMessage());
  76 + }
  77 + if ($result !== false) {
  78 + $this->success();
  79 + } else {
  80 + $this->error(__('No rows were updated'));
  81 + }
  82 + }
  83 + $this->error(__('Parameter %s can not be empty', ''));
  84 + }
  85 + $this->view->assign("row", $row);
  86 + return $this->view->fetch();
  87 + }
  88 +}
@@ -8,13 +8,13 @@ use think\Model; @@ -8,13 +8,13 @@ use think\Model;
8 class Seller extends Model 8 class Seller extends Model
9 { 9 {
10 10
11 -  
12 11
13 - 12 +
  13 +
14 14
15 // 表名 15 // 表名
16 protected $name = 'seller'; 16 protected $name = 'seller';
17 - 17 +
18 // 自动写入时间戳字段 18 // 自动写入时间戳字段
19 protected $autoWriteTimestamp = 'int'; 19 protected $autoWriteTimestamp = 'int';
20 20
@@ -25,23 +25,23 @@ class Seller extends Model @@ -25,23 +25,23 @@ class Seller extends Model
25 25
26 // 追加属性 26 // 追加属性
27 protected $append = [ 27 protected $append = [
28 - 'opentime_text', 28 +// 'opentime_text',
29 'is_show_text' 29 'is_show_text'
30 ]; 30 ];
31 -  
32 31
33 - 32 +
  33 +
34 public function getIsShowList() 34 public function getIsShowList()
35 { 35 {
36 return ['1' => __('Is_show 1'), '0' => __('Is_show 0')]; 36 return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
37 } 37 }
38 38
39 39
40 - public function getOpentimeTextAttr($value, $data)  
41 - {  
42 - $value = $value ? $value : (isset($data['opentime']) ? $data['opentime'] : '');  
43 - return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;  
44 - } 40 +// public function getOpentimeTextAttr($value, $data)
  41 +// {
  42 +// $value = $value ? $value : (isset($data['opentime']) ? $data['opentime'] : '');
  43 +// return $value;
  44 +// }
45 45
46 46
47 public function getIsShowTextAttr($value, $data) 47 public function getIsShowTextAttr($value, $data)
@@ -51,10 +51,10 @@ class Seller extends Model @@ -51,10 +51,10 @@ class Seller extends Model
51 return isset($list[$value]) ? $list[$value] : ''; 51 return isset($list[$value]) ? $list[$value] : '';
52 } 52 }
53 53
54 - protected function setOpentimeAttr($value)  
55 - {  
56 - return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);  
57 - } 54 +// protected function setOpentimeAttr($value)
  55 +// {
  56 +// return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  57 +// }
58 58
59 59
60 } 60 }