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.
jy-sdk/Application/Mobile/Model/WithdrawGoldCoinModel.class...

276 lines
7.2 KiB
PHTML

2 years ago
<?php
namespace Mobile\Model;
use Think\Model;
/**
* 金币提现记录
*/
class WithdrawGoldCoinModel extends Model{
/* 自动验证规则 */
protected $_validate = array(
array('money','require','到账金额不能为空',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
//array('money','/^\d+(\.\d{1,2})?$/','到账金额不正确',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
array('coin','require','提现金币不能为空',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
//array('coin','/^\d+(\.\d{1,2})?$/','提现金币不正确',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
array('poundage','require','手续费不能为空',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
//array('poundage','/^\d+(\.\d{1,2})?$/','手续费不正确',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
array('gold_coin_balance','require','金币余额不能为空',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
array('alipay','require','支付宝不能为空',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
array('alipay_real_name','require','支付宝真实姓名不能为空',self::MUST_VALIDATE,'regex', self::MODEL_BOTH),
);
/* 自动完成规则 */
protected $_auto = array(
array('create_time', 'getCreateTime', self::MODEL_INSERT, 'callback'),
array('order_number', 'get_order_number', self::MODEL_INSERT, 'callback'),
);
/**
* 构造函数
* @param string $name 模型名称
* @param string $tablePrefix 表前缀
* @param mixed $connection 数据库连接信息
*/
public function __construct($name = '', $tablePrefix = '', $connection = '') {
/* 设置默认的表前缀 */
$this->tablePrefix ='tab_';
/* 执行构造方法 */
parent::__construct($name, $tablePrefix, $connection);
}
/**
* 记录列表
* @param integer $p 页码
* @param array $map 条件数组
* @param string $fields 字段列表
* @param string $order 排序
* @param integer $row 每页数量
* @return array 结果数据集
* @author 鹿文学
*/
public function lists($p=1,$map=array(),$fields=true,$order='online_time desc',$row=10) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$user = D('User')->getLoginInfo();
if(is_array($user)){
$map['status'] = array('gt',0);
$map['user_id'] = $user['user_id'];
$lists = $this->alias('m')->field($fields)
->where($map)->page($page,$row)->order($order)->select();
$count = $this->alias('m')->where($map)->count();
}
if(is_array($lists)) {
$data['lists'] = $lists;$data['status']=1;
if($count > $row){
$data['total'] = ceil($count/$row);
} else {
$data['total']=1;
}
} else {
$data['lists']='';$data['total'] = 1;$data['status'] = 0;
}
$data['current'] = $page;
return $data;
}
/**
* 新增或更新一个记录
* @param array $data 手动传入的数据
* @return boolean fasle 失败 int 成功 返回完整的数据
* @author 王贺
*/
public function update($data = null){
/* 获取数据对象 */
$data = $this->token(false)->create($data);
if(empty($data)){
return false;
}
/* 添加或新增基础内容 */
if(empty($data['id'])){ //新增数据
$id = $this->add($data); //添加基础内容
if(!$id){
$this->error = '提现失败,请重新提交';
return false;
}else{
$data['id'] = $id;
}
} else { //更新数据
$status = $this->save(); //更新基础内容
if(false === $status){
$this->error = '更新基础内容出错!';
return false;
}
}
return $data;
}
/**
* 创建时间不写则取当前时间
* @return int 时间戳
* @author huajie <banhuajie@163.com>
*/
protected function getCreateTime(){
$create_time = I('post.create_time');
return $create_time?strtotime($create_time):NOW_TIME;
}
/**
* 创建订单号
* @return int 时间戳
* @author huajie <banhuajie@163.com>
*/
protected function get_order_number() {
$order_number = I('post.order_number');
return $order_number?$order_number:'WG_'.date('Ymd').date('His').sp_random_string(4);;
}
/**
* 获取商品总数
* @param array $map 条件数组
* @return integer 总数
* @author 鹿文学
*/
public function total($map) {
return $this->where($map)->count();
}
/**
* 商品详情
* @param integer $id 商品编号
* @return array 结果数据集
* @author 鹿文学
*/
public function detail($id=0) {
if(is_numeric($id) && $id > 0) {
$map['m.id'] = $id;
$data = $this->merchandise_info($map);
}
return $data;
}
/**
* 商品详情
* @param integer $id 商品编号
* @return array 结果数据集
* @author 鹿文学
*/
public function sale_detail($id=0) {
if(is_numeric($id) && $id > 0) {
$map['m.id'] = $id;
$map['m.status']=3;
$map['m.online_time'] = ['gt',0];
$data = $this->merchandise_info($map);
}
return $data;
}
/**
* 商品详情
* @param integer $id 商品编号
* @return array 结果数据集
* @author 鹿文学
*/
public function deal_detail($id=0) {
if(is_numeric($id) && $id > 0) {
$map['m.id'] = $id;
$map['m.status']=1;
$data = $this->merchandise_info($map);
}
return $data;
}
private function merchandise_info($map) {
return $this->alias('m')->field('m.id,m.title,m.content,m.status,m.screenshot,m.online_time,m.server_name,m.price,m.day,m.accumulation,m.small_account,g.relation_game_id,g.game_name,g.game_size,g.game_type_name,g.sdk_version,g.down_port,g.add_game_address,g.ios_game_address')
->join('tab_game as g on(g.id = m.game_id) ')
->where($map)->find();
}
/**
* 商品信息
* @param integer $id 商品编号
* @return array 结果数据集
* @author 鹿文学
*/
public function info($id=0) {
if(is_numeric($id) && $id > 0) {
$map['m.id'] = $id;
$map['m.status'] = 3;
$map['m.online_time'] = ['gt',0];
$data = $this->alias('m')->field('m.id,m.title,m.price,m.game_name,m.screenshot')
->where($map)->find();
}
return $data;
}
/**
* 商品购买需要的信息
* @param integer $id 商品编号
* @return array 结果数据集
* @author 鹿文学
*/
public function buy_info($id=0) {
if(is_numeric($id) && $id > 0) {
$map['m.id'] = $id;
$map['m.status'] = 3;
$data = $this->alias('m')->field('m.id,m.price,m.small_id,m.small_account,m.user_id as seller_id,m.user_account as seller_account,m.game_id')
->where($map)->find();
}
return $data;
}
}