Memberevaluate.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace app\common\logic;
  3. /**
  4. * ============================================================================
  5. *
  6. * ============================================================================
  7. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  8. * 网站地址: https://www.valimart.net/
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 逻辑层模型
  13. */
  14. class Memberevaluate{
  15. public function evaluateListDity($goods_eval_list) {
  16. foreach ($goods_eval_list as $key => $value) {
  17. $goods_eval_list[$key]['member_avatar'] = get_member_avatar_for_id($value['geval_frommemberid']);
  18. }
  19. return $goods_eval_list;
  20. }
  21. /* 查询订单信息 */
  22. public function validation($order_id, $member_id) {
  23. $condition = array();
  24. $condition[] = array('order_id','=',$order_id);
  25. $condition[] = array('buyer_id','=',$member_id);
  26. //获取订单信息
  27. $order_info = model('order')->getOrderInfo($condition);
  28. if (empty($order_info)) {
  29. $info = array('state' => '0', 'msg' => '订单出错');
  30. }
  31. $order_info['evaluate_able'] = model('order')->getOrderOperateState('evaluation', $order_info);
  32. if (empty($order_info) || !$order_info['evaluate_able']) {
  33. $info = array('state' => '0', 'msg' => '评价订单不存在');
  34. }
  35. //查询店铺信息
  36. $store_info = model('store')->getStoreInfoByID($order_info['store_id']);
  37. if (empty($store_info)) {
  38. $info = array('state' => '0', 'msg' => '店铺不存在');
  39. }
  40. //获取订单商品
  41. $order_goods = model('order')->getOrdergoodsList($condition);
  42. if (empty($order_goods)) {
  43. $info = array('state' => '0', 'msg' => '订单商品不存在');
  44. }
  45. foreach ($order_goods as $key => $value) {
  46. $order_goods[$key]['goods_image_url'] = goods_cthumb($value['goods_image']);
  47. }
  48. $info['data'] = array('order_goods' => $order_goods, 'store_info' => $store_info, 'order_info' => $order_info);
  49. return $info;
  50. }
  51. /* 保存订单评价信息 */
  52. public function saveorderevaluate($order_info, $store_info, $order_goods, $member_id, $member_name) {
  53. $evaluate_goods_array = array();
  54. $goodsid_array = array();
  55. $goods_array = input('post.goods/a');#获取评价数组
  56. foreach ($order_goods as $value) {
  57. //如果未评分,默认为5分
  58. $evaluate_score = intval($goods_array[$value['goods_id']]['score']);
  59. if ($evaluate_score <= 0 || $evaluate_score > 5) {
  60. $evaluate_score = 5;
  61. }
  62. //默认评语
  63. $evaluate_comment = $goods_array[$value['goods_id']]['comment'];
  64. if (empty($evaluate_comment)) {
  65. $evaluate_comment = '不错哦';
  66. }else{
  67. $res=word_filter($evaluate_comment);
  68. if($res['code']){
  69. $evaluate_comment=$res['data']['text'];
  70. }
  71. }
  72. $evaluate_goods_info = array();
  73. $evaluate_goods_info['geval_orderid'] = $order_info['order_id'];
  74. $evaluate_goods_info['geval_orderno'] = $order_info['order_sn'];
  75. $evaluate_goods_info['geval_ordergoodsid'] = $value['rec_id'];
  76. $evaluate_goods_info['geval_goodsid'] = $value['goods_id'];
  77. $evaluate_goods_info['geval_goodsname'] = $value['goods_name'];
  78. $evaluate_goods_info['geval_goodsprice'] = $value['goods_price'];
  79. $evaluate_goods_info['geval_goodsimage'] = $value['goods_image'];
  80. $evaluate_goods_info['geval_scores'] = $evaluate_score;
  81. $evaluate_goods_info['geval_content'] = $evaluate_comment;
  82. $evaluate_goods_info['geval_isanonymous'] = input('post.anony') ? 1 : 0;
  83. $evaluate_goods_info['geval_addtime'] = TIMESTAMP;
  84. $evaluate_goods_info['geval_storeid'] = $store_info['store_id'];
  85. $evaluate_goods_info['geval_storename'] = $store_info['store_name'];
  86. $evaluate_goods_info['geval_frommemberid'] = $member_id;
  87. $evaluate_goods_info['geval_frommembername'] = $member_name;
  88. $evaluate_goods_array[] = $evaluate_goods_info;
  89. $goodsid_array[] = $value['goods_id'];
  90. }
  91. model('evaluategoods')->addEvaluategoodsArray($evaluate_goods_array, $goodsid_array);
  92. $store_desccredit = intval(input('post.store_desccredit'));
  93. if ($store_desccredit <= 0 || $store_desccredit > 5) {
  94. $store_desccredit = 5;
  95. }
  96. $store_servicecredit = intval(input('post.store_servicecredit'));
  97. if ($store_servicecredit <= 0 || $store_servicecredit > 5) {
  98. $store_servicecredit = 5;
  99. }
  100. $store_deliverycredit = intval(input('post.store_deliverycredit'));
  101. if ($store_deliverycredit <= 0 || $store_deliverycredit > 5) {
  102. $store_deliverycredit = 5;
  103. }
  104. //添加店铺评价
  105. if (!$store_info['is_platform_store']) {
  106. $evaluate_store_info = array();
  107. $evaluate_store_info['seval_orderid'] = $order_info['order_id'];
  108. $evaluate_store_info['seval_orderno'] = $order_info['order_sn'];
  109. $evaluate_store_info['seval_addtime'] = TIMESTAMP;
  110. $evaluate_store_info['seval_storeid'] = $store_info['store_id'];
  111. $evaluate_store_info['seval_storename'] = $store_info['store_name'];
  112. $evaluate_store_info['seval_memberid'] = $member_id;
  113. $evaluate_store_info['seval_membername'] = $member_name;
  114. $evaluate_store_info['seval_desccredit'] = $store_desccredit;
  115. $evaluate_store_info['seval_servicecredit'] = $store_servicecredit;
  116. $evaluate_store_info['seval_deliverycredit'] = $store_deliverycredit;
  117. model('evaluatestore')->addEvaluatestore($evaluate_store_info);
  118. //更新店铺信用字段
  119. $store_credit=model('evaluatestore')->_getEvaluatestore(array('seval_storeid' => $store_info['store_id']));
  120. $store_credit_average = round((($store_credit['store_desccredit']['credit'] + $store_credit['store_servicecredit']['credit'] + $store_credit['store_deliverycredit']['credit']) / 3), 1);
  121. $update_store=array();
  122. $update_store['store_desccredit'] = $store_credit['store_desccredit']['credit'];
  123. $update_store['store_servicecredit'] = $store_credit['store_servicecredit']['credit'];
  124. $update_store['store_deliverycredit'] = $store_credit['store_deliverycredit']['credit'];
  125. $update_store['store_credit'] = intval($store_credit_average / 5 * 100);
  126. model('store')->editStore($update_store, array('store_id'=>$store_info['store_id']));
  127. }
  128. //更新订单信息并记录订单日志
  129. $state = model('order')->editOrder(array('evaluation_state' => 1), array('order_id' => $order_info['order_id']));
  130. model('order')->editOrdercommon(array('evaluation_time' => TIMESTAMP), array('order_id' => $order_info['order_id']));
  131. if ($state) {
  132. $data = array();
  133. $data['order_id'] = $order_info['order_id'];
  134. $data['log_role'] = 'buyer';
  135. $data['log_msg'] = lang('order_log_eval');
  136. model('order')->addOrderlog($data);
  137. $res = true;
  138. } else {
  139. $res = false;
  140. }
  141. //添加会员积分
  142. if (config('ds_config.points_isuse') == 1) {
  143. $points_model = model('points');
  144. $points_model->savePointslog('comments', array('pl_memberid' => $member_id, 'pl_membername' => $member_name));
  145. }
  146. //添加会员经验值
  147. model('exppoints')->saveExppointslog('comments', array('explog_memberid' => $member_id, 'explog_membername' => $member_name));
  148. return $res;
  149. }
  150. public function validationVr($order_id, $member_id) {
  151. $condition = array();
  152. $condition[] = array('order_id','=',$order_id);
  153. $condition[] = array('buyer_id','=',$member_id);
  154. //获取订单信息
  155. $order_info = model('vrorder')->getVrorderInfo($condition);
  156. if (empty($order_info)) {
  157. $info = array(
  158. 'state' => '0', 'msg' => '没有权限'
  159. );
  160. }
  161. //订单为'已收货'状态,并且未评论
  162. $order_info['evaluate_able'] = model('vrorder')->getVrorderOperateState('evaluation', $order_info);
  163. if (!$order_info['evaluate_able']) {
  164. $info = array(
  165. 'state' => '0', 'msg' => '订单已评价'
  166. );
  167. }
  168. //查询店铺信息
  169. $store_info = model('store')->getStoreInfoByID($order_info['store_id']);
  170. if (empty($store_info)) {
  171. $info = array(
  172. 'state' => '0', 'msg' => '评价店铺不存在'
  173. );
  174. }
  175. //单个商品
  176. $order_info['goods_image_url'] = goods_cthumb($order_info['goods_image']);
  177. $info['data'] = array('order_info' => $order_info, 'store_info' => $store_info);
  178. return $info;
  179. }
  180. public function saveVr($order_info, $store_info, $order_goods, $member_id, $member_name) {
  181. $evaluate_goods_array = array();
  182. $goodsid_array = array();
  183. $vrorder_model = model('vrorder');
  184. $evaluategoods_model = model('evaluategoods');
  185. $goods_array = input('post.goods/a'); #获取数组
  186. foreach ($order_goods as $value) {
  187. //如果未评分,默认为5分
  188. $evaluate_score = intval($goods_array[$value['goods_id']]['score']);
  189. if ($evaluate_score <= 0 || $evaluate_score > 5) {
  190. $evaluate_score = 5;
  191. }
  192. //默认评语
  193. $evaluate_comment = $goods_array[$value['goods_id']]['comment'];
  194. if (empty($evaluate_comment)) {
  195. $evaluate_comment = '不错哦';
  196. }
  197. $evaluate_goods_info = array();
  198. $evaluate_goods_info['geval_orderid'] = $order_info['order_id'];
  199. $evaluate_goods_info['geval_orderno'] = $order_info['order_sn'];
  200. $evaluate_goods_info['geval_ordergoodsid'] = $order_info['order_id'];
  201. $evaluate_goods_info['geval_goodsid'] = $value['goods_id'];
  202. $evaluate_goods_info['geval_goodsname'] = $value['goods_name'];
  203. $evaluate_goods_info['geval_goodsprice'] = $value['goods_price'];
  204. $evaluate_goods_info['geval_goodsimage'] = $value['goods_image'];
  205. $evaluate_goods_info['geval_scores'] = $evaluate_score;
  206. $evaluate_goods_info['geval_content'] = $evaluate_comment;
  207. $evaluate_goods_info['geval_isanonymous'] = input('post.anony') ? 1 : 0;
  208. $evaluate_goods_info['geval_addtime'] = TIMESTAMP;
  209. $evaluate_goods_info['geval_storeid'] = $store_info['store_id'];
  210. $evaluate_goods_info['geval_storename'] = $store_info['store_name'];
  211. $evaluate_goods_info['geval_frommemberid'] = $member_id;
  212. $evaluate_goods_info['geval_frommembername'] = $member_name;
  213. $evaluate_goods_array[] = $evaluate_goods_info;
  214. $goodsid_array[] = $value['goods_id'];
  215. }
  216. $evaluategoods_model->addEvaluategoodsArray($evaluate_goods_array, $goodsid_array);
  217. //更新订单信息并记录订单日志
  218. $state = $vrorder_model->editVrorder(array('evaluation_state' => 1, 'evaluation_time' => TIMESTAMP), array('order_id' => $order_info['order_id']));
  219. //添加会员积分
  220. if (config('ds_config.points_isuse') == 1) {
  221. $points_model = model('points');
  222. $points_model->savePointslog('comments', array('pl_memberid' => $member_id, 'pl_membername' => $member_name));
  223. }
  224. //添加会员经验值
  225. model('exppoints')->saveExppointslog('comments', array('explog_memberid' => $member_id, 'explog_membername' => $member_name));
  226. return $state;
  227. }
  228. }