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/Admin/Model/MerchandiseModel.class.php

139 lines
3.9 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Admin\Model;
use Think\Model;
/**
* 商品模型
*/
class MerchandiseModel extends Model{
/* 自动验证规则 */
protected $_validate = array(
);
/* 自动完成规则 */
protected $_auto = array(
array('create_time', 'getCreateTime', 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 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{
if(!isset($data['relation_game_id'])){
$relation=M('Game','tab_')->where(array('id'=>$id))->save(array('relation_game_id'=>$id));
if(!$relation){
$this->error('关联id添加失败');//游戏添加完成
}
}
}
} else { //更新数据
$status = $this->save(); //更新基础内容
if(false === $status){
$this->error = '更新基础内容出错!';
return false;
}
}
// 添加或新增扩展内容
$logic = $this->logic('Set');
$logic->checkModelAttr(5);
if(!$logic->update($id)){
if(isset($id)){ //新增失败,删除基础数据
$this->delete($id);
}
$this->error = $logic->getError();
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;
}
protected function ratio_c(){
$ratio=I('post.ratio');
if((0<=$ratio)&&(100>=$ratio)){
return true;
}else{
return false;
}
}
/*
* 未审核商品列表
* @return array 检测结果数据集
* @author 鹿文学
*/
public function checkMerchandise() {
$list = $this->field('id,title')
->where(array('status'=>array('eq',0)))->select();
$type=407;
if ($list[0]) {
$list = D('check')->dealWithCheckList($type,$list);
if (empty($list[0])) {return '';}
foreach ($list as $k => $v) {
$data[$k]['info'] = '商品:['.$v['title'].'],审核状态:未审核';
$data[$k]['type'] = $type;
$data[$k]['url'] = U('Merchandise/lists',array('id'=>$v['id']));
$data[$k]['create_time'] = time();
$data[$k]['status']=0;
$data[$k]['position'] = $v['id'];
}
return $data;
}else {
D('check')->dealWithCheckListOnNull($type);
return '';
}
}
}