public function actionDelete() { $id = Yii::$app->request->post('id'); if (!intval($id)) { Error::output(Error::ERR_NOID); } $model = $this->findModel($id); if ($model->delete()) { Error::output(Error::SUCCESS); } else { Error::output(Error::ERR_FAIL); } }
public function actionSyncMenus() { //首先查询出所有数据 $menus = CustomMenus::find()->where(['public_id' => $this->pid])->orderBy(['order_id' => SORT_ASC])->asArray()->all(); if (empty($menus)) { Error::output(Error::ERR_NO_MENUS); } //构造菜单结构体 $buttons = []; foreach ($menus as $k => $v) { $item = ['name' => $v['title'], 'type' => $v['type']]; if ($v['type'] == 'view') { $item['url'] = $v['url']; } else { $item['key'] = $v['keyword']; } if (!empty($v['fid'])) { $buttons[$v['fid']]['sub_button'][] = $item; } else { $buttons[$v['id']] = $item; } } //对于一级菜单,如果存在子菜单,把不必要的参数去除掉 foreach ($buttons as $k => &$v) { if (array_key_exists('sub_button', $v) && !empty($v['sub_button'])) { unset($v['type'], $v['key'], $v['url']); } } //提交到微信接口同步 $ret = $this->wechat->createMenu(['button' => array_values($buttons)]); if ($ret === false) { Error::output(Error::ERR_SYNC_MENUS_FAIL); } Error::output(Error::SUCCESS); }