model(); $table->title('包邮设置'); $table->key('id'); $table->eventName(md5(get_called_class()));//设置事件名,后面更改数据对应 $table->url(\Yii::$app->urlManager->createUrl("system/free-rule/list")); $table->filter('规则名称', 'name',false)->text('请输入配置名')->quick(); $table->action()->button('添加', $this->createUrl('system/free-rule/edit')); $table->column('规则名称','name'); $table->column('包邮类型','typeText'); $table->column('是否默认','status')->status(['否','是'],['gray','red']); $column = $table->column('操作')->width(200); $column->link('设为默认',$this->createUrl('system/free-rule/status'), ['id' => 'id'])->type('ajax', ['method' => 'post']); $column->link('编辑', $this->createUrl('system/free-rule/edit'), ['id' => 'id']); $column->link('删除', $this->createUrl('system/free-rule/del'), ['id' => 'id'])->type('ajax', ['method' => 'post']); return $table->renderArray(); } public function actionEdit(){ return $this->render('edit'); } public function actionStatus(){ $params = $this->requestValidate($this->get(),[ ['id','required'], ['id','integer'] ]); $this->callbackEvent([],'id','refresh'); return FreeDeliveryRules::setStatus($params->id); } public function actionInfo(){ $id = $this->get('id'); $model = FreeDeliveryRules::findOne([ 'is_delete' => 0, 'mall_id' => \Yii::$app->mallId, 'id' => $id ]); if (!$model) { $model = new FreeDeliveryRules(); $model->mall_id = \Yii::$app->mallId; } else { $model->detail = $model->decodeDetail(); } return [ 'model' => $model, ]; } public function actionEditSave(){ $id = $this->get('id'); $model = FreeDeliveryRules::findOne([ 'is_delete' => 0, 'mall_id' => \Yii::$app->mallId, 'id' => $id ]); if (!$model) { $model = new FreeDeliveryRules(); $model->mall_id = \Yii::$app->mallId; } else { $model->detail = $model->decodeDetail(); } $form = new FreeRuleEditForm(); $form->attributes = \Yii::$app->request->post('form'); $form->model = $model; return $form->save(); } public function actionList() { $commonSearch = new CommonSearch(['name']); $commonSearch->setQuery(FreeDeliveryRules::find() ->select(['id', 'name', 'type','status']) ->where(['mall_id'=>\Yii::$app->mallId])->andWhere(['is_delete'=>0])); $commonSearch->additionRules = [ ['name', 'string'] ]; $commonSearch->bindFilter(function(/** @var ActiveQuery $q */ $q) { $q->andFilterWhere(['like','name',$this->name]); }); $this->field = [ FreeDeliveryRules::class=>[ 'id','name','type','status','typeText' ] ]; return $commonSearch->search($this->get()); } public function actionAllList(){ $allList = FreeDeliveryRules::find()->where([ 'is_delete' => 0, 'mall_id' => \Yii::$app->mallId, ])->select('id as value,name as label')->asArray()->all(); foreach ($allList as &$v){ $v['value'] = (int)$v['value']; } unset($v); array_unshift($allList, [ 'value' => 0, 'label' => '默认包邮规则' ]); return [ 'list' => $allList ]; } public function actionDel(){ $id = $this->get('id'); if(FreeDeliveryRules::updateAll(['is_delete'=>1],['id'=>$id,'mall_id'=>\Yii::$app->mallId])){ $this->callbackEvent([],'id','refresh'); return []; }else{ throw new ApiException("删除失败"); } } }