0) { $model = NewIntegralCat::findOne(['id' => $id, 'store_id' => $store_id]); $model->updated_at = time(); } else { $model = new NewIntegralCat(); $model->created_at = time(); } $model->name = post_params('name'); $model->is_enable = post_params('status'); $model->sort = post_params('sort',999); $model->store_id = $store_id; if (!$model->save()) { $data = [ 'code' => 1, 'msg' => '保存失败' ]; }else{ $data = [ 'code' => 0, 'msg' => '保存成功' ]; } return $this->asJson($data); } /** * 积分分类列表 */ public function actionCatList(){ $store_id = get_store_id(); $name = post_params('name'); $status = post_params('status',0); $query = NewIntegralCat::find()->where(['store_id'=>$store_id,'is_delete'=>0]); if(!empty($name)){ $query->andWhere(['like','name',$name]); } if($status == 1){ $query->andWhere(['is_enable'=>1]); } if($status == 2){ $query->andWhere(['is_enable'=>0]); } $query->orderBy(['sort'=>SORT_ASC]); $list = pagination_make($query); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 积分分类列表 */ public function actionCatAll(){ $store_id = get_store_id(); $query = NewIntegralCat::find()->where(['store_id'=>$store_id,'is_delete'=>0,'is_enable'=>1]); $list = $query->orderBy(['sort'=>SORT_ASC])->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list ] ]); } /** * 修改分类状态 */ public function actionCatStatus(){ $ids = post_params('ids'); $status = post_params('status'); $store_id = get_store_id(); if(empty($ids)){ return $this->asJson([ 'code' => 1, 'msg' => '请检查参数信息' ]); } $statusInfo = NewIntegralCat::updateAll(['is_enable'=>$status],['id'=>$ids,'store_id'=>$store_id]); if($statusInfo){ if (count($ids) === 1) { (new DiyCommon)->JobBehaviors($store_id, StoreSyncExtLog::TYPE_INTEGRAL_STORE, [$this->id]); } $data = [ 'code' => 0, 'msg' => '修改成功' ]; }else{ $data = [ 'code' => 1, 'msg' => '修改失败' ]; } return $this->asJson($data); } /** * 删除分类 */ public function actionCatDel(){ $ids = post_params('ids'); $store_id = get_store_id(); if(empty($ids)){ return $this->asJson([ 'code' => 1, 'msg' => '请传入id' ]); } $is_int = true; foreach($ids as $val){ if(!is_numeric($val) || strpos($val,".")!==false){ $is_int = false; } } if(!$is_int){ return $this->asJson([ 'code' => 1, 'msg' => '数据类型有误!' ]); } $delInfo = NewIntegralCat::updateAll(['is_delete'=>1],['id'=>$ids,'store_id'=>$store_id]); if($delInfo){ if (count($ids) === 1) { (new DiyCommon)->JobBehaviors($store_id, StoreSyncExtLog::TYPE_INTEGRAL_STORE, [$this->id]); } $data = [ 'code' => 0, 'msg' => '删除成功' ]; }else{ $data = [ 'code' => 1, 'msg' => '删除失败' ]; } return $this->asJson($data); } /** * 积分设置 */ public function actionSetting(){ $polling_img = post_params('polling'); $explain = post_params('explain'); $store_id = get_store_id(); $request = \Yii::$app->request; //获取 if ($request->isGet){ $settingInfo = NewIntegralSetting::find()->where(['store_id'=>$store_id])->asArray()->one(); if($settingInfo){ $data = [ 'code' => 0, 'msg' => '获取成功', 'data' =>[ 'polling' => json_decode($settingInfo['polling_img'],true) ?: [] , 'explain' => $settingInfo['explain'] ?: '' ] ]; } else { $data = [ 'code' => 0, 'msg' => '暂未设置', 'data' => [ 'polling' => [], 'explain' => '' ] ]; } return $this->asJson($data); } //保存 if ($request->isPost){ if(empty($polling_img) ){ $data = [ 'code' => 1, 'msg' => '轮播图为必填项!' ]; return $this->asJson($data); } if(empty($explain) ){ $data = [ 'code' => 1, 'msg' => '说明信息为必填项!' ]; return $this->asJson($data); } $settingInfo = NewIntegralSetting::find()->where(['store_id'=>$store_id])->one(); if(empty($settingInfo)){ $settingInfo = new NewIntegralSetting(); $settingInfo->created_at = time(); } $settingInfo->store_id = $store_id; $settingInfo->polling_img = json_encode($polling_img); $settingInfo->explain = $explain; if($settingInfo->save()){ $data = [ 'code' => 0, 'msg' => '保存成功', ]; }else{ $data = [ 'code' => 1, 'msg' => '保存失败', ]; } return $this->asJson($data); } } }