/b2b/core/model/system/mdl.cur.php
PHP | 230 lines | 194 code | 20 blank | 16 comment | 20 complexity | f40f5736cff526afc10555e2876a5843 MD5 | raw file
- <?php
- class mdl_cur extends modelFactory {
- function mdl_cur($system){
- parent::modelFactory($system);
- $this->_money_format=array(
- 'decimals'=>$this->system->getConf('system.money.operation.decimals'),
- 'dec_point'=>$this->system->getConf('system.money.dec_point'),
- 'thousands_sep'=>$this->system->getConf('system.money.thousands_sep'),
- 'fonttend_decimal_type'=>$this->system->getConf('system.money.operation.carryset'),
- 'fonttend_decimal_remain'=>$this->system->getConf('system.money.operation.decimals')
- );
- }
- /**
- * getSysCur
- *
- * @access privite
- * @return void
- */
- function getSysCur(){
- $CON_CURRENCY['CNY'] = "???";
- $CON_CURRENCY['USD'] = "??";
- $CON_CURRENCY['EUR'] = "??";
- $CON_CURRENCY['GBP'] = "??";
- $CON_CURRENCY['CAD'] = "????";
- $CON_CURRENCY['AUD'] = "??";
- $CON_CURRENCY['RUB'] = "??";
- $CON_CURRENCY['HKD'] = "??";
- $CON_CURRENCY['TWD'] = "???";
- $CON_CURRENCY['KRW'] = "??";
- $CON_CURRENCY['SGD'] = "????";
- $CON_CURRENCY['NZD'] = "????";
- $CON_CURRENCY['JPY'] = "??";
- $CON_CURRENCY['MYR'] = "??";
- $CON_CURRENCY['CHF'] = "????";
- $CON_CURRENCY['SEK'] = "????";
- $CON_CURRENCY['DKK'] = "????";
- $CON_CURRENCY['PLZ'] = "???";
- $CON_CURRENCY['NOK'] = "????";
- $CON_CURRENCY['HUF'] = "??";
- $CON_CURRENCY['CSK'] = "????";
- $CON_CURRENCY['MOP'] = "??";
- return $CON_CURRENCY;
- }
- function curAdd($data){
- if ($data['def_cur']=='true') {
- $sql="select cur_code from sdb_currency where def_cur=1 and cur_code<>'{$data['cur_code']}'";
- $dat=$this->db->select($sql);
- if (!empty($dat[0]['cur_code'])) {
- $this->setError(2005001);
- trigger_error(__('??????????'),E_USER_ERROR);
- return false;
- }
- }
- $rs=$this->db->query('select * from sdb_currency where 0=1');
- $sql=$this->db->GetInsertSQL($rs,$data);
- if(!$sql || $this->db->query($sql)){
- return true;
- }else{
- $this->setError(2005002);
- trigger_error(__('???????'));
- return false;
- }
- }
- function curList(){
- return $this->db->select_b('select * from sdb_currency',50);
- }
- function curAll(){
- return $this->db->select('select * from sdb_currency');
- }
- function curDel($id){
- $sql = 'delete from sdb_currency where cur_code="'.$id.'"';
- if($this->db->exec($sql)){
- return true;
- }else{
- return false;
- }
- }
- function getcur($id, $getDef=false){
- $aCur = $this->db->selectrow('select * FROM sdb_currency where cur_code="'.$id.'"');
- if($aCur['cur_code'] || !$getDef){
- return $this->_in_cur = $aCur;
- }else{
- return $this->_in_cur = $this->getDefault();
- }
- }
-
- function getDefault(){
- if($cur = $this->db->selectrow('select * from sdb_currency where def_cur=1')){
- return $cur;
- }else{ //if have no default currency, read the first currency as default value
- return $this->db->selectrow('select * FROM sdb_currency');
- }
- }
- function curEdit($id,$data){
- if ($data['def_cur']=='true') {
- $sql="select cur_code from sdb_currency where def_cur=1 and cur_code<>'{$data['cur_code']}'";
- $dat=$this->db->select($sql);
- if (!empty($dat[0]['cur_code'])) {
- $this->setError(2005003);
- trigger_error(__('??????????'),E_USER_ERROR);
- return false;
- }
- }
- $rs=$this->db->query('select * from sdb_currency where cur_code="'.$data['cur_code'].'"');
- $sql=$this->db->GetUpdateSQL($rs,$data);
- if($sql){
- if($this->db->exec($sql)){
- return true;
- }else{
- trigger_error(__('??????'),E_USER_ERROR);
- return false;
- }
- }else return true;
- }
- //????????
- function getFormat($cur){
- $ret = array();
- $cursign = $this->getcur($cur, true);
-
- $this->_money_format=array(
- 'decimals'=>$this->system->getConf('system.money.operation.decimals'),
- 'dec_point'=>$this->system->getConf('system.money.dec_point'),
- 'thousands_sep'=>$this->system->getConf('system.money.thousands_sep'),
- 'fonttend_decimal_type'=>$this->system->getConf('system.money.operation.carryset'),
- 'fonttend_decimal_remain'=>$this->system->getConf('system.money.operation.decimals')
- );
- $ret = $this->_money_format;
- $ret['sign'] = $cursign['cur_sign'];
- return $ret;
- }
- function changer($money,$currency='',$basicFormat=false,$chgval=true,$is_sign=true){
-
- if(empty($currency)) $currency = $this->system->request['cur'];
- if($currency || empty($this->_in_cur['cur_rate'])){
- $this->_in_cur = $this->getcur($currency, true);
- }
- if($chgval){
- $money = $money*($this->_in_cur['cur_rate'] ? $this->_in_cur['cur_rate'] : 1);
- }
-
- if($basicFormat){
- return $is_sign ? $this->_in_cur['cur_sign'].$money:$money;
- }
-
- //$decimal_digit =
- //$decimal_type = $this->system->getConf('site.decimal_type');
- if($this->_money_format['fonttend_decimal_type']){
- $mul = 1;
- $mul = pow(10, $this->_money_format['decimals']);
- switch($this->_money_format['fonttend_decimal_type']){
- case 0:
- $money = number_format(trim($money), $this->_money_format['decimals'], '.', '');
- break;
- case 1:
- $money = ceil((trim($money)*$mul).'') / $mul;
- break;
- case 2:
- $money = floor(trim($money)*$mul) / $mul;
- break;
- }
- }
- $money = $this->formatNumber($money);
- if($this->_money_format['fonttend_decimal_remain']>$this->_money_format['decimals']){
- return $is_sign ? $this->_in_cur['cur_sign'].number_format($money,
- $this->_money_format['fonttend_decimal_remain'],
- $this->_money_format['dec_point'],
- '0') : number_format($money,
- $this->_money_format['fonttend_decimal_remain'],
- $this->_money_format['dec_point'],
- '0');
- }else{
- return $is_sign ? $this->_in_cur['cur_sign'].number_format($money,
- $this->_money_format['fonttend_decimal_remain'],
- $this->_money_format['dec_point'],
- $this->_money_format['thousands_sep']) : number_format($money,
- $this->_money_format['fonttend_decimal_remain'],
- $this->_money_format['dec_point'],
- $this->_money_format['thousands_sep']);
- }
-
- /*
- return $this->_in_cur['cur_sign'].number_format(trim($money),
- $this->_money_format['decimals'],
- $this->_money_format['dec_point'],
- $this->_money_format['thousands_sep']);
- */
- }
-
- function formatNumber($number){ //??????????????
- return number_format(trim($number),
- $this->_money_format['decimals'],
- $this->_money_format['dec_point'],'');
- }
-
- //?????????????????
- function getFormatNumber($number){
- if($this->_money_format['fonttend_decimal_type']){
- $mul = 1;
- $mul = pow(10, $this->_money_format['decimals']);
- switch($this->_money_format['fonttend_decimal_type']){
- case 0:
- $number = number_format($number, $this->_money_format['fonttend_decimal_remain'], '.', '');
- break;
- case 1:
- $number = ceil($number*$mul) / $mul;
- break;
- case 2:
- $number = floor($number*$mul) / $mul;
- break;
- }
- }
- return $number;
- }
-
- function sub_changer($mkprice,$goodprice){
- return $this->_in_cur['cur_sign'].($this->getFormatNumber($mkprice)-$this->getFormatNumber($goodprice));
- }
- }
- ?>