1258 lines
46 KiB
PHP
Executable File
1258 lines
46 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Http\Controllers\Api\Customer;
|
||
|
||
use App\Enums\BillType;
|
||
use App\Enums\BoolEnum;
|
||
use App\Enums\FeedbackType;
|
||
use App\Enums\LottState;
|
||
use App\Enums\MaterialScene;
|
||
use App\Enums\OrderType;
|
||
use App\Enums\PayState;
|
||
use App\Enums\UserType;
|
||
use App\Exceptions\JingCaiException;
|
||
use App\Http\RequestValidators\AuthValidator;
|
||
use App\Model\Config;
|
||
use App\Model\Customer\Customer;
|
||
use App\Model\Customer\CustomerBill;
|
||
use App\Model\Customer\CustomerFollow;
|
||
use App\Model\Feedback;
|
||
use App\Model\Material;
|
||
use App\Model\Order;
|
||
use App\Model\Seller\Shop;
|
||
use App\Service\CustomerService;
|
||
use App\Service\MaterialService;
|
||
use App\Service\OrderService;
|
||
use App\Service\RechargeService;
|
||
use App\Utils\Helps;
|
||
use App\Utils\ThrowException;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Pagination\LengthAwarePaginator;
|
||
use Illuminate\Support\Arr;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
class CustomerController extends BaseController
|
||
{
|
||
/**
|
||
* @api {POST} /api/customer/customer/standings 用户战绩
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} [customer_id] 用户id(不传默认当前登录用户)
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "customer": { // 用户信息
|
||
* "id": 2,
|
||
* "shop_id": 1,
|
||
* "phone": "13511111111",
|
||
* "name": "",
|
||
* "nickname": "匿名用户", // 所有接口中,使用该子弹展示用户名称
|
||
* "email": "",
|
||
* "email_verified_at": null,
|
||
* "balance": "0.00", // 余额
|
||
* "prize_today": "0.00", // 今日中奖
|
||
* "prize_total": "0.00", // 累计中奖
|
||
* "remark": "",
|
||
* "has_pay_password": "", // 是否有支付密码
|
||
* "real_phone": "", // 实名手机号
|
||
* "real_identity": "", // 实名身份证
|
||
* "win_lead_num": 0, // 带红人数
|
||
* "win_alway_num": 0, // 连胜次数
|
||
* "star": 0, // 是否为星标客户,1是
|
||
* "agent": 0, // 是否为代理客户,1是
|
||
* "avatar": "", // 头像
|
||
* "seven_hit": "", // 7日命中
|
||
* "profit_rate": "", // 盈利率
|
||
* "fans_num": 0, // 粉丝数
|
||
* "follower_num": 0, // 关注数
|
||
* "lottery_draft_num": 0, // 待出票数
|
||
* "lottery_wait_num": 0, // 待开奖数
|
||
* "lottery_win_num": 0, // 已中奖
|
||
* "followed": true, // true已关注,false未关注
|
||
* "created_at": "2023-04-06T13:17:42.000000Z",
|
||
* "updated_at": "2023-04-06T13:17:42.000000Z",
|
||
* "deleted_at": null
|
||
* },
|
||
* "five" : [true,false] // true中奖,false未中奖
|
||
* }
|
||
* }
|
||
*/
|
||
public function standings(Request $request)
|
||
{
|
||
$id = $request->input('customer_id');
|
||
if ($id) {
|
||
$customer = Customer::find($id);
|
||
ThrowException::isTrue(!$customer, '无此用户');
|
||
} else {
|
||
$id = $this->customerId();
|
||
$customer = Customer::find($this->customerId());
|
||
}
|
||
|
||
$customer->has_pay_password = $customer->password_pay ? true : false;
|
||
unset($customer->password);
|
||
unset($customer->password_pay);
|
||
|
||
$sumTotal = Order::select(
|
||
DB::raw('sum(case when lottery_send_prize>0 then lottery_send_prize else lottery_tax_prize end ) as totalprize')
|
||
)
|
||
->where('customer_id', $id)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->whereIn('lottery_state', [LottState::WIN, LottState::SEND])->first();
|
||
|
||
$todayTotal = Order::select(
|
||
DB::raw('sum(case when lottery_send_prize>0 then lottery_send_prize else lottery_tax_prize end ) as totalprize')
|
||
)
|
||
->where('customer_id', $id)
|
||
->where('win_date', date('Ymd'))
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->whereIn('lottery_state', [LottState::WIN, LottState::SEND])->first();
|
||
|
||
$waitNum = Order::where('customer_id', $id)
|
||
->where('lottery_state', LottState::WAIT)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->count();
|
||
$draftNum = Order::where('customer_id', $id)
|
||
->where('lottery_state', LottState::DRAFT)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->count();
|
||
$pendingNum = Order::where('customer_id', $id)
|
||
->where('lottery_state', LottState::PENDING)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->count();
|
||
$winNum = Order::where('customer_id', $id)
|
||
->whereIn('lottery_state', [LottState::WIN, LottState::SEND])
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->count();
|
||
|
||
$fives = Order::where('customer_id', $id)
|
||
->whereIn('lottery_state', [LottState::WIN, LottState::LOSS, LottState::SEND])
|
||
->where('type', OrderType::FADAN)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->orderBy('id', 'desc')
|
||
->limit(5)
|
||
->pluck('lottery_state')->toArray();
|
||
|
||
$fiveRes = [];
|
||
foreach ($fives as $val) {
|
||
$fiveRes[] = $val == LottState::LOSS ? false : true;
|
||
}
|
||
|
||
$customer->prize_today = Helps::floatFormat($todayTotal->totalprize);
|
||
$customer->prize_total = Helps::floatFormat($sumTotal->totalprize);
|
||
$customer->lottery_draft_num = $draftNum;
|
||
$customer->lottery_pending_num = $pendingNum;
|
||
$customer->lottery_wait_num = $waitNum;
|
||
$customer->lottery_win_num = $winNum;
|
||
$customer->followed = false;
|
||
// 代红人数
|
||
$customer->win_lead_num = $customer->gendan_num;
|
||
$customer->seven_hit = $customer->sevenHit();
|
||
$customer->profit_rate = $customer->sevenWinRate();
|
||
if ($id != $this->customerId()) {
|
||
$exist = CustomerFollow::where('follower_id', $this->customerId())
|
||
->where('customer_id', $id)
|
||
->first();
|
||
$customer->followed = $exist ? true :false;
|
||
}
|
||
|
||
return $this->jsonSuccess([
|
||
'customer' => $customer,
|
||
'five' => $fiveRes
|
||
]);
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {GET} /api/customer/customer/pay_channel 店铺支付渠道
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":[
|
||
* {
|
||
* "pay_type":"qrcode",
|
||
* "name":"二维码支付",
|
||
* "wechat_qrcode":"http://jingcai.quickfly.eu.org:3000/uploads/shop/202306/59gvKD.png",
|
||
* "alipay_qrcode":"",
|
||
* "remind_after":"",
|
||
* "remind_before":"付款前djdjdkdk"
|
||
* },
|
||
* {
|
||
* "pay_type":"alipay",
|
||
* "name":"支付宝",
|
||
* "wechat_qrcode":"http://jingcai.quickfly.eu.org:3000/uploads/shop/202JmgvKD.png",
|
||
* "alipay_qrcode":"",
|
||
* "remind_after":"",
|
||
* "remind_before":"付款前djdjdkdk"
|
||
* }
|
||
* ]
|
||
* }
|
||
*/
|
||
public function payChannel()
|
||
{
|
||
$payTypes = $this->getPayTypes();
|
||
return $this->jsonSuccess($payTypes);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/info 我的-用户信息
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "customer": { // 用户信息
|
||
* "id": 2,
|
||
* "shop_id": 1,
|
||
* "phone": "13511111111",
|
||
* "name": "",
|
||
* "nickname": "匿名用户", // 所有接口中,使用该子弹展示用户名称
|
||
* "email": "",
|
||
* "email_verified_at": null,
|
||
* "balance": "0.00", // 余额
|
||
* "prize_today": "0.00", // 今日中奖
|
||
* "prize_total": "0.00", // 累计中奖
|
||
* "remark": "",
|
||
* "has_pay_password": "", // 是否有支付密码
|
||
* "real_phone": "", // 实名手机号
|
||
* "real_identity": "", // 实名身份证
|
||
* "win_lead_num": 0, // 带红人数
|
||
* "win_alway_num": 0, // 连胜次数
|
||
* "star": 0, // 是否为星标客户,1是
|
||
* "agent": 0, // 是否为代理客户,1是
|
||
* "avatar": "", // 头像
|
||
* "seven_hit": "", // 7日命中
|
||
* "profit_rate": "", // 盈利率
|
||
* "fans_num": 0, // 粉丝数
|
||
* "follower_num": 0, // 关注数
|
||
* "lottery_draft_num": 0, // 待出票数
|
||
* "lottery_wait_num": 0, // 待开奖数
|
||
* "lottery_win_num": 0, // 已中奖
|
||
* "created_at": "2023-04-06T13:17:42.000000Z",
|
||
* "updated_at": "2023-04-06T13:17:42.000000Z",
|
||
* "deleted_at": null
|
||
* },
|
||
* "shop": { // 店铺信息
|
||
* "id": 1,
|
||
* "name": "天下第一点", // 店铺名称
|
||
* "seller_name": "天下第一点", // 店主名
|
||
* "seller_phone": "111", // 店主手机
|
||
* "seller_wechat": "111", // 店主微信
|
||
* "addr": "天下第一点", // 店铺地址
|
||
* "announcement": "天下第一点", /// 店铺公告
|
||
* "announcement_img_url": "天下第一点", /// 店铺公告图片地址
|
||
* "created_at": null,
|
||
* "updated_at": null,
|
||
* "deleted_at": null
|
||
* },
|
||
* "shops": [ // 包含当前登录账号对应的店铺
|
||
* {
|
||
* "id": 2, // 用户id
|
||
* "phone": "13511111111", // 用户电话
|
||
* "shop_id": 1, // 店铺id
|
||
* "shop": {
|
||
* "id": 1,
|
||
* "name": "天下第一点" // 店铺名称
|
||
* }
|
||
* }
|
||
* ],
|
||
* "config": [
|
||
* "fadan_brokage":6, // 发单佣金提成
|
||
* ]
|
||
* }
|
||
* }
|
||
*/
|
||
public function info()
|
||
{
|
||
$shop = Shop::find($this->customerShopId());
|
||
$customer = Customer::find($this->customerId());
|
||
|
||
$customer->has_pay_password = $customer->password_pay ? true : false;
|
||
unset($customer->password);
|
||
unset($customer->password_pay);
|
||
|
||
$todayTotal = Order::select(
|
||
DB::raw('sum(case when lottery_send_prize>0 then lottery_send_prize else lottery_tax_prize end ) as totalprize')
|
||
)
|
||
->where('customer_id', $this->customerId())
|
||
->where('win_date', date('Ymd'))
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where('lottery_state', LottState::WIN)->first();
|
||
|
||
$sumTotal = Order::select(
|
||
DB::raw('sum(case when lottery_send_prize>0 then lottery_send_prize else lottery_tax_prize end ) as totalprize')
|
||
)
|
||
->where('customer_id', $this->customerId())
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where('lottery_state', LottState::WIN)->first();
|
||
|
||
$waitNum = Order::leftJoin(DB::raw('`order` as p'), 'p.id', 'order.pid')
|
||
->select(DB::raw('order.*'))
|
||
->where('order.customer_id', $customer->id)
|
||
->where('order.pay_state', PayState::SUCCESS)
|
||
->where(function($query) {
|
||
$query->where(function($query) {
|
||
$query->where('order.lottery_state', LottState::WAIT)
|
||
->whereIn('order.type', [OrderType::NORMAL, OrderType::FADAN, OrderType::GENDAN]);
|
||
})
|
||
->orWhere(function ($query) {
|
||
$query->where(DB::raw('p.lottery_state'), LottState::WAIT)
|
||
->where('order.type',OrderType::UNION);
|
||
});
|
||
})
|
||
->count();
|
||
$draftNum = Order::leftJoin(DB::raw('`order` as p'), 'p.id', 'order.pid')
|
||
->select(DB::raw('order.*'))
|
||
->where('order.customer_id', $customer->id)
|
||
->where('order.pay_state', PayState::SUCCESS)
|
||
->where(function($query) {
|
||
$query->where(function($query) {
|
||
$query->where('order.lottery_state', LottState::DRAFT)
|
||
->whereIn('order.type', [OrderType::NORMAL, OrderType::FADAN, OrderType::GENDAN]);
|
||
})
|
||
->orWhere(function ($query) {
|
||
$query->where(DB::raw('p.lottery_state'), LottState::DRAFT)
|
||
->where('order.type',OrderType::UNION);
|
||
});
|
||
})
|
||
->count();
|
||
$pendingNum = Order::leftJoin(DB::raw('`order` as p'), 'p.id', 'order.pid')
|
||
->select(DB::raw('order.*'))
|
||
->where('order.customer_id', $customer->id)
|
||
->where('order.pay_state', PayState::SUCCESS)
|
||
->where(function($query) {
|
||
$query->where(function($query) {
|
||
$query->where('order.lottery_state', LottState::PENDING)
|
||
->whereIn('order.type', [OrderType::NORMAL, OrderType::FADAN, OrderType::GENDAN]);
|
||
})
|
||
->orWhere(function ($query) {
|
||
$query->where(DB::raw('p.lottery_state'), LottState::PENDING)
|
||
->where('order.type',OrderType::UNION);
|
||
});
|
||
})
|
||
->count();
|
||
$winNum = Order::leftJoin(DB::raw('`order` as p'), 'p.id', 'order.pid')
|
||
->select(DB::raw('order.*'))
|
||
->where('order.customer_id', $customer->id)
|
||
->where('order.pay_state', PayState::SUCCESS)
|
||
->where(function($query) {
|
||
$query->where(function($query) {
|
||
$query->whereIn('order.lottery_state', Order::zhongJiangStates())
|
||
->whereIn('order.type', [OrderType::NORMAL, OrderType::FADAN, OrderType::GENDAN]);
|
||
})
|
||
->orWhere(function ($query) {
|
||
$query->whereIn(DB::raw('p.lottery_state'), Order::zhongJiangStates())
|
||
->where('order.type',OrderType::UNION);
|
||
});
|
||
})
|
||
->count();
|
||
|
||
$customer->prize_today = Helps::floatFormat($todayTotal->totalprize);
|
||
$customer->prize_total = Helps::floatFormat($sumTotal->totalprize);
|
||
$customer->lottery_pending_num = $pendingNum;
|
||
$customer->lottery_draft_num = $draftNum;
|
||
$customer->lottery_wait_num = $waitNum;
|
||
$customer->lottery_win_num = $winNum;
|
||
$customer->level_list = $customer->getLevelList();
|
||
$customer->balance = Helps::floatFormat($customer->balance);
|
||
$result = [
|
||
'customer' => $customer,
|
||
'shop' => $shop,
|
||
'shops' => $this->customer()->shops(),
|
||
'config' => [
|
||
// 'fadan_brokage' => '6'
|
||
]
|
||
];
|
||
return $this->jsonSuccess($result);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/upload 我的-上传头像
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {String} file avatar // filename
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "path": "xxxxx", // 头像地址
|
||
* }
|
||
* }
|
||
*
|
||
*/
|
||
public function upload(Request $request, MaterialService $materialService)
|
||
{
|
||
$file = $request->file('avatar');
|
||
$material = $materialService->upload($file, $this->customerId(), MaterialScene::AVATAR, UserType::CUSTOMER);
|
||
|
||
$customer = $this->customer();
|
||
$customer->avatar = $material->path;
|
||
$customer->save();
|
||
|
||
return $this->jsonSuccess([
|
||
'avatar' => $customer->avatar
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/change_nickname 我的-修改昵称
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {String} nickname 昵称
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*
|
||
*/
|
||
public function changeNickname(Request $request)
|
||
{
|
||
$nickname = $request->input('nickname');
|
||
ThrowException::isTrue(!$nickname, '昵称不能为空');
|
||
if (preg_match('/[0-9]/', $nickname) || preg_match('/[a-zA-Z]/', $nickname)) {
|
||
ThrowException::run('昵称不允许包含数字或字母');
|
||
}
|
||
|
||
$customer = $this->customer();
|
||
$exist = Customer::where('nickname', $nickname)
|
||
->where('id', '<>', $customer->id)
|
||
->first();
|
||
ThrowException::isTrue($exist, '该昵称已存在,请更换其他昵称');
|
||
|
||
$customer->nickname = $nickname;
|
||
$customer->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/change_password 我的-修改密码
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {String} password_old 旧密码
|
||
* @apiParam {String} password 新密码
|
||
* @apiParam {String} password_confirmation 新密码确认
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*
|
||
*/
|
||
public function changePassword(Request $request)
|
||
{
|
||
$old = $request->input('password_old');
|
||
$password = $request->input('password');
|
||
|
||
$err = AuthValidator::changePasswordErrors($request);
|
||
ThrowException::isTrue($err, $err);
|
||
|
||
$customer = Customer::find($this->customerId());
|
||
ThrowException::isTrue(!Customer::checkPassword($old, $customer->password), '密码错误');
|
||
$customer->password = Customer::encryPassword($password);
|
||
$customer->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/change_pay_password 我的-设置支付密码
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {String} [password_old] 旧密码,第一次设置时,可以不传
|
||
* @apiParam {String} password 新密码
|
||
* @apiParam {String} password_confirmation 新密码确认
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*
|
||
*/
|
||
public function changePayPassword(Request $request)
|
||
{
|
||
$old = $request->input('password_old');
|
||
$password = $request->input('password');
|
||
|
||
$err = AuthValidator::changePasswordErrors($request, true);
|
||
ThrowException::isTrue($err, $err);
|
||
|
||
/** @var Customer $customer */
|
||
$customer = Customer::find($this->customerId());
|
||
|
||
if ($customer->password_pay) {
|
||
ThrowException::isTrue(!Customer::checkPassword($old, $customer->password_pay), '密码错误');
|
||
}
|
||
$customer->password_pay = Customer::encryPassword($password);
|
||
$customer->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/follow 我的-关注用户
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} customer_id 被关注人的id
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*/
|
||
public function follow(Request $request, CustomerService $customerService)
|
||
{
|
||
$customerId = $request->input('customer_id');
|
||
$cus = Customer::find($customerId);
|
||
ThrowException::isTrue(!$cus, '用户不存在');
|
||
$customerService->follow($cus, $this->customer());
|
||
return $this->jsonSuccess([]);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/followers 我的-关注列表
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "current_page":1,
|
||
* "data":[
|
||
* {
|
||
* "id":1,
|
||
* "customer_id":3,
|
||
* "follower_id":1,
|
||
* "created_at":"2023-04-06T06:54:56.000000Z",
|
||
* "updated_at":"2023-04-06T07:07:13.000000Z",
|
||
* "deleted_at":null,
|
||
* "customer":{
|
||
* "id":3,
|
||
* "name":"哦吼2", // 名称
|
||
* "nickname":"", // 昵称
|
||
* "avatar":"", // 头像
|
||
* "fans_num":1, // 粉丝
|
||
* "follower_num":0, // 关注
|
||
* "profit_rate":"", // 盈利率
|
||
* "seven_hit":"" // 七日命中
|
||
* }
|
||
* }
|
||
* ],
|
||
* "per_page":20, // 每页条数
|
||
* "total":2 // 总条数
|
||
* }
|
||
* }
|
||
*/
|
||
public function followers(Request $request)
|
||
{
|
||
$list = CustomerFollow::with('customer:id,name,nickname,avatar,fans_num,follower_num,profit_rate,seven_hit')
|
||
->where('follower_id', $this->customerId())
|
||
->paging();
|
||
return $this->jsonSuccess($list);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/fans 我的-粉丝列表
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "current_page":1,
|
||
* "data":[
|
||
* {
|
||
* "id":1,
|
||
* "customer_id":3,
|
||
* "follower_id":1,
|
||
* "created_at":"2023-04-06T06:54:56.000000Z",
|
||
* "updated_at":"2023-04-06T07:07:13.000000Z",
|
||
* "deleted_at":null,
|
||
* "follower":{
|
||
* "id":3,
|
||
* "name":"哦吼2", // 名称
|
||
* "nickname":"", // 昵称
|
||
* "avatar":"", // 头像
|
||
* "fans_num":1, // 粉丝
|
||
* "follower_num":0, // 关注
|
||
* "profit_rate":"", // 盈利率
|
||
* "seven_hit":"" // 七日命中
|
||
* }
|
||
* }
|
||
* ],
|
||
* "per_page":20, // 每页条数
|
||
* "total":2 // 总条数
|
||
* }
|
||
* }
|
||
*/
|
||
public function fans()
|
||
{
|
||
/** @var LengthAwarePaginator $list */
|
||
$list = CustomerFollow::with('follower:id,name,nickname,avatar,fans_num,follower_num,profit_rate,seven_hit')
|
||
->where('customer_id', $this->customerId())
|
||
->paging();
|
||
|
||
$customerIds = $list->collect()->pluck('follower_id')->toArray();
|
||
|
||
$follows = [];
|
||
if ($customerIds) {
|
||
$follows = CustomerFollow::whereIn('customer_id', $customerIds)
|
||
->where('follower_id', $this->customerId())
|
||
->pluck('follower_id', 'customer_id')
|
||
->toArray();
|
||
}
|
||
|
||
foreach ($list as $item) {
|
||
$item->followed = Arr::get($follows, $item->follower_id) ? true : false;
|
||
}
|
||
return $this->jsonSuccess($list);
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/copy_orders 我的-我的跟单
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} [page] 页数
|
||
* @apiParam {Int} [size] 每页条数,默认20
|
||
* @apiParam {Int} [customer_id] 彩民id
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "current_page":1,// 当前页
|
||
* "total":1,// 总条数
|
||
* "data":[{
|
||
* "id":8,
|
||
* "pid":0,
|
||
* "order_sn":"P2023040100000033", // 订单编号
|
||
* "pass_mode":[
|
||
* "2.1"
|
||
* ],
|
||
* "play_type":"mixed",
|
||
* "money":24, // 购买金额
|
||
* "pay_at":null, // 支付时间
|
||
* "lottery_state":3, //
|
||
* "lottery_prize":"0.00", // 奖金
|
||
* "play_type_name":"混合投注", // 玩法
|
||
* "buy_type_name":"自购",
|
||
* "pass_mode_name":[ // 串法
|
||
* "2串1"
|
||
* ],
|
||
* "p_order":{ //
|
||
* "id":10,
|
||
* "pid":8,
|
||
* "customer_id":1,
|
||
* "play_type_name":"",
|
||
* "buy_type_name":"跟单",
|
||
* "pass_mode_name":[
|
||
*
|
||
* ],
|
||
* "customer":{ // 发单人
|
||
* "id":1,
|
||
* "name":"发达",
|
||
* "nickname":"",
|
||
* "avatar":""
|
||
* }
|
||
* }
|
||
* }]
|
||
* }
|
||
* }
|
||
*/
|
||
public function copyOrders(Request $request)
|
||
{
|
||
$size = $request->input('size');
|
||
$customerId = $request->input('customer_id');
|
||
|
||
if (!$customerId) {
|
||
$customerId = $this->customerId();
|
||
}
|
||
$orders = Order::with([
|
||
'pOrder:id,pid,customer_id',
|
||
'pOrder.customer:id,name,nickname,avatar',
|
||
'lotteryType:id,name'
|
||
])
|
||
->select(['id', 'pid', 'order_sn', 'pass_mode', 'play_type', 'money', 'pay_at', 'lottery_state', 'lottery_prize','lottery_tax_prize','lottery_send_prize','gendan_num', 'bets_expect_num','odds_early_close_time', 'odds_late_close_time','type','lottery_type_id'])
|
||
->where('type', OrderType::GENDAN)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where('customer_id', $customerId)
|
||
->where('created_date', '>', Config::faDanVisibleDate())
|
||
->orderBy('id', 'desc')
|
||
->paging($size);
|
||
return $this->jsonSuccess($orders);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/fadan_orders 我的-我的跟单(我的方案)
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} [page] 页数
|
||
* @apiParam {Int} [size] 每页条数,默认20
|
||
* @apiParam {Int} [customer_id] 彩民id
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "current_page":1,// 当前页
|
||
* "total":1,// 总条数
|
||
* "data":[
|
||
* {"id":8,
|
||
* "pid":0,
|
||
* "order_sn":"P2023040100000033", // 订单编号
|
||
* "pass_mode":[
|
||
* "2.1"
|
||
* ],
|
||
* "play_type":"mixed",
|
||
* "money":24, // 购买金额
|
||
* "pay_at":null, // 支付时间
|
||
* "lottery_state":3, //
|
||
* "lottery_prize":"0.00", // 奖金
|
||
* "play_type_name":"混合投注", // 玩法
|
||
* "buy_type_name":"自购",
|
||
* "pass_mode_name":[ // 串法
|
||
* "2串1"
|
||
* ],
|
||
* }
|
||
* ]
|
||
* }
|
||
* }
|
||
*/
|
||
public function fadanOrders(Request $request)
|
||
{
|
||
$size = $request->input('size');
|
||
$customerId = $request->input('customer_id');
|
||
|
||
if (!$customerId) {
|
||
$customerId = $this->customerId();
|
||
}
|
||
$query = Order::with([
|
||
'pOrder:id,pid,customer_id',
|
||
'pOrder.customer:id,name,nickname,avatar',
|
||
'lotteryType:id,name'
|
||
])
|
||
->select(['id', 'pid', 'order_sn', 'pass_mode', 'play_type', 'money', 'pay_at', 'lottery_state', 'lottery_prize','lottery_tax_prize','lottery_send_prize','gendan_num','gendan_money', 'bets_expect_num','odds_early_close_time', 'odds_late_close_time','type','lottery_type_id'])
|
||
->where('type', OrderType::FADAN)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where('created_date', '>', Config::faDanVisibleDate())
|
||
->where('customer_id', $customerId);
|
||
|
||
if ($customerId != $this->customerId()) {
|
||
$query->whereIn('lottery_state',[
|
||
LottState::WAIT,LottState::WIN,LottState::LOSS,LottState::SEND
|
||
]);
|
||
}
|
||
|
||
$orders = $query->orderBy('id', 'desc')
|
||
->paging($size);
|
||
return $this->jsonSuccess($orders);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/bets_record 我的-投注记录
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} [lottery_state] 1中;2不中;3待开奖;4待出票;5接单;10已开奖
|
||
* @apiParam {Int} [page] 页数
|
||
* @apiParam {Int} [size] 每页条数,默认20
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "current_page": 1, // 当前页数
|
||
* "data": [
|
||
* {
|
||
* "id": 1, // 订单id
|
||
* "play_type": "mixed",
|
||
* "lottery_state": 3, // 中奖状态:1中;2不中;3待开奖;4待出票
|
||
* "lottery_prize": "0.00", // 奖金
|
||
* "lottery_id": 1,
|
||
* "pay_at": "2023-04-05 02:34:35", // 购买时间
|
||
* "play_type_name": "混合投注", // 玩法
|
||
* "buy_type_name": "自购", // 购买类型
|
||
* "lottery": { // 彩种信息
|
||
* "id": 1,
|
||
* "name": "竞彩足球", // 彩种
|
||
* "description": "出票,最低投注0元,停售前0分钟截止投注"
|
||
* }
|
||
* }
|
||
* ],
|
||
* "per_page": 20,
|
||
* "to": 1,
|
||
* "total": 1
|
||
* }
|
||
* }
|
||
*/
|
||
public function betsRecord(Request $request)
|
||
{
|
||
$lotteryState = $request->input('lottery_state');
|
||
|
||
$customer = $this->customer();
|
||
$size = $request->input('size');
|
||
$query = Order::with([
|
||
'lottery:id,name',
|
||
'pOrder:id,pid,lottery_state,lottery_prize,lottery_tax_prize,lottery_send_prize'
|
||
])->select([
|
||
'id', 'pid','type', 'play_type', 'lottery_state', 'lottery_prize','lottery_tax_prize','lottery_send_prize', 'lottery_id', 'pay_at','order_sn','money','union_piece_total', 'union_piece_buy','union_piece_money', 'union_money', 'union_piece_self','union_piece_keep'
|
||
])
|
||
->where('customer_id', $customer->id)
|
||
->where('pay_state', PayState::SUCCESS);
|
||
if ($lotteryState > 0 && LottState::hasValue($lotteryState, false)) {
|
||
if ($lotteryState == LottState::WIN) {
|
||
$query->whereIn('lottery_state', Order::zhongJiangStates());
|
||
} else {
|
||
$query->where('lottery_state', $lotteryState);
|
||
}
|
||
}
|
||
// 已开奖
|
||
if ($lotteryState == 10) {
|
||
$query->whereIn('lottery_state', [LottState::WIN, LottState::LOSS]);
|
||
}
|
||
$orders = $query->orderBy('id', 'desc')->paging($size);
|
||
foreach ($orders as $order) {
|
||
if ($order->type == OrderType::UNION) {
|
||
$order->lottery_state = $order->pOrder->lottery_state;
|
||
$order->union_show_piece_money = Helps::floatFormat(($order->union_piece_self + $order->union_piece_keep) * $order->union_piece_money);
|
||
|
||
if ($order->pOrder->lottery_state == LottState::WIN || $order->pOrder->lottery_state == LottState::SEND) {
|
||
$itemSendPrize = $order->pOrder->lottery_send_prize;
|
||
$itemTaxPrize = $order->pOrder->lottery_tax_prize;
|
||
$pieceBi = ($order->union_piece_self + $order->union_piece_keep) / $order->union_piece_total;
|
||
$order->union_send_prize = $itemSendPrize * $pieceBi;
|
||
$order->union_tax_prize = $itemTaxPrize * $pieceBi;
|
||
}
|
||
}
|
||
}
|
||
return $this->jsonSuccess($orders);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/order/bills 我的-交易明细
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} [lottery_state] 1中;2不中;3待开奖;4待出票;5接单;10已开奖
|
||
* @apiParam {Int} [page] 页数
|
||
* @apiParam {Int} [size] 每页条数,默认20
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "bill_types": [ // 交易明细类型
|
||
* {
|
||
* "name": "全部",
|
||
* "bill_type": 0
|
||
* },
|
||
* {
|
||
* "name": "充值",
|
||
* "bill_type": 1
|
||
* },
|
||
* {
|
||
* "name": "投注",
|
||
* "bill_type": 2
|
||
* },
|
||
* {
|
||
* "name": "反奖",
|
||
* "bill_type": 3
|
||
* },
|
||
* {
|
||
* "name": "提款",
|
||
* "bill_type": 4
|
||
* },
|
||
* {
|
||
* "name": "其他",
|
||
* "bill_type": -1
|
||
* }
|
||
* ],
|
||
* "bills": {
|
||
* "current_page": 1,
|
||
* "data": [
|
||
* {
|
||
* "id": 11,
|
||
* "type": 2, //
|
||
* "customer_id": 1,
|
||
* "customer_balance": "9856.00", // 用户余额
|
||
* "ie": "-", // - 减少,+增加
|
||
* "money": "120.00", // 金额
|
||
* "recharge_id": 0,
|
||
* "order_id": null,
|
||
* "title": "充值", // 标题
|
||
* "seller_id": 0,
|
||
* "created_at": "2023-04-09T07:36:12.000000Z", // 时间
|
||
* "updated_at": "2023-04-09T07:36:12.000000Z",
|
||
* "deleted_at": null
|
||
* },
|
||
* ],
|
||
* "prev_page_url": null,
|
||
* "to": 10,
|
||
* "total": 10 // 总条数
|
||
* }
|
||
* }
|
||
* }
|
||
*/
|
||
public function bills(Request $request)
|
||
{
|
||
$billType = $request->input('bill_type');
|
||
$size = $request->input('size');
|
||
$query = CustomerBill::where('customer_id', $this->customerId());
|
||
if (BillType::hasValue($billType, false)) {
|
||
$query->where('type', $billType);
|
||
}
|
||
// 其他类型
|
||
if ($billType == -1) {
|
||
$query->whereNotIn('type', [BillType::RECHARGE, BillType::BETTING, BillType::PRIZE, BillType::WITHDRAW]);
|
||
}
|
||
$result = $query->orderBy('id', 'desc')->paging($size);
|
||
return $this->jsonSuccess([
|
||
'bill_types' => BillType::asOptionArray(),
|
||
'bills' => $result
|
||
]);
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/unions 我的-合买列表
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} type 1我发起的,2我参与的
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "current_page":1,
|
||
* "data":[
|
||
* {
|
||
* "id":15,
|
||
* "pid":8,
|
||
* "order_sn":"P2023041900000010",
|
||
* "money":2, // 自购金额
|
||
* "pay_state":"success",
|
||
* "pay_at":"2023-04-19 14:44:51",
|
||
* "odds_early_close_time":"2023-04-05 15:38:38", // 截止时间
|
||
* "odds_late_close_time":"2023-04-06 15:38:38",
|
||
* "lottery_state":5,
|
||
* "type_desc":"",
|
||
* "union_piece_buy":1, // 购买份数
|
||
* "union_piece_total":12,
|
||
* "union_schedule":8,
|
||
* "union_order":{ // 合买主单信息
|
||
* "id":8,
|
||
* "order_sn":"xxxx", // 订单id,详情用这个字段
|
||
* "money":24, // 方案金额
|
||
* "pay_state":'', // ;success: 支付成功;unpay: 待支付;error: 支付失败;unequal: 支付异常,支付金额和实收金额不相等;pending: 支付处理中
|
||
* "lottery_state":5, // 1:中; 2:不中; 3:待开,已出票; 4:待出票,出票中; 5:待接单,未出票; 6:撤销订单
|
||
* "union_brokerage":1, // 佣金比例
|
||
* "union_piece_total":1, // 总份数
|
||
* "union_piece_buy":1, // 认购份数
|
||
* "play_type_name":"",
|
||
* "buy_type_name":"合买",
|
||
* "type_desc":"合买", // 合买宣言
|
||
* "pass_mode_name":[
|
||
*
|
||
* ]
|
||
* },
|
||
* "lottery_type":{
|
||
* "id":1,
|
||
* "name":"jc足球" // 彩种名称
|
||
* }
|
||
* }
|
||
* ],
|
||
* "from":1,
|
||
* "last_page":1,
|
||
* "to":1,
|
||
* "total":1
|
||
* }
|
||
* }
|
||
*
|
||
*/
|
||
public function unions(Request $request)
|
||
{
|
||
$size = $request->input('size');
|
||
// 1我发起的,2我参与的
|
||
$type = $request->input('type');
|
||
$query = Order::with([
|
||
'unionOrder:id,order_sn,money,union_brokerage,type_desc,pay_state,lottery_state,union_piece_total,union_piece_buy',
|
||
'lotteryType:id,type,name'
|
||
])
|
||
->where('type', OrderType::UNION)
|
||
->where('customer_id', $this->customerId());
|
||
|
||
if ($type == 1) {
|
||
$query->whereRaw('id = pid');
|
||
}
|
||
if ($type == 2) {
|
||
$query->whereRaw('id <> pid');
|
||
}
|
||
$query->orderBy('id', 'desc');
|
||
$orders = $query->paging($size);
|
||
return $this->jsonSuccess($orders);
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/real_verify 我的-实名认证
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {String} real_identity 身份证
|
||
* @apiParam {String} real_name 真实姓名
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*/
|
||
public function realVerify(Request $request)
|
||
{
|
||
// $real_phone = $request->input('real_phone');
|
||
$real_identity = $request->input('real_identity');
|
||
$real_name = $request->input('real_name');
|
||
ThrowException::isTrue(!$real_name, '姓名不能为空');
|
||
// ThrowException::isTrue(!Helps::validPhone($real_phone), '手机号格式有误');
|
||
ThrowException::isTrue(!Helps::validIdCard($real_identity), '身份证格式有误');
|
||
ThrowException::isTrue(!Helps::validIdCardIsAdult($real_identity), '您尚未未成年');
|
||
$customer = $this->customer();
|
||
ThrowException::isTrue($customer->real_identity, '不可重复认证');
|
||
|
||
$customer->real_phone = '';
|
||
$customer->real_identity = $real_identity;
|
||
$customer->name = $real_name;
|
||
$customer->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/customer/feedback 我的-反馈
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} type 反馈类型:1充值问题;2提现问题;3订单问题;4店铺问题;5账户问题;6其他问题
|
||
* @apiParam {String} content 内容
|
||
* @apiParam {Array} [material_ids] 图片
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*/
|
||
public function feedback(Request $request) {
|
||
$content = $request->input('content');
|
||
$type = $request->input('type');
|
||
$materialIds = $request->input('material_ids');
|
||
ThrowException::isTrue(!$content, '内容不能为空');
|
||
|
||
ThrowException::isTrue(!FeedbackType::hasValue($type), '类型不存在');
|
||
|
||
$feedback = new Feedback();
|
||
$feedback->customer_id = $this->customerId();
|
||
$feedback->shop_id = $this->customerShopId();
|
||
$feedback->content = $content;
|
||
$feedback->type = $type;
|
||
$feedback->save();
|
||
|
||
if ($materialIds) {
|
||
Material::whereIn('id', $materialIds)
|
||
->where('scene', MaterialScene::FEEDBACK)
|
||
->where('feedback_id', 0)
|
||
->update(['feedback_id' => $feedback->id]);
|
||
}
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/customer/customer/agent_regist 我的邀请-邀请记录
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {Int} [size] 每页条数
|
||
* @apiParam {String} [date_start] 开始(2001-01-01,默认当月第一天)
|
||
* @apiParam {String} [date_end] 开始(2001-01-01,默认当天)
|
||
* @apiSuccessExample {json} 返回结果 参考用户列表数据
|
||
* {
|
||
* }
|
||
*/
|
||
public function agentRegist(Request $request)
|
||
{
|
||
$dateStart = $request->input('date_start');
|
||
$dateEnd = $request->input('date_end');
|
||
|
||
if (!$dateStart) {
|
||
$dateStart = date('Y-m-01');
|
||
}
|
||
if (!$dateEnd) {
|
||
$dateEnd = date('Y-m-d');
|
||
}
|
||
$dateStart = date('Ymd', strtotime($dateStart));
|
||
$dateEnd = date('Ymd', strtotime($dateEnd));
|
||
|
||
$list = Customer::where('shop_id', $this->customerShopId())
|
||
->where('agent_id', $this->customerId())
|
||
->where('regist_agent_date', '>=', $dateStart)
|
||
->where('regist_agent_date', '<=', $dateEnd)
|
||
->paging();
|
||
return $this->jsonSuccess($list);
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/customer/customer/agent_order 我的邀请-订单列表
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {Int} [size] 每页条数
|
||
* @apiParam {String} [date_start] 开始(2001-01-01,默认当月第一天)
|
||
* @apiParam {String} [date_end] 开始(2001-01-01,默认当天)
|
||
* @apiSuccessExample {json} 返回结果 参考订单列表数据
|
||
* {
|
||
* }
|
||
*/
|
||
public function agentOrder(Request $request)
|
||
{
|
||
$size = $request->input('size');
|
||
$dateStart = $request->input('date_start');
|
||
$dateEnd = $request->input('date_end');
|
||
|
||
if (!$dateStart) {
|
||
$dateStart = date('Y-m-01');
|
||
}
|
||
if (!$dateEnd) {
|
||
$dateEnd = date('Y-m-d');
|
||
}
|
||
$dateStart = date('Ymd', strtotime($dateStart));
|
||
$dateEnd = date('Ymd', strtotime($dateEnd));
|
||
|
||
$customerIdList = Customer::where('shop_id', $this->customerShopId())
|
||
->where('agent_id', $this->customerId())
|
||
->pluck('id')
|
||
->toArray();
|
||
if (!$customerIdList) {
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
$query = Order::with([
|
||
'lottery:id,name',
|
||
'customer:id,nickname,phone,remark,avatar'
|
||
])
|
||
->agentUsable()
|
||
->select('*')
|
||
->where('shop_id', $this->customerShopId())
|
||
->whereIn('customer_id',$customerIdList)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where('created_date', '>=', $dateStart)
|
||
->where('created_date', '<=', $dateEnd);
|
||
$allMoney = $query->sum('money');
|
||
$list = $query->paging($size);
|
||
return $this->jsonSuccess([
|
||
'list' => $list,
|
||
'total_money' => $allMoney,
|
||
]);
|
||
}
|
||
/**
|
||
* @api {GET} /api/customer/customer/agent_order_v2 我的邀请-订单列表改为按人统计
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {Int} [size] 每页条数
|
||
* @apiParam {String} [date_start] 开始(2001-01-01,默认当月第一天)
|
||
* @apiParam {String} [date_end] 开始(2001-01-01,默认当天)
|
||
* @apiSuccessExample {json} 返回结果 参考订单列表数据
|
||
* {
|
||
* }
|
||
*/
|
||
public function agentOrderV2(Request $request)
|
||
{
|
||
$dateStart = $request->input('date_start');
|
||
$dateEnd = $request->input('date_end');
|
||
|
||
if (!$dateStart) {
|
||
$dateStart = date('Y-m-01');
|
||
}
|
||
if (!$dateEnd) {
|
||
$dateEnd = date('Y-m-d');
|
||
}
|
||
$dateStart = date('Ymd', strtotime($dateStart));
|
||
$dateEnd = date('Ymd', strtotime($dateEnd));
|
||
|
||
$customers = Customer::select([
|
||
'id',
|
||
'name',
|
||
'nickname',
|
||
'avatar',
|
||
'phone',
|
||
])
|
||
->where('shop_id', $this->customerShopId())
|
||
->where('agent_id', $this->customerId())
|
||
->get();
|
||
if (!$customers || count($customers) <= 0) {
|
||
return $this->jsonSuccess();
|
||
}
|
||
$customerIdList = $customers->pluck('id')->toArray();
|
||
|
||
$orders = Order::select([
|
||
'customer_id',
|
||
DB::raw('SUM(IF(type = 3, union_money, money)) AS money')
|
||
])->agentUsable()
|
||
->whereIn('customer_id',$customerIdList)
|
||
->where('pay_state', PayState::SUCCESS)
|
||
->where('created_date', '>=', $dateStart)
|
||
->where('created_date', '<=', $dateEnd)
|
||
->groupBy('customer_id')
|
||
->orderBy('money', 'desc')
|
||
->get();
|
||
|
||
foreach ($orders as $order) {
|
||
$order->customer = $customers->where('id', $order->customer_id)->first();
|
||
}
|
||
|
||
$allMoney = collect($orders)->sum('money');
|
||
return $this->jsonSuccess([
|
||
'list' => $orders,
|
||
'total_money' => $allMoney,
|
||
]);
|
||
}
|
||
}
|