Evaluatestore.php 7.8 KB

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