| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /**
- * 花店物流选项管理
- * 用途:配送方式-物流(style=3)关联的物流名称维护,与 ghs 端 WlClass 共用主账号维度数据
- */
- namespace hd\controllers;
- use bizGhs\merchant\classes\WlClass;
- use Yii;
- use common\components\util;
- class WlController extends BaseController
- {
- /** 获取全部物流(下拉用) */
- public function actionGetAllWl()
- {
- $list = WlClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], 'inTurn DESC', 'id,name');
- util::success(['list' => $list]);
- }
- /** 物流列表(分页) */
- public function actionList()
- {
- $where = ['mainId' => $this->mainId, 'delStatus' => 0];
- $list = WlClass::getWlList($where);
- util::success($list);
- }
- /** 删除物流 */
- public function actionDelWl()
- {
- $id = Yii::$app->request->get('id', 0);
- $wl = WlClass::getById($id, true);
- if (empty($wl)) {
- util::fail('没有物流信息');
- }
- if ($wl->mainId != $this->mainId) {
- util::fail('无法操作');
- }
- $wl->delStatus = 1;
- $wl->save();
- util::complete();
- }
- /** 添加物流 */
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $post['mainId'] = $this->mainId ?? 0;
- $name = trim($post['name'] ?? '');
- if (empty($name)) {
- util::fail('请填写名称');
- }
- $has = WlClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true);
- if (!empty($has)) {
- $has->delStatus = 0;
- $has->save();
- } else {
- WlClass::add($post);
- }
- util::complete('添加成功');
- }
- /** 更新物流 */
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- $name = trim($post['name'] ?? '');
- $inTurn = $post['inTurn'] ?? 100;
- $id = $post['id'] ?? 0;
- $pre = WlClass::getById($id, true);
- if (empty($pre)) {
- util::fail('修改失败');
- }
- if ($pre->mainId != $this->mainId) {
- util::fail('没有权限修改');
- }
- if ($name != $pre->name) {
- $repeat = WlClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true);
- if (!empty($repeat)) {
- util::fail('名称已经存在');
- }
- }
- $pre->name = $name;
- $pre->inTurn = $inTurn;
- $pre->save();
- util::complete();
- }
- }
|