221 lines
7.5 KiB
PHP
221 lines
7.5 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
|
|
namespace addon\saasagent\model;
|
|
|
|
use addon\aliapp\model\AliPaySubLedger;
|
|
use app\model\BaseModel;
|
|
use think\Exception;
|
|
use think\facade\Db;
|
|
|
|
class SiteWebsite extends BaseModel{
|
|
/**
|
|
* Common: 记录合伙人与店铺关系
|
|
* Author: wu-hui
|
|
* Time: 2023/01/29 14:11
|
|
* @return array
|
|
*/
|
|
public function addInfo(){
|
|
// 参数获取
|
|
$site_id = input('site_id',0);
|
|
$website_id = input('website_id',0);
|
|
$rate = input('rate',0);
|
|
$maxRate = (float)30;
|
|
$params = [
|
|
'site_id' => $site_id,
|
|
'website_id' => $website_id
|
|
];
|
|
// 判断:是否已经存在
|
|
$isHas = (int)Db::name('site_website')->where($params)->value('id');
|
|
if($isHas > 0) return $this->error('','关系已绑定,请勿重复操作!');
|
|
// 判断:总分润比例是否超出
|
|
$sumRate = (float)$this->getSiteSumRate($site_id)['data'];
|
|
if(((float)$rate + (float)$sumRate) > $maxRate) return $this->error('','总分润比例超出限制!');
|
|
// 记录合伙人与店铺关系
|
|
model('site_website')->startTrans();
|
|
try{
|
|
// 记录信息
|
|
$res = model('site_website')->add($params);
|
|
// 开始绑定
|
|
if($res > 0) (new AliPaySubLedger($site_id))->relationBind($website_id);
|
|
|
|
model('site_website')->commit();
|
|
return $this->success($res);
|
|
}catch(Exception $e){
|
|
model('site_website')->rollback();
|
|
return $this->error('',$e->getMessage());
|
|
}
|
|
}
|
|
/**
|
|
* Common: 删除合伙人与店铺的关联信息
|
|
* Author: wu-hui
|
|
* Time: 2023/01/29 14:01
|
|
* @param $condition
|
|
* @return array
|
|
*/
|
|
public function del(){
|
|
// 参数获取
|
|
$siteWebsiteId = input('site_website_id', 0);
|
|
// 删除操作
|
|
Db::name('site_website')->startTrans();
|
|
try{
|
|
// 删除前获取信息
|
|
$info = Db::name('site_website')->where('id',$siteWebsiteId)->find();
|
|
// 记录信息
|
|
$res = Db::name('site_website')->where('id',$siteWebsiteId)->delete();
|
|
// 解除绑定
|
|
if($res > 0) (new AliPaySubLedger($info['site_id']))->relationUnbind($info['website_id']);
|
|
|
|
Db::name('site_website')->commit();
|
|
return $this->success($res);
|
|
}catch(Exception $e){
|
|
Db::name('site_website')->rollback();
|
|
return $this->error('',$e->getMessage());
|
|
}
|
|
}
|
|
/**
|
|
* Common: 获取所有合伙人列表
|
|
* Author: wu-hui
|
|
* Time: 2023/01/29 10:21
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function getWebsiteList(){
|
|
// 参数获取
|
|
$site_id = input('site_id',0);
|
|
$page = input('page',1);
|
|
$pageSize = input('page_size',PAGE_LIST_ROWS);
|
|
// 列表获取
|
|
$field = [
|
|
'max(sw.id) as site_website_id',
|
|
'a.id as website_id',
|
|
'a.web_contacts',
|
|
'a.web_phone',
|
|
'a.role_ids',
|
|
'a.alipay_account',
|
|
'sum(al.rate) as rate',
|
|
'al.level_id'
|
|
];
|
|
$result = Db::name('website')->alias('a')
|
|
->field($field)
|
|
->join('site_website sw',"sw.site_id = {$site_id} AND sw.website_id = a.id",'left')
|
|
->join('agent_level al',"find_in_set(al.level_id,a.role_ids)",'left')
|
|
->group('a.id')
|
|
->paginate(['list_rows' => $pageSize,'page' => $page]);
|
|
if($result) $result = $result->toArray();
|
|
|
|
$list = [
|
|
'count' => $result['total'],
|
|
'list' => $result['data'],
|
|
'page_count' => $result['last_page'],
|
|
];
|
|
return $this->success($list);
|
|
}
|
|
/**
|
|
* Common: 获取某个店铺关联的合伙人列表
|
|
* Author: wu-hui
|
|
* Time: 2023/01/29 13:36
|
|
* @param $siteId
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function getSiteWebsiteList(){
|
|
// 参数获取
|
|
$siteId = input('site_id',1);
|
|
$page = input('page',1);
|
|
$pageSize = input('page_size',PAGE_LIST_ROWS);
|
|
// 列表获取
|
|
$field = [
|
|
'max(sw.id) as site_website_id',
|
|
'a.id as website_id',
|
|
'a.web_contacts',
|
|
'a.web_phone',
|
|
'a.role_ids',
|
|
'a.alipay_account',
|
|
'sum(al.rate) as rate',
|
|
'al.level_id'
|
|
];
|
|
$result = Db::name('site_website')
|
|
->alias('sw')
|
|
->field($field)
|
|
->join('website a',"sw.website_id = a.id",'left')
|
|
->join('agent_level al',"find_in_set(al.level_id,a.role_ids)",'left')
|
|
->where('sw.site_id',$siteId)
|
|
->group('sw.id')
|
|
->paginate(['list_rows' => $pageSize,'page' => $page]);
|
|
if($result) $result = $result->toArray();
|
|
|
|
$list = [
|
|
'count' => $result['total'],
|
|
'list' => $result['data'],
|
|
'page_count' => $result['last_page'],
|
|
];
|
|
return $this->success($list);
|
|
}
|
|
/**
|
|
* Common: 获取某个店铺全部的合伙人列表
|
|
* Author: wu-hui
|
|
* Time: 2023/02/01 15:39
|
|
* @param $siteId
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getWholeSiteWebsiteList($siteId){
|
|
$field = [
|
|
'max(sw.id) as site_website_id',
|
|
'a.id as website_id',
|
|
'a.web_contacts',
|
|
'a.web_phone',
|
|
'a.role_ids',
|
|
'a.alipay_account',
|
|
'sum(al.rate) as rate',
|
|
'al.level_id'
|
|
];
|
|
$result = Db::name('site_website')
|
|
->alias('sw')
|
|
->field($field)
|
|
->join('website a',"sw.website_id = a.id",'left')
|
|
->join('agent_level al',"find_in_set(al.level_id,a.role_ids)",'left')
|
|
->where('sw.site_id',$siteId)
|
|
->group('sw.id')
|
|
->select();
|
|
if($result) $result = $result->toArray();
|
|
|
|
return $this->success($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* Common: 获取当前店铺总分润比例
|
|
* Author: wu-hui
|
|
* Time: 2023/01/29 14:30
|
|
* @param $siteId
|
|
* @return array
|
|
*/
|
|
public function getSiteSumRate($siteId){
|
|
$sumRate = (float)Db::name('site_website')
|
|
->alias('sw')
|
|
->join('website a',"sw.website_id = a.id",'left')
|
|
->join('agent_level al',"find_in_set(al.level_id,a.role_ids)",'left')
|
|
->where('sw.site_id',$siteId)
|
|
->sum('al.rate');
|
|
|
|
return $this->success($sumRate);
|
|
}
|
|
|
|
|
|
|
|
|
|
} |