StoreTryProduct.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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\models\user\User;
  18. use app\Request;
  19. use crmeb\services\QrcodeService;
  20. use crmeb\services\UtilService;
  21. use app\models\store\StoreTryProduct as StoreTryProductModel;
  22. use think\facade\Db;
  23. use app\models\store\StoreTryRecord as StoreTryRecordModel;
  24. /**
  25. * 试用商品控制器
  26. * Class StoreActivityProduct
  27. * @package app\api\controller\activity
  28. */
  29. class StoreTryProduct
  30. {
  31. /**
  32. * 试用商品列表
  33. * @param Request $request
  34. * @return mixed
  35. */
  36. public function lst(Request $request)
  37. {
  38. list($page, $limit) = UtilService::getMore([
  39. ['page', 1],
  40. ['limit', 10],
  41. ], $request, true);
  42. $combinationList = StoreTryProductModel::getAll($page, $limit);
  43. if (!count($combinationList)) return app('json')->successful([]);
  44. return app('json')->successful($combinationList->toArray());
  45. }
  46. /**
  47. * 试用商品详情
  48. * @param Request $request
  49. * @param $id
  50. * @return mixed
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public function detail(Request $request, $id)
  56. {
  57. if (!$id || !($combinationOne = StoreTryProductModel::getTryOne($id))) return app('json')->fail('试用商品不存在或已下架');
  58. // echo 'ok';die;
  59. $combinationOne = $combinationOne->toArray();
  60. $combinationOne['images'] = json_decode($combinationOne['slider_image'], true);
  61. $siteUrl = sys_config('site_url');
  62. $combinationOne['image'] = set_file_url($combinationOne['image'], $siteUrl);
  63. $combinationOne['image_base'] = set_file_url($combinationOne['image'], $siteUrl);
  64. $combinationOne['code_base'] = QrcodeService::getWechatQrcodePath($id . '_try_detail_wap.jpg', '/activity/group_detail/' . $id);
  65. $combinationOne['sale_stock'] = 0;
  66. if ($combinationOne['stock'] > 0) $combinationOne['sale_stock'] = 1;
  67. if (!strlen(trim($combinationOne['unit_name']))) $combinationOne['unit_name'] = '个';
  68. $uid = $request->uid();
  69. $combinationOne['userCollect'] = StoreProductRelation::isProductRelation($combinationOne['id'], $uid, 'collect', 'try');
  70. $combinationOne['description'] = htmlspecialchars_decode(StoreDescription::getDescription($combinationOne['product_id'], 0));
  71. $data['storeInfo'] = $combinationOne;
  72. // $data['reply'] = StoreProductReply::getRecProductReply($combinationOne['product_id']);
  73. // $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $combinationOne['product_id'])->count();
  74. // if ($data['replyCount']) {
  75. // $goodReply = StoreProductReply::productValidWhere()->where('product_id', $combinationOne['product_id'])->where('product_score', 5)->count();
  76. // $data['replyChance'] = $goodReply;
  77. // if ($goodReply) {
  78. // $data['replyChance'] = bcdiv($goodReply, $data['replyCount'], 2);
  79. // $data['replyChance'] = bcmul($data['replyChance'], 100, 3);
  80. // }
  81. // } else $data['replyChance'] = 0;
  82. list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($combinationOne['product_id'], $uid, 0, 0);
  83. foreach ($productValue as $k => $v) {
  84. $productValue[$k]['product_stock'] = StoreProductAttrValue::where('product_id', $combinationOne['product_id'])->where('type', 0)->where('suk', $v['suk'])->value('stock');
  85. }
  86. $data['productAttr'] = $productAttr;
  87. $data['productValue'] = $productValue;
  88. $data['people_count'] = Db::name('store_try_record')->where("tid={$id} and is_del=0")->count(); //试用申请的总人数
  89. $data['is_apply'] = StoreTryRecordModel::be(['tid' => $id, 'uid' => $request->uid(), 'is_del' => 0]) ? 1 : 0;
  90. if ($combinationOne['is_finish']) {
  91. // $uids = StoreTryRecordModel::where("tid={$id} and is_check=1")->column('uid');
  92. // $user = User::where('uid', 'in', $uids)->field('avatar,phone')->select()->each(function ($item) {
  93. // $item['phone'] = substr_replace($item['phone'], '****', 3, 4);
  94. // })->toArray();
  95. $users = StoreTryRecordModel::where("r.tid={$id} and r.is_check=1")->alias('r')->field('r.phone,u.avatar')->join('user u', 'u.uid=r.uid')->select()->toArray();
  96. foreach ($users as $k => &$v) {
  97. $v['phone'] = substr_replace($v['phone'], '****', 3, 4);
  98. }
  99. $data['win_people'] = $users;
  100. } else {
  101. $data['win_people'] = [];
  102. }
  103. return app('json')->successful($data);
  104. }
  105. }