PrizeController.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Common\Api;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Prizes;
  7. use App\Models\Lotterys;
  8. use App\Services\PrizeService;
  9. class PrizeController extends Controller
  10. {
  11. public function __construct()
  12. {
  13. //加载中间键
  14. $this->middleware('CheckLogin');
  15. $this->middleware('Logs');
  16. $this->middleware('CacheClear');
  17. }
  18. /**
  19. * 宝箱——添加/修改奖品
  20. */
  21. public function postPrize(Request $request){
  22. try {
  23. $params = $request->all();
  24. $keys = array('activity_id', 'corp_id', 'lottery_level', 'prize_name', 'prize_day_rule', 'prize_count', 'prize_weights', 'prize_image_url');
  25. foreach ($keys as $key) {
  26. if (!isset($params[$key])) {
  27. return Api::json(config('code.params_error'), trans('params.'.$key) . trans('msg.params_not_null'));
  28. }
  29. }
  30. $res = PrizeService::prizeDetail($params);
  31. return Api::json($res['code'], $res['msg'], $res['data']);
  32. }catch(\Exception $e) {
  33. return Api::serviceError($e);
  34. }
  35. }
  36. /**
  37. * 获取宝箱内的奖品列表
  38. * @param Request $request
  39. * @return string
  40. */
  41. public function getPrizeList(Request $request){
  42. try {
  43. $params = $request->all();
  44. $keys = array('activity_id', 'lottery_level', 'corp_id');
  45. foreach ($keys as $key) {
  46. if (empty($params[$key])) {
  47. return Api::json(config('code.params_error'), trans('params.'.$key) . trans('msg.params_not_null'));
  48. }
  49. }
  50. $res = PrizeService::getPrizeList($params['corp_id'], $params['activity_id'], $params['lottery_level']);
  51. return Api::json($res['code'], $res['msg'], $res['data']);
  52. }catch(\Exception $e) {
  53. return Api::serviceError($e);
  54. }
  55. }
  56. /**
  57. * 奖品删除
  58. * @param Request $request
  59. * @return string
  60. */
  61. public function postPrizeDelete(Request $request){
  62. try {
  63. $params = $request->all();
  64. $keys = array('activity_id', 'lottery_level', 'corp_id', 'prize_id');
  65. foreach ($keys as $key) {
  66. if (empty($params[$key])) {
  67. return Api::json(config('code.params_error'), trans('params.'.$key) . trans('msg.params_not_null'));
  68. }
  69. }
  70. $res = PrizeService::prizeDelete($params);
  71. return Api::json($res['code'], $res['msg'], $res['data']);
  72. }catch(\Exception $e) {
  73. return Api::serviceError($e);
  74. }
  75. }
  76. }
  77. ?>