evaluate_store.model.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * 店铺评分模型
  4. *
  5. */
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class evaluate_storeModel extends Model {
  8. public function __construct(){
  9. parent::__construct('evaluate_store');
  10. }
  11. /**
  12. * 查询店铺评分列表
  13. *
  14. * @param array $condition 查询条件
  15. * @param int $page 分页数
  16. * @param string $order 排序
  17. * @param string $field 字段
  18. * @return array
  19. */
  20. public function getEvaluateStoreList($condition, $page=null, $order='seval_id desc', $field='*') {
  21. $list = $this->field($field)->where($condition)->page($page)->order($order)->select();
  22. return $list;
  23. }
  24. /**
  25. * 获取店铺评分信息
  26. */
  27. public function getEvaluateStoreInfo($condition, $field='*') {
  28. $list = $this->field($field)->where($condition)->find();
  29. return $list;
  30. }
  31. /**
  32. * 根据店铺编号获取店铺评分数据
  33. *
  34. * @param int @store_id 店铺编号
  35. * @param int @sc_id 分类编号,如果传入分类编号同时返回行业对比数据
  36. */
  37. public function getEvaluateStoreInfoByStoreID($store_id, $sc_id = 0) {
  38. $prefix = 'evaluate_store_info';
  39. $info = rcache($store_id, $prefix);
  40. if(empty($info)) {
  41. $info = array();
  42. $info['store_credit'] = $this->_getEvaluateStore(array('seval_storeid' => $store_id));
  43. $info['store_credit_average'] = round((($info['store_credit']['store_desccredit']['credit'] + $info['store_credit']['store_servicecredit']['credit'] + $info['store_credit']['store_deliverycredit']['credit']) / 3), 1);
  44. $info['store_credit_percent'] = intval($info['store_credit_average'] / 5 * 100);
  45. if($sc_id > 0) {
  46. $sc_info = $this->getEvaluateStoreInfoByScID($sc_id);
  47. foreach ($info['store_credit'] as $key => $value) {
  48. if($sc_info[$key]['credit'] > 0) {
  49. $info['store_credit'][$key]['percent'] = intval(($info['store_credit'][$key]['credit'] - $sc_info[$key]['credit']) / $sc_info[$key]['credit'] * 100);
  50. } else {
  51. $info['store_credit'][$key]['percent'] = 0;
  52. }
  53. if($info['store_credit'][$key]['percent'] > 0) {
  54. $info['store_credit'][$key]['percent_class'] = 'high';
  55. $info['store_credit'][$key]['percent_text'] = '高于';
  56. $info['store_credit'][$key]['percent'] .= '%';
  57. } elseif ($info['store_credit'][$key]['percent'] == 0) {
  58. $info['store_credit'][$key]['percent_class'] = 'equal';
  59. $info['store_credit'][$key]['percent_text'] = '持平';
  60. $info['store_credit'][$key]['percent'] = '----';
  61. } else {
  62. $info['store_credit'][$key]['percent_class'] = 'low';
  63. $info['store_credit'][$key]['percent_text'] = '低于';
  64. $info['store_credit'][$key]['percent'] = abs($info['store_credit'][$key]['percent']);
  65. $info['store_credit'][$key]['percent'] .= '%';
  66. }
  67. }
  68. }
  69. $cache = array();
  70. $cache['evaluate'] = serialize($info);
  71. wcache($store_id, $cache, $prefix, 60 * 24);
  72. } else {
  73. $info = unserialize($info['evaluate']);
  74. }
  75. return $info;
  76. }
  77. /**
  78. * 根据分类编号获取分类评分数据
  79. */
  80. public function getEvaluateStoreInfoByScID($sc_id) {
  81. $prefix = 'sc_evaluate_store_info';
  82. $info = rcache($sc_id, $prefix);
  83. if(empty($info)) {
  84. $model_store = Model('store');
  85. $store_id_string = $model_store->getStoreIDString(array('sc_id' => $sc_id));
  86. $info = $this->_getEvaluateStore(array('seval_storeid' => array('in', $store_id_string)));
  87. $cache = array();
  88. $cache['evaluate_store_info'] = serialize($info);
  89. wcache($sc_id, $cache, $prefix, 60 * 24);
  90. } else {
  91. $info = unserialize($info['evaluate_store_info']);
  92. }
  93. return $info;
  94. }
  95. /**
  96. * 获取店铺评分数据
  97. */
  98. private function _getEvaluateStore($condition) {
  99. $result = array();
  100. $field = 'AVG(seval_desccredit) as store_desccredit,';
  101. $field .= 'AVG(seval_servicecredit) as store_servicecredit,';
  102. $field .= 'AVG(seval_deliverycredit) as store_deliverycredit,';
  103. $field .= 'COUNT(seval_id) as count';
  104. $info = $this->getEvaluateStoreInfo($condition, $field);
  105. $result['store_desccredit']['text'] = '描述相符';
  106. $result['store_servicecredit']['text'] = '服务态度';
  107. $result['store_deliverycredit']['text'] = '发货速度';
  108. if(intval($info['count']) > 0) {
  109. $result['store_desccredit']['credit'] = round($info['store_desccredit'], 1);
  110. $result['store_servicecredit']['credit'] = round($info['store_servicecredit'], 1);
  111. $result['store_deliverycredit']['credit'] = round($info['store_deliverycredit'], 1);
  112. } else {
  113. $result['store_desccredit']['credit'] = round(5, 1);
  114. $result['store_servicecredit']['credit'] = round(5, 1);
  115. $result['store_deliverycredit']['credit'] = round(5, 1);
  116. }
  117. return $result;
  118. }
  119. /**
  120. * 添加店铺评分
  121. */
  122. public function addEvaluateStore($param) {
  123. return $this->insert($param);
  124. }
  125. /**
  126. * 删除店铺评分
  127. */
  128. public function delEvaluateStore($condition) {
  129. return $this->where($condition)->delete();
  130. }
  131. }