Evaluatestore.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Evaluatestore extends BaseModel {
  16. public $page_info;
  17. /**
  18. * 查询店铺评分列表
  19. * @access public
  20. * @author csdeshang
  21. * @param array $condition 查询条件
  22. * @param int $pagesize 分页数
  23. * @param string $order 排序
  24. * @param string $field 字段
  25. * @return array
  26. */
  27. public function getEvaluatestoreList($condition, $pagesize = null, $order = 'seval_id desc', $field = '*') {
  28. if($pagesize){
  29. $list = Db::name('evaluatestore')->field($field)->where($condition)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  30. $this->page_info=$list;
  31. return $list->items();
  32. }else{
  33. return Db::name('evaluatestore')->field($field)->where($condition)->order($order)->select()->toArray();
  34. }
  35. }
  36. /**
  37. * 获取店铺评分信息
  38. * @access public
  39. * @author csdeshang
  40. * @param type $condition 查询条件
  41. * @param type $field 字段
  42. * @return type
  43. */
  44. public function getEvaluatestoreInfo($condition, $field = '*') {
  45. $list = Db::name('evaluatestore')->field($field)->where($condition)->find();
  46. return $list;
  47. }
  48. /**
  49. * 根据店铺编号获取店铺评分数据
  50. * @access public
  51. * @author csdeshang
  52. * @param int $store_id 店铺编号
  53. * @param int $storeclass_id 分类编号,如果传入分类编号同时返回行业对比数据
  54. * @return array
  55. */
  56. public function getEvaluatestoreInfoByStoreID($store_id, $storeclass_id = 0) {
  57. $prefix = 'evaluate_store_info';
  58. $info = rcache($store_id, $prefix);
  59. if (empty($info)) {
  60. $info = array();
  61. $info['store_credit'] = $this->_getEvaluatestore(array('seval_storeid' => $store_id));
  62. $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);
  63. $info['store_credit_percent'] = intval($info['store_credit_average'] / 5 * 100);
  64. if ($storeclass_id > 0) {
  65. $sc_info = $this->getEvaluatestoreInfoByScID($storeclass_id);
  66. foreach ($info['store_credit'] as $key => $value) {
  67. if ($sc_info[$key]['credit'] > 0) {
  68. $info['store_credit'][$key]['percent'] = intval(($info['store_credit'][$key]['credit'] - $sc_info[$key]['credit']) / $sc_info[$key]['credit'] * 100);
  69. } else {
  70. $info['store_credit'][$key]['percent'] = 0;
  71. }
  72. if ($info['store_credit'][$key]['percent'] > 0) {
  73. $info['store_credit'][$key]['percent_class'] = 'high';
  74. $info['store_credit'][$key]['percent_text'] = '高于';
  75. $info['store_credit'][$key]['percent'] .= '%';
  76. } elseif ($info['store_credit'][$key]['percent'] == 0) {
  77. $info['store_credit'][$key]['percent_class'] = 'equal';
  78. $info['store_credit'][$key]['percent_text'] = '持平';
  79. $info['store_credit'][$key]['percent'] = '----';
  80. } else {
  81. $info['store_credit'][$key]['percent_class'] = 'low';
  82. $info['store_credit'][$key]['percent_text'] = '低于';
  83. $info['store_credit'][$key]['percent'] = abs($info['store_credit'][$key]['percent']);
  84. $info['store_credit'][$key]['percent'] .= '%';
  85. }
  86. }
  87. }
  88. $cache = array();
  89. $cache['evaluate'] = serialize($info);
  90. wcache($store_id, $cache, $prefix, 60 * 24);
  91. } else {
  92. $info = unserialize($info['evaluate']);
  93. }
  94. return $info;
  95. }
  96. /**
  97. * 根据分类编号获取分类评分数据
  98. * @access public
  99. * @author csdeshang
  100. * @param int $storeclass_id 店铺分类编号
  101. * @return array
  102. */
  103. public function getEvaluatestoreInfoByScID($storeclass_id) {
  104. $prefix = 'sc_evaluate_store_info';
  105. $info = rcache($storeclass_id, $prefix);
  106. if (empty($info)) {
  107. $store_model = model('store');
  108. $store_id_string = $store_model->getStoreIDString(array(array('storeclass_id' ,'=', $storeclass_id)));
  109. $info = $this->_getEvaluatestore(array(array('seval_storeid','in', $store_id_string)));
  110. $cache = array();
  111. $cache['evaluate_store_info'] = serialize($info);
  112. wcache($storeclass_id, $cache, $prefix, 60 * 24);
  113. } else {
  114. $info = unserialize($info['evaluate_store_info']);
  115. }
  116. return $info;
  117. }
  118. /**
  119. * 获取店铺评分数据
  120. * @access public
  121. * @author csdeshang
  122. * @param array $condition 查询条件
  123. * @return array
  124. */
  125. public function _getEvaluatestore($condition) {
  126. $result = array();
  127. $field = 'AVG(seval_desccredit) as store_desccredit,';
  128. $field .= 'AVG(seval_servicecredit) as store_servicecredit,';
  129. $field .= 'AVG(seval_deliverycredit) as store_deliverycredit,';
  130. $field .= 'COUNT(seval_id) as count';
  131. $info = $this->getEvaluatestoreInfo($condition, $field);
  132. $result['store_desccredit']['text'] = '描述相符';
  133. $result['store_servicecredit']['text'] = '服务态度';
  134. $result['store_deliverycredit']['text'] = '发货速度';
  135. if (intval($info['count']) > 0) {
  136. $result['store_desccredit']['credit'] = round($info['store_desccredit'], 1);
  137. $result['store_servicecredit']['credit'] = round($info['store_servicecredit'], 1);
  138. $result['store_deliverycredit']['credit'] = round($info['store_deliverycredit'], 1);
  139. } else {
  140. $result['store_desccredit']['credit'] = round(5, 1);
  141. $result['store_servicecredit']['credit'] = round(5, 1);
  142. $result['store_deliverycredit']['credit'] = round(5, 1);
  143. }
  144. return $result;
  145. }
  146. /**
  147. * 添加店铺评分
  148. * @access public
  149. * @author csdeshang
  150. * @param array $data 参数数据
  151. * @return type
  152. */
  153. public function addEvaluatestore($data) {
  154. dcache($data['seval_storeid'], 'evaluate_store_info');
  155. $storeclass_id=Db::name('store')->where(array(array('store_id','=',$data['seval_storeid'])))->value('storeclass_id');
  156. dcache($storeclass_id, 'sc_evaluate_store_info');
  157. return Db::name('evaluatestore')->insertGetId($data);
  158. }
  159. /**
  160. * 删除店铺评分
  161. * @access public
  162. * @author csdeshang
  163. * @param array $condition 条件
  164. * @return type
  165. */
  166. public function delEvaluatestore($condition) {
  167. $storeid_array = Db::name('evaluatestore')->where($condition)->column('seval_storeid');
  168. foreach ($storeid_array as $store_id) {
  169. dcache($store_id, 'evaluate_store_info');
  170. $storeclass_id=Db::name('store')->where(array(array('store_id','=',$store_id)))->value('storeclass_id');
  171. dcache($storeclass_id, 'sc_evaluate_store_info');
  172. }
  173. return Db::name('evaluatestore')->where($condition)->delete();
  174. }
  175. }