| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace addons\Area\backend\controllers;
- use addons\Area\common\service\CommunityService;
- use common\enums\StatusEnum;
- /**
- * 社区
- */
- class CommunityController extends BaseController
- {
- public $enableCsrfValidation = false;
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- $data = \Yii::$app->request->get();
- if (!\Yii::$app->services->validate->validate($data, [
- [['keyword', 'address'], 'string'],
- [['page', 'limit', 'town_id'], 'integer'],
- ])) {
- return $this->error(\Yii::$app->services->validate->getErrorMessage());
- }
- $ret = (new CommunityService())->page($this->mall_id, $data);
- return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
- }
- return $this->render('index');
- }
- /**
- * 不分页获取数据
- * @return mixed|void|null
- */
- public function actionList()
- {
- if (\Yii::$app->request->isAjax) {
- $data = \Yii::$app->request->get();
- if (!\Yii::$app->services->validate->validate($data, [
- [['town_id', 'is_district'], 'integer'],
- ])) {
- return $this->error(\Yii::$app->services->validate->getErrorMessage());
- }
- $ret = (new CommunityService())->list($this->mall_id, $data);
- return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
- }
- }
- public function actionCreate()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $data = \Yii::$app->request->get();
- if (!\Yii::$app->services->validate->validate($data, [
- [['id'], 'integer'],
- [['id'], 'required'],
- ])) {
- return $this->error(\Yii::$app->services->validate->getErrorMessage());
- }
- $ret = (new CommunityService())->fetch($this->mall_id, $data['id']);
- return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
- } else {
- $data = \Yii::$app->request->post();
- if (!\Yii::$app->services->validate->validate($data, [
- [['id', 'province_id', 'city_id', 'district_id', 'town_id'], 'integer'],
- [['community_name', 'province_id', 'city_id', 'district_id', 'lng', 'lat'], 'required'],
- [['lng', 'lat'], 'number'],
- [['community_name', 'street', 'fully_address'], 'string'],
- [['addressComponents'], 'safe']
- ])) {
- return $this->error(\Yii::$app->services->validate->getErrorMessage());
- }
- $ret = (new CommunityService())->create($this->mall_id, $data);
- return is_string($ret) ? $this->error($ret) : $this->success('操作成功', $ret);
- }
- }
- return $this->render('create');
- }
- /**
- * 更改状态
- * @return mixed|null
- */
- public function actionStatus()
- {
- $data = \Yii::$app->request->post();
- if (!\Yii::$app->services->validate->validate($data, [
- [['id', 'status'], 'integer'],
- [['id', 'status'], 'required'],
- [['status'], 'in', 'range' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]
- ])) {
- return $this->error(\Yii::$app->services->validate->getErrorMessage());
- }
- $ret = (new CommunityService())->status($this->mall_id, $data['id'], $data['status']);
- return is_string($ret) ? $this->error($ret) : $this->success();
- }
- /**
- * 删除记录行
- * @return mixed|null
- */
- public function actionDelete()
- {
- $data = \Yii::$app->request->post();
- if (!\Yii::$app->services->validate->validate($data, [
- [['id'], 'integer'],
- [['id'], 'required'],
- ])) {
- return $this->error(\Yii::$app->services->validate->getErrorMessage());
- }
- $ret = (new CommunityService())->delete($this->mall_id, $data['id']);
- return is_string($ret) ? $this->error($ret) : $this->success();
- }
- }
|