123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace App\Http\Controllers\Manage\Book;
- use App\Modules\Book\Services\ProductService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class ProductController extends Controller
- {
- /**
- * @apiDefine Product 产品/充值
- */
- /**
- * @apiVersion 1.0.0
- * @apiDescription 充值列表
- * @api {get} product/chargelists 充值列表
- * @apiGroup Product
- * @apiName getChargeLists
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data: [
- * {
- * product_id: 1,
- * price: "30.00",
- * given: 0,
- * is_default: 0,
- * type: "TICKET_RECHARGE"
- * },
- * {
- * product_id: 4,
- * price: "500.00",
- * given: 20000,
- * is_default: 0,
- * type: "TICKET_RECHARGE"
- * },
- * {
- * product_id: 5,
- * price: "365.00",
- * given: 0,
- * is_default: 1,
- * type: "TICKET_RECHARGE"
- * }
- * ]
- * }
- */
- public function getChargeLists(){
- $res = ProductService::getChargeProduct();
- return response()->collection(new ProductTransformer,$res);
- }
- /**
- * @apiVersion 1.0.0
- * @apiDescription 添加产品
- * @api {post} product 添加产品
- * @apiGroup Product
- * @apiName createProduct
- * @apiParam {float} price 价格
- * @apiParam {String} type 类型
- * @apiParam {int} given 奖励
- * @apiParam {int} is_enabled 是否启用
- * @apiParam {int} [sequence] 排序
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data:
- * {
- * product_id: 1,
- * price: "30.00",
- * given: 0,
- * is_default: 0,
- * type: "TICKET_RECHARGE"
- * }
- *
- * }
- */
- public function createProduct(Request $request){
- $param = $request->except('_url');
- if(checkParam($param,['price','type','given','is_enabled'])){
- return response()->error('PARAM_ERROR');
- }
- $param['is_default'] = 0;
- $res = ProductService::addProduct($param);
- return response()->item(new ProductTransformer,$res);
- }
- /**
- * @apiVersion 1.0.0
- * @apiDescription 编辑产品
- * @api {post} product/update 编辑产品
- * @apiGroup Product
- * @apiName updateProduct
- * @apiParam {int} is_default(1|0) 是否默认(只能有一个)
- * @apiParam {int} is_enabled(1|0) 是否启用
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data: [
- * {
- * product_id: 1,
- * price: "30.00",
- * given: 0,
- * is_default: 0,
- * type: "TICKET_RECHARGE"
- * },
- * {
- * product_id: 4,
- * price: "500.00",
- * given: 20000,
- * is_default: 0,
- * type: "TICKET_RECHARGE"
- * },
- * {
- * product_id: 5,
- * price: "365.00",
- * given: 0,
- * is_default: 1,
- * type: "TICKET_RECHARGE"
- * }
- * ]
- * }
- */
- public function updateProduct(Request $request){
- $id = $request->input('product_id');
- if(empty($id)) return response()->error('PARAM_ERROR');
- $default = $request->input('is_default');
- $is_enabled = $request->input('is_enabled');
- if($default == '' && $is_enabled == ''){
- return response()->error('PARAM_ERROR');
- }
- ProductService::updateProductDefault($id, $default);
- ProductService::updateProductEnabled($id, $is_enabled);
- return response()->success();
- }
- /**
- * @apiVersion 1.0.0
- * @apiDescription 根据id获取产品
- * @api {get} product/{id} 根据id获取产品
- * @apiGroup Product
- * @apiName getProductInfoById
- * @apiSuccess {int} code 状态码
- * @apiSuccess {String} msg 信息
- * @apiSuccess {object} data 结果集
- * @apiSuccess {Int} product_id product_id
- * @apiSuccess {float} price 价格
- * @apiSuccess {String} type 类型
- * @apiSuccess {int} given 奖励
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data:
- * {
- * product_id: 1,
- * price: "30.00",
- * given: 0,
- * is_default: 0,
- * type: "TICKET_RECHARGE"
- * }
- *
- * }
- */
- public function getProductInfoById(Request $request,$id){
- $res = ProductService::getProductSingle($id);
- return response()->item(new ProductTransformer,$res);
- }
- }
|