89 lines
1.9 KiB
PHP
89 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace app\merchant\service;
|
|
|
|
use app\core\Service;
|
|
use think\admin\extend\CodeExtend;
|
|
use app\merchant\service\MerchantService;
|
|
|
|
/**
|
|
* 商户分成服务
|
|
* Class MerchantService
|
|
* @package app\merchant\service
|
|
*/
|
|
class PercentService extends Service
|
|
{
|
|
/**
|
|
* 设置默认操作表
|
|
* @var string
|
|
*/
|
|
public $table = 'merchant_percent';
|
|
|
|
public $isp = array
|
|
(
|
|
1 => '移动',
|
|
2 => '联通',
|
|
3 => '电信',
|
|
4 => '其他',
|
|
);
|
|
|
|
public function getIsp($state = 1)
|
|
{
|
|
if ($state == 1) {
|
|
return $this->isp;
|
|
} else {
|
|
return array_flip($this->isp);
|
|
}
|
|
}
|
|
|
|
# 获取商户信息
|
|
public function getInfo($mid, $product_key)
|
|
{
|
|
$where['mid'] = $mid;
|
|
$where['product_key'] = $product_key;
|
|
|
|
$data = $this->db()->where($where)->find();
|
|
|
|
return $data;
|
|
}
|
|
|
|
# 获取缓存
|
|
public function get($mid, $product_key, $get = true)
|
|
{
|
|
if (!$get) {
|
|
return false;
|
|
}
|
|
$cache_key = 'percent_' . $mid . '_' . $product_key;
|
|
|
|
$data = !$get ? false : $this->cache($cache_key);
|
|
|
|
if (!$data) {
|
|
$data = $this->getInfo($mid, $product_key);
|
|
if ($data) {
|
|
$this->cache($cache_key, $data);
|
|
}
|
|
}
|
|
|
|
if ($data) {
|
|
if ($data['status'] != 1) {
|
|
return false;
|
|
}
|
|
if ($data['is_deleted'] != 0) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
# 更新
|
|
public function up($mid, $product_key)
|
|
{
|
|
$info = $this->db()->where(['mid' => $mid, 'product_key' => $product_key])->find();
|
|
if ($info) {
|
|
//$data['mid'] = $mid;
|
|
$data['product_key'] = $product_key;
|
|
$this->db()->where(['id' => $info['id']])->update($data);
|
|
}
|
|
}
|
|
} |