2021-11-25 10:11:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\repository;
|
|
|
|
|
|
|
|
use app\model\CouponBill;
|
2021-11-30 07:26:38 +00:00
|
|
|
use app\model\Member as MemberModel;
|
2021-11-25 10:11:50 +00:00
|
|
|
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
|
2021-11-29 05:56:26 +00:00
|
|
|
* @param $keyword
|
|
|
|
* @param null $startTime
|
|
|
|
* @param null $endTime
|
|
|
|
* @param array $orders
|
|
|
|
* @return array
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
2021-11-25 10:11:50 +00:00
|
|
|
*/
|
2021-11-29 05:56:26 +00:00
|
|
|
public function billList($page, $size, $keyword = null, $startTime = null, $endTime = null, $orders = ["id" => "desc"])
|
2021-11-25 10:11:50 +00:00
|
|
|
{
|
|
|
|
$failData = [
|
|
|
|
'total' => 0,
|
|
|
|
'current' => $page,
|
|
|
|
'size' => $size,
|
|
|
|
'list' => new Collection(),
|
|
|
|
];
|
2021-11-30 07:26:38 +00:00
|
|
|
$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")
|
|
|
|
|
|
|
|
->when(!empty($keyword),function ($q) use($keyword){
|
|
|
|
$q->where("b.business_name|c.nick_name|d.name", "like", "%$keyword%");
|
|
|
|
})
|
|
|
|
->when(MemberModel::is_agency(session("auth")['roles']),function ($q) {
|
|
|
|
$q->where("b.agency_code", "=", session("auth")['business_code']);
|
|
|
|
})
|
2021-11-29 05:56:26 +00:00
|
|
|
->when(!empty($startTime), function ($q) use ($startTime) {
|
2021-11-30 07:26:38 +00:00
|
|
|
$q->whereTime("a.create_time", ">=", $startTime);
|
2021-11-29 05:56:26 +00:00
|
|
|
})
|
|
|
|
->when(!empty($endTime), function ($q) use ($endTime) {
|
2021-11-30 07:26:38 +00:00
|
|
|
$q->whereTime("a.create_time", "<=", $endTime);
|
|
|
|
})
|
|
|
|
->field("a.*,b.business_name,c.nick_name,c.avatar_url,d.name as coupon_main_name")
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 10:11:50 +00:00
|
|
|
|
|
|
|
$failData ['total'] = $rep->count();
|
2021-11-29 05:56:26 +00:00
|
|
|
$failData ['list'] = $rep
|
2021-11-25 10:11:50 +00:00
|
|
|
->page($page, $size)
|
|
|
|
->order($orders)
|
|
|
|
->select();
|
|
|
|
return $failData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-29 05:56:26 +00:00
|
|
|
/**
|
|
|
|
* 总收益
|
|
|
|
* @param $field
|
|
|
|
* @param null $start_time
|
|
|
|
* @param null $end_time
|
|
|
|
* @return float
|
|
|
|
*/
|
|
|
|
public function getAgencyMoneySum($field, $start_time = null, $end_time = null)
|
|
|
|
{
|
|
|
|
return CouponBill::when(!empty($start_time), function ($q) use ($start_time) {
|
|
|
|
$q->whereTime("create_time", ">=", $start_time);
|
2021-11-30 07:26:38 +00:00
|
|
|
})
|
|
|
|
->when(!empty($end_time), function ($q) use ($end_time) {
|
2021-11-29 05:56:26 +00:00
|
|
|
$q->whereTime("create_time", "<=", $end_time);
|
2021-11-30 07:26:38 +00:00
|
|
|
})
|
|
|
|
->when(MemberModel::is_agency(session("auth")['roles']),function ($q) {
|
|
|
|
$q->where("agency_code", "=", session("auth")['business_code']);
|
|
|
|
})
|
2021-11-29 05:56:26 +00:00
|
|
|
->sum($field);
|
|
|
|
}
|
|
|
|
|
2021-11-25 10:11:50 +00:00
|
|
|
}
|