service = new ApplyService(); } public function actionIndex(){ if(!Yii::$app->request->isAjax){ return $this->render('index'); } $data = $this->service->getApply($this->mall_id); return $this->success('ok',$data); } /** * 编辑审核 * @desc * @return mixed|void * @throws \yii\db\Exception */ public function actionEdit(){ $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; if($id > 0){ $post['status'] = 1; $post['reason'] = ''; $model = Apply::findOne($id); }else{ $model = new Apply(); } if($model->isNewRecord){ $post['deal_sn'] = date('YmdHis').rand(1000,9999); } $post['mall_id'] = $this->mall_id; $db = Yii::$app->db->beginTransaction(); if( !($model->load($post,'') && $model->validate() && $model->save()) ){ return $this->error($model->getFirstErrors()); } $service = new ApplyService(); $result = $service->apply($this->mall_id,$model); if($result){ $db->commit(); return $this->success('提交成功,请等待审核'); }else{ $db->rollBack(); return $this->error($service->error); } } }