IntegralController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\jobs\storeSync\DiyCommon;
  9. use app\models\NewIntegralCat;
  10. use app\models\NewIntegralSetting;
  11. use app\models\StoreSyncExtLog;
  12. class IntegralController extends BaseController
  13. {
  14. /**
  15. * 添加修改积分分类
  16. */
  17. public function actionCatSave()
  18. {
  19. $id = post_params('id');
  20. $store_id = get_store_id();
  21. if ($id > 0) {
  22. $model = NewIntegralCat::findOne(['id' => $id, 'store_id' => $store_id]);
  23. $model->updated_at = time();
  24. } else {
  25. $model = new NewIntegralCat();
  26. $model->created_at = time();
  27. }
  28. $model->name = post_params('name');
  29. $model->is_enable = post_params('status');
  30. $model->sort = post_params('sort',999);
  31. $model->store_id = $store_id;
  32. if (!$model->save()) {
  33. $data = [
  34. 'code' => 1,
  35. 'msg' => '保存失败'
  36. ];
  37. }else{
  38. $data = [
  39. 'code' => 0,
  40. 'msg' => '保存成功'
  41. ];
  42. }
  43. return $this->asJson($data);
  44. }
  45. /**
  46. * 积分分类列表
  47. */
  48. public function actionCatList(){
  49. $store_id = get_store_id();
  50. $name = post_params('name');
  51. $status = post_params('status',0);
  52. $query = NewIntegralCat::find()->where(['store_id'=>$store_id,'is_delete'=>0]);
  53. if(!empty($name)){
  54. $query->andWhere(['like','name',$name]);
  55. }
  56. if($status == 1){
  57. $query->andWhere(['is_enable'=>1]);
  58. }
  59. if($status == 2){
  60. $query->andWhere(['is_enable'=>0]);
  61. }
  62. $query->orderBy(['sort'=>SORT_ASC]);
  63. $list = pagination_make($query);
  64. return $this->asJson([
  65. 'code' => 0,
  66. 'msg' => 'success',
  67. 'data' => [
  68. 'data' => $list['list'],
  69. 'pageNo' => $list['pageNo'],
  70. 'totalCount' => $list['totalCount'],
  71. ]
  72. ]);
  73. }
  74. /**
  75. * 积分分类列表
  76. */
  77. public function actionCatAll(){
  78. $store_id = get_store_id();
  79. $query = NewIntegralCat::find()->where(['store_id'=>$store_id,'is_delete'=>0,'is_enable'=>1]);
  80. $list = $query->orderBy(['sort'=>SORT_ASC])->asArray()->all();
  81. return $this->asJson([
  82. 'code' => 0,
  83. 'msg' => 'success',
  84. 'data' => [
  85. 'data' => $list
  86. ]
  87. ]);
  88. }
  89. /**
  90. * 修改分类状态
  91. */
  92. public function actionCatStatus(){
  93. $ids = post_params('ids');
  94. $status = post_params('status');
  95. $store_id = get_store_id();
  96. if(empty($ids)){
  97. return $this->asJson([
  98. 'code' => 1,
  99. 'msg' => '请检查参数信息'
  100. ]);
  101. }
  102. $statusInfo = NewIntegralCat::updateAll(['is_enable'=>$status],['id'=>$ids,'store_id'=>$store_id]);
  103. if($statusInfo){
  104. if (count($ids) === 1) {
  105. (new DiyCommon)->JobBehaviors($store_id, StoreSyncExtLog::TYPE_INTEGRAL_STORE, [$this->id]);
  106. }
  107. $data = [
  108. 'code' => 0,
  109. 'msg' => '修改成功'
  110. ];
  111. }else{
  112. $data = [
  113. 'code' => 1,
  114. 'msg' => '修改失败'
  115. ];
  116. }
  117. return $this->asJson($data);
  118. }
  119. /**
  120. * 删除分类
  121. */
  122. public function actionCatDel(){
  123. $ids = post_params('ids');
  124. $store_id = get_store_id();
  125. if(empty($ids)){
  126. return $this->asJson([
  127. 'code' => 1,
  128. 'msg' => '请传入id'
  129. ]);
  130. }
  131. $is_int = true;
  132. foreach($ids as $val){
  133. if(!is_numeric($val) || strpos($val,".")!==false){
  134. $is_int = false;
  135. }
  136. }
  137. if(!$is_int){
  138. return $this->asJson([
  139. 'code' => 1,
  140. 'msg' => '数据类型有误!'
  141. ]);
  142. }
  143. $delInfo = NewIntegralCat::updateAll(['is_delete'=>1],['id'=>$ids,'store_id'=>$store_id]);
  144. if($delInfo){
  145. if (count($ids) === 1) {
  146. (new DiyCommon)->JobBehaviors($store_id, StoreSyncExtLog::TYPE_INTEGRAL_STORE, [$this->id]);
  147. }
  148. $data = [
  149. 'code' => 0,
  150. 'msg' => '删除成功'
  151. ];
  152. }else{
  153. $data = [
  154. 'code' => 1,
  155. 'msg' => '删除失败'
  156. ];
  157. }
  158. return $this->asJson($data);
  159. }
  160. /**
  161. * 积分设置
  162. */
  163. public function actionSetting(){
  164. $polling_img = post_params('polling');
  165. $explain = post_params('explain');
  166. $store_id = get_store_id();
  167. $request = \Yii::$app->request;
  168. //获取
  169. if ($request->isGet){
  170. $settingInfo = NewIntegralSetting::find()->where(['store_id'=>$store_id])->asArray()->one();
  171. if($settingInfo){
  172. $data = [
  173. 'code' => 0,
  174. 'msg' => '获取成功',
  175. 'data' =>[
  176. 'polling' => json_decode($settingInfo['polling_img'],true) ?: [] ,
  177. 'explain' => $settingInfo['explain'] ?: ''
  178. ]
  179. ];
  180. } else {
  181. $data = [
  182. 'code' => 0,
  183. 'msg' => '暂未设置',
  184. 'data' => [
  185. 'polling' => [],
  186. 'explain' => ''
  187. ]
  188. ];
  189. }
  190. return $this->asJson($data);
  191. }
  192. //保存
  193. if ($request->isPost){
  194. if(empty($polling_img) ){
  195. $data = [
  196. 'code' => 1,
  197. 'msg' => '轮播图为必填项!'
  198. ];
  199. return $this->asJson($data);
  200. }
  201. if(empty($explain) ){
  202. $data = [
  203. 'code' => 1,
  204. 'msg' => '说明信息为必填项!'
  205. ];
  206. return $this->asJson($data);
  207. }
  208. $settingInfo = NewIntegralSetting::find()->where(['store_id'=>$store_id])->one();
  209. if(empty($settingInfo)){
  210. $settingInfo = new NewIntegralSetting();
  211. $settingInfo->created_at = time();
  212. }
  213. $settingInfo->store_id = $store_id;
  214. $settingInfo->polling_img = json_encode($polling_img);
  215. $settingInfo->explain = $explain;
  216. if($settingInfo->save()){
  217. $data = [
  218. 'code' => 0,
  219. 'msg' => '保存成功',
  220. ];
  221. }else{
  222. $data = [
  223. 'code' => 1,
  224. 'msg' => '保存失败',
  225. ];
  226. }
  227. return $this->asJson($data);
  228. }
  229. }
  230. }