429 lines
15 KiB
PHP
429 lines
15 KiB
PHP
<?php
|
|
|
|
namespace app\repository;
|
|
|
|
use app\model\CouponBill;
|
|
use app\model\Deduction;
|
|
use app\model\Member as MemberModel;
|
|
use app\model\Recharge;
|
|
use app\service\Repository;
|
|
use think\Collection;
|
|
use think\Model;
|
|
|
|
/**
|
|
* 流水相关
|
|
*
|
|
* Class BusinessRepository
|
|
* @package app\repository
|
|
* @method self getInstance(Model $model = null) static
|
|
*/
|
|
class BillRepository extends Repository
|
|
|
|
{
|
|
/**
|
|
* 流水列表
|
|
* @param $page
|
|
* @param $size
|
|
* @param $keyword
|
|
* @param null $businessCode
|
|
* @param null $startTime
|
|
* @param null $endTime
|
|
* @param array $orders
|
|
* @return array
|
|
*/
|
|
public function billList($page, $size, $keyword = null, $businessCode = null,$startTime = null, $endTime = null, $orders = ["a.id" => "desc"])
|
|
{
|
|
$failData = [
|
|
'total' => 0,
|
|
'current' => $page,
|
|
'size' => $size,
|
|
'list' => new Collection(),
|
|
];
|
|
$rep = CouponBill::alias("a")
|
|
->join("business b", "a.business_code = b.code")
|
|
->join("account c", "a.user_code = c.user_code")
|
|
->join("coupon_main d", "a.coupon_main_id = d.id")
|
|
->join("coupon e", "a.coupon_id = e.id")
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->where("b.business_name|c.nick_name|d.name", "like", "%{$keyword}%");
|
|
})
|
|
->when(!empty($businessCode), function ($q) use ($businessCode) {
|
|
$q->where("b.code", "=", $businessCode);
|
|
})
|
|
->when(MemberModel::is_agency(session("auth")['roles']), function ($q) {
|
|
$q->where("b.agency_code", "=", session("auth")['business_code']);
|
|
})
|
|
->when(!empty($startTime), function ($q) use ($startTime) {
|
|
$q->whereTime("a.create_time", ">=", $startTime);
|
|
})
|
|
->when(!empty($endTime), function ($q) use ($endTime) {
|
|
$q->whereTime("a.create_time", "<=", $endTime);
|
|
})
|
|
->field("a.*,a.coupon_id as user_coupon_id,b.business_name,
|
|
c.nick_name,c.avatar_url,d.name as coupon_main_name,d.deduction_money
|
|
,e.is_distribution_coupon");
|
|
|
|
$failData ['total'] = $rep->count();
|
|
$failData ['list'] = $rep
|
|
->page($page, $size)
|
|
->order($orders)
|
|
->select();
|
|
return $failData;
|
|
}
|
|
|
|
|
|
/**
|
|
* api获取签到流水列表
|
|
* @param $page
|
|
* @param $size
|
|
* @param $keyword
|
|
* @param null $businessCode
|
|
* @param null $startTime
|
|
* @param null $endTime
|
|
* @param array $orders
|
|
* @return array
|
|
*/
|
|
public function apiBillList($page, $size, $businessCode = null,$startTime = null, $endTime = null, $orders = ["id" => "desc"])
|
|
{
|
|
$failData = [
|
|
'total' => 0,
|
|
'current' => $page,
|
|
'size' => $size,
|
|
'list' => new Collection(),
|
|
];
|
|
$rep = CouponBill::with(["couponMain","account"])
|
|
->when(!empty($businessCode), function ($q) use ($businessCode) {
|
|
$q->where("business_code", "=", $businessCode);
|
|
})
|
|
->when(!empty($startTime), function ($q) use ($startTime) {
|
|
$q->whereTime("create_time", ">=", $startTime . "00:00:00");
|
|
})
|
|
->when(!empty($endTime), function ($q) use ($endTime) {
|
|
$q->whereTime("create_time", "<=", $endTime . "23:59:59");
|
|
});
|
|
;
|
|
$failData["total"] = $rep->count();
|
|
$failData["list"] = $rep->page($page,$size)
|
|
->order($orders)
|
|
->select();
|
|
return $failData;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 充值流水列表
|
|
* @param $page
|
|
* @param $size
|
|
* @param $keyword
|
|
* @param null $startTime
|
|
* @param null $endTime
|
|
* @param array $orders
|
|
* @return array
|
|
*/
|
|
public function rechargeBillList($page, $size, $keyword = null, $startTime = null, $endTime = null, $orders = ["a.id" => "desc"])
|
|
{
|
|
|
|
$failData = [
|
|
'total' => 0,
|
|
'current' => $page,
|
|
'size' => $size,
|
|
'list' => new Collection(),
|
|
];
|
|
$rep = Recharge::alias("a")
|
|
->join("account b", "a.open_id = b.open_id")
|
|
->join("business c", "a.business_code = c.code")
|
|
->join("member d", "a.member_id = d.id", "left")
|
|
->join("business e", "c.agency_code = e.code", "left")
|
|
->when(!empty($startTime), function ($q) use ($startTime) {
|
|
$q->whereTime("a.update_time", ">=", $startTime);
|
|
})
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->where("c.business_name", "like", "%$keyword%");
|
|
})
|
|
->when(!empty($endTime), function ($q) use ($endTime) {
|
|
$q->whereTime("a.update_time", "<=", $endTime);
|
|
})
|
|
->field(
|
|
[
|
|
"a.*",
|
|
"b.nick_name",
|
|
"b.avatar_url",
|
|
"d.nickname as member_nickname",
|
|
"c.business_name",
|
|
"e.business_name as agency_business_name",
|
|
]
|
|
);
|
|
|
|
$failData ['total'] = $rep->count();
|
|
$failData ['list'] = $rep
|
|
->page($page, $size)
|
|
->order($orders)
|
|
->select();
|
|
return $failData;
|
|
}
|
|
|
|
/**
|
|
* 扣款流水列表
|
|
* @param $page
|
|
* @param $size
|
|
* @param $keyword
|
|
* @param null $startTime
|
|
* @param null $endTime
|
|
* @param array $orders
|
|
* @return array
|
|
*/
|
|
public function deductionBillList($page, $size, $keyword = null, $startTime = null, $endTime = null, $orders = ["id" => "desc"])
|
|
{
|
|
|
|
$failData = [
|
|
'total' => 0,
|
|
'current' => $page,
|
|
'size' => $size,
|
|
'list' => new Collection(),
|
|
];
|
|
$rep = Deduction::alias("a")
|
|
->join("business c", "a.business_code = c.code")
|
|
->join("coupon_main e", "a.coupon_main_id = e.id")
|
|
->join("coupon_bill d", "a.bill_id = d.id")
|
|
->join("account b", "a.user_code = b.user_code")
|
|
->when(!empty($startTime), function ($q) use ($startTime) {
|
|
$q->whereTime("a.create_time", ">=", $startTime);
|
|
})
|
|
->when(!empty($endTime), function ($q) use ($endTime) {
|
|
$q->whereTime("a.create_time", "<=", $endTime);
|
|
})
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->where("c.business_name|e.name", "like", "%" . $keyword . "%");
|
|
})
|
|
|
|
->field(
|
|
[
|
|
"a.money",
|
|
"a.balance",
|
|
"a.create_time",
|
|
"a.coupon_id as user_coupon_id",
|
|
"b.nick_name",
|
|
"b.avatar_url",
|
|
"e.name as coupon_main_name",
|
|
"c.business_name",
|
|
"c.agency_code",
|
|
|
|
|
|
"d.consumer_money",
|
|
"d.distribution_money",
|
|
"d.admin_money",
|
|
"d.agency_money",
|
|
|
|
"d.lat",
|
|
"d.lng",
|
|
|
|
]
|
|
);
|
|
|
|
$failData ['total'] = $rep->count();
|
|
$failData ['list'] = $rep
|
|
->page($page, $size)
|
|
->order($orders)
|
|
->select();
|
|
$failData["list"]->each(function ($item){
|
|
if(!empty($item->agency_code)){
|
|
$item->agency_business_name = MemberModel::whereRaw("FIND_IN_SET('".MemberModel::ANENT_ROLE_ID."',roles)" )
|
|
->where("business_code",$item->agency_code)->value("nickname","");
|
|
}else{
|
|
$item->agency_business_name = "";
|
|
}
|
|
|
|
});
|
|
return $failData;
|
|
}
|
|
|
|
/**
|
|
* 总收益
|
|
* @param $field
|
|
* @param null $keyword
|
|
* @param null $start_time
|
|
* @param null $end_time
|
|
* @return float
|
|
*/
|
|
public function getAgencyMoneySum($field, $keyword = null, $start_time = null, $end_time = null)
|
|
{
|
|
|
|
return CouponBill::alias("a")
|
|
->join("business b", "a.business_code = b.code")
|
|
->join("business e", "a.agency_code = e.code", "left")
|
|
->join("account c", "a.user_code = c.user_code")
|
|
->join("coupon_main d", "a.coupon_main_id = d.id")
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->where("b.business_name|c.nick_name|d.name", "like", "%{$keyword}%");
|
|
})
|
|
->when(!empty($start_time), function ($q) use ($start_time) {
|
|
$q->whereTime("a.create_time", ">=", $start_time);
|
|
})
|
|
->when(!empty($end_time), function ($q) use ($end_time) {
|
|
$q->whereTime("a.create_time", "<=", $end_time);
|
|
})
|
|
->when(MemberModel::is_agency(session("auth")['roles']), function ($q) {
|
|
$q->where("b.agency_code", "=", session("auth")['business_code']);
|
|
})
|
|
->sum("a." . $field);
|
|
}
|
|
|
|
/**
|
|
* 总流水
|
|
* @param $businessCode
|
|
* @param null $startTime
|
|
* @param null $endTime
|
|
* @return float
|
|
*/
|
|
public function getBillMoneySum($businessCode, $startTime=null, $endTime=null )
|
|
{
|
|
return CouponBill::alias("a")
|
|
->join("account c", "a.user_code = c.user_code")
|
|
->join("coupon_main b", "a.coupon_main_id = b.id")
|
|
->where("a.business_code",$businessCode)
|
|
->when(!empty($startTime), function ($q) use ($startTime) {
|
|
$q->whereTime("a.create_time", ">=", $startTime. "00:00:00");
|
|
})
|
|
->when(!empty($endTime), function ($q) use ($endTime) {
|
|
$q->whereTime("a.create_time", "<=", $endTime. "23:59:59");
|
|
})
|
|
->sum("b.deduction_money");
|
|
}
|
|
|
|
/**
|
|
* 总充值流水
|
|
* @param null $keyword
|
|
* @param null $start_time
|
|
* @param null $end_time
|
|
* @return float
|
|
*/
|
|
public function getRechargeMoneySum($keyword = null, $start_time = null, $end_time = null)
|
|
{
|
|
return Recharge::alias("a")
|
|
->join("account b", "a.open_id = b.open_id")
|
|
->join("business c", "a.business_code = c.code")
|
|
->join("member d", "a.member_id = d.id", "left")
|
|
->join("business e", "c.agency_code = e.code", "left")
|
|
->where("a.state",Recharge::state_on)
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->whereTime("c.business_name|e.business_name", "like", "%" . $keyword . "%");
|
|
})
|
|
->when(!empty($start_time), function ($q) use ($start_time) {
|
|
$q->whereTime("a.update_time", ">=", $start_time);
|
|
})
|
|
->when(!empty($end_time), function ($q) use ($end_time) {
|
|
$q->whereTime("a.update_time", "<=", $end_time);
|
|
})
|
|
->sum("a.money");
|
|
}
|
|
|
|
/**
|
|
* 总扣款流水
|
|
* @param null $keyword
|
|
* @param null $start_time
|
|
* @param null $end_time
|
|
* @return float
|
|
*/
|
|
public function getDeductionMoneySum($keyword = null,$start_time = null, $end_time = null)
|
|
{
|
|
return Deduction::alias("a")
|
|
->join("business c", "a.business_code = c.code")
|
|
->join("business f", "f.code = c.agency_code", "left")
|
|
->join("coupon_main e", "a.coupon_main_id = e.id")
|
|
->join("coupon_bill d", "a.bill_id = d.id")
|
|
->join("account b", "d.user_code = b.user_code", "left")
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->where("e.name|c.business_name|f.business_name", "like", "%" . $keyword . "%");
|
|
})
|
|
->when(!empty($start_time), function ($q) use ($start_time) {
|
|
$q->whereTime("a.create_time", ">=", $start_time);
|
|
})
|
|
->when(!empty($end_time), function ($q) use ($end_time) {
|
|
$q->whereTime("a.create_time", "<=", $end_time);
|
|
})
|
|
->sum("a.money");
|
|
}
|
|
/**
|
|
* 总扣款流水-消费者红包
|
|
* @param null $keyword
|
|
* @param null $start_time
|
|
* @param null $end_time
|
|
* @return float
|
|
*/
|
|
public function getDeductionMoneySumRedPack($keyword = null,$start_time = null, $end_time = null)
|
|
{
|
|
return Deduction::alias("a")
|
|
->join("business c", "a.business_code = c.code")
|
|
->join("business f", "f.code = c.agency_code", "left")
|
|
->join("coupon_main e", "a.coupon_main_id = e.id")
|
|
->join("coupon_bill d", "a.bill_id = d.id")
|
|
->join("account b", "d.user_code = b.user_code", "left")
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->where("e.name|c.business_name|f.business_name", "like", "%" . $keyword . "%");
|
|
})
|
|
->when(!empty($start_time), function ($q) use ($start_time) {
|
|
$q->whereTime("a.create_time", ">=", $start_time);
|
|
})
|
|
->when(!empty($end_time), function ($q) use ($end_time) {
|
|
$q->whereTime("a.create_time", "<=", $end_time);
|
|
})
|
|
->sum("d.consumer_money");
|
|
}
|
|
|
|
/**
|
|
* 总扣款流水-平台商收益
|
|
* @param null $keyword
|
|
* @param null $start_time
|
|
* @param null $end_time
|
|
* @return float
|
|
*/
|
|
public function getDeductionMoneySumAgency($keyword = null,$start_time = null, $end_time = null)
|
|
{
|
|
return Deduction::alias("a")
|
|
->join("business c", "a.business_code = c.code")
|
|
->join("business f", "f.code = c.agency_code", "left")
|
|
->join("coupon_main e", "a.coupon_main_id = e.id")
|
|
->join("coupon_bill d", "a.bill_id = d.id")
|
|
->join("account b", "d.user_code = b.user_code", "left")
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->where("e.name|c.business_name|f.business_name", "like", "%" . $keyword . "%");
|
|
})
|
|
->when(!empty($start_time), function ($q) use ($start_time) {
|
|
$q->whereTime("a.create_time", ">=", $start_time);
|
|
})
|
|
->when(!empty($end_time), function ($q) use ($end_time) {
|
|
$q->whereTime("a.create_time", "<=", $end_time);
|
|
})
|
|
->sum("d.agency_money");
|
|
}
|
|
|
|
/**
|
|
* 总扣款流水-太古收益
|
|
* @param null $keyword
|
|
* @param null $start_time
|
|
* @param null $end_time
|
|
* @return float
|
|
*/
|
|
public function getDeductionMoneySumTaigu($keyword = null,$start_time = null, $end_time = null)
|
|
{
|
|
return Deduction::alias("a")
|
|
->join("business c", "a.business_code = c.code")
|
|
->join("business f", "f.code = c.agency_code", "left")
|
|
->join("coupon_main e", "a.coupon_main_id = e.id")
|
|
->join("coupon_bill d", "a.bill_id = d.id")
|
|
->join("account b", "d.user_code = b.user_code", "left")
|
|
->when(!empty($keyword), function ($q) use ($keyword) {
|
|
$q->where("e.name|c.business_name|f.business_name", "like", "%" . $keyword . "%");
|
|
})
|
|
->when(!empty($start_time), function ($q) use ($start_time) {
|
|
$q->whereTime("a.create_time", ">=", $start_time);
|
|
})
|
|
->when(!empty($end_time), function ($q) use ($end_time) {
|
|
$q->whereTime("a.create_time", "<=", $end_time);
|
|
})
|
|
->sum("d.admin_money");
|
|
}
|
|
|
|
|
|
} |