request; if ($request->isGet){ $result=axios_request(); $table= (new \yii\db\Query()) ->select('id, sort,name,attr_str,display') ->from('{{%ybwm_attribute}}'); if($result['id']){ $re=$table->where(['id'=>$result['id']])->one(); $re['attr_str']=json_decode($re['attr_str'],true); }else{ $re=$table->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$this->wqData['storeId']])->all(); foreach ($re as $k=>$v){ $re[$k]['attr_str']=json_decode($v['attr_str'],true); } } echo json_encode(['code'=>1,'msg'=>'成功','data'=>$re]); } } public function actionAttrSave(){ $request = Yii::$app->request; if ($request->isPost){ $shop_id=Store::getMainStore($this->wqData['uniacid'])['id']; if(!$shop_id){ return $this->result(3,'无效的门店,请先添加商店');die; } $result=axios_request(); $storeId=$result['storeId']?:$this->wqData['storeId']; $data=array( 'sort'=>$result['sort'], 'name'=>trim($result['name']), 'attr_str'=>json_encode($result['attr_str'],JSON_UNESCAPED_UNICODE), 'display'=>1, 'uniacid'=>$this->wqData['uniacid'], 'storeId'=>$storeId, ); if($result['id']){ $res=YII::$app->db->createCommand()->update('{{%ybwm_attribute}}',$data, 'id=:id', ['id' =>$result['id']])->execute(); }else{ $data['createdAt']=time(); $row= (new \yii\db\Query()) ->from('{{%ybwm_attribute}}') ->where(['uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId,'name'=>trim($result['name'])]) ->one(); if($row){ return $this->result(2,'属性名已存在'); } $res=Yii::$app->db->createCommand()->insert('{{%ybwm_attribute}}', $data)->execute(); } if($res!==false){ return $this->result(1,'操作成功'); }else{ return $this->result(2,'网络异常,请稍后再试'); } } } public function actionChangeAttr(){ $request = Yii::$app->request; if ($request->isPost){ $result=axios_request(); $re = YII::$app->db->createCommand()->update('{{%ybwm_attribute}}', ['display'=>$result['display']],'id=:id', ['id' =>$result['id']])->execute(); if($re){ return $this->result(1,'成功'); }else{ return $this->result(2,'网络异常,请稍后再试'); } } } public function actionAttrDel(){ $request = Yii::$app->request; if ($request->isPost){ $result=axios_request(); if(is_array($result['id'])){ $re=YII::$app->db->createCommand()->delete('{{%ybwm_attribute}}', ['in','id',$result['id']])->execute(); }else { $re = YII::$app->db->createCommand()->delete('{{%ybwm_attribute}}', 'id=:id', ['id' => $result['id']])->execute(); } if($re!==false){ return $this->result(1,'成功'); }else{ return $this->result(2,'网络异常,请稍后再试'); } } } }