PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/b2b/core/model/system/mdl.cur.php

http://phpfor.googlecode.com/
PHP | 230 lines | 194 code | 20 blank | 16 comment | 20 complexity | f40f5736cff526afc10555e2876a5843 MD5 | raw file
  1. <?php
  2. class mdl_cur extends modelFactory {
  3. function mdl_cur($system){
  4. parent::modelFactory($system);
  5. $this->_money_format=array(
  6. 'decimals'=>$this->system->getConf('system.money.operation.decimals'),
  7. 'dec_point'=>$this->system->getConf('system.money.dec_point'),
  8. 'thousands_sep'=>$this->system->getConf('system.money.thousands_sep'),
  9. 'fonttend_decimal_type'=>$this->system->getConf('system.money.operation.carryset'),
  10. 'fonttend_decimal_remain'=>$this->system->getConf('system.money.operation.decimals')
  11. );
  12. }
  13. /**
  14. * getSysCur
  15. *
  16. * @access privite
  17. * @return void
  18. */
  19. function getSysCur(){
  20. $CON_CURRENCY['CNY'] = "???";
  21. $CON_CURRENCY['USD'] = "??";
  22. $CON_CURRENCY['EUR'] = "??";
  23. $CON_CURRENCY['GBP'] = "??";
  24. $CON_CURRENCY['CAD'] = "????";
  25. $CON_CURRENCY['AUD'] = "??";
  26. $CON_CURRENCY['RUB'] = "??";
  27. $CON_CURRENCY['HKD'] = "??";
  28. $CON_CURRENCY['TWD'] = "???";
  29. $CON_CURRENCY['KRW'] = "??";
  30. $CON_CURRENCY['SGD'] = "????";
  31. $CON_CURRENCY['NZD'] = "????";
  32. $CON_CURRENCY['JPY'] = "??";
  33. $CON_CURRENCY['MYR'] = "??";
  34. $CON_CURRENCY['CHF'] = "????";
  35. $CON_CURRENCY['SEK'] = "????";
  36. $CON_CURRENCY['DKK'] = "????";
  37. $CON_CURRENCY['PLZ'] = "???";
  38. $CON_CURRENCY['NOK'] = "????";
  39. $CON_CURRENCY['HUF'] = "??";
  40. $CON_CURRENCY['CSK'] = "????";
  41. $CON_CURRENCY['MOP'] = "??";
  42. return $CON_CURRENCY;
  43. }
  44. function curAdd($data){
  45. if ($data['def_cur']=='true') {
  46. $sql="select cur_code from sdb_currency where def_cur=1 and cur_code<>'{$data['cur_code']}'";
  47. $dat=$this->db->select($sql);
  48. if (!empty($dat[0]['cur_code'])) {
  49. $this->setError(2005001);
  50. trigger_error(__('??????????'),E_USER_ERROR);
  51. return false;
  52. }
  53. }
  54. $rs=$this->db->query('select * from sdb_currency where 0=1');
  55. $sql=$this->db->GetInsertSQL($rs,$data);
  56. if(!$sql || $this->db->query($sql)){
  57. return true;
  58. }else{
  59. $this->setError(2005002);
  60. trigger_error(__('???????'));
  61. return false;
  62. }
  63. }
  64. function curList(){
  65. return $this->db->select_b('select * from sdb_currency',50);
  66. }
  67. function curAll(){
  68. return $this->db->select('select * from sdb_currency');
  69. }
  70. function curDel($id){
  71. $sql = 'delete from sdb_currency where cur_code="'.$id.'"';
  72. if($this->db->exec($sql)){
  73. return true;
  74. }else{
  75. return false;
  76. }
  77. }
  78. function getcur($id, $getDef=false){
  79. $aCur = $this->db->selectrow('select * FROM sdb_currency where cur_code="'.$id.'"');
  80. if($aCur['cur_code'] || !$getDef){
  81. return $this->_in_cur = $aCur;
  82. }else{
  83. return $this->_in_cur = $this->getDefault();
  84. }
  85. }
  86. function getDefault(){
  87. if($cur = $this->db->selectrow('select * from sdb_currency where def_cur=1')){
  88. return $cur;
  89. }else{ //if have no default currency, read the first currency as default value
  90. return $this->db->selectrow('select * FROM sdb_currency');
  91. }
  92. }
  93. function curEdit($id,$data){
  94. if ($data['def_cur']=='true') {
  95. $sql="select cur_code from sdb_currency where def_cur=1 and cur_code<>'{$data['cur_code']}'";
  96. $dat=$this->db->select($sql);
  97. if (!empty($dat[0]['cur_code'])) {
  98. $this->setError(2005003);
  99. trigger_error(__('??????????'),E_USER_ERROR);
  100. return false;
  101. }
  102. }
  103. $rs=$this->db->query('select * from sdb_currency where cur_code="'.$data['cur_code'].'"');
  104. $sql=$this->db->GetUpdateSQL($rs,$data);
  105. if($sql){
  106. if($this->db->exec($sql)){
  107. return true;
  108. }else{
  109. trigger_error(__('??????'),E_USER_ERROR);
  110. return false;
  111. }
  112. }else return true;
  113. }
  114. //????????
  115. function getFormat($cur){
  116. $ret = array();
  117. $cursign = $this->getcur($cur, true);
  118. $this->_money_format=array(
  119. 'decimals'=>$this->system->getConf('system.money.operation.decimals'),
  120. 'dec_point'=>$this->system->getConf('system.money.dec_point'),
  121. 'thousands_sep'=>$this->system->getConf('system.money.thousands_sep'),
  122. 'fonttend_decimal_type'=>$this->system->getConf('system.money.operation.carryset'),
  123. 'fonttend_decimal_remain'=>$this->system->getConf('system.money.operation.decimals')
  124. );
  125. $ret = $this->_money_format;
  126. $ret['sign'] = $cursign['cur_sign'];
  127. return $ret;
  128. }
  129. function changer($money,$currency='',$basicFormat=false,$chgval=true,$is_sign=true){
  130. if(empty($currency)) $currency = $this->system->request['cur'];
  131. if($currency || empty($this->_in_cur['cur_rate'])){
  132. $this->_in_cur = $this->getcur($currency, true);
  133. }
  134. if($chgval){
  135. $money = $money*($this->_in_cur['cur_rate'] ? $this->_in_cur['cur_rate'] : 1);
  136. }
  137. if($basicFormat){
  138. return $is_sign ? $this->_in_cur['cur_sign'].$money:$money;
  139. }
  140. //$decimal_digit =
  141. //$decimal_type = $this->system->getConf('site.decimal_type');
  142. if($this->_money_format['fonttend_decimal_type']){
  143. $mul = 1;
  144. $mul = pow(10, $this->_money_format['decimals']);
  145. switch($this->_money_format['fonttend_decimal_type']){
  146. case 0:
  147. $money = number_format(trim($money), $this->_money_format['decimals'], '.', '');
  148. break;
  149. case 1:
  150. $money = ceil((trim($money)*$mul).'') / $mul;
  151. break;
  152. case 2:
  153. $money = floor(trim($money)*$mul) / $mul;
  154. break;
  155. }
  156. }
  157. $money = $this->formatNumber($money);
  158. if($this->_money_format['fonttend_decimal_remain']>$this->_money_format['decimals']){
  159. return $is_sign ? $this->_in_cur['cur_sign'].number_format($money,
  160. $this->_money_format['fonttend_decimal_remain'],
  161. $this->_money_format['dec_point'],
  162. '0') : number_format($money,
  163. $this->_money_format['fonttend_decimal_remain'],
  164. $this->_money_format['dec_point'],
  165. '0');
  166. }else{
  167. return $is_sign ? $this->_in_cur['cur_sign'].number_format($money,
  168. $this->_money_format['fonttend_decimal_remain'],
  169. $this->_money_format['dec_point'],
  170. $this->_money_format['thousands_sep']) : number_format($money,
  171. $this->_money_format['fonttend_decimal_remain'],
  172. $this->_money_format['dec_point'],
  173. $this->_money_format['thousands_sep']);
  174. }
  175. /*
  176. return $this->_in_cur['cur_sign'].number_format(trim($money),
  177. $this->_money_format['decimals'],
  178. $this->_money_format['dec_point'],
  179. $this->_money_format['thousands_sep']);
  180. */
  181. }
  182. function formatNumber($number){ //??????????????
  183. return number_format(trim($number),
  184. $this->_money_format['decimals'],
  185. $this->_money_format['dec_point'],'');
  186. }
  187. //?????????????????
  188. function getFormatNumber($number){
  189. if($this->_money_format['fonttend_decimal_type']){
  190. $mul = 1;
  191. $mul = pow(10, $this->_money_format['decimals']);
  192. switch($this->_money_format['fonttend_decimal_type']){
  193. case 0:
  194. $number = number_format($number, $this->_money_format['fonttend_decimal_remain'], '.', '');
  195. break;
  196. case 1:
  197. $number = ceil($number*$mul) / $mul;
  198. break;
  199. case 2:
  200. $number = floor($number*$mul) / $mul;
  201. break;
  202. }
  203. }
  204. return $number;
  205. }
  206. function sub_changer($mkprice,$goodprice){
  207. return $this->_in_cur['cur_sign'].($this->getFormatNumber($mkprice)-$this->getFormatNumber($goodprice));
  208. }
  209. }
  210. ?>