1013 lines
36 KiB
PHP
Executable File
1013 lines
36 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Http\Controllers\Api\Seller;
|
||
|
||
use App\Enums\BoolEnum;
|
||
use App\Enums\LottState;
|
||
use App\Enums\OrderType;
|
||
use App\Enums\PayState;
|
||
use App\Model\LotteryType;
|
||
use App\Model\Order;
|
||
use App\Model\OrderZuhe;
|
||
use App\Model\Zq\JczqOdds;
|
||
use App\Service\JczqService;
|
||
use App\Service\LotteryService;
|
||
use App\Service\OrderService;
|
||
use App\Utils\Helps;
|
||
use App\Utils\ThrowException;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Redis;
|
||
|
||
class OrderController extends BaseController
|
||
{
|
||
const FILTER_DRAFT = 'draft'; // 未出票
|
||
const FILTER_PENDING = 'pending'; // 未接单
|
||
const FILTER_UNION = 'union'; // 合买
|
||
const FILTER_FEAT_CP = 'feat_cp'; // 合作出票
|
||
const FILTER_FEAT_PDWC = 'feat_pdwc'; // 合作派单未出
|
||
const FILTER_FEAT_PD = 'feat_pd'; // 合作派单
|
||
const FILTER_INSTORE = 'feat_instore'; // 店内
|
||
const FILTER_CP = 'cp'; // 出票
|
||
|
||
|
||
/**
|
||
* @api {GET} /api/seller/order/list 订单管理-订单列表
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} filter 过滤条件,对应tabs中的filter
|
||
* @apiParam {String} sort close_time截止时间,money金额排序,pay_at下单时间
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "orders": [
|
||
* {
|
||
* "id": 2,
|
||
* "pid": 0,
|
||
* "order_sn": "P2023040900000002",
|
||
* "money": 24,
|
||
* "pay_state": "success",
|
||
* "pay_at": "2023-04-09 03:41:06",
|
||
* "odds_early_close_time": "2023-04-15 15:38:38",
|
||
* "odds_late_close_time": "2023-04-16 15:38:38",
|
||
* "lottery_state": 5,
|
||
* "lottery_prize": "0.00",
|
||
* "lottery_tax_prize": "0.00",
|
||
* "type_mode": 1,
|
||
* "type_desc": "浪费大家发的啦",
|
||
* "play_type_name": "混合投注",
|
||
* "buy_type_name": "自购",
|
||
* "lottery": {
|
||
* "id": 1,
|
||
* "name": "竞彩足球",
|
||
* "description": "出票,最低投注0元,停售前0分钟截止投注"
|
||
* },
|
||
* "customer": {
|
||
* "id": 1,
|
||
* "nickname": "大象",
|
||
* "phone": "13511111111",
|
||
* "level_name": "储备组长",
|
||
* "level_score_group": "5000"
|
||
* }
|
||
* },
|
||
* ],
|
||
* "tabs": [
|
||
* {
|
||
* "name": "未接单",
|
||
* "count": 2,
|
||
* "filter": "pending"
|
||
* },
|
||
* {
|
||
* "name": "未出票",
|
||
* "count": 0,
|
||
* "filter": "draft"
|
||
* },
|
||
* {
|
||
* "name": "合买",
|
||
* "count": 0,
|
||
* "filter": "union"
|
||
* },
|
||
* { // 这一部分暂时不支持
|
||
* "name": "合作",
|
||
* "feat_cp_count": 2,
|
||
* "feat_pdwc_count": 2,
|
||
* "child": [
|
||
* {
|
||
* "name": "合作出票",
|
||
* "count": 2,
|
||
* "filter": "feat_cp"
|
||
* },
|
||
* {
|
||
* "name": "合作派单未出",
|
||
* "count": 2,
|
||
* "filter": "feat_pdwc"
|
||
* }
|
||
* ]
|
||
* }
|
||
* ]
|
||
* }
|
||
* }
|
||
*
|
||
*/
|
||
public function list(Request $request)
|
||
{
|
||
$sort = $request->input('sort');
|
||
$lotteryTypeId = $request->input('lottery_type_id');
|
||
$filter = $request->input('filter');
|
||
$query = Order::with([
|
||
'lottery:id,name',
|
||
'customer:id,nickname,phone,remark,avatar',
|
||
'lotteryType:id,name,type',
|
||
])->select('*')
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where(function($query) {
|
||
$query->whereIn('type', [OrderType::NORMAL, OrderType::FADAN, OrderType::GENDAN])
|
||
->orWhere(function($query) {
|
||
$query->where('type', OrderType::UNION)
|
||
->whereRaw('id = pid and union_piece_buy + union_piece_keep >= union_piece_total');
|
||
});
|
||
});
|
||
if ($lotteryTypeId) {
|
||
$query->where('lottery_type_id', $lotteryTypeId);
|
||
}
|
||
if ($filter == self::FILTER_DRAFT) {
|
||
$query->where('cooperate_show', BoolEnum::NO)
|
||
->where('shop_id', $this->shopId())
|
||
->where('receive_user_id', $this->sellerId())
|
||
->where('lottery_state', LottState::DRAFT);
|
||
}
|
||
if ($filter == self::FILTER_PENDING) {
|
||
$query->where('cooperate_show', BoolEnum::NO)
|
||
->where('shop_id', $this->shopId())
|
||
->where('lottery_state', LottState::PENDING);
|
||
}
|
||
if ($filter == self::FILTER_UNION) {
|
||
$query = Order::with([
|
||
'lottery:id,name',
|
||
'customer:id,nickname,phone,remark,avatar',
|
||
'lotteryType:id,name,type',
|
||
])->select('*')
|
||
->where('shop_id', $this->shopId())
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where('lottery_state', LottState::PENDING)
|
||
->where('type', OrderType::UNION)
|
||
->whereRaw('id=pid and union_piece_total > union_piece_buy + union_piece_keep');
|
||
}
|
||
if ($filter == self::FILTER_FEAT_CP) {
|
||
$query->where('cooperate_show', BoolEnum::YES)
|
||
->where('cooperate_id', $this->shopId())
|
||
->whereIn('lottery_state', [LottState::PENDING,LottState::DRAFT]);
|
||
}
|
||
if ($filter == self::FILTER_FEAT_PDWC) {
|
||
$query->where('cooperate_show', BoolEnum::YES)
|
||
->where('shop_id', $this->shopId())
|
||
->whereIn('lottery_state', [LottState::PENDING,LottState::DRAFT]);
|
||
}
|
||
|
||
if ($sort == 'money') {
|
||
$orders = $query->orderBy('money', 'desc')->limit(50)->get();
|
||
} else if ($sort == 'pay_at') {
|
||
$orders = $query->orderBy('pay_at', 'asc')->limit(50)->get();
|
||
} else {
|
||
$orders = $query->orderBy('odds_early_close_time', 'asc')->limit(50)->get();
|
||
}
|
||
|
||
$pendingCount = Order::where('lottery_state', LottState::PENDING)
|
||
->where(function($query) {
|
||
$query->whereIn('type', [OrderType::NORMAL, OrderType::FADAN, OrderType::GENDAN])
|
||
->orWhere(function($query) {
|
||
$query->where('type', OrderType::UNION)
|
||
->whereRaw('id = pid and union_piece_buy + union_piece_keep >= union_piece_total');
|
||
});
|
||
})
|
||
->where('cooperate_show', BoolEnum::NO)
|
||
->where('shop_id', $this->shopId())
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->count();
|
||
$draftCount = Order::where('lottery_state', LottState::DRAFT)
|
||
->where(function($query) {
|
||
$query->whereIn('type', [OrderType::NORMAL, OrderType::FADAN, OrderType::GENDAN])
|
||
->orWhere(function($query) {
|
||
$query->where('type', OrderType::UNION)
|
||
->whereRaw('id = pid and union_piece_buy + union_piece_keep >= union_piece_total');
|
||
});
|
||
})
|
||
->where('cooperate_show', BoolEnum::NO)
|
||
->where('shop_id', $this->shopId())
|
||
->where('receive_user_id', $this->sellerId())
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->count();
|
||
$unionCount = Order::where('type', OrderType::UNION)
|
||
->where('cooperate_show', BoolEnum::NO)
|
||
->whereRaw('id = pid')
|
||
->where('shop_id', $this->shopId())
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where('lottery_state', LottState::PENDING)
|
||
->whereRaw('union_piece_total > union_piece_buy + union_piece_keep')
|
||
->count();
|
||
|
||
$cooperatePaiDanCount = Order::where('shop_id', $this->shopId())
|
||
->where('cooperate_id', '>', 0)
|
||
->where('cooperate_show', BoolEnum::YES)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->whereIn('lottery_state', [LottState::PENDING,LottState::DRAFT])
|
||
->count();
|
||
$cooperateChupiaoCount = Order::where('cooperate_id', $this->shopId())
|
||
->where('cooperate_show', BoolEnum::YES)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->whereIn('lottery_state', [LottState::PENDING,LottState::DRAFT])
|
||
->count();
|
||
|
||
$result = [
|
||
'orders' => $orders,
|
||
'tabs' => [
|
||
['name' => '未接单', 'count' => $pendingCount, 'filter' => self::FILTER_PENDING],
|
||
['name' => '未出票', 'count' => $draftCount, 'filter' => self::FILTER_DRAFT],
|
||
['name' => '合买', 'count' => $unionCount, 'filter' => self::FILTER_UNION],
|
||
['name' => '合作','count' => $cooperateChupiaoCount+$cooperatePaiDanCount, 'filter' => 'cooperate', 'child' => [
|
||
['name' => '合作出票', 'count' => $cooperateChupiaoCount, 'filter' => self::FILTER_FEAT_CP],
|
||
['name' => '合作派单未出', 'count' => $cooperatePaiDanCount, 'filter' => self::FILTER_FEAT_PDWC]
|
||
]],
|
||
]
|
||
];
|
||
return $this->jsonSuccess($result);
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/seller/order/show 订单管理-订单详情(竞彩足球)
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "id": 2,
|
||
* "pid": 0,
|
||
* "order_sn": "P2023040900000002",
|
||
* "customer_id": 1,
|
||
* "lottery_id": 1,
|
||
* "shop_id": 0,
|
||
* "lottery_type_id": 0,
|
||
* "type": 1,
|
||
* "copy_num": 0, // 跟单数
|
||
* "bets_num": 2, // 倍数
|
||
* "piao_num": 0, //
|
||
* "money": 24, // 购买金额
|
||
* "prize_min": "11.04", // 最低奖金
|
||
* "prize_max": "142.56", // 最高奖金
|
||
* "pass_mode": [
|
||
* "2.1"
|
||
* ],
|
||
* "play_type": "mixed",
|
||
* "pay_type": "",
|
||
* "pay_state": "success",
|
||
* "pay_at": "2023-04-09 03:41:06",
|
||
* "odds_early_close_time": "2023-04-05 15:38:38",
|
||
* "odds_late_close_time": "2023-04-06 15:38:38",
|
||
* "lottery_state": 5,
|
||
* "lottery_prize": "0.00", // 中奖金额
|
||
* "lottery_tax_prize": "0.00", // 中奖金额
|
||
* "type_mode": 1,
|
||
* "type_desc": "浪费大家发的啦",
|
||
* "created_at": "2023-04-09T03:32:51.000000Z",
|
||
* "updated_at": "2023-04-09T03:41:06.000000Z",
|
||
* "deleted_at": null,
|
||
* "sellings": [ // 未接单时,为空数组
|
||
* {
|
||
* "issue_num": "2022-01-01/周一",
|
||
* "play_num": 21,
|
||
* "jc_competition_name": "adsf离开家",
|
||
* "jc_competition_name_full": "发三分大赛",
|
||
* "jc_home_team_name": "发顺丰",
|
||
* "jc_home_team_name_full": "发送",
|
||
* "jc_away_team_name": "fda",
|
||
* "jc_away_team_name_full": "fda",
|
||
* "id": 3,
|
||
* "order_id": 2,
|
||
* "jczq_odds_id": 3,
|
||
* "odds_id": 1,
|
||
* "match_id": 1,
|
||
* "odds_result": 0,
|
||
* "issue_num_week": "周一",
|
||
* "issue_num_day": "2022-01-01",
|
||
* "vs_b": "发顺丰",
|
||
* "vs_m": "vs",
|
||
* "vs_a": "fda",
|
||
* "play_items": [ // 每种玩法和对应的投注项
|
||
* {
|
||
* "win_result": "",
|
||
* "play_name": "胜平负", // 玩法
|
||
* "play_items": [
|
||
* [
|
||
* "胜(2.85)" // 投注项
|
||
* ],
|
||
* [
|
||
* "负(2.25)"
|
||
* ]
|
||
* ]
|
||
* },
|
||
* {
|
||
* "win_result": "",
|
||
* "play_name": "让球胜平负-1",
|
||
* "play_items": [
|
||
* [
|
||
* "胜(2.85)"
|
||
* ]
|
||
* ]
|
||
* }
|
||
* ]
|
||
* },
|
||
*
|
||
* ],
|
||
* "chang_num": 2,
|
||
* "pass_mode_names": [ // 串关
|
||
* "2x1"
|
||
* ],
|
||
* "play_name": "竞彩足球", // 彩种
|
||
* "play_type_name": "混合投注", // 玩法
|
||
* "buy_type_name": "自购",
|
||
* "pass_mode_name": [
|
||
* "2串1"
|
||
* ],
|
||
* "materials": []
|
||
* }
|
||
* }
|
||
*
|
||
*/
|
||
public function show(Request $request)
|
||
{
|
||
$orderSn = $request->input('order_sn');
|
||
/** @var Order $order */
|
||
$order = Order::with([
|
||
'materials:id,order_id,path',
|
||
'receiver:id,nickname,name,avatar',
|
||
'lotteryType:id,type,name',
|
||
'customer:id,nickname,name,avatar,remark',
|
||
'cooperate:id,name,seller_phone',
|
||
'shop:id,name,seller_phone',
|
||
])->sn($orderSn)->first();
|
||
ThrowException::isTrue(!$order, '订单不存在');
|
||
|
||
ThrowException::isTrue($order->lottery->shop_id != $this->shopId() && $order->lottery->cooperate_id != $this->shopId(), '无法跨店接单');
|
||
|
||
$order->setButtonsShow($this->seller());
|
||
|
||
$order->withShuziCai();
|
||
|
||
$unionInfo = $order->getUnionInfo();
|
||
$union = $unionInfo['list'];
|
||
// 认购人数
|
||
$order->union_user_num = collect($union)->count() ;
|
||
// 认购金额
|
||
$order->union_user_money = Helps::floatFormat(collect($union)->sum('union_money'));
|
||
|
||
$jingcaiService = LotteryService::getJingcaiServiceByOrder($order);
|
||
$od = $jingcaiService->sellerShowOrder($this->seller(), $order);
|
||
return $this->jsonSuccess($od);
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/seller/order/union_users 订单管理-订单详情-合买认购人数
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
*/
|
||
public function unionUsers(Request $request) {
|
||
$orderSn = $request->input('order_sn');
|
||
/** @var Order $order */
|
||
$order = Order::sn($orderSn)->first();
|
||
ThrowException::isTrue(!$orderSn, '订单不存在');
|
||
ThrowException::isTrue($order->type != OrderType::UNION, '订单不存在!');
|
||
$info = $order->getUnionInfo();
|
||
return $this->jsonSuccess($info);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/order/piao_show 订单-拆票明细
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "piaos":[ // 篮球和足球: 票的数据
|
||
* {
|
||
* "header":[ // header
|
||
* {
|
||
* "prop":"index",
|
||
* "title":"序号"
|
||
* },
|
||
* ],
|
||
* "data":{ // 票信息
|
||
* "index":1,
|
||
* "type":[
|
||
* "2串1"
|
||
* ],
|
||
* "play_name":[
|
||
* "97880 (主胜 客胜)",
|
||
* "97835 (主胜)"
|
||
* ],
|
||
* "nums":"4倍/1张"
|
||
* },
|
||
* "summary":"" // 票的简介
|
||
* }
|
||
* ],
|
||
* "money":16, // 总金额
|
||
* "piao_num":1, // 总票数
|
||
* "prize_max":"49.60" // 最大中奖数
|
||
* }
|
||
* }
|
||
*/
|
||
public function piaoShow(Request $request) {
|
||
$orderSn = $request->input('order_sn');
|
||
/** @var Order $order */
|
||
$order = Order::sn($orderSn)->first();
|
||
ThrowException::isTrue(!$order, '订单不存在');
|
||
|
||
ThrowException::isTrue($order->lottery->shop_id != $this->shopId() && $order->lottery->cooperate_id != $this->shopId(), '无法跨店接单');
|
||
|
||
$jingcaiService = LotteryService::getJingcaiServiceByOrder($order);
|
||
|
||
$piaos = $jingcaiService->chaiPiao($order);
|
||
|
||
$zhangArray = array_column($piaos, 'zhang');
|
||
return $this->jsonSuccess([
|
||
'piaos' => $piaos,
|
||
'money' => $order->money,
|
||
'piao_num' => array_sum($zhangArray),
|
||
'prize_max' => $order->prize_max
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/order/throw_cooperate 订单-合作甩单
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*
|
||
*/
|
||
public function throwCooperate(Request $request, OrderService $orderService)
|
||
{
|
||
$orderSn = $request->input('order_sn');
|
||
$orderService->sellerThrowCooperate($this->seller(), $orderSn);
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/order/receive 订单-接单
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*
|
||
*/
|
||
public function receive(Request $request, OrderService $orderService)
|
||
{
|
||
$orderSn = $request->input('order_sn');
|
||
$lockKey = 'order:receive:'.$orderSn;
|
||
$lock = Redis::setnx($lockKey, 1);
|
||
ThrowException::isTrue(!$lock, '接单中...');
|
||
try {
|
||
$orderService->sellerReceive($this->seller(), $orderSn);
|
||
} catch (\Exception $e) {
|
||
throw $e;
|
||
} finally {// 确保释放锁
|
||
Redis::del($lockKey);
|
||
}
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/order/revoke 订单-撤单
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*
|
||
*/
|
||
public function revoke(Request $request, OrderService $orderService)
|
||
{
|
||
$orderSn = $request->input('order_sn');
|
||
$orderService->sellerRevoke($this->seller(), $orderSn, $request->input('revoke_message'));
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/order/upload_piao 订单-上传票据
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
* @apiParam {Array} material_ids 上传图片后的图片id
|
||
* @apiParamExample {json} 请求示例
|
||
* {
|
||
* "pay_type":"alipay",
|
||
* "pay_money":2.0,
|
||
* "oddses": {}, // 订单中oddses的数据
|
||
* }
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*/
|
||
public function uploadPiao(Request $request, OrderService $orderService)
|
||
{
|
||
$orderSn = $request->input('order_sn');
|
||
$materialIds = $request->input('material_ids');
|
||
$orderService->sellerUploadPiao($this->seller(), $orderSn, $materialIds);
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/order/draw 订单-出票
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
* @apiParam {Array} material_ids 上传图片后的图片id
|
||
* @apiParam {Object} oddses 赔率
|
||
* @apiParamExample {json} 请求示例
|
||
* {
|
||
* "pay_type":"alipay",
|
||
* "pay_money":2.0,
|
||
* "oddses": {}, // 订单中oddses的数据
|
||
* }
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*/
|
||
public function draw(Request $request, OrderService $orderService)
|
||
{
|
||
$orderSn = $request->input('order_sn');
|
||
$materialIds = $request->input('material_ids');
|
||
$oddses = $request->input('oddses');
|
||
$orderService->sellerDraw($this->seller(), $orderSn, $materialIds, $oddses);
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/order/send_prize 派奖-派奖
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
* @apiParam {Float} prize 派奖金额
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*/
|
||
public function sendPrize(Request $request, OrderService $orderService)
|
||
{
|
||
$orderSn = $request->input('order_sn');
|
||
$prize = $request->input('prize');
|
||
$orderService->sellerSendPrize($this->seller(), $orderSn, $prize);
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/order/take_ticket 取票
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} order_sn 订单编号
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*/
|
||
public function takeTicket(Request $request, OrderService $orderService)
|
||
{
|
||
$orderSn = $request->input('order_sn');
|
||
$orderService->sellerTakeTicket($this->seller(), $orderSn);
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/seller/order/search_filter 个人中心-订单查询搜索条件
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "lottery_types": [ // 彩种类型
|
||
* {
|
||
* "id": 0,
|
||
* "type": "",
|
||
* "name": "全部"
|
||
* },
|
||
* {
|
||
* "id": 1,
|
||
* "type": "jczq",
|
||
* "name": "jc足球"
|
||
* },
|
||
* ],
|
||
* "lottery_states": [ // 订单状态
|
||
* {
|
||
* "id": 0,
|
||
* "name": "全部"
|
||
* },
|
||
* {
|
||
* "id": 5,
|
||
* "name": "未出票"
|
||
* }
|
||
* ],
|
||
* "filter": [ // tab选项
|
||
* {
|
||
* "name": "店内订单",
|
||
* "filter": "feat_instore"
|
||
* },
|
||
* {
|
||
* "name": "合作订单(出票)",
|
||
* "filter": "feat_cp"
|
||
* },
|
||
* {
|
||
* "name": "合作订单(派单)",
|
||
* "filter": "feat_pd"
|
||
* }
|
||
* ],
|
||
* "filter_child": [ // 出票,合买
|
||
* {
|
||
* "name": "出票",
|
||
* "filter": "cp"
|
||
* },
|
||
* {
|
||
* "name": "合买",
|
||
* "filter": "union"
|
||
* }
|
||
* ]
|
||
* }
|
||
* }
|
||
*/
|
||
public function searchFilter()
|
||
{
|
||
$lotteryTypes = [['id' => 0, 'type' => '', 'name' => '全部']];
|
||
$types = LotteryType::select('id', 'type', 'name')->get();
|
||
$lotteryTypes = array_merge($lotteryTypes, $types->toArray());
|
||
|
||
$lotteryStates = LottState::asOptionArray();
|
||
return $this->jsonSuccess([
|
||
'lottery_types' => $lotteryTypes,
|
||
'lottery_states' => $lotteryStates,
|
||
'filter' => [
|
||
['name' => '店内订单', 'filter' => self::FILTER_INSTORE],
|
||
// ['name' => '合作订单(出票)', 'filter' => self::FILTER_FEAT_CP],
|
||
// ['name' => '合作订单(派单)', 'filter' => self::FILTER_FEAT_PD],
|
||
],
|
||
'filter_child' => [
|
||
['name' => '出票', 'filter' => self::FILTER_CP],
|
||
['name' => '合买', 'filter' => self::FILTER_UNION],
|
||
]
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/seller/order/search 个人中心-订单查询
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} filter 过滤条件,对应tabs中的filter
|
||
* @apiParam {String} filter_child 过滤条件,对应search_filter中的filter_child的filter
|
||
* @apiParam {Int} [lottery_type_id] 彩种类型id
|
||
* @apiParam {Int} [lottery_state_id] 订单状态id,对应search_filter中的lottery_states的id
|
||
* @apiParam {String} [date_start] 开始日期,2001-01-01
|
||
* @apiParam {String} [date_end] 结束日期,2001-01-01
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "orders": [
|
||
* {
|
||
* "id": 2,
|
||
* "pid": 0,
|
||
* "order_sn": "P2023040900000002",
|
||
* "money": 24,
|
||
* "pay_state": "success",
|
||
* "pay_at": "2023-04-09 03:41:06",
|
||
* "odds_early_close_time": "2023-04-15 15:38:38",
|
||
* "odds_late_close_time": "2023-04-16 15:38:38",
|
||
* "lottery_state": 5,
|
||
* "lottery_prize": "0.00",
|
||
* "lottery_tax_prize": "0.00",
|
||
* "type_mode": 1,
|
||
* "type_desc": "浪费大家发的啦",
|
||
* "play_type_name": "混合投注",
|
||
* "buy_type_name": "自购",
|
||
* "lottery": {
|
||
* "id": 1,
|
||
* "name": "竞彩足球",
|
||
* "description": "出票,最低投注0元,停售前0分钟截止投注"
|
||
* },
|
||
* "customer": {
|
||
* "id": 1,
|
||
* "nickname": "大象",
|
||
* "phone": "13511111111",
|
||
* "level_name": "储备组长",
|
||
* "level_score_group": "5000"
|
||
* }
|
||
* },
|
||
* ],
|
||
* "tabs": [
|
||
* {
|
||
* "name": "未接单",
|
||
* "count": 2,
|
||
* "filter": "pending"
|
||
* },
|
||
* {
|
||
* "name": "未出票",
|
||
* "count": 0,
|
||
* "filter": "draft"
|
||
* },
|
||
* {
|
||
* "name": "合买",
|
||
* "count": 0,
|
||
* "filter": "union"
|
||
* },
|
||
* {
|
||
* "name": "合作",
|
||
* "feat_cp_count": 2,
|
||
* "feat_pdwc_count": 2,
|
||
* "child": [
|
||
* {
|
||
* "name": "合作出票",
|
||
* "count": 2,
|
||
* "filter": "feat_cp"
|
||
* },
|
||
* {
|
||
* "name": "合作派单未出",
|
||
* "count": 2,
|
||
* "filter": "feat_pdwc"
|
||
* }
|
||
* ]
|
||
* }
|
||
* ]
|
||
* }
|
||
* }
|
||
*
|
||
*/
|
||
public function search(Request $request)
|
||
{
|
||
$shopCooperateId = $request->input('shop_cooperate_id');
|
||
$lotteryTypeId = $request->input('lottery_type_id');
|
||
$lotteryStateId = $request->input('lottery_state_id');
|
||
$filter = $request->input('filter_child');
|
||
$dateStart = $request->input('date_start');
|
||
$dateEnd = $request->input('date_end');
|
||
$size = $request->input('size');
|
||
if ($dateStart) {
|
||
$dateStart = date('Y-m-d 00:00:00', strtotime($dateStart));
|
||
}
|
||
if ($dateEnd) {
|
||
$dateEnd = date('Y-m-d 23:59:59', strtotime($dateEnd));
|
||
}
|
||
$query = Order::with([
|
||
'lottery:id,name',
|
||
'customer:id,nickname,phone',
|
||
'lotteryType:id,name,type',
|
||
])->select('*');
|
||
if ($shopCooperateId) {
|
||
$query->where('shop_cooperate_id', $shopCooperateId);
|
||
} else {
|
||
$query->where('shop_id', $this->shopId());
|
||
}
|
||
|
||
$query = $query->where('pay_state', PayState::SUCCESS)
|
||
->where(function($query) {
|
||
$query->whereIn('type', [OrderType::NORMAL, OrderType::FADAN, OrderType::GENDAN])
|
||
->orWhere(function($query) {
|
||
$query->where('type', OrderType::UNION)
|
||
->whereRaw('id = pid and union_piece_buy + union_piece_keep >= union_piece_total');
|
||
});
|
||
});
|
||
if ($dateStart) {
|
||
$query->where('pay_at', '>=', $dateStart);
|
||
}
|
||
if ($dateEnd) {
|
||
$query->where('pay_at', '<=', $dateEnd);
|
||
}
|
||
|
||
if ($lotteryStateId && LottState::hasValue($lotteryStateId, false)) {
|
||
$query->where('lottery_state', $lotteryStateId);
|
||
}
|
||
|
||
// 已派奖
|
||
if ($lotteryStateId == 11) {
|
||
$query->where('lottery_state', LottState::SEND);
|
||
}
|
||
// 已取票
|
||
if ($lotteryStateId == 12) {
|
||
$query->where('lottery_take_ticket', BoolEnum::YES);
|
||
}
|
||
|
||
if ($lotteryTypeId) {
|
||
$query->where('lottery_type_id', $lotteryTypeId);
|
||
}
|
||
|
||
if ($filter == self::FILTER_UNION) {
|
||
$query->where('type', OrderType::UNION)
|
||
->whereRaw('id=pid');
|
||
}
|
||
if ($filter == self::FILTER_FEAT_CP) {
|
||
// $query->where('lottery_state', LottState::PENDING);
|
||
}
|
||
if ($filter == self::FILTER_FEAT_PDWC) {
|
||
// $query->where('lottery_state', LottState::PENDING);
|
||
}
|
||
|
||
$orders = $query->orderBy('pay_at', 'desc')->paging($size);
|
||
|
||
return $this->jsonSuccess($orders);
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/seller/order/win_list 派奖-派奖管理
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "current_page":1,
|
||
* "data":[
|
||
* {
|
||
* "id":8,
|
||
* "type":1, // 1普通下注;2发单;3合买;4跟单
|
||
* "order_sn":"P2023041900000003",
|
||
* "lottery_prize":"184.80", // 总奖金
|
||
* "lottery_send_prize":0, // 实际派奖金额
|
||
* "lottery_estimate_send_prize":0, // 预估派奖金额
|
||
* "gendan_brokerage":0, // 跟单佣金
|
||
* "lottery_tax_prize":"0.00", // 税后奖金
|
||
* "union_lottery_prize":"184.80", // 合买总奖金
|
||
* "union_lottery_send_prize":0, // 合买派奖金额
|
||
* "union_lottery_tax_prize":"0.00", // 合买税后奖金
|
||
* "draft_at":null, // 出票时间
|
||
* "deleted_at":null,
|
||
* "play_type_name":"混合投注", // 彩种玩法
|
||
* "buy_type_name":"合买",
|
||
* "pass_mode_name":[
|
||
* "2串1"
|
||
* ],
|
||
* "lottery_type":{
|
||
* "id":1,
|
||
* "name":"jc足球" // 彩种类型名称
|
||
* }
|
||
* }
|
||
* ],
|
||
* "from":1,
|
||
* "last_page":1,
|
||
* "per_page":20,
|
||
* "to":1,
|
||
* "total":1
|
||
* }
|
||
* }
|
||
*/
|
||
public function winList(Request $request)
|
||
{
|
||
$size = $request->input('size');
|
||
|
||
$orders = Order::with('lotteryType:id,type,name')
|
||
->where('lottery_state', LottState::WIN)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where(function($query) {
|
||
$query->where(function($query) {
|
||
$query->where('shop_id', $this->shopId())
|
||
->where('cooperate_show', BoolEnum::NO);
|
||
})
|
||
->orWhere(function($query) {
|
||
$query->where('cooperate_id', $this->shopId())
|
||
->where('cooperate_show', BoolEnum::YES);
|
||
});
|
||
})
|
||
->where(function($query) {
|
||
$query->where('type', '<>', OrderType::UNION)
|
||
->orWhere(function ($query) {
|
||
$query->where('type', OrderType::UNION)
|
||
->whereRaw('pid = id');
|
||
});
|
||
})
|
||
->orderBy('id','desc')
|
||
->paging($size);
|
||
return $this->jsonSuccess($orders);
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {GET} /api/seller/order/send_list 派奖-派奖记录
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "current_page":1,
|
||
* "data":[
|
||
* {
|
||
* "id":8,
|
||
* "type":1, // 1普通下注;2发单;3合买
|
||
* "order_sn":"P2023041900000003",
|
||
* "lottery_prize":"184.80", // 总奖金
|
||
* "lottery_send_prize":0, // 派奖金额
|
||
* "lottery_tax_prize":"0.00", // 税后奖金
|
||
* "union_lottery_prize":"184.80", // 合买总奖金
|
||
* "union_lottery_send_prize":0, // 合买派奖金额
|
||
* "union_lottery_tax_prize":"0.00", // 合买税后奖金
|
||
* "draft_at":null, // 出票时间
|
||
* "deleted_at":null,
|
||
* "play_type_name":"混合投注", // 彩种玩法
|
||
* "buy_type_name":"合买",
|
||
* "pass_mode_name":[
|
||
* "2串1"
|
||
* ],
|
||
* "lottery_type":{
|
||
* "id":1,
|
||
* "name":"jc足球" // 彩种类型名称
|
||
* }
|
||
* }
|
||
* ],
|
||
* "from":1,
|
||
* "last_page":1,
|
||
* "per_page":20,
|
||
* "to":1,
|
||
* "total":1
|
||
* }
|
||
* }
|
||
*/
|
||
public function sendList(Request $request)
|
||
{
|
||
$size = $request->input('size');
|
||
|
||
$orders = Order::with('lotteryType:id,type,name')
|
||
->where(function($query) {
|
||
$query->where(function($query) {
|
||
$query->where('shop_id', $this->shopId())
|
||
->where('cooperate_show', BoolEnum::NO);
|
||
})
|
||
->orWhere(function($query) {
|
||
$query->where('cooperate_id', $this->shopId())
|
||
->where('cooperate_show', BoolEnum::YES);
|
||
});
|
||
})
|
||
->where('lottery_state', LottState::SEND)
|
||
->orderBy('id','desc')
|
||
->paging($size);
|
||
return $this->jsonSuccess($orders);
|
||
}
|
||
}
|