Evaluatestore.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Evaluatestore extends BaseModel {
  17. public $page_info;
  18. /**
  19. * 查询店铺评分列表
  20. * @access public
  21. * @author csdeshang
  22. * @param array $condition 查询条件
  23. * @param int $pagesize 分页数
  24. * @param string $order 排序
  25. * @param string $field 字段
  26. * @return array
  27. */
  28. public function getEvaluatestoreList($condition, $pagesize = null, $order = 'seval_id desc', $field = '*') {
  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. $list = Db::name('evaluatestore')->field($field)->where($condition)->find();
  47. return $list;
  48. }
  49. /**
  50. * 根据店铺编号获取店铺评分数据
  51. * @access public
  52. * @author csdeshang
  53. * @param int $store_id 店铺编号
  54. * @param int $storeclass_id 分类编号,如果传入分类编号同时返回行业对比数据
  55. * @return array
  56. */
  57. public function getEvaluatestoreInfoByStoreID($store_id, $storeclass_id = 0) {
  58. $prefix = 'evaluate_store_info';
  59. $info = rcache($store_id, $prefix);
  60. if (empty($info)) {
  61. $info = array();
  62. $info['store_credit'] = $this->_getEvaluatestore(array('seval_storeid' => $store_id));
  63. $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);
  64. $info['store_credit_percent'] = intval($info['store_credit_average'] / 5 * 100);
  65. if ($storeclass_id > 0) {
  66. $sc_info = $this->getEvaluatestoreInfoByScID($storeclass_id);
  67. foreach ($info['store_credit'] as $key => $value) {
  68. if ($sc_info[$key]['credit'] > 0) {
  69. $info['store_credit'][$key]['percent'] = intval(($info['store_credit'][$key]['credit'] - $sc_info[$key]['credit']) / $sc_info[$key]['credit'] * 100);
  70. } else {
  71. $info['store_credit'][$key]['percent'] = 0;
  72. }
  73. if ($info['store_credit'][$key]['percent'] > 0) {
  74. $info['store_credit'][$key]['percent_class'] = 'high';
  75. $info['store_credit'][$key]['percent_text'] = '高于';
  76. $info['store_credit'][$key]['percent'] .= '%';
  77. } elseif ($info['store_credit'][$key]['percent'] == 0) {
  78. $info['store_credit'][$key]['percent_class'] = 'equal';
  79. $info['store_credit'][$key]['percent_text'] = '持平';
  80. $info['store_credit'][$key]['percent'] = '----';
  81. } else {
  82. $info['store_credit'][$key]['percent_class'] = 'low';
  83. $info['store_credit'][$key]['percent_text'] = '低于';
  84. $info['store_credit'][$key]['percent'] = abs($info['store_credit'][$key]['percent']);
  85. $info['store_credit'][$key]['percent'] .= '%';
  86. }
  87. }
  88. }
  89. $cache = array();
  90. $cache['evaluate'] = serialize($info);
  91. wcache($store_id, $cache, $prefix, 60 * 24);
  92. } else {
  93. $info = unserialize($info['evaluate']);
  94. }
  95. return $info;
  96. }
  97. /**
  98. * 根据分类编号获取分类评分数据
  99. * @access public
  100. * @author csdeshang
  101. * @param int $storeclass_id 店铺分类编号
  102. * @return array
  103. */
  104. public function getEvaluatestoreInfoByScID($storeclass_id) {
  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. $result = array();
  128. $field = 'AVG(seval_desccredit) as store_desccredit,';
  129. $field .= 'AVG(seval_servicecredit) as store_servicecredit,';
  130. $field .= 'AVG(seval_deliverycredit) as store_deliverycredit,';
  131. $field .= 'COUNT(seval_id) as count';
  132. $info = $this->getEvaluatestoreInfo($condition, $field);
  133. $result['store_desccredit']['text'] = '描述相符';
  134. $result['store_servicecredit']['text'] = '服务态度';
  135. $result['store_deliverycredit']['text'] = '发货速度';
  136. if (intval($info['count']) > 0) {
  137. $result['store_desccredit']['credit'] = round($info['store_desccredit'], 1);
  138. $result['store_servicecredit']['credit'] = round($info['store_servicecredit'], 1);
  139. $result['store_deliverycredit']['credit'] = round($info['store_deliverycredit'], 1);
  140. } else {
  141. $result['store_desccredit']['credit'] = round(5, 1);
  142. $result['store_servicecredit']['credit'] = round(5, 1);
  143. $result['store_deliverycredit']['credit'] = round(5, 1);
  144. }
  145. return $result;
  146. }
  147. /**
  148. * 添加店铺评分
  149. * @access public
  150. * @author csdeshang
  151. * @param array $data 参数数据
  152. * @return type
  153. */
  154. public function addEvaluatestore($data) {
  155. dcache($data['seval_storeid'], 'evaluate_store_info');
  156. $storeclass_id=Db::name('store')->where(array(array('store_id','=',$data['seval_storeid'])))->value('storeclass_id');
  157. dcache($storeclass_id, 'sc_evaluate_store_info');
  158. return Db::name('evaluatestore')->insertGetId($data);
  159. }
  160. /**
  161. * 删除店铺评分
  162. * @access public
  163. * @author csdeshang
  164. * @param array $condition 条件
  165. * @return type
  166. */
  167. public function delEvaluatestore($condition) {
  168. $storeid_array = Db::name('evaluatestore')->where($condition)->column('seval_storeid');
  169. foreach ($storeid_array as $store_id) {
  170. dcache($store_id, 'evaluate_store_info');
  171. $storeclass_id=Db::name('store')->where(array(array('store_id','=',$store_id)))->value('storeclass_id');
  172. dcache($storeclass_id, 'sc_evaluate_store_info');
  173. }
  174. return Db::name('evaluatestore')->where($condition)->delete();
  175. }
  176. }