Memberevaluate.php 12 KB

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