123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- namespace app\index\controller;
- use app\common\library\express\Usps;
- use app\console\model\Order as OrderModel;
- use app\console\service\OrderGetYundan as OrderGetYundanService;
- use app\index\model\Article as ArticleModel;
- use app\index\model\Comment as CommentModel;
- use app\index\model\Goods as GoodsModel;
- use think\facade\Cache;
- use think\facade\Log;
- use think\facade\Session;
- use think\response\View;
- /**
- * 默认控制器
- * Class Index
- * @package app\api\controller
- */
- class Index extends Controller
- {
- public function index()
- {
- Log::notice($this->request->ip());
- //banner位
- $newArrivalCache = Cache::get('index_newArrival');
- $bestsellerCache = Cache::get('index_bestseller');
- $superDealsCache = Cache::get('index_superDeals');
- $articleCache = Cache::get('index_article');
- if ($newArrivalCache && $bestsellerCache && $superDealsCache && $articleCache) {
- $newArrival = json_decode($newArrivalCache, true);
- $bestseller = json_decode($bestsellerCache, true);
- $superDeals = json_decode($superDealsCache, true);
- $article = json_decode($articleCache, true);
- } else {
- //商品区。new,video,bestseller
- $model = new GoodsModel;
- $newArrival = $model->getList(['listType' => 'on_sale'], 4)->toArray()['data'];
- $bestseller = $model->getList(['sortType' => 'sales'], 4)->toArray()['data'];
- //$superDeals = $model->getList(['categoryId' => '10002',], 8)->toArray()['data'];
- $superDeals = $bestseller;
- $newGoodsId = array_column($newArrival, 'goods_id');
- $bestGoodsId = array_column($bestseller, 'goods_id');
- $superDealsGoodsId = array_column($superDeals, 'goods_id');
- //获取评价数量
- $goodsIds = array_unique(array_merge($newGoodsId, $bestGoodsId, $superDealsGoodsId));
- $commentModel = new CommentModel();
- $rows = $commentModel->rowsTotalBatch($goodsIds)->toArray();
- $rowsByGoodsId = array_column($rows, 'cnt', 'goods_id');
- //获取评论分数
- $commentScores = $commentModel->getTotalAll($goodsIds)->toArray();
- $scoresByGoodsId = array_column($commentScores, 'score_total', 'goods_id');
- //dd($rowsByGoodsId);
- //可考虑缓存
- foreach ($newArrival as &$item) {
- $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
- $temp = bcmul($item['comment_cnt'], 10, 0);
- if ($temp) {
- $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
- } else {
- $item['avg_score'] = 5;
- }
- }
- Cache::set('index_newArrival', json_encode($newArrival), 1200);
- foreach ($bestseller as &$item) {
- $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
- $temp = bcmul($item['comment_cnt'], 10, 0);
- if ($temp) {
- $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
- } else {
- $item['avg_score'] = 5;
- }
- }
- Cache::set('index_bestseller', json_encode($bestseller), 1200);
- foreach ($superDeals as &$item) {
- $item['comment_cnt'] = $rowsByGoodsId[$item['goods_id']] ?? 0;
- $temp = bcmul($item['comment_cnt'], 10, 0);
- if ($temp) {
- $item['avg_score'] = bcdiv($scoresByGoodsId[$item['goods_id']] ?? '0', $temp, 0);
- } else {
- $item['avg_score'] = 5;
- }
- }
- Cache::set('index_superDeals', json_encode($superDeals), 1200);
- $model = new ArticleModel;
- $article = $model->getList(0, 5)->toArray()['data'];
- foreach ($article as &$datum) {
- $datum['year'] = substr($datum['create_time'], 0, 4);
- $datum['month_day'] = substr($datum['create_time'], 5, 5);
- $datum['date'] = substr($datum['create_time'], 0, 10);
- }
- Cache::set('index_article', json_encode($article), 1200);
- }
- $superDeals1 = $superDeals2 = [];
- isset($superDeals[0]) && $superDeals1[] = $superDeals[0];
- isset($superDeals[1]) && $superDeals1[] = $superDeals[1];
- isset($superDeals[2]) && $superDeals1[] = $superDeals[2];
- isset($superDeals[3]) && $superDeals1[] = $superDeals[3];
- isset($superDeals[4]) && $superDeals2[] = $superDeals[4];
- isset($superDeals[5]) && $superDeals2[] = $superDeals[5];
- isset($superDeals[6]) && $superDeals2[] = $superDeals[6];
- isset($superDeals[7]) && $superDeals2[] = $superDeals[7];
- return view('/index/index', [
- 'newGoods' => $newArrival,
- 'bestseller' => $bestseller,
- 'superDealsOne' => $superDeals1,
- 'superDealsTwo' => $superDeals2,
- 'article' => $article,
- ]);
- }
- /**
- * 产品详情页
- * @return \think\response\Redirect|View
- * @throws \cores\exception\BaseException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function productDetails($goodsId)
- {
- //$goodsId = $this->request->param('goodsId', 0);
- if (empty($goodsId)) {
- return \redirect('index');
- }
- $key = $this->request->param('key', '');
- $goodsModel = new GoodsModel();
- $goods = $goodsModel->getDetails($goodsId)->toArray();
- $goods['content'] = html_entity_decode($goods['content']);
- $model = new CommentModel;
- $total = $model->rowsTotal($goodsId);
- $flavors = ['STRAWBERRY-MANGO', 'BLUE RAZZ-ICE', 'WATERMELON', 'GRAPE', 'KIWI-PASSION-FRUIT-GUAVA', 'JUICY-PEACH', 'BLUEBERRY-ICE'];
- return view('productDetails', ['goods' => $goods, 'comment_total' => $total, 'key' => $key]);
- }
- public function aboutUs(): View
- {
- return view('index/aboutUs');
- }
- public function privacyPolicy(): View
- {
- return view('privacyPolicy');
- }
- public function salesTerms(): View
- {
- return view('salesTerms');
- }
- public function vapePoints(): View
- {
- return view('vapePoints');
- }
- public function returnWarranty(): View
- {
- return view('returnWarranty');
- }
- public function newsDetail($newsId): View
- {
- //$newsId = $this->request->param('newsId');
- if (empty($newsId)) {
- return view('/error');
- }
- $model = new ArticleModel;
- $article = $model->find($newsId)->toArray();
- return view('newsDetails', ['article' => $article]);
- }
- public function goldTest($name)
- {
- $ip = $this->request->ip();
- //$b = bcmod(1, 0);
- Log::debug($ip);
- Log::info('888');
- Log::error('xxx');
- Log::notice($ip);
- return $this->renderSuccess([],'OK');
- dd($ip);
- $conf = config('paypal');
- dd($conf['sandbox'], $conf['live']);
- dd('this is ' . $name);
- $service = new OrderGetYundanService();
- $r = $service->orderCreateYundans($this->storeId);
- dd($r);
- $orderModel = new OrderModel();
- $r = $orderModel->getUsableList(10001);
- dd($r->toArray());
- $Usps = new Usps();
- // 请求查询接口
- $res = $Usps->getItdidaToken();
- dd($res);
- }
- }
|