2023-03-17 16:43:27 +08:00

185 lines
4.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* 店铺保证金管理
*
* @author刘孝全
* @emailq8197264@126.com
* @date 2023年03月3日
*/
declare (strict_types = 1);
namespace app\admin\controller\merchant\system\merchant;
use think\facade\View;
use think\exception\ValidateException;
use think\facade\Request;
use app\admin\BaseController;
use app\common\model\merchant\system\serve\ServeOrder as ServeOrderModel;
use app\common\model\merchant\user\UserBill as UserBillModel;
use app\common\model\merchant\system\merchant\Merchant as MerchantModel;
use app\common\model\merchant\system\merchant\MerchantType;
use app\common\model\merchant\system\merchant\MerchantCategory;
/**
* 店铺保证金管理类
*/
class MerchantMargin extends BaseController
{
protected $margin;
protected $path;
public function __construct()
{
// $this->margin = $margin;
$this->path = [
'index' => 'merchant/system/merchant/margin/list',
'read' => 'merchant/system/merchant/margin/read',
'edit' => 'merchant/system/merchant/margin/edit'
];
}
public function index(MerchantCategory $category, MerchantType $type)
{
// 商户分类
$category = $category->select();
//审核
// 店铺类弄
$type = $type->select();
// search
View::assign('category',$category);
View::assign('type',$type);
return View($this->path['index']);
}
/**
* 获取保证金列表
*
* @return json
*/
public function lst(ServeOrderModel $order)
{
$params = get_params();
$page = empty($params['page'])? 1 : (int)$params['page'];
$limit = empty($params['limit'])? (int)get_config('app . page_size') : (int)$params['limit'];
$where = get_params(['date','keyword','is_trader','category_id','is_margin','type_id', 'start_date', 'end_date']);
$where['type'] = 10;//10==保证金
$data = $order->GetList($where, $page, $limit);
return to_assign(0,'success', $data['data']=$data['list']);
}
/**
* 打开保证金扣费记录面
*
* @param int $id
* @return \think\Response
*/
public function GetMarginLstForm($id)
{
view::assign('id', $id);
return View($this->path['read']);
}
/**
* 获取保证金扣费记录 record
*
*/
public function GetMarginLst(UserBillModel $bill)
{
$params = get_params();
$mer_id = empty($params['id']) ? 0 : $params['id'];
$page = empty($params['page'])? 1 : (int)$params['page'];
$limit = empty($params['limit'])? (int)get_config('app . page_size') :(int)$params['limit'];
$where['mer_id'] = (int)$mer_id;
$where['category'] = 'mer_margin';
$data = $bill->GetList($where, $page, $limit);
return to_assign(0,'请求成功', $data);
}
/**
* 设置扣减保证金表单
*/
public function setMarginForm(MerchantModel $merchant)
{
$mer_id = get_params('id');
$data = $merchant->GetMerchantById($mer_id);
if (isset($data->is_margin) && $data->is_margin !== 10) {
throw new ValidateException('商户无保证金可扣');
}
return View($this->path['edit'], ['data'=>$data]);
}
/**
* 设置扣减保证金
*/
public function setMargin(MerchantModel $merchant)
{
$data = get_params(['mer_id','number','mer_name','margin','mark']);
if (empty($data['mer_name']) || empty($data['mer_id'])) {
return to_assign(0,'商户信息不能为空');
}
$data['title'] = '保证金扣除';
$data['type'] = 'mer_margin';//明细类型=保证金扣除
if (!empty($data['number']) && $data['number'] < 0)
return to_assign(0,'扣除金额不能小于0');
$data = $merchant->SetMargin($data);
return to_assign(0,'扣除保证金成功',[]);
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}
}