Memberevaluate.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. namespace app\common\logic;
  3. /**
  4. * ============================================================================
  5. * DSMall多用户商城
  6. * ============================================================================
  7. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  8. * 网站地址: http://www.csdeshang.com
  9. * ----------------------------------------------------------------------------
  10. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  11. * 不允许对程序代码以任何形式任何目的的再发布。
  12. * ============================================================================
  13. * 逻辑层模型
  14. */
  15. class Memberevaluate{
  16. public function evaluateListDity($goods_eval_list) {
  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. $condition = array();
  25. $condition[] = array('order_id','=',$order_id);
  26. $condition[] = array('buyer_id','=',$member_id);
  27. //获取订单信息
  28. $order_info = model('order')->getOrderInfo($condition);
  29. if (empty($order_info)) {
  30. $info = array('state' => '0', 'msg' => '订单出错');
  31. }
  32. $order_info['evaluate_able'] = model('order')->getOrderOperateState('evaluation', $order_info);
  33. if (empty($order_info) || !$order_info['evaluate_able']) {
  34. $info = array('state' => '0', 'msg' => '评价订单不存在');
  35. }
  36. //查询店铺信息
  37. $store_info = model('store')->getStoreInfoByID($order_info['store_id']);
  38. if (empty($store_info)) {
  39. $info = array('state' => '0', 'msg' => '店铺不存在');
  40. }
  41. //获取订单商品
  42. $order_goods = model('order')->getOrdergoodsList($condition);
  43. if (empty($order_goods)) {
  44. $info = array('state' => '0', 'msg' => '订单商品不存在');
  45. }
  46. foreach ($order_goods as $key => $value) {
  47. $order_goods[$key]['goods_image_url'] = goods_cthumb($value['goods_image']);
  48. }
  49. $info['data'] = array('order_goods' => $order_goods, 'store_info' => $store_info, 'order_info' => $order_info);
  50. return $info;
  51. }
  52. /* 保存订单评价信息 */
  53. public function saveorderevaluate($order_info, $store_info, $order_goods, $member_id, $member_name) {
  54. $evaluate_goods_array = array();
  55. $goodsid_array = array();
  56. $goods_array = input('post.goods/a');#获取评价数组
  57. foreach ($order_goods as $value) {
  58. //如果未评分,默认为5分
  59. $evaluate_score = intval($goods_array[$value['goods_id']]['score']);
  60. if ($evaluate_score <= 0 || $evaluate_score > 5) {
  61. $evaluate_score = 5;
  62. }
  63. //默认评语
  64. $evaluate_comment = $goods_array[$value['goods_id']]['comment'];
  65. if (empty($evaluate_comment)) {
  66. $evaluate_comment = '不错哦';
  67. }else{
  68. $res=word_filter($evaluate_comment);
  69. if($res['code']){
  70. $evaluate_comment=$res['data']['text'];
  71. }
  72. }
  73. $evaluate_goods_info = array();
  74. $evaluate_goods_info['geval_orderid'] = $order_info['order_id'];
  75. $evaluate_goods_info['geval_orderno'] = $order_info['order_sn'];
  76. $evaluate_goods_info['geval_ordergoodsid'] = $value['rec_id'];
  77. $evaluate_goods_info['geval_goodsid'] = $value['goods_id'];
  78. $evaluate_goods_info['geval_goodsname'] = $value['goods_name'];
  79. $evaluate_goods_info['geval_goodsprice'] = $value['goods_price'];
  80. $evaluate_goods_info['geval_goodsimage'] = $value['goods_image'];
  81. $evaluate_goods_info['geval_scores'] = $evaluate_score;
  82. $evaluate_goods_info['geval_content'] = $evaluate_comment;
  83. $evaluate_goods_info['geval_isanonymous'] = input('post.anony') ? 1 : 0;
  84. $evaluate_goods_info['geval_addtime'] = TIMESTAMP;
  85. $evaluate_goods_info['geval_storeid'] = $store_info['store_id'];
  86. $evaluate_goods_info['geval_storename'] = $store_info['store_name'];
  87. $evaluate_goods_info['geval_frommemberid'] = $member_id;
  88. $evaluate_goods_info['geval_frommembername'] = $member_name;
  89. $evaluate_goods_array[] = $evaluate_goods_info;
  90. $goodsid_array[] = $value['goods_id'];
  91. }
  92. model('evaluategoods')->addEvaluategoodsArray($evaluate_goods_array, $goodsid_array);
  93. $store_desccredit = intval(input('post.store_desccredit'));
  94. if ($store_desccredit <= 0 || $store_desccredit > 5) {
  95. $store_desccredit = 5;
  96. }
  97. $store_servicecredit = intval(input('post.store_servicecredit'));
  98. if ($store_servicecredit <= 0 || $store_servicecredit > 5) {
  99. $store_servicecredit = 5;
  100. }
  101. $store_deliverycredit = intval(input('post.store_deliverycredit'));
  102. if ($store_deliverycredit <= 0 || $store_deliverycredit > 5) {
  103. $store_deliverycredit = 5;
  104. }
  105. //添加店铺评价
  106. if (!$store_info['is_platform_store']) {
  107. $evaluate_store_info = array();
  108. $evaluate_store_info['seval_orderid'] = $order_info['order_id'];
  109. $evaluate_store_info['seval_orderno'] = $order_info['order_sn'];
  110. $evaluate_store_info['seval_addtime'] = TIMESTAMP;
  111. $evaluate_store_info['seval_storeid'] = $store_info['store_id'];
  112. $evaluate_store_info['seval_storename'] = $store_info['store_name'];
  113. $evaluate_store_info['seval_memberid'] = $member_id;
  114. $evaluate_store_info['seval_membername'] = $member_name;
  115. $evaluate_store_info['seval_desccredit'] = $store_desccredit;
  116. $evaluate_store_info['seval_servicecredit'] = $store_servicecredit;
  117. $evaluate_store_info['seval_deliverycredit'] = $store_deliverycredit;
  118. model('evaluatestore')->addEvaluatestore($evaluate_store_info);
  119. //更新店铺信用字段
  120. $store_credit=model('evaluatestore')->_getEvaluatestore(array('seval_storeid' => $store_info['store_id']));
  121. $store_credit_average = round((($store_credit['store_desccredit']['credit'] + $store_credit['store_servicecredit']['credit'] + $store_credit['store_deliverycredit']['credit']) / 3), 1);
  122. $update_store=array();
  123. $update_store['store_desccredit'] = $store_credit['store_desccredit']['credit'];
  124. $update_store['store_servicecredit'] = $store_credit['store_servicecredit']['credit'];
  125. $update_store['store_deliverycredit'] = $store_credit['store_deliverycredit']['credit'];
  126. $update_store['store_credit'] = intval($store_credit_average / 5 * 100);
  127. model('store')->editStore($update_store, array('store_id'=>$store_info['store_id']));
  128. }
  129. //更新订单信息并记录订单日志
  130. $state = model('order')->editOrder(array('evaluation_state' => 1), array('order_id' => $order_info['order_id']));
  131. model('order')->editOrdercommon(array('evaluation_time' => TIMESTAMP), array('order_id' => $order_info['order_id']));
  132. if ($state) {
  133. $data = array();
  134. $data['order_id'] = $order_info['order_id'];
  135. $data['log_role'] = 'buyer';
  136. $data['log_msg'] = lang('order_log_eval');
  137. model('order')->addOrderlog($data);
  138. $res = true;
  139. } else {
  140. $res = false;
  141. }
  142. //添加会员积分
  143. if (config('ds_config.points_isuse') == 1) {
  144. $points_model = model('points');
  145. $points_model->savePointslog('comments', array('pl_memberid' => $member_id, 'pl_membername' => $member_name));
  146. }
  147. //添加会员经验值
  148. model('exppoints')->saveExppointslog('comments', array('explog_memberid' => $member_id, 'explog_membername' => $member_name));
  149. return $res;
  150. }
  151. public function validationVr($order_id, $member_id) {
  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. $evaluate_goods_array = array();
  183. $goodsid_array = array();
  184. $vrorder_model = model('vrorder');
  185. $evaluategoods_model = model('evaluategoods');
  186. $goods_array = input('post.goods/a'); #获取数组
  187. foreach ($order_goods as $value) {
  188. //如果未评分,默认为5分
  189. $evaluate_score = intval($goods_array[$value['goods_id']]['score']);
  190. if ($evaluate_score <= 0 || $evaluate_score > 5) {
  191. $evaluate_score = 5;
  192. }
  193. //默认评语
  194. $evaluate_comment = $goods_array[$value['goods_id']]['comment'];
  195. if (empty($evaluate_comment)) {
  196. $evaluate_comment = '不错哦';
  197. }
  198. $evaluate_goods_info = array();
  199. $evaluate_goods_info['geval_orderid'] = $order_info['order_id'];
  200. $evaluate_goods_info['geval_orderno'] = $order_info['order_sn'];
  201. $evaluate_goods_info['geval_ordergoodsid'] = $order_info['order_id'];
  202. $evaluate_goods_info['geval_goodsid'] = $value['goods_id'];
  203. $evaluate_goods_info['geval_goodsname'] = $value['goods_name'];
  204. $evaluate_goods_info['geval_goodsprice'] = $value['goods_price'];
  205. $evaluate_goods_info['geval_goodsimage'] = $value['goods_image'];
  206. $evaluate_goods_info['geval_scores'] = $evaluate_score;
  207. $evaluate_goods_info['geval_content'] = $evaluate_comment;
  208. $evaluate_goods_info['geval_isanonymous'] = input('post.anony') ? 1 : 0;
  209. $evaluate_goods_info['geval_addtime'] = TIMESTAMP;
  210. $evaluate_goods_info['geval_storeid'] = $store_info['store_id'];
  211. $evaluate_goods_info['geval_storename'] = $store_info['store_name'];
  212. $evaluate_goods_info['geval_frommemberid'] = $member_id;
  213. $evaluate_goods_info['geval_frommembername'] = $member_name;
  214. $evaluate_goods_array[] = $evaluate_goods_info;
  215. $goodsid_array[] = $value['goods_id'];
  216. }
  217. $evaluategoods_model->addEvaluategoodsArray($evaluate_goods_array, $goodsid_array);
  218. //更新订单信息并记录订单日志
  219. $state = $vrorder_model->editVrorder(array('evaluation_state' => 1, 'evaluation_time' => TIMESTAMP), array('order_id' => $order_info['order_id']));
  220. //添加会员积分
  221. if (config('ds_config.points_isuse') == 1) {
  222. $points_model = model('points');
  223. $points_model->savePointslog('comments', array('pl_memberid' => $member_id, 'pl_membername' => $member_name));
  224. }
  225. //添加会员经验值
  226. model('exppoints')->saveExppointslog('comments', array('explog_memberid' => $member_id, 'explog_membername' => $member_name));
  227. return $state;
  228. }
  229. }