isMethod('post')){ $data = request()->all(); //更新config数据 $this->update($data); return $this->apiResponseSuccess('更新成功'); }else{ $configs = Config::whereIn('key',['consume_money','consume_for','consume_give'])->pluck('value','key'); return $this->apiResponseSuccess('获取成功',$configs); } } /** *获取&更新振合豆使用规则 * @return \Illuminate\Http\JsonResponse */ function setBean(){ if(request()->isMethod('post')){ $data = request()->all(); //金额固定为1 $data['use_bean'] = 1; $data['bean_money'] = 1; //更新config数据 $this->update($data); return $this->apiResponseSuccess('更新成功'); }else{ $configs = Config::whereIn('key',['is_bean','bean_money','bean_give','use_bean','offset_bean_money','is_bean_expense'])->pluck('value','key'); return $this->apiResponseSuccess('获取成功',$configs); } } /** * 更新config数据 * @param $data * @return bool */ function update($data){ foreach ($data as $key => $value ){ // 查找当前数据是否存在 if( Config::where('key', $key)->where('value', $value)->count() ){ continue; } Config::where('key', $key)->update([ 'value' => $value ]); } return true; } }