| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\jobs\storeSync\DiyCommon;
- use app\models\NewIntegralCat;
- use app\models\NewIntegralSetting;
- use app\models\StoreSyncExtLog;
- class IntegralController extends BaseController
- {
- /**
- * 添加修改积分分类
- */
- public function actionCatSave()
- {
- $id = post_params('id');
- $store_id = get_store_id();
- if ($id > 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);
- }
- }
- }
|