ConfigController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers\AdminApi;
  3. use App\Models\SysModels\Config;
  4. use App\Http\Controllers\AdminController;
  5. class ConfigController extends AdminController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. /**
  12. * 获取&更新消费金奖励规则
  13. * @return \Illuminate\Http\JsonResponse
  14. */
  15. function setConsume(){
  16. if(request()->isMethod('post')){
  17. $data = request()->all();
  18. //更新config数据
  19. $this->update($data);
  20. return $this->apiResponseSuccess('更新成功');
  21. }else{
  22. $configs = Config::whereIn('key',['consume_money','consume_for','consume_give'])->pluck('value','key');
  23. return $this->apiResponseSuccess('获取成功',$configs);
  24. }
  25. }
  26. /**
  27. *获取&更新振合豆使用规则
  28. * @return \Illuminate\Http\JsonResponse
  29. */
  30. function setBean(){
  31. if(request()->isMethod('post')){
  32. $data = request()->all();
  33. //金额固定为1
  34. $data['use_bean'] = 1;
  35. $data['bean_money'] = 1;
  36. //更新config数据
  37. $this->update($data);
  38. return $this->apiResponseSuccess('更新成功');
  39. }else{
  40. $configs = Config::whereIn('key',['is_bean','bean_money','bean_give','use_bean','offset_bean_money','is_bean_expense'])->pluck('value','key');
  41. return $this->apiResponseSuccess('获取成功',$configs);
  42. }
  43. }
  44. /**
  45. * 更新config数据
  46. * @param $data
  47. * @return bool
  48. */
  49. function update($data){
  50. foreach ($data as $key => $value ){
  51. // 查找当前数据是否存在
  52. if( Config::where('key', $key)->where('value', $value)->count() ){ continue; }
  53. Config::where('key', $key)->update([ 'value' => $value ]);
  54. }
  55. return true;
  56. }
  57. }