| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\common\dao\shared;
- use app\common\dao\BaseDao;
- use app\common\enum\shared\SharedProsperityRewardRecordEnum;
- use app\common\model\BaseModel;
- use app\common\model\shared\SharedProsperityRewardRecord;
- use app\entity\data\shared\SharedProsperityRewardRecordEntity;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- class SharedProsperityRewardRecordDao extends BaseDao
- {
- /**
- * @return BaseModel
- */
- protected function getModel(): string
- {
- return SharedProsperityRewardRecord::class;
- }
- /**
- * @param array $idList
- * @return SharedProsperityRewardRecordEntity[]
- */
- public function getSharedProsperityRewardRecordEntityListByIdList(array $idList): array
- {
- $entityList = [];
- try {
- /** @var SharedProsperityRewardRecord $model */
- $model = $this->getModel();
- $dataRes = $model::getDB()
- ->whereIn('id', $idList)
- ->select()
- ->toArray();
- if (!empty($dataRes)) {
- $entityList = array_map(function ($data) {
- return SharedProsperityRewardRecordEntity::newInstance($data);
- }, $dataRes);
- }
- } catch (\Exception $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 [];
- }
- }
- /**
- * @param string $typeShop
- * @param array $orderSnList
- * @return SharedProsperityRewardRecordEntity[]
- */
- public function getSharedProsperityRewardRecordEntityListByOrderSnListAndPending(string $typeShop, array $orderSnList): array
- {
- $entityList = [];
- try {
- /** @var SharedProsperityRewardRecord $model */
- $model = $this->getModel();
- $dataList = $model::getDB()
- ->where('type_shop', '=', $typeShop)
- ->whereIn('order_sn', $orderSnList)
- ->where('status', '=', SharedProsperityRewardRecordEnum::STATUS['PENDING']['code'])
- ->select()
- ->toArray();
- if (!empty($dataList)) {
- $entityList = array_map(function ($data) {
- return SharedProsperityRewardRecordEntity::newInstance($data);
- }, $dataList);
- }
- } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
- }
- return $entityList;
- }
- }
|