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

90 lines
3.6 KiB
PHTML

4 years ago
<?php
namespace Base\Service;
use Base\Facade\Request;
class PartnerService
{
public function checkRelation($params)
{
if (empty($params['self_company_id'])) {
throw new \Exception('请选择己方公司');
}
}
public function adminAgree($application)
{
$adminInfo = $_SESSION['onethink_admin']['user_auth'];
4 years ago
$application['verify_log'] = json_decode($application['verify_log'], true);
$application['verify_log']['verify_user'] = $adminInfo["username"];
4 years ago
$application['verify_log']['verify_time'] = date("Y-m-d H:i:s");
$application['verify_log'] = json_encode($application['verify_log']);
4 years ago
$application['verify_status'] = 1;
4 years ago
$application["create_time"] = time();
$partnerInfo = json_decode($application['partner_info'], true);
$relation = $partnerInfo['relation'];
unset($partnerInfo['relation']);
if($application['partner_id'] == 0){
//新增
$application['partner_id'] = $partnerInfo['id'] = M('partner', 'tab_')->add($partnerInfo);
}else{
//编辑
M('partner', 'tab_')->save($partnerInfo);
}
$this->saveRelation($relation, $partnerInfo);
M('partner_verify', 'tab_')->save($application);
addOperationLog(['op_type' => 1, 'key'=>$application['partner_id'], "op_name"=>"管理员审核", 'url'=>U('index')]);
}
protected function saveRelation($relation, $company)
{
$selfCompany = M('company_info', 'tab_')->where(['id' => $relation['self_company_id']])->find();
4 years ago
$where = '(first_company_type=1 and first_company_id=' . $company['id'] .
') or (second_company_type=1 and second_company_id=' . $company['id'] . ')';
$oldRelation = M('company_relation', 'tab_')->where($where)->find();
4 years ago
$data = [];
if ($relation['collaborate_way'] == 1) {
$data['first_company_id'] = $company['id'];
$data['first_company_name'] = $company['partner'];
4 years ago
$data['first_company_type'] = 1;
4 years ago
$data['second_company_id'] = $selfCompany['id'];
$data['second_company_name'] = $selfCompany['partner'];
$data['second_company_type'] = 0;
} else {
$data['first_company_id'] = $selfCompany['id'];
$data['first_company_name'] = $selfCompany['partner'];
$data['first_company_type'] = 0;
$data['second_company_id'] = $company['id'];
$data['second_company_name'] = $company['partner'];
4 years ago
$data['second_company_type'] = 1;
4 years ago
}
$data['settlement_type'] = $relation['settlement_type'];
$data['invoice_type'] = $relation['invoice_type'];
$data['collection'] = $relation['collection'];
$data['is_payment'] = $relation['is_payment'];
$data['invoice_content'] = $relation['invoice_content'];
4 years ago
if ($oldRelation) {
M('company_relation', 'tab_')->where(['id' => $oldRelation['id']])->save($data);
4 years ago
} else {
M('company_relation', 'tab_')->add($data);
}
}
4 years ago
public function findBaseGamesByPartnerId($partnerId)
{
$gameIds = M('game', 'tab_')->where(['partner_id' => $partnerId])->getField('id', true);
$conditions = ['_string' => '1=1'];
if (empty($gameIds)) {
$conditions['_string'] .= ' and 1=0';
} else {
$conditions['_string'] .= ' and (android_game_id in(' . implode(',', $gameIds) . ') or ios_game_id in(' . implode(',', $gameIds) . '))';
}
return M('base_game', 'tab_')->where($conditions)->select();
}
4 years ago
}