render('index'); } /** * Function Description:品牌列表 * Function Name: actionList * * @return string * * @author 温依莅 */ public function actionBrandList() { \Yii::$app->view->title = '品牌管理'; //品牌列表 $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->orderBy(['update_time' => SORT_DESC])->all(); return $this->render('brand-list', ['brandList' => $brand_list]); } /** * Function Description:品牌增加 * Function Name: actionBrandAdd * * @return string * * @author 温依莅 */ public function actionBrandAdd() { $request = Yii::$app->request; $user_id=$request->cookies->getValue('user_id',0); $res_name = $request->post('res_name', ''); if ($res_name == '') { $json["code"] = '1'; $json["info"] = '品牌名不能为空'; return json_encode($json); } try { //1判断是否存在res_name相同的选项,如果存在 $brand = BaseResource::find()->where(['res_type_id' => 134, 'res_name' => $res_name])->one(); if (!is_null($brand)) { #1.1如果cancel_flag为0,则返回提示,已有该品牌 if ($brand->CANCEL_FLAG == 0) { $json["code"] = '1'; $json["info"] = '已有该品牌,请勿重复提交'; return json_encode($json); } else if ($brand->CANCEL_FLAG == 1) { #1.2如果cancel_flag为1,则将该res_name的cancel_flag置为0 $brand->CANCEL_FLAG=0; $brand->UPDATE_TIME=date('Y-m-d H:i:s', time()); $brand->UPDATE_USER_ID=$user_id; if(!$brand->update()){ throw new Exception($brand->getErrors()); } } } else { //2若不存在res_name相同的选项,则插入新数据 #目前最大的res_id值,加1 $new_res_id=BaseResource::find()->max('res_id')+1; $values= [ 'RES_ID' => $new_res_id, 'RES_NAME' => $res_name, 'CREATE_USER_ID' => $user_id, 'CANCEL_FLAG' => 0, 'RES_TYPE_ID' => 134, 'CREATE_TIME' => date('Y-m-d H:i:s', time()), 'UPDATE_TIME' => date('Y-m-d H:i:s', time()), ]; $new_brand=new BaseResource; $new_brand->attributes = $values; if(!$new_brand->insert()){ throw new Exception($new_brand->getErrors()); } } } catch (\Exception $e) { $json["code"] = '1'; $json["info"] = '品牌增加失败'; $json["error_info"] = $e->getMessage(); return json_encode($json); } $json["code"] = '0'; $json["info"] = '品牌添加成功'; return json_encode($json); } /** * Function Description:品牌删除 * Function Name: actionBrandDelete * * @return string * * @author 温依莅 */ public function actionBrandDelete() { $request = Yii::$app->request; $res_id= $request->post('res_id', ''); $brand = new BaseResource(); $res = $brand->baseDeleteBrand($res_id); return json_encode($res); } /** * Function Description:品牌修改 * Function Name: actionBrandAdd * * @return string * * @author 温依莅 */ public function actionBrandModify() { $request = Yii::$app->request; $res_id= $request->post('res_id', ''); $res_name = $request->post('res_name', ''); $brand = new BaseResource(); $res = $brand->baseUpdateBrand($res_id,$res_name); return json_encode($res); } /** * Function Description:车型增加 * Function Name: actionCarSortAdd * * @return string * * @author 温依莅 */ public function actionCarSortAdd(){ $request = Yii::$app->request; $car_sort_name= $request->post('car_sort_name', ''); $car_seat_num = $request->post('car_seat_num', ''); $car = new BaseResource(); $res = $car->CarSortAdd($car_sort_name,$car_seat_num); return json_encode($res); } /** * Function Description:车型删除 * Function Name: actionCarSortDelete * * @return string * * @author 温依莅 */ public function actionCarSortDelete() { $request = Yii::$app->request; $res_id= $request->post('res_id', ''); $carSort = new BaseResource(); $res = $carSort->baseDeleteCar($res_id); return json_encode($res); } /** * Function Description:车型列表 * Function Name: actionCarList * * @return string * * @author 温依莅 */ public function actionCarList() { \Yii::$app->view->title = '车型管理'; //车型列表 $car_list = BaseResource::find()->select(['a.res_id', 'a.res_name','b.id','b.type_name'])->from('base_resource a')->leftJoin('dict_type as b', 'a.parent_id=b.id')->where(['a.res_type_id' => 69,'b.parent_id'=>71,'cancel_flag' => 0])->orderBy(['update_time'=>SORT_DESC])->asArray()->all(); return $this->render('car-list', ['carList' => $car_list]); } /** * Function Description:获取渠道商列表 * Function Name: actionGetSupplier * * @return string * * @author 娄梦宁 */ public function actionGetSupplierList(){ $base_supplier=new BaseSupplier(); $result=$base_supplier->getChannelList(); return json_encode( ['code'=>0,'list'=>$result] ); } }