StoreProductReplyServices.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\product\product;
  12. use app\dao\product\product\StoreProductReplyDao;
  13. use app\services\BaseServices;
  14. use app\services\product\branch\StoreBranchProductServices;
  15. use app\services\product\sku\StoreProductAttrValueServices;
  16. use app\services\store\SystemStoreServices;
  17. use app\services\supplier\SystemSupplierServices;
  18. use app\services\user\UserRelationServices;
  19. use app\services\user\UserServices;
  20. use crmeb\exceptions\AdminException;
  21. use crmeb\services\FormBuilder as Form;
  22. use crmeb\traits\ServicesTrait;
  23. use think\db\exception\DataNotFoundException;
  24. use think\db\exception\DbException;
  25. use think\db\exception\ModelNotFoundException;
  26. use think\exception\ValidateException;
  27. use think\facade\Route as Url;
  28. /**
  29. * Class StoreProductReplyService
  30. * @package app\services\product\product
  31. * @mixin StoreProductReplyDao
  32. */
  33. class StoreProductReplyServices extends BaseServices
  34. {
  35. use ServicesTrait;
  36. /**
  37. * StoreProductReplyServices constructor.
  38. * @param StoreProductReplyDao $dao
  39. */
  40. public function __construct(StoreProductReplyDao $dao)
  41. {
  42. $this->dao = $dao;
  43. }
  44. /**
  45. * 获取评论列表
  46. * @param array $where
  47. * @return array
  48. */
  49. public function sysPage(array $where)
  50. {
  51. //平台共享到门店商品处理
  52. if (isset($where['product_id']) && $where['product_id']) {
  53. $productId = $this->checkReplyProductId($where['product_id']);
  54. $where['product_id'] = $productId;
  55. }
  56. /** @var StoreProductReplyStoreProductServices $storeProductReplyStoreProductServices */
  57. $storeProductReplyStoreProductServices = app()->make(StoreProductReplyStoreProductServices::class);
  58. $data = $storeProductReplyStoreProductServices->getProductReplyList($where, [
  59. 'replyComment' => function ($query) use ($where) {
  60. if ($where['type'] ?? 0) {
  61. $query->where('uid', 0)->where('pid', 0)->where('type', $where['type'] ?? 0)->where('relation_id', $where['relation_id'] ?? 0);
  62. } else {
  63. $query->where('uid', 0)->where('pid', 0);
  64. }
  65. }
  66. ]);
  67. foreach ($data['list'] as &$item) {
  68. $item['time'] = time_tran(strtotime($item['add_time']));
  69. $item['create_time'] = $item['add_time'];
  70. $item['score'] = ($item['product_score'] + $item['service_score']) / 2;
  71. }
  72. return $data;
  73. }
  74. /**
  75. * 创建自评表单
  76. * @param int $product_id
  77. * @return array
  78. * @throws \FormBuilder\Exception\FormBuilderException
  79. */
  80. public function createForm(int $product_id)
  81. {
  82. if ($product_id == 0) {
  83. $field[] = Form::frameImage('image', '商品', Url::buildUrl(config('admin.admin_prefix') . '/store.StoreProduct/index', array('fodder' => 'image')))->icon('ios-add')->width('960px')->height('560px')->modal(['footer-hide' => true])->Props(['srcKey' => 'image']);
  84. } else {
  85. $field[] = Form::hidden('product_id', $product_id);
  86. }
  87. $field[] = Form::frameImage('avatar', '用户头像', Url::buildUrl(config('admin.admin_prefix') . '/widget.images/index', array('fodder' => 'avatar')))->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
  88. $field[] = Form::input('nickname', '用户名称')->col(24);
  89. $field[] = Form::input('comment', '评价文字')->type('textarea');
  90. $field[] = Form::rate('product_score', '商品分数', 0)->allowHalf(false);
  91. $field[] = Form::rate('service_score', '服务分数', 0)->allowHalf(false);
  92. $field[] = Form::frameImages('pics', '评价图片', Url::buildUrl(config('admin.admin_prefix') . '/widget.images/index', array('fodder' => 'pics', 'type' => 'many', 'maxLength' => 8)))->maxLength(8)->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true])->modal(['footer-hide' => true])->props(['closeBtn' => false, 'okBtn' => false]);
  93. $field[] = Form::dateTime('add_time', '评论时间', '')->placeholder('请选择评论时间(不选择默认当前添加时间)');
  94. return create_form('添加自评', $field, Url::buildUrl('/product/reply/save_fictitious_reply'), 'POST');
  95. }
  96. /**
  97. * 添加自评
  98. * @param array $data
  99. * @param int $type
  100. * @param int $relation_id
  101. * @return void
  102. * @throws DataNotFoundException
  103. * @throws DbException
  104. * @throws ModelNotFoundException
  105. */
  106. public function saveReply(array $data, int $type = 0, int $relation_id = 0)
  107. {
  108. $time = time();
  109. $data['uid'] = 0;
  110. $data['oid'] = 0;
  111. $data['type'] = $type;
  112. $data['relation_id'] = $relation_id;
  113. $data['unique'] = uniqid();
  114. $data['reply_type'] = 'product';
  115. $data['add_time'] = empty($data['add_time']) ? $time : strtotime($data['add_time']);
  116. $data['pics'] = json_encode($data['pics']);
  117. if (isset($data['sku_unique']) && $data['sku_unique']) {
  118. /** @var StoreProductAttrValueServices $productAttrValueServices */
  119. $productAttrValueServices = app()->make(StoreProductAttrValueServices::class);
  120. $attrDetail = $productAttrValueServices->getone(['product_id' => $data['product_id'], 'unique' => $data['sku_unique']]);
  121. $data['sku'] = $attrDetail ? $attrDetail['suk'] : '';
  122. }
  123. unset($data['image']);
  124. if ($data['add_time'] > $time) {
  125. throw new AdminException('评论时间应小于当前时间');
  126. }
  127. $res = $this->dao->save($data);
  128. if (!$res) throw new AdminException('添加自评失败');
  129. $this->dao->cacheTag()->clear();
  130. }
  131. /**
  132. * 回复评论
  133. * @param int $replyId
  134. * @param string $content
  135. * @param int $type
  136. * @param int $relation_id
  137. * @return void
  138. */
  139. public function setReply(int $replyId, string $content, int $type = 0, int $relation_id = 0)
  140. {
  141. if ($content == '') throw new AdminException('请输入回复内容');
  142. $reply = $this->dao->get($replyId);
  143. if (!$reply) {
  144. throw new AdminException('评论不存在或已删除');
  145. }
  146. $save['content'] = $content;
  147. $save['create_time'] = time();
  148. $save['type'] = $type;
  149. $save['relation_id'] = $relation_id;
  150. $save['reply_id'] = $replyId;
  151. /** @var StoreProductReplyCommentServices $service */
  152. $service = app()->make(StoreProductReplyCommentServices::class);
  153. $where = ['reply_id' => $replyId, 'uid' => 0, 'type' => $type, 'relation_id' => $relation_id, 'pid' => 0];
  154. if ($service->count($where)) {
  155. $res = $service->update($where, ['content' => $content, 'update_time' => time()]);
  156. } else {
  157. $res = $service->save($save);
  158. }
  159. if (!$res) throw new AdminException('回复失败,请稍后再试');
  160. if ($type == $reply['type']) {//回复端 与商品端一致 修改回复状态
  161. $this->dao->update($replyId, ['is_reply' => 1]);
  162. }
  163. $this->dao->cacheTag()->clear();
  164. }
  165. /**
  166. * 删除
  167. * @param int $id
  168. */
  169. public function del(int $id)
  170. {
  171. $res = $this->dao->update($id, ['is_del' => 1]);
  172. if (!$res) throw new AdminException('删除失败');
  173. $this->dao->cacheTag()->clear();
  174. }
  175. /**
  176. * @param int $productId
  177. * @param int $limit
  178. * @return mixed
  179. * @throws \Throwable
  180. * @author 等风来
  181. * @email 136327134@qq.com
  182. * @date 2022/11/3
  183. */
  184. public function getRecProductReplyCache(int $productId, int $limit = 1)
  185. {
  186. return $this->dao->cacheTag()->remember('id:' . $productId . ':limit:' . $limit, function () use ($productId, $limit) {
  187. return $this->getRecProductReply($productId, $limit);
  188. }, 3600);
  189. }
  190. /**
  191. * 获取最近的几条评论
  192. * @param int $productId
  193. * @param int $limit
  194. * @return array
  195. * @throws DataNotFoundException
  196. * @throws DbException
  197. * @throws ModelNotFoundException
  198. */
  199. public function getRecProductReply(int $productId, int $limit = 1)
  200. {
  201. $productId = $this->checkReplyProductId($productId);
  202. $page = $limit ? 1 : 0;
  203. $list = $this->dao->getProductReply($productId, '*', $page, $limit);
  204. if ($list) {
  205. foreach ($list as &$item) {
  206. $item['suk'] = $item['sku'];
  207. $item['nickname'] = anonymity($item['nickname']);
  208. $item['merchant_reply_time'] = date('Y-m-d H:i', $item['merchant_reply_time']);
  209. $item['add_time'] = time_tran($item['add_time']);
  210. $item['star'] = bcadd($item['product_score'], $item['service_score'], 2);
  211. $item['star'] = bcdiv($item['star'], '2', 0);
  212. $item['comment'] = $item['comment'] ?: '此用户没有填写评价';
  213. $item['pics'] = $item['pics'] ? (is_string($item['pics']) ? json_decode($item['pics'], true) : $item['pics']) : [];
  214. }
  215. }
  216. return $list;
  217. }
  218. /**
  219. * 获取好评率
  220. * @param int $id
  221. * @return int|string
  222. */
  223. public function getProductReplyChance(int $id)
  224. {
  225. $id = $this->checkReplyProductId($id);
  226. $replyCount = $this->dao->replyCount($id);
  227. if ($replyCount) {
  228. $goodReply = $this->dao->replyCount($id, 1);
  229. if ($goodReply) {
  230. $replyCount = bcdiv((string)$goodReply, (string)$replyCount, 2);
  231. $replyCount = bcmul((string)$replyCount, '100', 0);
  232. } else {
  233. $replyCount = 0;
  234. }
  235. } else {
  236. $replyCount = 100;
  237. }
  238. return $replyCount;
  239. }
  240. /**
  241. * 获取评论数据 评论总数 好评总数 好评率
  242. * @param int $id
  243. * @return array
  244. */
  245. public function getProductReplyData(int $id)
  246. {
  247. $goodReply = 0;
  248. $id = $this->checkReplyProductId($id);
  249. return $this->dao->cacheTag()->remember('ReplyData_' . $id, function () use ($id) {
  250. $goodReply = $replyChance = 0;
  251. $replyCount = $this->dao->replyCount($id);
  252. if ($replyCount) {
  253. $goodReply = $this->dao->replyCount($id, 1);
  254. if ($goodReply) {
  255. $replyChance = bcmul((string)bcdiv((string)$goodReply, (string)$replyCount, 2), '100', 0);
  256. } else {
  257. $replyChance = 0;
  258. }
  259. } else {
  260. $replyChance = 100;
  261. }
  262. return [$replyCount, $goodReply, $replyChance];
  263. }, 3600);
  264. }
  265. /**
  266. * 商品评论数量
  267. * @param int $type
  268. * @param int $relation_id
  269. * @return int
  270. */
  271. public function replyCount(int $type = 0, int $relation_id = 0)
  272. {
  273. return $this->dao->count(['is_reply' => 0, 'is_del' => 0, 'type' => $type, 'relation_id' => $relation_id]);
  274. }
  275. /**
  276. * 获取商品评论数量
  277. * @param int $id
  278. * @return mixed
  279. */
  280. public function productReplyCount(int $id)
  281. {
  282. $id = $this->checkReplyProductId($id);
  283. $data['sum_count'] = $this->dao->replyCount($id);
  284. $data['good_count'] = $this->dao->replyCount($id, 1);
  285. $data['in_count'] = $this->dao->replyCount($id, 2);
  286. $data['poor_count'] = $this->dao->replyCount($id, 3);
  287. if ($data['sum_count'] != 0) {
  288. $data['reply_chance'] = bcdiv($data['good_count'], $data['sum_count'], 2);
  289. $data['reply_star'] = bcdiv(($this->dao->sum(['product_id' => $id, 'is_del' => 0], 'product_score') + $this->dao->sum(['product_id' => $id, 'is_del' => 0], 'service_score')), $data['sum_count'] * 2, 0);
  290. } else {
  291. $data['reply_chance'] = 100;
  292. $data['reply_star'] = 5;
  293. }
  294. // $data['reply_star'] = bcmul($data['reply_chance'], 5, 0);
  295. $data['reply_chance'] = $data['sum_count'] == 0 ? 100 : bcmul($data['reply_chance'], 100, 0);
  296. return $data;
  297. }
  298. /**
  299. * 获取商品评论列表
  300. * @param int $id
  301. * @param int $type
  302. * @return array
  303. * @throws DataNotFoundException
  304. * @throws DbException
  305. * @throws ModelNotFoundException
  306. */
  307. public function getProductReplyList(int $id, int $type)
  308. {
  309. $id = $this->checkReplyProductId($id);
  310. if (!$id) {
  311. return [];
  312. }
  313. [$page, $limit] = $this->getPageValue();
  314. $list = $this->dao->replyList($id, $type, $page, $limit);
  315. foreach ($list as &$item) {
  316. $item['suk'] = $item['sku'];
  317. $item['nickname'] = anonymity($item['nickname']);
  318. $item['merchant_reply_time'] = date('Y-m-d H:i', $item['merchant_reply_time']);
  319. $item['add_time'] = date('Y-m-d H:i', $item['add_time']);
  320. $item['star'] = bcadd($item['product_score'], $item['service_score'], 2);
  321. $item['star'] = bcdiv($item['star'], 2, 0);
  322. $item['comment'] = $item['comment'] ?: '此用户没有填写评价';
  323. $item['pics'] = is_string($item['pics']) ? json_decode($item['pics'], true) : $item['pics'];
  324. }
  325. return $list;
  326. }
  327. /**
  328. * 评价点赞
  329. * @param int $id
  330. * @param int $uid
  331. * @return bool
  332. * @throws DataNotFoundException
  333. * @throws DbException
  334. * @throws ModelNotFoundException
  335. */
  336. public function replyPraise(int $id, int $uid)
  337. {
  338. $relyInfo = $this->dao->get($id, ['id', 'praise']);
  339. if (!$relyInfo) {
  340. throw new ValidateException('点赞的评价不存在');
  341. }
  342. /** @var UserRelationServices $service */
  343. $service = app()->make(UserRelationServices::class);
  344. if ($service->getUserCount($uid, $id, UserRelationServices::TYPE_COLLECT, UserRelationServices::CATEGORY_REPLY)) {
  345. return true;
  346. }
  347. $relyInfo->praise++;
  348. $this->transaction(function () use ($uid, $relyInfo, $service, $id) {
  349. $res = $service->save([
  350. 'uid' => $uid,
  351. 'relation_id' => $id,
  352. 'type' => UserRelationServices::TYPE_LIKE,
  353. 'category' => UserRelationServices::CATEGORY_REPLY,
  354. 'add_time' => time()
  355. ]);
  356. $res = $res && $relyInfo->save();
  357. if (!$res) {
  358. throw new ValidateException('点赞失败');
  359. }
  360. });
  361. event('product.reply.update', [$uid]);
  362. $this->dao->cacheTag()->clear();
  363. return true;
  364. }
  365. /**
  366. * 取消点赞
  367. * @param int $id
  368. * @param int $uid
  369. * @return bool
  370. * @throws DataNotFoundException
  371. * @throws DbException
  372. * @throws ModelNotFoundException
  373. */
  374. public function unReplyPraise(int $id, int $uid)
  375. {
  376. $relyInfo = $this->dao->get($id, ['id', 'praise']);
  377. if (!$relyInfo) {
  378. throw new ValidateException('点赞的评价不存在');
  379. }
  380. /** @var UserRelationServices $service */
  381. $service = app()->make(UserRelationServices::class);
  382. $relyInfo->praise--;
  383. $this->transaction(function () use ($uid, $relyInfo, $service, $id) {
  384. $res = $service->delete([
  385. 'uid' => $uid,
  386. 'relation_id' => $id,
  387. 'type' => UserRelationServices::TYPE_LIKE,
  388. 'category' => UserRelationServices::CATEGORY_REPLY
  389. ]);
  390. $res = $res && $relyInfo->save();
  391. if (!$res) {
  392. throw new ValidateException('取消点赞失败');
  393. }
  394. });
  395. event('product.reply.update', [$uid]);
  396. $this->dao->cacheTag()->clear();
  397. return true;
  398. }
  399. /**
  400. * 获取评论详情
  401. * @param int $id
  402. * @param int $uid
  403. * @return mixed
  404. * @throws DataNotFoundException
  405. * @throws DbException
  406. * @throws ModelNotFoundException
  407. */
  408. public function getReplyInfo(int $id, int $uid)
  409. {
  410. $replyInfo = $this->dao->get($id, ['*']);
  411. if (!$replyInfo) {
  412. throw new ValidateException('查看的评论不存在');
  413. }
  414. /** @var StoreProductServices $productServices */
  415. $productServices = app()->make(StoreProductServices::class);
  416. $productInfo = $productServices->get($replyInfo->product_id, ['image', 'store_name', 'id']);
  417. /** @var UserServices $userService */
  418. $userService = app()->make(UserServices::class);
  419. $userInfo = $userService->get($replyInfo->uid, ['nickname', 'uid', 'avatar', 'is_money_level']);
  420. $userInfo = $userInfo ? $userInfo->toArray() : [];
  421. $userInfo['nickname'] = anonymity($userInfo['nickname'] ?? '');
  422. $replyInfo->nickname = anonymity($replyInfo['nickname'] ?? '');
  423. $data['reply'] = $replyInfo->toArray();
  424. $data['reply']['add_time'] = $data['reply']['add_time'] ? date('Y-m-d H:i:s', $data['reply']['add_time']) : '';
  425. $data['reply']['suk'] = $replyInfo['sku'] ?? '';
  426. /** @var StoreProductReplyCommentServices $commentService */
  427. $commentService = app()->make(StoreProductReplyCommentServices::class);
  428. $data['reply']['comment_sum'] = $commentService->count(['reply_id' => $id, 'pid' => 0]);
  429. $data['product'] = $productInfo ? $productInfo->toArray() : [];
  430. $data['user'] = $userInfo;
  431. $data['star'] = bcdiv(bcadd($data['reply']['product_score'], $data['reply']['service_score'], 2), 2, 0);
  432. /** @var UserRelationServices $make */
  433. $make = app()->make(UserRelationServices::class);
  434. $data['is_praise'] = !!$make->getUserCount($uid, $id, UserRelationServices::TYPE_LIKE, UserRelationServices::CATEGORY_REPLY);
  435. //记录浏览量
  436. $replyInfo->views_num++;
  437. $replyInfo->save();
  438. return $data;
  439. }
  440. /**
  441. * 新版本获取商品评价
  442. * @param int $id
  443. * @param int $type
  444. * @return array
  445. * @throws DataNotFoundException
  446. * @throws DbException
  447. * @throws ModelNotFoundException
  448. */
  449. public function getNewProductReplyList(int $id, int $type, int $uid)
  450. {
  451. $id = $this->checkReplyProductId($id);
  452. if (!$id) {
  453. return [];
  454. }
  455. [$page, $limit] = $this->getPageValue();
  456. $list = $this->dao->replyList($id, $type, $page, $limit, ['userInfo',
  457. 'replyComment' => function ($query) {
  458. $query->with([
  459. 'user' => function ($query) {
  460. $query->field('uid,avatar,nickname');
  461. }
  462. ])->where('pid', 0)->field(['uid', 'reply_id', 'content'])
  463. ->order('praise desc,create_time desc');
  464. },
  465. 'productRelation' => function ($query) use ($uid) {
  466. $query->where('uid', $uid)->where('type', UserRelationServices::TYPE_LIKE)->where('category', UserRelationServices::CATEGORY_REPLY)->field(['uid', 'relation_id']);
  467. }
  468. ]);
  469. if ($list) {
  470. $siteLogoSquare = sys_config('site_logo_square');
  471. $siteName = sys_config('site_name');
  472. $supplierIds = $storeIds = [];
  473. foreach ($list as $value) {
  474. switch ($value['type']) {
  475. case 0:
  476. break;
  477. case 1://门店
  478. $storeIds[] = $value['relation_id'];
  479. break;
  480. case 2://供应商
  481. $supplierIds[] = $value['relation_id'];
  482. break;
  483. }
  484. }
  485. $supplierIds = array_unique($supplierIds);
  486. $storeIds = array_unique($storeIds);
  487. $supplierList = $storeList = [];
  488. if ($supplierIds) {
  489. /** @var SystemSupplierServices $supplierServices */
  490. $supplierServices = app()->make(SystemSupplierServices::class);
  491. $supplierList = $supplierServices->getColumn([['id', 'in', $supplierIds], ['is_del', '=', 0]], 'id,supplier_name,avatar', 'id');
  492. }
  493. if ($storeIds) {
  494. /** @var SystemStoreServices $storeServices */
  495. $storeServices = app()->make(SystemStoreServices::class);
  496. $storeList = $storeServices->getColumn([['id', 'in', $storeIds], ['is_del', '=', 0]], 'id,name,image', 'id');
  497. }
  498. $replyId = array_column($list, 'id');
  499. /** @var StoreProductReplyCommentServices $make */
  500. $make = app()->make(StoreProductReplyCommentServices::class);
  501. $replySum = $make->getReplyCommentCountList($replyId);
  502. foreach ($list as &$item) {
  503. $item['suk'] = $item['sku'];
  504. $item['nickname'] = anonymity($item['nickname']);
  505. $item['merchant_reply_time'] = date('Y-m-d H:i', $item['merchant_reply_time']);
  506. $item['add_time'] = date('Y-m-d H:i', $item['add_time']);
  507. $item['star'] = bcadd($item['product_score'], $item['service_score'], 2);
  508. $item['star'] = bcdiv($item['star'], 2, 0);
  509. $item['comment'] = $item['comment'] ?: '此用户没有填写评价';
  510. $item['pics'] = $item['pics'] ? (is_string($item['pics']) ? json_decode($item['pics'], true) : $item['pics']) : [];
  511. if (isset($item['replyComment']['user']['nickname'])) {
  512. $item['replyComment']['user']['nickname'] = anonymity($item['replyComment']['user']['nickname']);
  513. } else if (isset($item['replyComment']) && !$item['replyComment']['user'] && $item['replyComment']['uid'] === 0) {
  514. $user = [];
  515. switch ($item['replyComment']['type'] ?? 0) {
  516. case 0:
  517. $user = ['nickname' => $siteName, 'avatar' => $siteLogoSquare];
  518. break;
  519. case 1://门店
  520. $user = ['nickname' => $storeList[$item['relation_id']]['name'] ?? '', 'avatar' => $storeList[$item['relation_id']]['image'] ?? ''];
  521. break;
  522. case 2://供应商
  523. $user = ['nickname' => $supplierList[$item['relation_id']]['supplier_name'] ?? '', 'avatar' => $supplierList[$item['relation_id']]['avatar'] ?? ''];
  524. break;
  525. default:
  526. $user = ['nickname' => $siteName, 'avatar' => $siteLogoSquare];
  527. break;
  528. }
  529. $item['replyComment']['user'] = $user;
  530. }
  531. if ($uid) {
  532. $item['is_praise'] = !empty($item['productRelation']);
  533. } else {
  534. $item['is_praise'] = false;
  535. }
  536. if (isset($item['replyComment'])) {
  537. foreach ($replySum as $value) {
  538. if ($item['id'] === $value['reply_id']) {
  539. $item['replyComment']['sum'] = $value['sum'];
  540. }
  541. }
  542. }
  543. }
  544. }
  545. return $list;
  546. }
  547. /**
  548. * 检测获取评论商品ID(门店商品,处理为平台商品ID)
  549. * @param int $id
  550. * @return int
  551. */
  552. public function checkReplyProductId(int $id)
  553. {
  554. /** @var StoreBranchProductServices $productServices */
  555. $productServices = app()->make(StoreBranchProductServices::class);
  556. return $productServices->getStoreProductId($id);
  557. }
  558. }