Commit 611ce6693ede48976eaa1287fab6c9a183d3bae6
1 parent
7c8f40d4
Exists in
master
app-ht(build v0.0.1 build 1)
1. 后台厂商编辑功能实现。
Showing
6 changed files
with
237 additions
and
10 deletions
Show diff stats
app-ht/config/params.php
@@ -3,5 +3,5 @@ return [ | @@ -3,5 +3,5 @@ return [ | ||
3 | 'adminEmail' => 'tech@jiwork.com', | 3 | 'adminEmail' => 'tech@jiwork.com', |
4 | 'DINGTALKL_URL' => 'https://tdd.jiwork.com/', //在钉钉端用系统扫码之后跳转到钉钉对应的界面,里面要指定钉钉的网址 | 4 | 'DINGTALKL_URL' => 'https://tdd.jiwork.com/', //在钉钉端用系统扫码之后跳转到钉钉对应的界面,里面要指定钉钉的网址 |
5 | 'BAIDU_MAP_BROWSER_KEY' => 'UzLG5fpQtralY2hXO3wvVFzvlCmw6Rue', | 5 | 'BAIDU_MAP_BROWSER_KEY' => 'UzLG5fpQtralY2hXO3wvVFzvlCmw6Rue', |
6 | - 'VERSION' => 'v1.8.6 build 6', | 6 | + 'VERSION' => 'v0.0.1 build 1', |
7 | ]; | 7 | ]; |
8 | \ No newline at end of file | 8 | \ No newline at end of file |
app-ht/modules/manufacturer/controllers/ManufacturerController.php
@@ -6,6 +6,7 @@ use Yii; | @@ -6,6 +6,7 @@ use Yii; | ||
6 | use yii\data\Pagination; | 6 | use yii\data\Pagination; |
7 | use domain\manufacturer\Manufacturer; | 7 | use domain\manufacturer\Manufacturer; |
8 | use domain\manufacturer\ManufacturerRepository; | 8 | use domain\manufacturer\ManufacturerRepository; |
9 | +use common\models\SysUser as SysUserModel; | ||
9 | use app\ht\controllers\BaseController; | 10 | use app\ht\controllers\BaseController; |
10 | 11 | ||
11 | /** | 12 | /** |
@@ -116,9 +117,80 @@ class ManufacturerController extends BaseController | @@ -116,9 +117,80 @@ class ManufacturerController extends BaseController | ||
116 | } else { | 117 | } else { |
117 | Yii::$app->session->setFlash('error', '添加失败'); | 118 | Yii::$app->session->setFlash('error', '添加失败'); |
118 | } | 119 | } |
119 | - return $this->render('create'); | 120 | + $info = ManufacturerRepository::selectInfoById($result, true); |
121 | + | ||
122 | + return $this->render('edit', ["isCreateSuccess" => true, "info" => $info]); | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * 编辑厂商 | ||
127 | + * @return string | ||
128 | + */ | ||
129 | + public function actionEdit() | ||
130 | + { | ||
131 | + $manufacturerId = $this->request->get("mid"); | ||
132 | + $info = ManufacturerRepository::selectInfoById($manufacturerId, true); | ||
133 | + return $this->render('edit', ["isCreateSuccess" => false, "info" => $info]); | ||
120 | } | 134 | } |
121 | 135 | ||
136 | + /** | ||
137 | + * 创建厂商 | ||
138 | + * @return string | ||
139 | + */ | ||
140 | + public function actionDoEdit() | ||
141 | + { | ||
142 | + $request = Yii::$app->request; | ||
143 | + $name = $request->post("name"); | ||
144 | + $phone = $request->post("phone"); | ||
145 | + $username = $request->post("username"); | ||
146 | + $password = $request->post("password"); | ||
147 | + $mid = $request->post("mid"); | ||
148 | + if (empty($mid)) { | ||
149 | + Yii::$app->session->setFlash('error', '厂商编号不能为空'); | ||
150 | + $params = $this->dataList(1); | ||
151 | + return $this->render('index', $params); | ||
152 | + } | ||
153 | + $manufacturer = ManufacturerRepository::selectInfoById($mid,true); | ||
154 | + if (empty($manufacturer)) { | ||
155 | + Yii::$app->session->setFlash('error', '该厂商不存在'); | ||
156 | + $params = $this->dataList(1); | ||
157 | + return $this->render('index', $params); | ||
158 | + } | ||
159 | + if (empty($name)) { | ||
160 | + Yii::$app->session->setFlash('error', '厂商名称不能为空'); | ||
161 | + return $this->render('edit', ["isCreateSuccess" => false, "info" => $manufacturer]); | ||
162 | + } | ||
163 | + if (empty($phone)) { | ||
164 | + Yii::$app->session->setFlash('error', '厂商电话不能为空'); | ||
165 | + return $this->render('edit', ["isCreateSuccess" => false, "info" => $manufacturer]); | ||
166 | + } | ||
167 | + if (empty($username)) { | ||
168 | + Yii::$app->session->setFlash('error', '账号不能为空'); | ||
169 | + return $this->render('edit', ["isCreateSuccess" => false, "info" => $manufacturer]); | ||
170 | + } | ||
171 | + if (empty($password)) { | ||
172 | + Yii::$app->session->setFlash('error', '密码不能为空'); | ||
173 | + return $this->render('edit', ["isCreateSuccess" => false, "info" => $manufacturer]); | ||
174 | + } | ||
175 | + if (isset($manufacturer["name"]) && $name != $manufacturer["name"]) { | ||
176 | + if (ManufacturerRepository::findOne(["name" => $name])) { | ||
177 | + Yii::$app->session->setFlash('error', '修改的用户名已经存在'); | ||
178 | + return $this->render('edit', ["isCreateSuccess" => false, "info" => $manufacturer]); | ||
179 | + } | ||
180 | + if (SysUserModel::findOne(["username" => $username])) { | ||
181 | + Yii::$app->session->setFlash('error', '账号已经存在'); | ||
182 | + return $this->render('edit', ["isCreateSuccess" => false, "info" => $manufacturer]); | ||
183 | + } | ||
184 | + } | ||
185 | + $result = Manufacturer::update($mid, $request->post()); | ||
186 | + if ($result) { | ||
187 | + Yii::$app->session->setFlash('success', '编辑成功'); | ||
188 | + } else { | ||
189 | + Yii::$app->session->setFlash('error', '编辑失败'); | ||
190 | + } | ||
191 | + $manufacturer = ManufacturerRepository::selectInfoById($mid,true); | ||
192 | + return $this->render('edit', ["isCreateSuccess" => false, "info" => $manufacturer]); | ||
193 | + } | ||
122 | 194 | ||
123 | /** | 195 | /** |
124 | * 删除商品 | 196 | * 删除商品 |
@@ -0,0 +1,110 @@ | @@ -0,0 +1,110 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Url; | ||
4 | +if ($isCreateSuccess) { | ||
5 | + $this->title = '创建账号'; | ||
6 | +} else { | ||
7 | + $this->title = '编辑厂商'; | ||
8 | +} | ||
9 | +$this->params['breadcrumbs'][] = '厂商管理'; | ||
10 | +$this->params['breadcrumbs'][] = ['label' => '厂商管理', 'url' => ['/manufacturer/manufacturer/index']]; | ||
11 | +$this->params['breadcrumbs'][] = $this->title; | ||
12 | + | ||
13 | +?> | ||
14 | + | ||
15 | +<form action="<?php echo Url::toRoute(['/manufacturer/manufacturer/do-add']); ?>" name="myFrom" id="myFrom" method="post" enctype="multipart/form-data"> | ||
16 | + <div class="panel panel-default"> | ||
17 | + <div class="panel-body"> | ||
18 | + <div style="margin-bottom: 15px;text-align: right;"> | ||
19 | + <a href="<?=Url::toRoute("/manufacturer/manufacturer/create")?>" class="btn btn-success"> + 创建厂商账号</a> | ||
20 | + </div> | ||
21 | + <div class="form-group col-sm-12" style="text-align: center"> | ||
22 | + <?php if ($isCreateSuccess) { ?> | ||
23 | + <h3>厂商创建成功!</h3> | ||
24 | + <?php } else { ?> | ||
25 | + <h3>编辑厂商</h3> | ||
26 | + <?php } ?> | ||
27 | + </div> | ||
28 | + <div class="form-group col-sm-12"> | ||
29 | + <label for="skillName" class="col-sm-4 control-label text-right">厂商名称:</label> | ||
30 | + <div class="col-sm-4 text-left"> | ||
31 | + <input type="text" value="<?= isset($info["name"]) ? $info["name"] : "" ?>" name="name" placeholder="请填写厂商名称" class="form-control"> | ||
32 | + </div> | ||
33 | + </div> | ||
34 | + <div class="form-group col-sm-12"> | ||
35 | + <label for="skillName" class="col-sm-4 control-label text-right">厂商电话:</label> | ||
36 | + <div class="col-sm-4 text-left"> | ||
37 | + <input type="text" value="<?= isset($info["phone"]) ? $info["phone"] : "" ?>" name="phone" placeholder="请填写联系电话" class="form-control" > | ||
38 | + </div> | ||
39 | + </div> | ||
40 | + <div class="form-group col-sm-12"> | ||
41 | + <label for="skillName" class="col-sm-4 control-label text-right">账号:</label> | ||
42 | + <div class="col-sm-4 text-left"> | ||
43 | + <input type="text" value="<?= isset($info["username"]) ? $info["username"] : "" ?>" name="username" placeholder="请填写账号名称" class="form-control" > | ||
44 | + </div> | ||
45 | + </div> | ||
46 | + <div class="form-group col-sm-12"> | ||
47 | + <label for="skillName" class="col-sm-4 control-label text-right">密码:</label> | ||
48 | + <div class="col-sm-4 text-left"> | ||
49 | + <input type="password" value="1234567" name="password" placeholder="请填写密码" class="form-control" > | ||
50 | + </div> | ||
51 | + </div> | ||
52 | + </div> | ||
53 | + | ||
54 | + <div class="panel-footer text-center"> | ||
55 | + <input type="hidden" value="<?= isset($info["id"]) ? $info["id"] : "" ?>" name="mid" class="form-control""> | ||
56 | + <button type="button" class="btn btn-primary ladda-button" data-style="slide-up" id="save">确 定</button> | ||
57 | + <a class="btn btn-default" href="<?=Url::toRoute("/manufacturer/manufacturer/index")?>">返 回</a> | ||
58 | + </div> | ||
59 | + </div> | ||
60 | + | ||
61 | +</form> | ||
62 | + | ||
63 | +<script> | ||
64 | + // 表单提交验证 | ||
65 | + seajs.use("base/1.0.0/unit/validate/custom-1.0.0",function () { | ||
66 | + var validator = $("#myFrom").validate({ | ||
67 | + //debug:true, | ||
68 | + rules: { | ||
69 | + } | ||
70 | + }); | ||
71 | + }); | ||
72 | + | ||
73 | + $("#save").bind("click", function () { | ||
74 | + var getUrl = '<?=Url::toRoute("/manufacturer/manufacturer/do-edit")?>'; | ||
75 | + $('#myFrom').attr('action', getUrl); | ||
76 | + var a = $("input[name='name']").val(); | ||
77 | + var b = $("input[name='phone']").val(); | ||
78 | + var c = $("input[name='username']").val(); | ||
79 | + var d = $("input[name='password']").val(); | ||
80 | + if (a == ""){ | ||
81 | + alert("用户名称不能为空"); | ||
82 | + return false; | ||
83 | + } | ||
84 | + if (!new RegExp("^0?(13|15|18|14|17)[0-9]{9}$").test(b)){ | ||
85 | + alert("请填写正确的手机号码"); | ||
86 | + return false; | ||
87 | + } | ||
88 | + if (c == ""){ | ||
89 | + alert("账号不能为空"); | ||
90 | + $("input[name='username']").focus(); | ||
91 | + return false; | ||
92 | + } | ||
93 | + if (d == ""){ | ||
94 | + alert("密码不能为空"); | ||
95 | + return false; | ||
96 | + } | ||
97 | + if (d.length < 7 || d.length > 20){ | ||
98 | + alert("密码应该在7位到20位之间"); | ||
99 | + return false; | ||
100 | + } | ||
101 | + var cb = $("#myFrom").validate().form(); | ||
102 | + if (!cb){ | ||
103 | + return; | ||
104 | + } | ||
105 | + var submit = $('#myFrom').submit(); | ||
106 | + var l = $.ladda(this); | ||
107 | + l.start(); | ||
108 | + return false; | ||
109 | + }); | ||
110 | +</script> | ||
0 | \ No newline at end of file | 111 | \ No newline at end of file |
app-ht/modules/manufacturer/views/manufacturer/index.php
@@ -70,8 +70,8 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -70,8 +70,8 @@ $this->params['breadcrumbs'][] = $this->title; | ||
70 | <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['created_at'])?></td> | 70 | <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['created_at'])?></td> |
71 | <td style="padding:12px;"> | 71 | <td style="padding:12px;"> |
72 | <button class="btn btn-danger btn-sm btn_del" aid="<?=$item['id'] ?>">删除</button> | | 72 | <button class="btn btn-danger btn-sm btn_del" aid="<?=$item['id'] ?>">删除</button> | |
73 | - <button class="btn btn-info btn-sm btn_auth_success" aid="<?=$item['id'] ?>">编辑</button> | | ||
74 | - <button class="btn btn-success btn-sm btn_auth_fail" aid="<?=$item['id'] ?>">查看</button> | 73 | + <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/manufacturer/manufacturer/edit", "mid" => $item['id']])?>" aid="<?=$item['id'] ?>">编辑</a> | |
74 | + <a class="btn btn-success btn-sm btn_auth_fail" href="<?=Url::toRoute(["/manufacturer/manufacturer/edit", "mid" => $item['id']])?>" aid="<?=$item['id'] ?>">查看</a> | ||
75 | </td> | 75 | </td> |
76 | </tr> | 76 | </tr> |
77 | <?php endforeach; ?> | 77 | <?php endforeach; ?> |
@@ -98,7 +98,7 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -98,7 +98,7 @@ $this->params['breadcrumbs'][] = $this->title; | ||
98 | <script> | 98 | <script> |
99 | $(document).ready(function () { | 99 | $(document).ready(function () { |
100 | $(".btn_del").bind("click",function () { | 100 | $(".btn_del").bind("click",function () { |
101 | - if (confirm("确定要删除商品吗?对应工程师商品列表中也会一并删除,请谨慎操作")){ | 101 | + if (confirm("确定要删除该厂商吗?对应厂商的登录账号也会一并删除,请谨慎操作")){ |
102 | var data_id = $.trim($(this).attr("aid")); | 102 | var data_id = $.trim($(this).attr("aid")); |
103 | if (data_id == null || data_id == ""){ | 103 | if (data_id == null || data_id == ""){ |
104 | alert("丢失参数,暂时无法删除,请刷新后再试"); | 104 | alert("丢失参数,暂时无法删除,请刷新后再试"); |
domain/manufacturer/Manufacturer.php
@@ -48,6 +48,7 @@ class Manufacturer | @@ -48,6 +48,7 @@ class Manufacturer | ||
48 | $saveResult = $profile->save(); | 48 | $saveResult = $profile->save(); |
49 | } | 49 | } |
50 | if($saveResult) { | 50 | if($saveResult) { |
51 | + $saveResult = $manufacturerModel->id; | ||
51 | $transaction->commit(); | 52 | $transaction->commit(); |
52 | } else { | 53 | } else { |
53 | $transaction->rollBack(); | 54 | $transaction->rollBack(); |
@@ -55,7 +56,6 @@ class Manufacturer | @@ -55,7 +56,6 @@ class Manufacturer | ||
55 | return $saveResult; | 56 | return $saveResult; |
56 | } catch (Exception $e) { | 57 | } catch (Exception $e) { |
57 | $transaction->rollBack(); | 58 | $transaction->rollBack(); |
58 | - var_dump($e->getTraceAsString()); | ||
59 | return false; | 59 | return false; |
60 | } | 60 | } |
61 | } | 61 | } |
@@ -68,15 +68,27 @@ class Manufacturer | @@ -68,15 +68,27 @@ class Manufacturer | ||
68 | static function update($id, $item) | 68 | static function update($id, $item) |
69 | { | 69 | { |
70 | $manufacturerModel = ManufacturerModel::findOne($id); | 70 | $manufacturerModel = ManufacturerModel::findOne($id); |
71 | + if (empty($manufacturerModel)) { | ||
72 | + return false; | ||
73 | + } | ||
74 | + $sysUserModel = SysUserModel::findOne($manufacturerModel->sys_user_id); | ||
75 | + if (empty($sysUserModel)) { | ||
76 | + return false; | ||
77 | + } | ||
71 | if (isset($item['name']) && !empty($item['name'])) { | 78 | if (isset($item['name']) && !empty($item['name'])) { |
72 | $manufacturerModel->name = $item['name']; | 79 | $manufacturerModel->name = $item['name']; |
73 | } | 80 | } |
74 | if (isset($item['phone'])) { | 81 | if (isset($item['phone'])) { |
75 | $manufacturerModel->phone = $item["phone"]; // 厂商电话 | 82 | $manufacturerModel->phone = $item["phone"]; // 厂商电话 |
76 | } | 83 | } |
84 | + | ||
77 | $manufacturerModel->save(); | 85 | $manufacturerModel->save(); |
78 | 86 | ||
79 | - return $manufacturerModel; | 87 | + $sysUserModel->username = $item['username']; |
88 | + $sysUserModel->password = $item['password']; | ||
89 | + $resultSave = $sysUserModel->save(); | ||
90 | + | ||
91 | + return $resultSave; | ||
80 | } | 92 | } |
81 | 93 | ||
82 | /** | 94 | /** |
domain/manufacturer/ManufacturerRepository.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace domain\manufacturer; | 3 | namespace domain\manufacturer; |
4 | 4 | ||
5 | -use common\models\SysUser; | 5 | +use common\models\SysUser as SysUserModel; |
6 | use domain\manufacturer\models\Manufacturer as ManufacturerModel; | 6 | use domain\manufacturer\models\Manufacturer as ManufacturerModel; |
7 | 7 | ||
8 | 8 | ||
@@ -27,7 +27,7 @@ class ManufacturerRepository | @@ -27,7 +27,7 @@ class ManufacturerRepository | ||
27 | "su.username", | 27 | "su.username", |
28 | "su.password_hash" | 28 | "su.password_hash" |
29 | ]); | 29 | ]); |
30 | - $manufacturerFind->leftJoin(SysUser::tableName() . " su", "su.id = m.sys_user_id"); | 30 | + $manufacturerFind->leftJoin(SysUserModel::tableName() . " su", "su.id = m.sys_user_id"); |
31 | 31 | ||
32 | if (!empty($where)) { | 32 | if (!empty($where)) { |
33 | $manufacturerFind->where($where); | 33 | $manufacturerFind->where($where); |
@@ -53,7 +53,7 @@ class ManufacturerRepository | @@ -53,7 +53,7 @@ class ManufacturerRepository | ||
53 | static function getPageCount($map = '') | 53 | static function getPageCount($map = '') |
54 | { | 54 | { |
55 | $manufacturerFind = ManufacturerModel::find()->alias("m"); | 55 | $manufacturerFind = ManufacturerModel::find()->alias("m"); |
56 | - $manufacturerFind->leftJoin(SysUser::tableName() . " su", "su.id = m.sys_user_id"); | 56 | + $manufacturerFind->leftJoin(SysUserModel::tableName() . " su", "su.id = m.sys_user_id"); |
57 | if (!empty($map)) { | 57 | if (!empty($map)) { |
58 | $manufacturerFind->where($map); | 58 | $manufacturerFind->where($map); |
59 | } | 59 | } |
@@ -75,4 +75,37 @@ class ManufacturerRepository | @@ -75,4 +75,37 @@ class ManufacturerRepository | ||
75 | } | 75 | } |
76 | return $manufacturer; | 76 | return $manufacturer; |
77 | } | 77 | } |
78 | + | ||
79 | + /** | ||
80 | + * @param $id | ||
81 | + * @param bool|false $asArr | ||
82 | + * @return null|static | ||
83 | + */ | ||
84 | + static function selectInfoById($id, $asArr = false) | ||
85 | + { | ||
86 | + if (empty($id)) { | ||
87 | + return $asArr ? [] : null; | ||
88 | + } | ||
89 | + $manufacturer = ManufacturerModel::find(); | ||
90 | + $manufacturer->alias("mf"); | ||
91 | + $manufacturer->select(["mf.*", "su.username"]); | ||
92 | + $manufacturer->leftJoin(SysUser::tableName() . " su", "su.id = mf.sys_user_id"); | ||
93 | + $manufacturer->where("mf.id = " . $id); | ||
94 | + if ($asArr && $manufacturer) { | ||
95 | + $manufacturer = $manufacturer->asArray(); | ||
96 | + } | ||
97 | + $resultData = $manufacturer->one(); | ||
98 | + return $resultData; | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * @param $id | ||
103 | + * @param bool|false $asArr | ||
104 | + * @return null|static | ||
105 | + */ | ||
106 | + static function findOne($condition) | ||
107 | + { | ||
108 | + $manufacturer = ManufacturerModel::findOne($condition); | ||
109 | + return $manufacturer; | ||
110 | + } | ||
78 | } | 111 | } |
79 | \ No newline at end of file | 112 | \ No newline at end of file |