pull/1/head
wanghousheng 1 year ago
parent 914b8dc14b
commit 246a091bb3
  1. 10
      app/api/controller/Goods.php
  2. 55
      app/api/model/Goods.php
  3. 14
      app/api/model/GoodsBrowseLog.php

@ -12,12 +12,11 @@ declare (strict_types=1);
namespace app\api\controller;
use app\common\enum\dealer\withdraw\PayType;
use think\response\Json;
use app\api\model\{Goods as GoodsModel};
use app\api\service\{User as UserService, Goods as GoodsService};
use app\api\service\{Goods as GoodsService, User as UserService};
use app\common\service\qrcode\Goods as GoodsPoster;
use cores\exception\BaseException;
use think\response\Json;
/**
* 商品控制器
@ -63,11 +62,10 @@ class Goods extends Controller
return $this->renderSuccess(['detail' => $goodsInfo]);
}
public function browseLog()
public function browseLog(): Json
{
$param = $this->request->param();
$model = new GoodsModel;
$goodsInfo = $model->browseLog($param);
$goodsInfo = $model->browseLogList();
return $this->renderSuccess($goodsInfo);
}

@ -12,26 +12,22 @@ declare (strict_types=1);
namespace app\api\model;
use app\api\model\GoodsBrowseLog;
use app\api\model\GoodsSku as GoodsSkuModel;
use app\api\model\GoodsSpecRel as GoodsSpecRelModel;
use app\api\model\store\Module as StoreModuleModel;
use app\api\service\Goods as GoodsService;
use app\api\service\User as UserService;
use app\api\service\user\Grade as UserGradeService;
use app\api\model\GoodsSku as GoodsSkuModel;
use app\api\model\store\Module as StoreModuleModel;
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel;
use app\api\model\GoodsSpecRel as GoodsSpecRelModel;
use app\common\enum\goods\Status as GoodsStatusEnum;
use app\common\model\Goods as GoodsModel;
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel;
use app\common\model\GoodsImage as GoodsImageModel;
use app\common\model\UploadFile as UploadFileModel;
use app\common\enum\goods\Status as GoodsStatusEnum;
use app\store\model\goods\GoodsPrice as GoodsPriceModel;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use app\store\model\goods\GoodsPrice as GoodsPriceModel;
use app\api\model\PreSale;
use app\api\model\PreSaleMessage;
use app\api\model\PreSaleLog;
/**
* 商品模型
@ -143,6 +139,43 @@ class Goods extends GoodsModel
return false;
}
/**
* @notes:浏览记录
* @return array
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function browseLogList(): array
{
$userId = UserService::getCurrentLoginUserId();
$model = new GoodsBrowseLog;
$end_time = date('Y-m-d');
$start_time = date('Y-m-d', strtotime($end_time . ' - 3 days'));
$list = $model->with(['sku', 'goods'])
->withoutField(['content'])
->where('ctime', '>=', $start_time)
->where('ctime', '<=', $end_time)
->where(['user_id' => $userId])
->select();
$data = [];
$array = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
if (!$list->isEmpty()) {
foreach ($list as $value) {
$data[$value['ctime']]['name'] = date('m-d', strtotime($value['ctime']));
$data[$value['ctime']]['week'] = $array[date("w", strtotime($value['ctime']))];
$data[$value['ctime']]['list'][] = [
'goods' => $value['goods'],
'sku_list' => $value['sku'],
'log_id' => $value['id'],
];
}
}
return array_values($data);
}
public function browseLog()
{
$userId = UserService::getCurrentLoginUserId(true);
@ -223,7 +256,7 @@ class Goods extends GoodsModel
'store_id' => request()->header()['storeid'],
'goods_id' => $v['goods_id'],
])->field('image_id')->find()->image_id;
$file_path = UploadFileModel::where([
'store_id' => request()->header()['storeid'],
'file_id' => $file_id,

@ -13,6 +13,8 @@ declare (strict_types=1);
namespace app\api\model;
use app\common\model\GoodsSpecRel as GoodsSpecRelModel;
use think\model\relation\HasMany;
use think\model\relation\HasOne;
/**
* 商品规格关系模型
@ -28,4 +30,16 @@ class GoodsBrowseLog extends GoodsSpecRelModel
protected $pk = 'id';
protected $updateTime = false;
public function sku(): HasMany
{
return $this->hasMany(GoodsSku::class, 'goods_id', 'goods_id');
}
public function goods(): HasOne
{
return $this->hasOne(Goods::class, 'goods_id', 'goods_id')
->withoutField(['content']);
}
}

Loading…
Cancel
Save