| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace hd\controllers;
- use bizHd\admin\classes\AddressClass;
- use Yii;
- use common\components\util;
- class AddressController extends BaseController
- {
- //详情 ssh 20221003
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $address = AddressClass::getById($id, true);
- if (empty($address)) {
- util::fail('没有找到地址');
- }
- if ($address->mainId != $this->mainId) {
- util::fail('没有权限');
- }
- util::success(['info' => $address]);
- }
- //删除地址 ssh 202201003
- public function actionDel()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $address = AddressClass::getById($id, true);
- if (empty($address)) {
- util::fail('没有找到地址');
- }
- if ($address->mainId != $this->mainId) {
- util::fail('没有权限');
- }
- $address->delete();
- util::complete('删除成功');
- }
- //地址列表 ssh 20221003
- public function actionList()
- {
- //$get = Yii::$app->request->get();
- $where = ['adminId' => $this->adminId];
- $list = AddressClass::getAddressList($where);
- util::success($list);
- }
- //地址列表 ssh 20221003
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['mainId'] = $this->mainId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $default = $post['default'] ?? 0;
- if ($default == 1) {
- AddressClass::updateByCondition(['adminId' => $this->adminId], ['default' => 0]);
- }
- AddressClass::addData($post);
- util::complete('添加成功');
- }
- //修改地址 ssh 20221003
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- unset($post['id']);
- $address = AddressClass::getById($id, true);
- if (empty($address)) {
- util::fail('没有找到地址');
- }
- if ($address->mainId != $this->mainId) {
- util::fail('没有权限修改');
- }
- $default = $post['default'] ?? 0;
- if ($default == 1) {
- AddressClass::updateByCondition(['adminId' => $this->adminId], ['default' => 0]);
- }
- AddressClass::updateById($id, $post);
- util::complete('修改成功');
- }
- }
|