// +---------------------------------------------------------------------- namespace app\common\repositories\user; use app\common\dao\user\UserAssetsDao; use app\common\repositories\BaseRepository; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; /** * @mixin UserAssetsDao */ class UserAssetsRepository extends BaseRepository { public function __construct(UserAssetsDao $dao) { $this->dao = $dao; } public function getList(array $where, $page, $limit) { $query = $this->dao->search($where); $count = $query->count(); $list = $query->page($page, $limit)->with(['spread' => function ($query) { $query->field('uid,nickname,avatar'); }])->select(); return compact('count', 'list'); } /** * notes 订单状态发生变更,影响用户资产 * @param $uid * @param $status * @param $data * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @create 2024/3/15 17:23 * @update 2024/3/15 17:23 * @author zhangkxiang * @editor */ public function orderEvent($uid, $status, $data = array()) { $assets = array(); $info = $this->dao->get($uid); if($info){ // 购买订单获得冻结资产 if($status == UserAssetsLogRepository::STATUS_FROZEN) { $assets = array( 'consume_frozen' => $info['consume_frozen'] + $data['consume'], 'welfare_frozen' => $info['welfare_frozen'] + $data['welfare'], 'huitong_frozen' => $info['huitong_frozen'] + $data['huitong'], 'contribution_frozen' => $info['contribution_frozen'] + $data['contribution'], ); }elseif ($status == UserAssetsLogRepository::STATUS_SUCCESS){ $assets = array( 'consume' => $info['consume'] + $data['consume'], 'welfare' => $info['welfare'] + $data['welfare'], 'huitong' => $info['huitong'] + $data['huitong'], 'contribution' => $info['contribution'] + $data['contribution'], 'consume_frozen' => $info['consume_frozen'] - $data['consume'], 'welfare_frozen' => $info['welfare_frozen'] - $data['welfare'], 'huitong_frozen' => $info['huitong_frozen'] - $data['huitong'], 'contribution_frozen' => $info['contribution_frozen'] - $data['contribution'], ); }elseif ($status == UserAssetsLogRepository::STATUS_REFUND){ $assets = array( 'consume_frozen' => $info['consume_frozen'] - $data['consume'], 'welfare_frozen' => $info['welfare_frozen'] - $data['welfare'], 'huitong_frozen' => $info['huitong_frozen'] - $data['huitong'], 'contribution_frozen' => $info['contribution_frozen'] - $data['contribution'], ); } $this->dao->update($uid, $assets); }else{ $assets = array( 'uid' => $uid, 'consume_frozen' => $data['consume'] ?? 0, 'welfare_frozen' => $data['welfare'] ?? 0, 'huitong_frozen' => $data['huitong'] ?? 0, 'contribution_frozen' => $data['contribution'] ?? 0, ); $this->dao->create($assets); } } }