Memberevaluate.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. namespace app\common\logic;
  3. /**
  4. *
  5. *
  6. * ----------------------------------------------------------------------------
  7. *
  8. * 逻辑层模型
  9. */
  10. class Memberevaluate
  11. {
  12. public function evaluateListDity($goods_eval_list)
  13. {
  14. foreach ($goods_eval_list as $key => $value) {
  15. $goods_eval_list[$key]['member_avatar'] = get_member_avatar_for_id($value['geval_frommemberid']);
  16. }
  17. return $goods_eval_list;
  18. }
  19. /* 查询订单信息 */
  20. public function validation($order_id, $member_id)
  21. {
  22. $condition = array();
  23. $condition[] = array('order_id', '=', $order_id);
  24. $condition[] = array('buyer_id', '=', $member_id);
  25. //获取订单信息
  26. $order_info = model('order')->getOrderInfo($condition);
  27. if (empty($order_info)) {
  28. $info = array('state' => '0', 'msg' => '订单出错');
  29. }
  30. $order_info['evaluate_able'] = model('order')->getOrderOperateState('evaluation', $order_info);
  31. if (empty($order_info) || !$order_info['evaluate_able']) {
  32. $info = array('state' => '0', 'msg' => '评价订单不存在');
  33. }
  34. //查询店铺信息
  35. $store_info = model('store')->getStoreInfoByID($order_info['store_id']);
  36. if (empty($store_info)) {
  37. $info = array('state' => '0', 'msg' => '店铺不存在');
  38. }
  39. //获取订单商品
  40. $order_goods = model('order')->getOrdergoodsList($condition);
  41. if (empty($order_goods)) {
  42. $info = array('state' => '0', 'msg' => '订单商品不存在');
  43. }
  44. foreach ($order_goods as $key => $value) {
  45. $order_goods[$key]['goods_image_url'] = goods_cthumb($value['goods_image']);
  46. }
  47. $info['data'] = array('order_goods' => $order_goods, 'store_info' => $store_info, 'order_info' => $order_info);
  48. return $info;
  49. }
  50. /* 保存订单评价信息 */
  51. public function saveorderevaluate($order_info, $store_info, $order_goods, $member_id, $member_name)
  52. {
  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. {
  152. $condition = array();
  153. $condition[] = array('order_id', '=', $order_id);
  154. $condition[] = array('buyer_id', '=', $member_id);
  155. //获取订单信息
  156. $order_info = model('vrorder')->getVrorderInfo($condition);
  157. if (empty($order_info)) {
  158. $info = array(
  159. 'state' => '0', 'msg' => '没有权限'
  160. );
  161. }
  162. //订单为'已收货'状态,并且未评论
  163. $order_info['evaluate_able'] = model('vrorder')->getVrorderOperateState('evaluation', $order_info);
  164. if (!$order_info['evaluate_able']) {
  165. $info = array(
  166. 'state' => '0', 'msg' => '订单已评价'
  167. );
  168. }
  169. //查询店铺信息
  170. $store_info = model('store')->getStoreInfoByID($order_info['store_id']);
  171. if (empty($store_info)) {
  172. $info = array(
  173. 'state' => '0', 'msg' => '评价店铺不存在'
  174. );
  175. }
  176. //单个商品
  177. $order_info['goods_image_url'] = goods_cthumb($order_info['goods_image']);
  178. $info['data'] = array('order_info' => $order_info, 'store_info' => $store_info);
  179. return $info;
  180. }
  181. public function saveVr($order_info, $store_info, $order_goods, $member_id, $member_name)
  182. {
  183. $evaluate_goods_array = array();
  184. $goodsid_array = array();
  185. $vrorder_model = model('vrorder');
  186. $evaluategoods_model = model('evaluategoods');
  187. $goods_array = input('post.goods/a'); #获取数组
  188. foreach ($order_goods as $value) {
  189. //如果未评分,默认为5分
  190. $evaluate_score = intval($goods_array[$value['goods_id']]['score']);
  191. if ($evaluate_score <= 0 || $evaluate_score > 5) {
  192. $evaluate_score = 5;
  193. }
  194. //默认评语
  195. $evaluate_comment = $goods_array[$value['goods_id']]['comment'];
  196. if (empty($evaluate_comment)) {
  197. $evaluate_comment = '不错哦';
  198. }
  199. $evaluate_goods_info = array();
  200. $evaluate_goods_info['geval_orderid'] = $order_info['order_id'];
  201. $evaluate_goods_info['geval_orderno'] = $order_info['order_sn'];
  202. $evaluate_goods_info['geval_ordergoodsid'] = $order_info['order_id'];
  203. $evaluate_goods_info['geval_goodsid'] = $value['goods_id'];
  204. $evaluate_goods_info['geval_goodsname'] = $value['goods_name'];
  205. $evaluate_goods_info['geval_goodsprice'] = $value['goods_price'];
  206. $evaluate_goods_info['geval_goodsimage'] = $value['goods_image'];
  207. $evaluate_goods_info['geval_scores'] = $evaluate_score;
  208. $evaluate_goods_info['geval_content'] = $evaluate_comment;
  209. $evaluate_goods_info['geval_isanonymous'] = input('post.anony') ? 1 : 0;
  210. $evaluate_goods_info['geval_addtime'] = TIMESTAMP;
  211. $evaluate_goods_info['geval_storeid'] = $store_info['store_id'];
  212. $evaluate_goods_info['geval_storename'] = $store_info['store_name'];
  213. $evaluate_goods_info['geval_frommemberid'] = $member_id;
  214. $evaluate_goods_info['geval_frommembername'] = $member_name;
  215. $evaluate_goods_array[] = $evaluate_goods_info;
  216. $goodsid_array[] = $value['goods_id'];
  217. }
  218. $evaluategoods_model->addEvaluategoodsArray($evaluate_goods_array, $goodsid_array);
  219. //更新订单信息并记录订单日志
  220. $state = $vrorder_model->editVrorder(array('evaluation_state' => 1, 'evaluation_time' => TIMESTAMP), array('order_id' => $order_info['order_id']));
  221. //添加会员积分
  222. if (config('ds_config.points_isuse') == 1) {
  223. $points_model = model('points');
  224. $points_model->savePointslog('comments', array('pl_memberid' => $member_id, 'pl_membername' => $member_name));
  225. }
  226. //添加会员经验值
  227. model('exppoints')->saveExppointslog('comments', array('explog_memberid' => $member_id, 'explog_membername' => $member_name));
  228. return $state;
  229. }
  230. }