REAPI/app/channel/service/KamiGroupService.php

61 lines
1.5 KiB
PHP

<?php
namespace app\channel\service;
use app\core\Service;
use app\channel\service\KamiGroupService as KamiGroup;
use think\facade\Db;
/**
* 游戏点卡卡密服务
* Class ChannelService
* @package app\channel\service
*/
class KamiGroupService extends Service
{
/**
* 设置默认操作表
* @var string
*/
public $table = 'channel_kami_group';
# 获取一个批次
public function getOne()
{
$where = array();
$where['status'] = 1;
$info = $this->db()->where($where)->order('status desc, reorder desc, id desc')->find();
if ($info) {
$card = KamiGroup::instance()->db()->where(array('kami_group_id' => $info['id'], 'status' => 1, 'use' => 1))->find();
if ($card) {
return $info['id'];
} else {
$this->db()->where(array('id' => $info['id']))->update(array('status' => '0'));
return $this->getOne();
}
}
return 1;
}
public function up($name, $reorder = 1)
{
$data = array();
$data['name'] = $name;
$info = $this->db()->where($where)->find();
if ($reorder) {
$data['reorder'] = $reorder;
}
$data['status'] = 1;
if (!$info) {
return $this->db()->insertGetId($data);
} else {
$this->db()->where(array('id' => $info['id']))->update($data);
return $info['id'];
}
}
}