middleware(function ($request, $next) { $this->validShopCentify(); return $next($request); }); } private function validShopCentify() { $extra = ShopExtra::where('shop_id', $this->shopId())->first(); ThrowException::isTrue(!$extra, '请先完成店铺认证'); ThrowException::isTrue($extra->state != AuditState::SUCCESS, '请先完成店铺认证!'); } /** * @api {GET} /api/seller/lottery 彩种列表(订单管理搜索用) * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [ * { * "id": 0, // id * "type": "", // 彩种类型 * "name": "全部" // 彩种名称 * }, * { * "id": 1, * "type": "jczq", * "name": "竞彩足球" * }, * ] * } * */ public function types() { $result = [['id' => 0, 'type'=> '', 'name' => '全部']]; $types = LotteryType::select('id', 'type', 'name')->get(); $result = array_merge($result, $types->toArray()); return $this->jsonSuccess($result); } /** * @api {GET} /api/seller/lottery 彩种管理 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiSuccessExample {json} 返回结果 * [ * { * "id": 1, // id * "opened": 1, // 彩种开关:1开启,0关闭 * "description": "出票,最低投注10元,停售前10分钟截止投注", // 描述 * "lottery_type": { * "id": 1, * "type": "jczq", * "name": "jc足球", // 彩名称 * }, * ... * ] * */ public function index() { $list = Lottery::with(['lotteryType','cooperateLottery:id,shop_id,early_minute','cooperateLottery.shop:id,name']) ->where('shop_id', $this->shopId()) ->get(); return $this->jsonSuccess($list); } /** * @api {GET} /api/seller/lottery/config_list 彩种配置-列表 * @apiVersion 0.1.0 * @apiGroup 店主 * @apiSuccessExample {json} 返回结果 * { * "code":200, * "message":"", * "data":[ * { * "lottery_type":{ * "id":2, // 彩种id * "type":"jclq", * "status":1, * "name":"jc篮球", // 彩种名称 * "icon":"", * "info":"谢谢谢谢谢寻寻", * "created_at":null, * "updated_at":null, * "deleted_at":null * }, * "description":"出票,最低投注10元,停售前20分钟截止投注" // 描述 * }, * ] * } * */ public function configList(Request $request) { $lotteryTypes = LotteryType::where('status', BoolEnum::YES)->get(); if (count($lotteryTypes) < 1) { return $this->jsonSuccess(); } $lotterys = Lottery::with(['cooperateLottery:id,shop_id,early_minute','cooperateLottery.shop:id,name']) ->where('shop_id', $this->shopId()) ->whereIn('lottery_type_id', $lotteryTypes->pluck('id')->toArray()) ->get() ->keyBy('lottery_type_id'); $result = []; foreach ($lotteryTypes as $lotteryType) { $lottery = Arr::get($lotterys, $lotteryType->id); if (!$lottery) { $lottery = new Lottery(); } $lottery->lottery_type = $lotteryType; $result[] = $lottery; } return $this->jsonSuccess($result); } /** * @api {GET} /api/seller/lottery/config 彩种配置-展示 * @apiVersion 0.1.0 * @apiGroup 店主 * @apiParam {Int} lottery_type_id 彩种id * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [ * { * "type": "switch", // switch开关,input弹框input表单 * "field": "opened", // 配置字段 * "field_val": 1, // 配置字段的值 * "name": "彩种开关", // 标题 * "desc": "关闭后,用户无法看到此彩种,请谨慎操作!" // 描述 * }, * ... * ] * } * */ public function configShow(Request $request) { $lotteryTypeId = $request->input('lottery_type_id'); $lotteryType = LotteryType::where('status', BoolEnum::YES) ->find($lotteryTypeId); ThrowException::isTrue(!$lotteryType, '无此彩种'); /** @var Lottery $lottery */ $lottery = Lottery::where('shop_id', $this->shopId()) ->where('lottery_type_id', $lotteryTypeId) ->where('opened', BoolEnum::YES) ->first(); if (!$lottery) { return $this->jsonSuccess([ [ 'type' => 'switch', 'field' => 'opened', 'field_val' => BoolEnum::NO, 'name' => '彩种开关', 'desc' => '关闭后,用户无法看到此彩种,请谨慎操作!' ], ]); } $config = $lottery->getConfig(); return $this->jsonSuccess($config); } /** * @api {POST} /api/seller/lottery/config 彩种配置-保存 * @apiVersion 0.1.0 * @apiGroup 店主 * @apiParam {Int} lottery_type_id 彩种id * @apiParam {String} field 字段名 * @apiParam {String|Int} field_val 字段的值 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } * */ public function configStore(Request $request) { $lotteryTypeId = $request->input('lottery_type_id'); $field = $request->input('field'); $fieldVal = $request->input('field_val'); $lotteryType = LotteryType::where('status', BoolEnum::YES) ->find($lotteryTypeId); ThrowException::isTrue(!$lotteryType, '无此彩种'); /** @var Lottery $lottery */ $lottery = Lottery::where('shop_id', $this->shopId()) ->where('lottery_type_id', $lotteryTypeId) ->first(); if ($lottery) { if ($lottery->opened == BoolEnum::NO) { ThrowException::isTrue($field != 'opened', '该项不可设置'); $lottery->opened = $fieldVal; $lottery->save(); return $this->jsonSuccess(); } $configs = $lottery->getConfig(); $has = false; foreach ($configs as $conf) { if ($conf['field'] == $field) { $has = true; break; } } ThrowException::isTrue(!$has, '该项不可设置'); $lottery->{$field} = $fieldVal; $lottery->save(); return $this->jsonSuccess(); } ThrowException::isTrue($field != 'opened', '该项不可设置'); $lottery = new Lottery(); $lottery->lottery_type_id = $lotteryTypeId; $lottery->shop_id = $this->shopId(); $lottery->name = $lotteryType->name; $lottery->opened = $fieldVal; $lottery->owned = BoolEnum::YES; $lottery->chupiao = BoolEnum::YES; $lottery->hemai = BoolEnum::YES; $lottery->plan_multi = BoolEnum::NO; $lottery->plan_num = 4; $lottery->early_minute = 10; $lottery->min_money = 10; $lottery->save(); return $this->jsonSuccess(); } }