<?php
|
|
namespace app\operations\model\supplier;
|
|
use app\common\model\supplier\Capital as SupplierCapitalModel;
|
use app\common\model\supplier\Supplier as SupplierModel;
|
use app\operations\service\order\ExportService;
|
|
/**
|
* 供应商资金明细模型
|
*/
|
class Capital extends SupplierCapitalModel
|
{
|
// 定义全局的查询范围
|
protected $globalScope = ['status'];
|
public function scopeStatus($query)
|
{
|
$shop_supplier_ids = \app\operations\model\supplier\Supplier::getSupplierIdsByUser(session('jjjshop_operations')['user']);
|
if (empty($shop_supplier_ids)){
|
$query->where($query->getTable() . '.shop_supplier_id', -1);
|
}else{
|
$query->where($query->getTable() . '.shop_supplier_id', 'in', $shop_supplier_ids);
|
}
|
}
|
/**
|
* 获取列表数据
|
*/
|
public function getList($params,$page = true)
|
{
|
$model = $this;
|
if(isset($params['flow_type']) && $params['flow_type'] != 0){
|
$model = $model->where('flow_type', '=', $params['flow_type']);
|
}
|
if(isset($params['start_day']) && !empty($params['start_day'])){
|
$model = $model->where('create_time', '>=', strtotime($params['start_day']));
|
}
|
if(isset($params['end_day']) && !empty($params['end_day'])){
|
$end_day = strtotime($params['end_day']) + 86400;
|
$model = $model->where('create_time', '<', $end_day);
|
}
|
if(!empty($params['search'])){
|
//获取商户id
|
$shop_supplier_id = SupplierModel::getSupplierIdByName($params['search']);
|
$model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
|
}
|
if(!empty($params['supplier_name'])){
|
//获取商户id
|
$shop_supplier_id = SupplierModel::getSupplierIdByName($params['supplier_name']);
|
$model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
|
}
|
if(isset($params['is_settled']) && $params['is_settled'] >= 0){
|
//提现状态
|
$model = $model->where('is_settled', '=', $params['is_settled']);
|
}
|
// 查询列表数据
|
if($page){
|
$data["list"] = $model->with(["supplier"])->order(['create_time' => 'desc'])->paginate($params);
|
}else{
|
$data["list"] = $model->with(["supplier"])->order(['create_time' => 'desc'])->select();
|
}
|
|
$data["total_money"] = $model->sum("money");
|
return $data;
|
}
|
|
/**
|
* 修改状态
|
*/
|
public static function editStatus($shop_supplier_id, $start_day,$end_day,$is_settled=1)
|
{
|
$model = new static();
|
$end_day = $end_day + 86400;
|
// 查询列表数据
|
return $model->where('shop_supplier_id', '=', $shop_supplier_id)
|
->where('create_time', '>=', $start_day)
|
->where('create_time', '<', $end_day)
|
->where('flow_type', '=', 10)
|
->where('is_settled', '=', 1)
|
->update(["is_settled"=>$is_settled]);
|
}
|
|
/**
|
* 订单导出
|
*/
|
public function exportList($query)
|
{
|
// 获取订单列表
|
$list = $this->getList($query,false);
|
// 导出excel文件
|
return (new Exportservice)->supplierCapitalList($list);
|
}
|
|
/**
|
* 订单导出
|
*/
|
public function exportCashList($query)
|
{
|
// 获取订单列表
|
$query["flow_type"] = 10;//收入
|
$list = $this->getList($query,false);
|
// 导出excel文件
|
return (new Exportservice)->supplierCashList($list);
|
}
|
|
}
|