| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\common\dao\user;
- use app\common\dao\BaseDao;
- use app\common\enum\user\UserPvLogEnum;
- use app\common\model\BaseModel;
- use app\common\model\user\UserPvLog;
- use app\entity\CommonEntity;
- use app\entity\data\user\UserPvLogEntity;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- class UserPvLogDao extends BaseDao
- {
- /**
- * @return BaseModel
- */
- protected function getModel(): string
- {
- return UserPvLog::class;
- }
- /**
- * @param array $idList
- * @return CommonEntity[]
- */
- public function getUserPvLogEntityListByIdList(array $idList): array
- {
- $entityList = [];
- try {
- /** @var UserPvLog $model */
- $model = $this->getModel();
- $dataRes = $model::getDB()
- ->whereIn('id', $idList)
- ->select()
- ->toArray();
- if (!empty($dataRes)) {
- $entityList = array_map(function ($data) {
- return UserPvLogEntity::newInstance($data);
- }, $dataRes);
- }
- } catch (\Exception $e) {
- }
- return $entityList;
- }
- /**
- * @param string $orderType
- * @param array $orderIdList
- * @return UserPvLogEntity[]
- */
- public function getUserPvLogEntityListByOrderIdListAndPending(string $orderType, array $orderIdList): array
- {
- $entityList = [];
- try {
- $dataList = UserPvLog::getDB()
- ->where('order_type', '=', $orderType)
- ->whereIn('order_id', $orderIdList)
- ->where('status', '=', UserPvLogEnum::STATUS['PendingConfirmation']['code'])
- ->select()
- ->toArray();
- if (!empty($dataList)) {
- $entityList = array_map(function ($data) {
- return UserPvLogEntity::newInstance($data);
- }, $dataList);
- }
- } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
- }
- return $entityList;
- }
- /**
- * 批量更新
- * @param $dataList
- * @return array
- */
- public function saveAll($dataList): array
- {
- try {
- return $this->getModel()::getInstance()->allowField(array_keys(reset($dataList)))->saveAll($dataList)->toArray();
- } catch (\Exception $e) {
- return [];
- }
- }
- /**
- * 根据order_id和status查找pv值
- */
- public function getPVFromStatusOrderId($orderId)
- {
- try {
- return $this::getModel()::getDB()->where('order_id', '=', $orderId)->where('status','=',1)->value('pv');
- } catch (\Exception $e) {
- return [];
- }
- }
- /**
- * 根据order_id获取pv值(用于备份用户变更记录)
- */
- public function getPvForBackupFromOrderId($orderId)
- {
- try {
- $value = $this::getModel()::getDB()
- ->where('order_id', '=', $orderId)
- ->where('status', '=', 1)
- ->value('pv');
- return $value ?: 0;
- } catch (\Exception $e) {
- return 0;
- }
- }
- }
|