StoreLiveProduct.php 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * Author: 向往那片天空
  5. * Date: 2020/6/11
  6. * Time: 10:32
  7. * 微信/QQ: 250023777
  8. * 格言: 抓住中心,宁精勿杂,宁专勿多
  9. */
  10. namespace app\api\controller\activity;
  11. use app\admin\model\store\StoreDescription;
  12. use app\admin\model\store\StoreProductAttrValue;
  13. use app\models\store\StoreActivity;
  14. use app\models\store\StoreOrder;
  15. use app\models\store\StoreProductAttr;
  16. use app\models\store\StoreProductRelation;
  17. use app\Request;
  18. use crmeb\services\QrcodeService;
  19. use crmeb\services\UtilService;
  20. use app\models\store\StoreActivityProduct as StoreActivityProductModel;
  21. use app\models\store\StoreLiveProduct as StoreLiveProductModel;
  22. /**
  23. * 直播商品控制器
  24. * Class StoreActivityProduct
  25. * @package app\api\controller\activity
  26. */
  27. class StoreLiveProduct
  28. {
  29. /**
  30. * 活动商品列表
  31. * @param Request $request
  32. * @return mixed
  33. */
  34. public function lst(Request $request)
  35. {
  36. list($title, $page, $limit) = UtilService::getMore([
  37. ['title', ''],
  38. ['page', 1],
  39. ['limit', 10],
  40. ], $request, true);
  41. $combinationList = StoreLiveProductModel::getAll($title, $page, $limit);
  42. if (!count($combinationList)) return app('json')->successful([]);
  43. return app('json')->successful($combinationList->hidden(['info', 'product_id', 'start_time', 'stop_time', 'effective_time', 'images', 'mer_id', 'attr', 'sort', 'stock', 'add_time', 'is_del', 'is_show', 'browse', 'cost', 'is_show', 'postage', 'is_postage', 'is_host', 'mer_use', 'combination'])->toArray());
  44. }
  45. /**
  46. * 活动商品详情
  47. * @param Request $request
  48. * @param $id
  49. * @return mixed
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public function detail(Request $request, $id)
  55. {
  56. if (!$id || !($combinationOne = StoreLiveProductModel::getLiveOne($id))) return app('json')->fail('活动商品不存在或已下架');
  57. // echo 'ok';die;
  58. $combinationOne = $combinationOne->hidden(['mer_id', 'attr', 'sort', 'start_time', 'stop_time', 'effective_time', 'add_time', 'is_host', 'is_show', 'is_del', 'mer_use', 'cost', 'combination'])->toArray();
  59. $combinationOne['images'] = json_decode($combinationOne['images'], true);
  60. $siteUrl = sys_config('site_url');
  61. $combinationOne['image'] = set_file_url($combinationOne['image'], $siteUrl);
  62. $combinationOne['image_base'] = set_file_url($combinationOne['image'], $siteUrl);
  63. $combinationOne['code_base'] = QrcodeService::getWechatQrcodePath($id . '_activity_detail_wap.jpg', '/activity/group_detail/' . $id);
  64. $combinationOne['sale_stock'] = 0;
  65. if ($combinationOne['stock'] > 0) $combinationOne['sale_stock'] = 1;
  66. if (!strlen(trim($combinationOne['unit_name']))) $combinationOne['unit_name'] = '个';
  67. $uid = $request->uid();
  68. $combinationOne['userCollect'] = StoreProductRelation::isProductRelation($combinationOne['id'], $uid, 'collect', 'activity');
  69. $combinationOne['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id, 5));
  70. $data['storeInfo'] = $combinationOne;
  71. // $data['reply'] = StoreProductReply::getRecProductReply($combinationOne['product_id']);
  72. // $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $combinationOne['product_id'])->count();
  73. // if ($data['replyCount']) {
  74. // $goodReply = StoreProductReply::productValidWhere()->where('product_id', $combinationOne['product_id'])->where('product_score', 5)->count();
  75. // $data['replyChance'] = $goodReply;
  76. // if ($goodReply) {
  77. // $data['replyChance'] = bcdiv($goodReply, $data['replyCount'], 2);
  78. // $data['replyChance'] = bcmul($data['replyChance'], 100, 3);
  79. // }
  80. // } else $data['replyChance'] = 0;
  81. list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, 0, 5);
  82. foreach ($productValue as $k => $v) {
  83. $productValue[$k]['product_stock'] = StoreProductAttrValue::where('product_id', $combinationOne['product_id'])->where('type', 5)->where('suk', $v['suk'])->value('stock');
  84. }
  85. $data['productAttr'] = $productAttr;
  86. $data['productValue'] = $productValue;
  87. return app('json')->successful($data);
  88. }
  89. }