id) { return '玩法关闭'; } return sprintf('出票,最低投注%d元,停售前%d分钟截止投注', Helps::floatFormat($this->min_money), $this->early_minute); } public function cooperateLottery() { return $this->hasOne(Lottery::class, 'id', 'lottery_id'); } public function shopCooperateLottery() { return $this->hasOne(ShopCooperateLottery::class, 'id', 'shop_cooperate_lottery_id'); } public function shop() { return $this->hasOne(Shop::class, 'id', 'shop_id'); } public function lotteryType() { return $this->belongsTo(LotteryType::class, 'lottery_type_id', 'id'); } public function scopeActive($query) { return $query->where('opened', BoolEnum::YES); } public function scopeShopAndType($query, $shopId, $typeId) { return $query->where('lottery_type_id', $typeId)->where('shop_id', $shopId); } public function isActive() { return $this->opened == BoolEnum::YES && $this->chupiao == BoolEnum::YES; } public function earlySecond() { $cooperateLottery = $this->cooperateLottery; $earlyTime = $this->early_minute; if ($cooperateLottery && $cooperateLottery->early_minute > $earlyTime) { $earlyTime = $cooperateLottery->early_minute; } return $earlyTime * 60; } public function getConfig() { switch ($this->lotteryType->type) { case LottType::JCZQ: return $this->jczqConfig(); case LottType::JCLQ: return $this->jclqConfig(); case LottType::CTZQ_JQC: return $this->ctzqJqcConfig(); case LottType::CTZQ_BQC: return $this->ctzqBqcConfig(); case LottType::DLT: return $this->shuziCommonConfig(); case LottType::QXC: return $this->shuziCommonConfig(); case LottType::PLS: return $this->shuziCommonConfig(); case LottType::PLW: return $this->shuziCommonConfig(); case LottType::BJDC: case LottType::BJDC_SFGG: case LottType::CTZQ_SFC14: case LottType::CTZQ_SFC9: return $this->shuziCommonConfig(); case LottType::GUAN: case LottType::GUAN_YA: return $this->guanYaCommonConfig(); } } private function commonPrefixConfigField() { return [ ['type' => 'switch', 'field' => 'opened', 'field_val' => $this->opened, 'name' => '彩种开关', 'desc' => '关闭后,用户无法看到此彩种,请谨慎操作!'], ['type' => 'switch', 'field' => 'chupiao', 'field_val' => $this->chupiao, 'name' => '出票开关', 'desc' => '关闭后用户无法看到此彩种,请谨慎操作!合作模式,打开为手动派单,关闭为自动派单。'], ['type' => 'switch', 'field' => 'hemai','field_val' => $this->hemai, 'name' => '合买开关', 'desc' => '关闭后,用户无法发起合买,也无法参与合买。'], ]; } public function commonSuffixConfigField() { $res = []; if ($this->shop_cooperate_lottery_id) { $res = [ ['type' => 'label','field' => 'coop_shop_name', 'field_val' => $this->cooperateLottery->shop->name, 'name' => '当前合作店铺', 'desc' => $this->cooperateLottery->shop->name], ['type' => 'label','field' => 'coop_early_minute', 'field_val' => $this->cooperateLottery->early_minute, 'name' => '合作店铺提前截止时间', 'desc' => '提前'.$this->cooperateLottery->early_minute.'分钟'] ]; } return array_merge($res, [ ['type' => 'input','field' => 'min_money', 'field_val' => $this->min_money, 'name' => '用户投注最低金额', 'desc' => '用户投注时低于此金额无法投注成功'], ['type' => 'input', 'field' => 'early_minute', 'field_val' => $this->early_minute, 'name' => '用户投注截止时间提前', 'desc' => '用户需要在官方截止时间前' . $this->early_minute . '分钟下单'], ]); } private function jczqConfig() { $fields = [ ['type' => 'switch','field' => 'plan_multi', 'field_val' => $this->plan_multi, 'name' => '禁止复杂方案', 'desc' => '开启后,用户投注时允许的方案组合不超过' . $this->plan_num . '个'], ['type' => 'switch', 'field' => 'one_multi', 'field_val' => $this->one_multi, 'name' => '投注方案其中一场玩法多选', 'desc' => '开启后,用户投注时只能选择其中一场比赛进行玩法多选'], // ['type' => 'switch', 'field' => 'prize_optimize', 'field_val' => $this->prize_optimize, 'name' => '是否允许奖金优化', 'desc' => '开启后,本店用户投注时可选择奖金优化'], ['type' => 'switch', 'field' => 'mn', 'field_val' => $this->mn, 'name' => 'M串N组合过关', 'desc' => '关闭后,用户投注时无法使用M串N组合过关'], ['type' => 'switch', 'field' => 'prize_optimize', 'field_val' => $this->prize_optimize, 'name' => '是否允许奖金优化', 'desc' => '开启后,本店用户投注时可选择奖金优化'], ]; return array_merge($this->commonPrefixConfigField(), $fields, $this->commonSuffixConfigField()); } private function jclqConfig() { $fields = [ ['type' => 'switch','field' => 'plan_multi', 'field_val' => $this->plan_multi, 'name' => '禁止复杂方案', 'desc' => '开启后,用户投注时允许的方案组合不超过' . $this->plan_num . '个'], ['type' => 'switch', 'field' => 'one_multi', 'field_val' => $this->one_multi, 'name' => '投注方案其中一场玩法多选', 'desc' => '开启后,用户投注时只能选择其中一场比赛进行玩法多选'], // ['type' => 'switch', 'field' => 'prize_optimize', 'field_val' => $this->prize_optimize, 'name' => '是否允许奖金优化', 'desc' => '开启后,本店用户投注时可选择奖金优化'], ['type' => 'switch', 'field' => 'mn', 'field_val' => $this->mn, 'name' => 'M串N组合过关', 'desc' => '关闭后,用户投注时无法使用M串N组合过关'], ]; return array_merge($this->commonPrefixConfigField(), $fields, $this->commonSuffixConfigField()); } private function guanYaCommonConfig() { $prefix = [ ['type' => 'switch', 'field' => 'opened', 'field_val' => $this->opened, 'name' => '彩种开关', 'desc' => '关闭后,用户无法看到此彩种,请谨慎操作!'], ]; return array_merge($prefix, $this->commonSuffixConfigField()); } private function shuziCommonConfig() { return array_merge($this->commonPrefixConfigField(), $this->commonSuffixConfigField()); } private function ctzqJqcConfig() { return array_merge($this->commonPrefixConfigField(), $this->commonSuffixConfigField()); } private function ctzqBqcConfig() { return array_merge($this->commonPrefixConfigField(), $this->commonSuffixConfigField()); } public function validMixMoney($money) { ThrowException::isTrue($money < $this->min_money, '最低投注金额为' . Helps::floatFormat($this->min_money)); } public function validEnableHemai() { if ($this->hemai != BoolEnum::YES) { ThrowException::run('未开启合买'); } } public function enableHemai() { return $this->hemai == BoolEnum::YES; } public function validEnableOptimizePrize() { if ($this->prize_optimize != BoolEnum::YES) { ThrowException::run('未开启奖金优化'); } } public function enableOptimizePrize() { return $this->prize_optimize == BoolEnum::YES; } public function getOrderCooperateInfo(Order $order) { $info = [ 'shop_cooperate_id' => 0, 'cooperate_id' => 0, 'cooperate_show' => 0, 'cooperate_brokerage' => 0, 'cooperate_method' => 0, 'cooperate_common' => BoolEnum::NO, ]; $scl = $this->shopCooperateLottery; if (!$scl) { return $info; } $show = BoolEnum::YES; if ($scl->order_method == ShopCooperateLottery::METHOD_MANUAL) { $show = BoolEnum::NO; } else { if ($scl->money_limit == BoolEnum::YES) { if (bc_gt($order->getPayMoney(), $scl->money_max) || bc_lt($order->getPayMoney(), $scl->money_min)) { $show = BoolEnum::NO; } } } return [ 'shop_cooperate_id' => $scl->shop_cooperate_id, 'cooperate_brokerage' => $order->getPayMoney() * ($scl->brokerage / 100), 'cooperate_show' => $show, 'cooperate_id' => $scl->cooperate_id, 'cooperate_common' => $this->owned ? 1 : 2, 'cooperate_method' => $scl->order_method, ]; } public static function openAllLottery($shopId) { $types = LotteryType::get(); foreach ($types as $type) { $lottery = new Lottery(); $lottery->lottery_type_id = $type->id; $lottery->shop_id = $shopId; $lottery->name = $type->name; $lottery->opened = BoolEnum::YES; $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 = 2; $lottery->save(); } } }