get_store_id() ]); if (!$model) { $model = new PondSetting(); } if (\Yii::$app->request->isPost) { $form = new PondSettingForm(); $form->store_id = get_store_id(); $form->model = $model; $data = post_params(); $form->rule = $data['rule']; $form->start_time = $data['start_time']; $form->end_time = $data['end_time']; $form->integral = $data['integral']; $result = $form->save(); if ($result['code'] === 0) { Option::set(OptionSetting::WEB_KF_WECHAT_IMG, $data['kf_wechat_img'], get_store_id(), 'display'); } return $this->asJson($result); } $model = ArrayHelper::toArray($model); $model['kf_wechat_img'] = Option::get(OptionSetting::WEB_KF_WECHAT_IMG, get_store_id(), 'display')['value']; return $this->asJson([ 'code' => 0, 'data' => [ 'setting' => $model ], ]); } public function actionEdit() { $query = Pond::find() ->where([ 'store_id' => get_store_id(), ])->with(['gift' => function ($query) { $query->where([ 'store_id' => get_store_id(), 'is_delete' => 0 ]); }]) ->orderBy('id ASC'); $list = $this->simplifyData($query->all()) ? $this->simplifyData($query->all()) : []; return $this->asJson([ 'code' => 0, 'data' => $list ]); } protected function simplifyData($data) { foreach ($data as $key => $val) { $newData[$key] = $val->attributes; if ($val->gift) { $newData[$key]['gift'] = $val->gift->attributes['name']; $newData[$key]['gift_img_url'] = $val->gift->attributes['cover_pic']; } } return $newData; } public function actionSubmit() { $data = post_params('data'); if (!is_array($data)) { return $this->asJson([ 'code' => 1, 'msg' => '格式不正确', ]); } //处理保存后 前端不刷新 一直点击添加导致的问题 if (count($data) >= 6) { Pond::deleteAll(['store_id' => get_store_id()]); } if ($data) { $pond_data_type = array_column($data, 'type'); if (!in_array(1, $pond_data_type)) { return $this->asJson([ 'code' => 1, 'msg' => '至少设置一个谢谢惠顾奖', ]); } } foreach ($data as $v) { $model = Pond::findOne($v['id']); if (!$model) { $model = new Pond(); } $form = new PondForm(); $form->store_id = get_store_id(); $form->model = $model; $form->name = $v['name']; $form->image_url = $v['image_url']; $form->winning_rate = $v['winning_rate']; $form->type = $v['type']; $form->stock = $v['stock']; $form->gift_id = $v['gift_id']; $form->user_id = $v['user_id']; $form->save(); } return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } }