作者 王智

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 /**
@@ -32,4 +33,56 @@ class Seller extends Backend @@ -32,4 +33,56 @@ class Seller extends Backend
32 */ 33 */
33 34
34 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 + }
35 } 88 }
@@ -25,7 +25,7 @@ class Seller extends Model @@ -25,7 +25,7 @@ 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 31
@@ -37,11 +37,11 @@ class Seller extends Model @@ -37,11 +37,11 @@ class Seller extends Model
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 }