bourse stock
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.6 KiB

<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\BrokerageSettingModel;
// 配置 返佣配置
class BrokerageService extends AdminBaseService
{
// 列表
public function index()
{
try {
$list = BrokerageSettingModel::order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙');
}
}
public function add($param)
{
try {
if(!isset($param['brok_type']) || !in_array($param['brok_type'], [0,1,2])){
return $this->toData('1', '返佣类型无效');
}
if(!isset($param['pay_type']) || !in_array($param['pay_type'], [0,1])){
return $this->toData('1', '结算方式无效');
}
if(!isset($param['parent_fee']) || !is_numeric($param['parent_fee']) || $param['parent_fee'] < 0){
return $this->toData('1', '返佣比例无效1');
}
if(!isset($param['grandpa_fee']) || !is_numeric($param['grandpa_fee']) || $param['grandpa_fee'] < 0){
return $this->toData('1', '返佣比例无效2');
}
if(!isset($param['top_fee']) || !is_numeric($param['top_fee']) || $param['top_fee'] < 0){
return $this->toData('1', '返佣比例无效3');
}
if(isset($param['remark']) && (!is_string($param['remark']) || strlen($param['remark']) >= 15) ){
return $this->toData('1', '备注无效');
}
$remark = $param['remark']?? '';
$brok = new BrokerageSettingModel;
$brok->brok_type = $param['brok_type'];
$brok->pay_type = $param['pay_type'];
$brok->parent_fee = $param['parent_fee'];
$brok->grandpa_fee = $param['grandpa_fee'];
$brok->top_fee = $param['top_fee'];
$brok->remark = $remark;
$brok->save();
$fee_key=$this->getBrokerageKey($param['brok_type']);
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key, $param);
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙');
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '主键无效');
}
$brok = BrokerageSettingModel::where('id', $param['id'])->find();
if(empty($brok)){
return $this->toData('1', '主键无效');
}
if(!isset($param['brok_type']) || !in_array($param['brok_type'], [0,1,2])){
return $this->toData('1', '返佣类型无效');
}
if(!isset($param['pay_type']) || !in_array($param['pay_type'], [0,1])){
return $this->toData('1', '结算方式无效');
}
if(!isset($param['parent_fee']) || !is_numeric($param['parent_fee']) || $param['parent_fee'] < 0){
return $this->toData('1', '返佣比例无效');
}
if(!isset($param['grandpa_fee']) || !is_numeric($param['grandpa_fee']) || $param['grandpa_fee'] < 0){
return $this->toData('1', '返佣比例无效');
}
if(!isset($param['top_fee']) || !is_numeric($param['top_fee']) || $param['top_fee'] < 0){
return $this->toData('1', '返佣比例无效');
}
if(isset($param['remark']) && (!is_string($param['remark']) || strlen($param['remark']) >= 15) ){
return $this->toData('1', '备注无效');
}
$remark = $param['remark']?? '';
$brok->brok_type = $param['brok_type'];
$brok->pay_type = $param['pay_type'];
$brok->parent_fee = $param['parent_fee'];
$brok->grandpa_fee = $param['grandpa_fee'];
$brok->top_fee = $param['top_fee'];
$brok->remark = $remark;
$brok->save();
$fee_key=$this->getBrokerageKey($param['brok_type']);
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key, $param);
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙');
}
}
}