| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Http\Controllers\AdminApi;
- use App\Models\SysModels\Config;
- use App\Http\Controllers\AdminController;
- class ConfigController extends AdminController
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 获取&更新消费金奖励规则
- * @return \Illuminate\Http\JsonResponse
- */
- function setConsume(){
- if(request()->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;
- }
- }
|