186 lines
6.4 KiB
PHP
186 lines
6.4 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 作者:修缘 联系QQ:278896498 QQ群:1054861244
|
||
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
|
||
// | 另接php业务,网站制作、代理后台、gm后台、支付对接等
|
||
// +----------------------------------------------------------------------
|
||
// | 创建时间: 2022/1/7 21:03
|
||
// +----------------------------------------------------------------------
|
||
|
||
|
||
namespace app\common\model;
|
||
|
||
|
||
use think\facade\Config;
|
||
use Wenpeng\Curl\Curl;
|
||
|
||
class CdkRecord extends GameGm
|
||
{
|
||
protected $autoWriteTimestamp = true;
|
||
protected $createTime = 'create_time';
|
||
protected $updateTime = 'update_time';
|
||
|
||
|
||
|
||
protected $searchField = ['cdk_code', 'account', 'role_id', 'item_name'];
|
||
protected $whereField = ['type', 'agency_account'];
|
||
protected $timeField = ['create_time'];
|
||
|
||
static $api_url;
|
||
static $sign;
|
||
static $Curl;
|
||
|
||
|
||
/**
|
||
* Author:修缘
|
||
* 联系QQ:278896498
|
||
* Date: 2022/1/5 22:46
|
||
*/
|
||
protected static function init()
|
||
{
|
||
parent::init(); // TODO: Change the autogenerated stub
|
||
$ip = Config::get('game.gm.ip');
|
||
$port = Config::get('game.gm.port');
|
||
self::$api_url = "http://{$ip}:$port";
|
||
self::$sign = Config::get('game.gm.sign');
|
||
self::$Curl = new Curl();
|
||
|
||
}
|
||
|
||
|
||
public function scopeSon($query, $son_agency)
|
||
{
|
||
$query->whereIn('agency_account', $son_agency);
|
||
}
|
||
|
||
|
||
public function scopeDirectlySon($query, $directlySon)
|
||
{
|
||
$query->whereIn('agency_account', $directlySon);
|
||
}
|
||
|
||
|
||
|
||
public static function get_send_cdk(array $param, array $cdk_code, $agency = null)
|
||
{
|
||
$cdk = self::where(['cdk_code' => $param['cdk_code']])->find();
|
||
if (!$cdk) {
|
||
self::create([
|
||
'cdk_code' => $param['cdk_code'],
|
||
'account' => $param['account'],
|
||
'role_id' => $param['role_id'],
|
||
'money' => $cdk_code['money'],
|
||
'agency_account' => $agency,
|
||
'type' => $cdk_code['type'],
|
||
'item_name' => "{$cdk_code['item_name']} · 【{$cdk_code['num']}份】",
|
||
]);
|
||
}
|
||
if ($cdk_code['type'] == 1) {
|
||
$gm_result = GameGm::agent_charge((int)$param['role_id'], (int)$cdk_code['item_id'], (int)$cdk_code['num']);
|
||
}
|
||
if ($cdk_code['type'] == 2) {
|
||
$gm_result = GameGm::add_item((int)$param['role_id'], (int)$cdk_code['item_id'], (int)$cdk_code['num']);
|
||
}
|
||
if ($cdk_code['type'] == 3) {
|
||
$data = [
|
||
'role_id' => $param['role_id'],
|
||
'mail_title' => Config::get('game.cdk.mail_title'),
|
||
'mail_content' => Config::get('game.cdk.mail_content'),
|
||
'gets' => $cdk_code['mail'],
|
||
];
|
||
$gm_result = GameGm::send_mail($data, 'R');
|
||
}
|
||
if ($gm_result['code'] != 0) {
|
||
exception(lang('gm_api_send_cdk_error'));
|
||
} else {
|
||
CdkCode::update(['status' => 1], ['cdk_code' => $param['cdk_code']]);
|
||
self::update(['status' => 1], ['cdk_code' => $param['cdk_code']]);
|
||
}
|
||
}
|
||
|
||
public static function verify_cdk(array $param)
|
||
{
|
||
$cdk_result = CdkCode::where(['cdk_code' => $param['cdk_code']])->find();
|
||
if (!$cdk_result) {
|
||
exception(lang('cdk_error'));
|
||
}
|
||
if ($cdk_result['status'] == 1) {
|
||
exception(lang('cdk_failure'));
|
||
}
|
||
$cdk_record = self::where(['cdk_code' => $param['cdk_code'], 'status' => 1])->find();
|
||
if ($cdk_record) {
|
||
exception(lang('cdk_failure'));
|
||
}
|
||
return $cdk_result->toArray();
|
||
}
|
||
|
||
public static function verify_role_info(array $param)
|
||
{
|
||
$user = User::where(['account' => $param['account']])
|
||
->with([
|
||
'agency' => function ($query) {
|
||
$query->field('username,invite');
|
||
}
|
||
])
|
||
->field('account,invite')
|
||
->find() ?? exception(lang('account_absence'));
|
||
$player = Player::where(['roleid' => $param['role_id']])
|
||
->with([
|
||
'account' => function ($query) {
|
||
$query->field('accountid,account,invite');
|
||
}
|
||
])
|
||
->field('roleid,accountid')
|
||
->find() ?? exception(lang('role_id_absence'));
|
||
if ($player->account->account != $param['account']) {
|
||
exception(lang('account_and_roleid_disagree'));
|
||
}
|
||
return $user->agency->username ?? null;
|
||
}
|
||
|
||
public function scopeWhere($query, $param): void
|
||
{
|
||
//关键词like搜索
|
||
$keywords = $param['_keywords'] ?? '';
|
||
if ('' !== $keywords && count($this->searchField) > 0) {
|
||
$this->searchField = implode('|', $this->searchField);
|
||
$query->where($this->searchField, 'like', '%' . $keywords . '%');
|
||
}
|
||
|
||
//字段条件查询
|
||
if (count($this->whereField) > 0 && count($param) > 0) {
|
||
foreach ($param as $key => $value) {
|
||
if ($value !== '' && in_array((string)$key, $this->whereField, true)) {
|
||
$query->where($key, $value);
|
||
}
|
||
}
|
||
}
|
||
|
||
//时间范围查询
|
||
if (count($this->timeField) > 0 && count($param) > 0) {
|
||
foreach ($param as $key => $value) {
|
||
if ($value !== '' && in_array((string)$key, $this->timeField, true)) {
|
||
$field_type = $this->getFieldsType($this->table, $key);
|
||
$time_range = explode(' - ', $value);
|
||
[$start_time,$end_time] = $time_range;
|
||
//如果是int,进行转换
|
||
if (false !== strpos($field_type, 'int')) {
|
||
$start_time = strtotime($start_time);
|
||
if (strlen($end_time) === 10) {
|
||
$end_time .= '23:59:59';
|
||
}
|
||
$end_time = strtotime($end_time);
|
||
}
|
||
$query->where($key, 'between', [$start_time, $end_time]);
|
||
}
|
||
}
|
||
}
|
||
|
||
//排序
|
||
$order = $param['_order'] ?? '';
|
||
$by = $param['_by'] ?? 'desc';
|
||
$query->order($order ?: 'id', $by ?: 'desc');
|
||
}
|
||
|
||
|
||
} |