Evaluatestore.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Evaluatestore extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 查询店铺评分列表
  16. * @access public
  17. * @author csdeshang
  18. * @param array $condition 查询条件
  19. * @param int $pagesize 分页数
  20. * @param string $order 排序
  21. * @param string $field 字段
  22. * @return array
  23. */
  24. public function getEvaluatestoreList($condition, $pagesize = null, $order = 'seval_id desc', $field = '*')
  25. {
  26. if ($pagesize) {
  27. $list = Db::name('evaluatestore')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  28. $this->page_info = $list;
  29. return $list->items();
  30. } else {
  31. return Db::name('evaluatestore')->field($field)->where($condition)->order($order)->select()->toArray();
  32. }
  33. }
  34. /**
  35. * 获取店铺评分信息
  36. * @access public
  37. * @author csdeshang
  38. * @param type $condition 查询条件
  39. * @param type $field 字段
  40. * @return type
  41. */
  42. public function getEvaluatestoreInfo($condition, $field = '*')
  43. {
  44. $list = Db::name('evaluatestore')->field($field)->where($condition)->find();
  45. return $list;
  46. }
  47. /**
  48. * 根据店铺编号获取店铺评分数据
  49. * @access public
  50. * @author csdeshang
  51. * @param int $store_id 店铺编号
  52. * @param int $storeclass_id 分类编号,如果传入分类编号同时返回行业对比数据
  53. * @return array
  54. */
  55. public function getEvaluatestoreInfoByStoreID($store_id, $storeclass_id = 0)
  56. {
  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. {
  105. $prefix = 'sc_evaluate_store_info';
  106. $info = rcache($storeclass_id, $prefix);
  107. if (empty($info)) {
  108. $store_model = model('store');
  109. $store_id_string = $store_model->getStoreIDString(array(array('storeclass_id', '=', $storeclass_id)));
  110. $info = $this->_getEvaluatestore(array(array('seval_storeid', 'in', $store_id_string)));
  111. $cache = array();
  112. $cache['evaluate_store_info'] = serialize($info);
  113. wcache($storeclass_id, $cache, $prefix, 60 * 24);
  114. } else {
  115. $info = unserialize($info['evaluate_store_info']);
  116. }
  117. return $info;
  118. }
  119. /**
  120. * 获取店铺评分数据
  121. * @access public
  122. * @author csdeshang
  123. * @param array $condition 查询条件
  124. * @return array
  125. */
  126. public function _getEvaluatestore($condition)
  127. {
  128. $result = array();
  129. $field = 'AVG(seval_desccredit) as store_desccredit,';
  130. $field .= 'AVG(seval_servicecredit) as store_servicecredit,';
  131. $field .= 'AVG(seval_deliverycredit) as store_deliverycredit,';
  132. $field .= 'COUNT(seval_id) as count';
  133. $info = $this->getEvaluatestoreInfo($condition, $field);
  134. $result['store_desccredit']['text'] = '描述相符';
  135. $result['store_servicecredit']['text'] = '服务态度';
  136. $result['store_deliverycredit']['text'] = '发货速度';
  137. if (intval($info['count']) > 0) {
  138. $result['store_desccredit']['credit'] = round($info['store_desccredit'], 1);
  139. $result['store_servicecredit']['credit'] = round($info['store_servicecredit'], 1);
  140. $result['store_deliverycredit']['credit'] = round($info['store_deliverycredit'], 1);
  141. } else {
  142. $result['store_desccredit']['credit'] = round(5, 1);
  143. $result['store_servicecredit']['credit'] = round(5, 1);
  144. $result['store_deliverycredit']['credit'] = round(5, 1);
  145. }
  146. return $result;
  147. }
  148. /**
  149. * 添加店铺评分
  150. * @access public
  151. * @author csdeshang
  152. * @param array $data 参数数据
  153. * @return type
  154. */
  155. public function addEvaluatestore($data)
  156. {
  157. dcache($data['seval_storeid'], 'evaluate_store_info');
  158. $storeclass_id = Db::name('store')->where(array(array('store_id', '=', $data['seval_storeid'])))->value('storeclass_id');
  159. dcache($storeclass_id, 'sc_evaluate_store_info');
  160. return Db::name('evaluatestore')->insertGetId($data);
  161. }
  162. /**
  163. * 删除店铺评分
  164. * @access public
  165. * @author csdeshang
  166. * @param array $condition 条件
  167. * @return type
  168. */
  169. public function delEvaluatestore($condition)
  170. {
  171. $storeid_array = Db::name('evaluatestore')->where($condition)->column('seval_storeid');
  172. foreach ($storeid_array as $store_id) {
  173. dcache($store_id, 'evaluate_store_info');
  174. $storeclass_id = Db::name('store')->where(array(array('store_id', '=', $store_id)))->value('storeclass_id');
  175. dcache($storeclass_id, 'sc_evaluate_store_info');
  176. }
  177. return Db::name('evaluatestore')->where($condition)->delete();
  178. }
  179. }