PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://phpfor.googlecode.com/
PHP | 191 lines | 152 code | 23 blank | 16 comment | 7 complexity | 0927bdb4a959352e12c45a0571a069b0 MD5 | raw file
  1. <?php
  2. class mdl_status extends modelFactory {
  3. function getList(){
  4. $return = array();
  5. foreach($this->db->select('select * from sdb_status where date_affect="0000-00-00"') as $row){
  6. $return[$row['status_key']] = $row['status_value'];
  7. }
  8. return $return;
  9. }
  10. function add($key,$value=1,$skip_history=false){
  11. $key = strtoupper($key);
  12. if(!$skip_history){
  13. $this->_add_value($key,date('Y-m-d'),$value);
  14. }
  15. $this->_add_value($key,'0000-00-00',$value);
  16. return true;
  17. }
  18. function _add_value($key,$date,$value){
  19. if(false!==$this->get($key,$date)){
  20. $this->db->exec('update sdb_status set status_value=status_value+'.floatval($value).' where status_key=\''.$key.'\' and date_affect="'.$date.'"');
  21. }else{
  22. $this->set($key,$this->get($key,$date)+$value,$date);
  23. }
  24. }
  25. function set($key,$value,$date='0000-00-00'){
  26. $key = strtoupper($key);
  27. $rs = $this->db->exec('select * from sdb_status where status_key=\''.$key.'\' and date_affect="'.$date.'"');
  28. $sql = $this->db->getUpdateSQL($rs,array('status_key'=>$key,'status_value'=>$value,'last_update'=>time(),'date_affect'=>$date),true);
  29. return $this->db->exec($sql);
  30. }
  31. function get($key,$date='0000-00-00'){
  32. $key = strtoupper($key);
  33. if($row = $this->db->selectrow('select status_value from sdb_status where status_key=\''.$key.'\' and date_affect="'.$date.'"')){
  34. return $row['status_value'];
  35. }else{
  36. return false;
  37. }
  38. }
  39. function cleanup(){
  40. return $this->db->exec('delete from sdb_status where date_affect < "'.date('Y-m-d',time()-24*30).'"');
  41. }
  42. function update($force_count=false){
  43. $in_lib = $this->getList();
  44. foreach(get_class_methods($this) as $func){
  45. if(substr($func,0,6)=='count_'){
  46. if($force_count || !isset($in_lib[strtoupper(substr($func,6))])){
  47. $this->$func();
  48. }
  49. }
  50. }
  51. }
  52. function _update_count($func,$count){
  53. return $this->set(substr($func,6),$count);
  54. }
  55. //?????
  56. function count_order_new(){
  57. $oOrder = &$this->system->loadModel('trading/order');
  58. $filter['status'] = 'active';
  59. $filter['pay_status'] = array(0);
  60. $filter['ship_status'] = array(0);
  61. $filter['disabled'] = 'false';
  62. $filter['confirm'] = 'N';
  63. $count = $oOrder->count($filter);
  64. return $this->_update_count(__FUNCTION__,$count);
  65. }
  66. //???????
  67. function count_gnotify(){
  68. $oNotify = &$this->system->loadModel('goods/goodsNotify');
  69. $filter['status'] = 'ready';
  70. $filter['disabled'] = 'false';
  71. $count = $oNotify->count($filter);
  72. return $this->_update_count(__FUNCTION__,$count);
  73. }
  74. //??????
  75. function count_galert(){
  76. $oProduct = &$this->system->loadModel('goods/finderPdt');
  77. $oGoods = &$this->system->loadModel('goods/products');
  78. $filter_p['store_alarm'] = $this->system->getConf('system.product.alert.num');
  79. foreach($oProduct->getList('goods_id', $filter_p, 0, -1) as $row){
  80. $filter['goods_id'][] = $row['goods_id'];
  81. }
  82. $filter['goods_id'] = array_unique($filter['goods_id']);
  83. if(empty($filter['goods_id'])) $filter['goods_id'][] = -1;
  84. unset($filter_p);
  85. $filter['disabled'] = 'false';
  86. $filter['marketable'] = 'true';
  87. $count = $oGoods->count($filter);
  88. return $this->_update_count(__FUNCTION__,$count);
  89. }
  90. //???????
  91. function count_gdiscuss(){
  92. $oDiscuss = &$this->system->loadModel('comment/discuss');
  93. $filter['adm_read_status'] = 'false';
  94. $filter['disabled'] = 'false';
  95. $count = $oDiscuss->count($filter);
  96. return $this->_update_count(__FUNCTION__,$count);
  97. }
  98. //???????
  99. function count_gask(){
  100. $oGask = &$this->system->loadModel('comment/gask');
  101. $filter['adm_read_status'] = 'false';
  102. $filter['disabled'] = 'false';
  103. $count = $oGask->count($filter);
  104. return $this->_update_count(__FUNCTION__,$count);
  105. }
  106. //???????
  107. function count_messages(){
  108. $oBBS = &$this->system->loadModel('resources/shopbbs');
  109. $filter['unread'] = 0;
  110. $filter['disabled'] = 'false';
  111. $count = $oBBS->count($filter);
  112. return $this->_update_count(__FUNCTION__,$count);
  113. }
  114. // ?????
  115. // Add By Gesion
  116. function count_msgbox() {
  117. $oMsg = &$this->system->loadModel('resources/msgbox');
  118. $filter['unread'] = 0;
  119. $filter['disabled'] = 'false';
  120. $count = $oMsg->count($filter);
  121. return $this->_update_count(__FUNCTION__, $count);
  122. }
  123. //?????
  124. function count_order_to_pay(){
  125. $sales = &$this->system->loadModel('utility/salescount');
  126. $count=$sales->orderWithoutPay();
  127. return $this->_update_count(__FUNCTION__,$count);
  128. }
  129. //????????
  130. function count_order_to_dly(){
  131. $sales = &$this->system->loadModel('utility/salescount');
  132. $count=$sales->playWithoutDeliever();
  133. return $this->_update_count(__FUNCTION__,$count);
  134. }
  135. //????
  136. function count_goods_online(){
  137. $oGoods = &$this->system->loadModel('goods/products');
  138. $count=$oGoods->getMarketGoods('true');
  139. return $this->_update_count(__FUNCTION__,$count);
  140. }
  141. //?????
  142. function count_goods_hidden(){
  143. $oGoods = &$this->system->loadModel('goods/products');
  144. $count=$oGoods->getMarketGoods('false');
  145. return $this->_update_count(__FUNCTION__,$count);
  146. }
  147. //????
  148. function count_drawdeposit_process(){
  149. $sql = 'SELECT * FROM sdb_drawdeposit_apply WHERE `status` = "progress"';
  150. return $this->db->_count($sql);
  151. }
  152. //????
  153. function count_offlinepay_process(){
  154. $sql = 'SELECT * FROM sdb_offlinepay_log WHERE `status` = "1"';
  155. return $this->db->_count($sql);
  156. }
  157. //????
  158. function count_kickback(){
  159. $sql = 'SELECT * FROM sdb_kickback_setting WHERE end_time > '.time().' AND (begin_time <= '.time().' OR notice_time >0 AND notice_time<= '.time().') AND pub="true"';
  160. return $this->db->_count($sql);
  161. }
  162. //???
  163. function count_orderactivity(){
  164. $sql = 'SELECT * FROM sdb_order_activity WHERE end_time > '.time().' AND (begin_time <= '.time().' OR notice_time >0 AND notice_time<= '.time().')';
  165. return $this->db->_count($sql);
  166. }
  167. }
  168. ?>