147 lines
4.4 KiB
PHP
147 lines
4.4 KiB
PHP
<?php
|
|
namespace app\repository;
|
|
|
|
use app\exception\RepositoryException;
|
|
use app\model\Business;
|
|
use app\model\BusinessCircle;
|
|
use app\model\BusinessFlow;
|
|
use app\model\CouponMain;
|
|
use app\model\Deduction;
|
|
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 BusinessRepository extends Repository
|
|
{
|
|
/**
|
|
* 根据条件查询列表
|
|
*
|
|
* @param array $where 查询条件
|
|
* @param int $page 默认第一页 0不限制
|
|
* @param int $limit 限制条数 0不限制
|
|
* @param array $order
|
|
* @return array
|
|
* @throws RepositoryException
|
|
*/
|
|
public function businessList(array $where = [], int $page = 1, int $limit = 0, array $order = [])
|
|
{
|
|
$q = $this->model->alias("a")
|
|
->join("account b","a.user_code = b.user_code")
|
|
->join("business c","a.business_code = c.code")
|
|
->field(["c.code as business_code","b.avatar_url", "b.nick_name as account_nick_name","c.business_name","c.total_recharge","c.id as basiness_id","c.balance"]);
|
|
$data = [
|
|
'total' => 0,
|
|
'current' => $page,
|
|
'size' => $limit,
|
|
'list' => new Collection(),
|
|
];
|
|
|
|
|
|
if (count($where)) {
|
|
$q = $q->where($where);
|
|
}
|
|
if (count($order)) {
|
|
$q = $q->order($order);
|
|
}
|
|
$data['total'] = $q->count();
|
|
if ($data['total']) {
|
|
if ($limit) {
|
|
if ($page) {
|
|
$q = $q->page($page);
|
|
}
|
|
$q = $q->limit($limit);
|
|
}
|
|
|
|
$data['list'] = $q->select();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 优惠券列表
|
|
*
|
|
* @param string $businessCode 商家code
|
|
* @param int $page 默认第一页 0不限制
|
|
* @param int $limit 限制条数 0不限制
|
|
* @param array $order
|
|
* @return array
|
|
* @throws RepositoryException
|
|
*/
|
|
public function businessCouponList($where, int $page = 1, int $limit = 0, array $order = ["create_time" => "desc", "id" => "desc"])
|
|
{
|
|
return CouponMain::findList($where, [], $page, $limit, null, $order);
|
|
}
|
|
|
|
/**
|
|
* 扣费记录
|
|
*
|
|
* @param string $businessCode 商家code
|
|
* @param int $page 默认第一页 0不限制
|
|
* @param int $limit 限制条数 0不限制
|
|
* @param array $order
|
|
* @return array
|
|
* @throws RepositoryException
|
|
*/
|
|
public function businessDeductionList($where, int $page = 1, int $limit = 0, array $order = ["create_time" => "desc", "id" => "desc"])
|
|
{
|
|
return Deduction::findList($where, [], $page, $limit, null, $order);
|
|
}
|
|
|
|
/**
|
|
* 充值记录
|
|
*
|
|
* @param string $businessCode 商家code
|
|
* @param int $page 默认第一页 0不限制
|
|
* @param int $limit 限制条数 0不限制
|
|
* @param array $order
|
|
* @return array
|
|
* @throws RepositoryException
|
|
*/
|
|
public function businessRechargeList($where, int $page = 1, int $limit = 0, array $order = ["create_time" => "desc", "id" => "desc"])
|
|
{
|
|
return Recharge::findList($where, [], $page, $limit, function ($q) {
|
|
return $q->withJoin(["business" => ["business_name"]]);
|
|
}, $order);
|
|
}
|
|
|
|
/* 获取所有的商家*/
|
|
public function getBusinessAll()
|
|
{
|
|
return BusinessFlow::alias("a")
|
|
->join("account b","a.user_code = b.user_code")
|
|
->join("business c","a.business_code = c.code")
|
|
->field("c.code , c.business_name ")
|
|
->order("a.id desc")
|
|
->select();
|
|
}
|
|
|
|
/**
|
|
* 获取单个商家详情
|
|
* @param $businessCode
|
|
* @param bool $lock
|
|
* @return BusinessFlow|array|Model|null
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getBusinessAccount($businessCode,bool $lock = false)
|
|
{
|
|
$Flow = BusinessFlow::with(["account", "business"])->where("business_code", $businessCode)->when($lock,function ($q){
|
|
$q->lock(true);
|
|
})->find();
|
|
if (empty($Flow) || empty($Flow->account) || empty($Flow->business)) {
|
|
return null;
|
|
}
|
|
return $Flow;
|
|
}
|
|
|
|
} |